Previous Blog Next Blog
Prev/Next Blog
by date

customMaterial function, with specular and normal map

customMaterial function, with specular and normal map
Name:Itla Itla 
Date Posted:Aug 08, 2008
Rating:4.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Itla Itla

Blog post
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;
};

Submit ResourceSubmit your own resources!

Erik Madison   (Aug 08, 2008 at 17:06 GMT)
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);
}

Ben Acord   (Aug 11, 2008 at 01:14 GMT)   Resource Rating: 5
Sounds like a nice addition for TDN's TGEA for Coders "How To". Hint. Hint.

You must be a member and be logged in to either append comments or rate this resource.