Game Development Community

customMaterial function, with specular and normal map

by Itla Itla · 08/08/2008 (8:51 am) · 2 comments

This is the function of a custom material, if you have many textures you use this function:

function custMate( %name)
{
%mate = "new customMaterial("@%name@") {"@
"mapTo = \"" @ %name @ ".jpg\";" @
"texture[0] = \"" @ %name @ "\";" @
"texture[1] = \"" @ %name @ "_NRM\";" @
"texture[2] = \"" @ %name @ "_SPEC\";" @
"version = 2.0;"@
"shader = SpecMap;"@
"};";
eval(%mate);
}

this is with a shader that i found here, anyway, you only have to include the function in any .cs, and in the properly materials.cs, you say

custMate("examplename");

aaah, in mapTo, the .jpg is because i use maya, and it has to use in that way, also, _NRM is the normal map, i mean,

custMate("examplename");

its like

new customMaterial(examplename)
{
mapTo = "examplename.jpg";
texture[0] = "examplename"; //the diffuse file is examplename.jpg
texture[1] = "examplename_NRM"; //the normal map is examplename_NRM.jpg
texture[2] = "examplename_SPEC"; //the specular map is examplename_SPEC.jpg
version = 2.0;
shader = SpecMap;
};

About the author

Recent Blogs


#1
08/08/2008 (10:06 am)
Looks good. Here's an alternative I use; you may not have a normal for every texture, so we check for one first. I hadn't added an auto shader, but thats a good idea. I think I will adjust these soon :)
function createMaterial( %name )
{
%com = "new Material(MAT_"@%name@"){"@
"baseTex[0]= " @%name@ ";";
if (isFile(%name@ "_nrm"))
%com = %com @ "bumpTex[0]= " @%name@ "_nrm;";
%com = %com @ "mapTo =" @ %name @";" @
"};";
eval(%com);
}

function createShinyMaterial( %name )
{
%com = "new Material(MAT_"@%name@"){"@
"baseTex[0]= " @%name@ ";";
if (isFile(%name@ "_nrm"))
%com = %com @ "bumpTex[0]= " @%name@ "_nrm;";
%com = %com @ "pixelSpecular[0] = true;"@
"specular[0] =\"0.6 0.6 0.6 0.6\";" @
"specularPower[0]= 32.0;"@
"mapTo =" @ %name @";" @
"};";
eval(%com);
}

function createTransMaterial(%name)
{
%com = "new Material(MAT_"@%name@"){"@
"baseTex[0]= " @%name@ ";"@
"specular =\"0.60.6 0.6 0.6\";" @
"specularPower= 16.0;"@
"Translucent =true;" @
"translucentBlendOp = LerpAlpha;" @
"emmisive[0] =true;" @
"translucentZWrite =true;" @
"alphaRef =128;"@
"mapTo =" @ %name @";" @
"};";
eval(%com);
}
#2
08/10/2008 (6:14 pm)
Sounds like a nice addition for TDN's TGEA for Coders "How To". Hint. Hint.