### Do TerrainMaterials need a Material for their diffuseMap?

Materials, textures, lighting, postfx

#### Do TerrainMaterials need a Material for their diffuseMap?

Mud-H
Posts: 183
Joined: Thu Feb 19, 2015 3:08 pm
I'm trying to get a rid of the missing material warning for TerrainMaterial:

Code: Select all

 [MaterialList::mapMaterials] Unable to find material for texture: [matName]
After comparing with fullTemplate, I realized that all TerrainMaterial have a Material defined for the diffuseMap, what is it needed for? Just to get rid off the warning?

I remember a while back I was making a Material for each of my TerrainMaterial but I lost this habit and I don't see a difference. I just want to know if I'm missing something, is there a use for the extra Material or it's just in case you need the TerrainMaterial as standard material?
If it's not needed, anyone have a solution to get rid of the warning?

#### Re: Do TerrainMaterials need a Material for their diffuseMap?

Duion
Posts: 969
Joined: Sun Feb 08, 2015 1:51 am

Terrain materials don't need a standard material, but there is a case where they do, there are Terrain_FX materials that define some settings like footstep sound, decals, particle effects etc.
So you need a "new TerrainMaterial()" and a "singleton Material(TerrainFX_)
No idea why, but it works that way.

#### Re: Do TerrainMaterials need a Material for their diffuseMap?

Mud-H
Posts: 183
Joined: Thu Feb 19, 2015 3:08 pm
Well since I'm lasy and don't like having to write extra Material, I made a TerrainMaterial fix function that check all TerrainMaterial in art/terrains folder. It create a new material file with a pre_ prefix containing all diffuseMap with missing Materials.

Here's the initial version in case someone want to use it, it's a quick scripting job but it do the job and save time writing material. Also you can use the %reset to regenerate all the materials. The %loadNew var is for loading the new Material file instantly once created . For future updates, it will be included in my helpers collection.

Code: Select all

function fixTerrainMaterialsStock(%loadNew,%reset) { %searchFolder = "art/terrains/*materials.cs"; //Now go through each files again to add a brush with latest items for(%matFile = findFirstFile(%searchFolder); %matFile !\$= ""; %matFile = findNextFile(%searchFolder)) { %fileObj = new FileObject(); // Open a text file, if it exists %fileObj.OpenForRead(%matFile); %folder = filePath(%matFile); %fileBase = fileBase(%matFile); %newMatFile = %folder@"/pre_"@%fileBase@".cs"; %fileWrite = ""; while( !%fileObj.isEOF() ) { %line = %fileObj.readLine(); if (strFind(%line,"TerrainMaterial")) { %inTerrainMaterial = true; } else if(%inTerrainMaterial && strFind(%line,"diffuseMap")) { %lineFields = strreplace(%line,"\"","\t"); %difMap = getField(%lineFields,getFieldCount(%lineFields)-2); %difMapName = fileBase(%difMap); %matObj = "Mat_"@%difMapName; %matObj = strReplaceList(%matObj,"-" TAB "_" NL " " TAB "_"); if (isObject(%matObj) && %reset) delObj(%matObj); if (!isObject(%matObj)) { if (!isObject(%fileWrite)) { %fileWrite = new FileObject(); %fileWrite.OpenForWrite(%newMatFile); %fileWrite.writeLine("//=============================================================================="); %fileWrite.writeLine("//Auto generated material for TerrainMaterial in:"@%fileBase@""); %fileWrite.writeLine("//------------------------------------------------------------------------------"); %fileWrite.writeLine("//=============================================================================="); %fileWrite.writeLine("info(\"Loading generated materials for:"@%fileBase@"\");"); } %fileWrite.writeLine("//=============================================================================="); %fileWrite.writeLine("singleton Material("@%matObj@")"); %fileWrite.writeLine("{"); %fileWrite.writeLine(" mapTo = \""@%difMapName@"\";"); %fileWrite.writeLine(" footstepSoundId = 0;"); %fileWrite.writeLine(" terrainMaterials = \"1\";"); %fileWrite.writeLine(" ShowDust = \"1\";"); %fileWrite.writeLine(" showFootprints = \"1\";"); %fileWrite.writeLine(" materialTag0 = \"Terrain\";"); %fileWrite.writeLine(" impactSoundId = 0;"); %fileWrite.writeLine("};"); %fileWrite.writeLine("//------------------------------------------------------------------------------"); } } else if (strFind(%line,"};")) { %inTerrainMaterial = false; } } if (isObject(%fileWrite)) { %fileWrite.close(); %fileWrite.delete(); if (%loadNew) exec(%newMatFile); } %fileObj.close(); %fileObj.delete(); } }
You could then simply paster the new material file before your terrain materials or to keep the pre_ material file, I have add a check for that file in the loadMaterials function, if the pre_ file is found, it will execute it before executing the standard material file.

Code: Select all

%folder = filePath(%file); %fileBase = fileBase(%file); %preMatFile = %folder@"/pre_"@%fileBase@".cs"; if (isFile(%preMatFile)) exec(%preMatFile); 

#### Re: Do TerrainMaterials need a Material for their diffuseMap?

Duion
Posts: 969
Joined: Sun Feb 08, 2015 1:51 am

I don't understand what you are doing there, I just create materials by copy and paste by hand and then change the values I need.

#### Re: Do TerrainMaterials need a Material for their diffuseMap?

Mud-H
Posts: 183
Joined: Thu Feb 19, 2015 3:08 pm
Yeah, I know but like I said I'm lazy. These days I'm experimenting a lot with terrains and I often change or create materials. With that functions, I can make sure the linked Materials are up-to-date.
It's quite useless for basic use of already develloped materials but it will help me a bit... And I would expand it someday...

#### Who is online

Users browsing this forum: No registered users and 3 guests