Material Questions
by Ronald J Nelson · in Torque Game Engine Advanced · 01/08/2008 (3:04 pm) · 5 replies
I have a few questions about custom materials and regular materials. I am using this custommaterial from the TDN resource titled "Working Example of a Colorpicker" as an example to illustrate what I am asking.
1. I have been told the texture[0] has a maximum of 8 meaning texture[0] - texture[7] , is that true?
2. Is there a specific use for each of these texutres? Meaning is [0] always for the base texture and [1] always for the bump map?
3. If so where can I find what each has to be?
4. I have seen "$lightmap"; used in a couple of things, what is it and why is it a global variable?
5. Is there anyway to force one of these textures on or off?
6. If one of these textures has transparency, how would that be specified? I already know how in a regular material, just not a custom material.
7. Is mapto even used in a custom shader? TDN says its not necessary, but that doesn't mean it cannot be used.
8. Is baseTex[0] ever used in a custom material?
9. In a regular material, in baseTex[0] the [0] portion what is it for?
Please don't tell me to look at TDN for the answers. I have read them over and over and these are questions it does not answer.
1. I have been told the texture[0] has a maximum of 8 meaning texture[0] - texture[7] , is that true?
2. Is there a specific use for each of these texutres? Meaning is [0] always for the base texture and [1] always for the bump map?
3. If so where can I find what each has to be?
4. I have seen "$lightmap"; used in a couple of things, what is it and why is it a global variable?
5. Is there anyway to force one of these textures on or off?
6. If one of these textures has transparency, how would that be specified? I already know how in a regular material, just not a custom material.
7. Is mapto even used in a custom shader? TDN says its not necessary, but that doesn't mean it cannot be used.
8. Is baseTex[0] ever used in a custom material?
9. In a regular material, in baseTex[0] the [0] portion what is it for?
new CustomMaterial( buggy_body001a )
{
texture[0] = "./microt";
texture[1] = "./microtb";
texture[2] = "$lightmap";
shader = ColorPickerShader;
version = 1.1;
OverrideColor = true;
/mapto = "microt";
};Please don't tell me to look at TDN for the answers. I have read them over and over and these are questions it does not answer.
#2
Yes. Note that you can't actually use all 8 textures on all hardware though.
No. How the texture will be used depends on the shader. If you take a look at one of the HLSL pixel shaders used by TGEA, you should see a line like this
Do/Don't read from it in the shader.
You deal with it in your shader. You don't have to specify anything extra in the CustomMaterial.
You must use either mapTo or baseTex[0]. If you don't specify mapTo the material will use baseTex[0]. The same thing should hold true for non-custom Materials as well.
Not sure, look at the various setStageData methods and see if it is (I don't have the TGEA source in front of me).
Hope that helps.
01/08/2008 (4:29 pm)
Quote:I have been told the texture[0] has a maximum of 8 meaning texture[0] - texture[7] , is that true?
Yes. Note that you can't actually use all 8 textures on all hardware though.
Quote:Is there a specific use for each of these texutres? Meaning is [0] always for the base texture and [1] always for the bump map?
No. How the texture will be used depends on the shader. If you take a look at one of the HLSL pixel shaders used by TGEA, you should see a line like this
uniform sampler2D bumpMap : register(S1),this simply states that when the bumpMap sampler is read from in the shader (i.e. tex2D(bumpMap, texCoord)) it will read from the texture bound to sampler #1, which corresponds to texture[1] in your CustomMaterial.
Quote:I have seen "$lightmap"; used in a couple of things, what is it and why is it a global variable?It isn't actually a global variable. It's a special setting checked for during material loading. It just indicates that you would like the lightmap on whatever texture unit you've assigned "$lightmap" to. Off the top of my head, some other special settings are "$dynamiclight" for the dynamic lightmap, "$dynamiclightmask" for the dynamic light mask, "$normmap" for the lightmap normalmap, "$fog" for the fog texture, "$cubemap" for the cubemap specified in the CustomMaterial, "$dynamicCubemap" for a dynamically generated cubemap reflection, and "$backbuff" for the backbuffer. This isn't quite a complete list, take a look at CustomMaterial::setStageData() (I think).
Quote:Is there anyway to force one of these textures on or off?
Do/Don't read from it in the shader.
Quote:If one of these textures has transparency, how would that be specified? I already know how in a regular material, just not a custom material.
You deal with it in your shader. You don't have to specify anything extra in the CustomMaterial.
Quote:Is mapto even used in a custom shader? TDN says its not necessary, but that doesn't mean it cannot be used.
You must use either mapTo or baseTex[0]. If you don't specify mapTo the material will use baseTex[0]. The same thing should hold true for non-custom Materials as well.
Quote:Is baseTex[0] ever used in a custom material?
Not sure, look at the various setStageData methods and see if it is (I don't have the TGEA source in front of me).
Quote:In a regular material, in baseTex[0] the [0] portion what is it for?A regular material can have up to 4 "stages". Think of stages like passes, except ShaderGen may break up each stage into additional passes. The [0] specifies that this is the baseTex for stage 0, baseTex[1] would be the base texture for stage 1.
Hope that helps.
#3
Updated it with a bit more elaboration, as well as a simple masking setup. also got rid of the $lightmap bit, since that was left unused. apologies for the confusion there Ron.
re:5- the updated masking bit checks a value with an ifswitch and if that case is found, blends it. you can just as easily set it *to* a number/different texture instead
re:6- transparency is a big word for the 4th bit in the rgba pixel values. *can* mean don't draw at all, or could mean something else entirely.
re:8- basetex[0] is never really used in a custom material that i've been able to determine (see custommaterial.cpp/material.cpp for definitions
re:9- in a regular material basetex[0] refers to wich pass youre doing. so if youre alphablending two textures, ou'd be looking at something using basetex[0] = baselinetexture; basetex[1] = overlaytexture;
01/08/2008 (4:32 pm)
Re: 2&3-Updated it with a bit more elaboration, as well as a simple masking setup. also got rid of the $lightmap bit, since that was left unused. apologies for the confusion there Ron.
re:5- the updated masking bit checks a value with an ifswitch and if that case is found, blends it. you can just as easily set it *to* a number/different texture instead
re:6- transparency is a big word for the 4th bit in the rgba pixel values. *can* mean don't draw at all, or could mean something else entirely.
re:8- basetex[0] is never really used in a custom material that i've been able to determine (see custommaterial.cpp/material.cpp for definitions
re:9- in a regular material basetex[0] refers to wich pass youre doing. so if youre alphablending two textures, ou'd be looking at something using basetex[0] = baselinetexture; basetex[1] = overlaytexture;
#4
01/08/2008 (4:37 pm)
Thanks a ton for the information guys. I just a learned a ton thanks to you.
#5
Samplers are transparent handlers of textures. They are used for texture access and are declared as functional parameters or uniform (using int).
They do not join in as operands and can not be associated with other ones.
Samplers in fact represent texture units, not the texture object itself. These units consist of image, interpolator, preprocessor generator and matrix. Image count > unit count in most cases.
Example:
register(Sn), n=0+
uniform sampler2D map : register(Sn)
'n' represent the Tn register, pointer stored in Sn register
Samplers are: sampler, sampler1D, sampler2D, sampler3D, samplerCUBE
Samplers are valid in SM2.0 (and above) because of missing sampler registers in previous shader models.
The sample unit coresponds with exact level (stage), assigned with IDirect3DDevice9::SetSamplerState.
Each sampler unifies a texture, set with it using IDirect3DDevice9::SetTexture.
A texture can possess more than one sampler, but they're independent.
In fact why we use samplers ?
Because textures can not transform itself in Render Targets (RT) or transform as textures in a level.
01/09/2008 (7:59 am)
About the texel render:Samplers are transparent handlers of textures. They are used for texture access and are declared as functional parameters or uniform (using int).
They do not join in as operands and can not be associated with other ones.
Samplers in fact represent texture units, not the texture object itself. These units consist of image, interpolator, preprocessor generator and matrix. Image count > unit count in most cases.
Example:
register(Sn), n=0+
uniform sampler2D map : register(Sn)
'n' represent the Tn register, pointer stored in Sn register
Samplers are: sampler, sampler1D, sampler2D, sampler3D, samplerCUBE
Samplers are valid in SM2.0 (and above) because of missing sampler registers in previous shader models.
The sample unit coresponds with exact level (stage), assigned with IDirect3DDevice9::SetSamplerState.
Each sampler unifies a texture, set with it using IDirect3DDevice9::SetTexture.
A texture can possess more than one sampler, but they're independent.
In fact why we use samplers ?
Because textures can not transform itself in Render Targets (RT) or transform as textures in a level.
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
$lightmap as a few others are special textures. they instruct the engine to feed the shader there with a special engine from within the engine, not one that is directly stored for the model. They span over multiple objects or are highly dynamic like the cubemap and reflection.
In everythign else beside texture, the [x] defines to which renderpass that is related to. this holds for everything, bumptex, basetex, specular settings etc etc.