Tinting textures
by Eric Fleming · in Torque Game Engine Advanced · 11/07/2006 (12:26 pm) · 3 replies
I have a game where there are dozens of possible textures that can be applied via skinning to a single simple DTS object. I would like the ability to change each individual texture further by tinting them red, blue, etc.
It is not acceptable to create multiple versions of each texture, because if we decide to have in the future ten shadings, that could quickly result in way too many textures.
Ideally, I would like to blend an alphaed red texture with the underlying texture to result in a new version of the texture with red tinting. (Or whatever color).
I've tried all sorts of ways to do this to no avail. There is a diffuse[] setting that gets saved in the engine if you set diffuse[1] = '1 1 1 1' or whatever. But as far as I can tell, it is not used. Next, I tried creating a material something like this:
new Material(texture_to_change)
{
baseTex[0] = "tex1.jpg";
baseTex[1] = "overlay.jpg";
translucent[1] = true;
translucentBlendOp[1] = Add;
};
No matter what I set the blend op to, I always get the second jpg appearing only. No blending. The overlay has a built in alpha channel, but it still does not work. If I do this:
translucent[0] = true;
translucentBlendOp = Add;
The textures come out all blasted looking (bright white). The Mul blend Op does create the tinted texture, but makes it transparent, which I also don't want. That's as close as I've been able to get.
Am I going to have to write my own shader to handle this? Or is there a combo of elements in a material that will allow this with a procedural shader?
PS - none of the blending ops do anything if you actually use setSkinName(), but that's another problem...
It is not acceptable to create multiple versions of each texture, because if we decide to have in the future ten shadings, that could quickly result in way too many textures.
Ideally, I would like to blend an alphaed red texture with the underlying texture to result in a new version of the texture with red tinting. (Or whatever color).
I've tried all sorts of ways to do this to no avail. There is a diffuse[] setting that gets saved in the engine if you set diffuse[1] = '1 1 1 1' or whatever. But as far as I can tell, it is not used. Next, I tried creating a material something like this:
new Material(texture_to_change)
{
baseTex[0] = "tex1.jpg";
baseTex[1] = "overlay.jpg";
translucent[1] = true;
translucentBlendOp[1] = Add;
};
No matter what I set the blend op to, I always get the second jpg appearing only. No blending. The overlay has a built in alpha channel, but it still does not work. If I do this:
translucent[0] = true;
translucentBlendOp = Add;
The textures come out all blasted looking (bright white). The Mul blend Op does create the tinted texture, but makes it transparent, which I also don't want. That's as close as I've been able to get.
Am I going to have to write my own shader to handle this? Or is there a combo of elements in a material that will allow this with a procedural shader?
PS - none of the blending ops do anything if you actually use setSkinName(), but that's another problem...
#2
Thanks for your answer. I understand how to get the color to tint if I write my own shader, I was just curious if anyone knew how to do this through the provided blending options in materials using the engine generated shaders?
If I do write my own shader (I haven't tried that yet with Torque), how do I set the diffuse color from outside the shader to apply different colors? In other words, how do you set constants used in shaders (like the diffuse tinting color) from script?
11/07/2006 (2:30 pm)
Hi Stefan,Thanks for your answer. I understand how to get the color to tint if I write my own shader, I was just curious if anyone knew how to do this through the provided blending options in materials using the engine generated shaders?
If I do write my own shader (I haven't tried that yet with Torque), how do I set the diffuse color from outside the shader to apply different colors? In other words, how do you set constants used in shaders (like the diffuse tinting color) from script?
#3
example/shaders/procedural
If you take a look in there you will see that there are many shader files, covering all different implementations of different effects. On the other hand, I have seen shader generating code in the engine so you might be correct.
To set a parameter you do GFX->setVertexShaderConstF ();.
11/07/2006 (2:43 pm)
AFAIK, the engine generated shaders are still normal shaders called from C++. example/shaders/procedural
If you take a look in there you will see that there are many shader files, covering all different implementations of different effects. On the other hand, I have seen shader generating code in the engine so you might be correct.
To set a parameter you do GFX->setVertexShaderConstF ();.
Torque Owner Stefan Lundmark