Game Development Community

Render monkey multiple passes and TSE

by Dave · in Torque Game Engine Advanced · 01/16/2006 (1:56 am) · 9 replies

Hi folks,

I've used the fur generator to create a furry cube in Render Monkey. I copied the pix and vert shaders to TSE and with a bit of twiddling (mostly renaming the main section and "including the include") got them to compile in TSE. I added a specular effect to the .cs file just for fun. What happened was that I got the specular effect, so I knew my mapping/scripting was working correctly. However the fur effects didn't happen.

Going back to RM, I noticed that in fact there were three pairs of pix and vert shaders created, a pair for each pass. Is there a way to run three pairs of shaders on a material in TSE? I have used the "shader = " command for the first pair, but how do I specify the other two shaders to follow on from the first? Is it possible?

Secondary question if you have the patience - the fur generator outputs targa files for the textures. Is there a way to make it output jpg? Does it matter to TSE? I know TSE only supports JPG at the moment, but I know very little about shaders at this point. Will the shaders use the tga files themselves, therefore it's irrelevant, or will TSE try to use the tga files and barf all over the place?

Thanks a mill,

Dave.

#1
01/16/2006 (3:45 am)
Although it doesn't really answer your question, there is a resource to get Targa files working in TGE here: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3598. I got it working in TSE with some minor changes.
#2
01/16/2006 (3:53 am)
Thanks JC, handy patch. Will look at that when I have question 1 sorted out.
#3
01/16/2006 (12:52 pm)
Hey Dave, yes you can set up multiple passes with a different shader in each pass. Create a CustomMaterial for each pass, and then in the first pass, list the other CustomMaterials using the "pass" parameter.

Ie:

new CustomMaterial(Three)
{
   mapTo = someTexture;
   version = 2.0;
   shader = ThreeShader;
   texture[0] = "three";
};

new CustomMaterial(Two)
{
   mapTo = someTexture;
   version = 2.0;
   shader = TwoShader;
   texture[0] = "two";
};


new CustomMaterial(One)
{
   mapTo = one;
   version = 2.0;
   shader = Waves;
   texture[0] = "one";
   specular[0] = "1.0 1.0 1.0 1.0";
   specularPower[0] = 16;
   pass[0] = Two;
   pass[1] = Three;
};

Note that the first two passes must be declared first.

You can control the blending of each pass by using the "blendOp" parameter.
#4
01/17/2006 (2:28 am)
Woo hooo! Thanks Brian. Time for more fun/headaches/cursing :-)

Just out of interest, I did search thoroughly in the forums and on TDN but didn't find this. Is it up anywhere? If not I'll put it on TDN.

Damn, forgot to ask - If each pass uses multiple textures, is there a way of specifying this? For example the fur effect uses an offset tex, a density tex and a fur tex for each pass.

Many Thanks,

Dave.
#5
01/17/2006 (10:32 am)
Brian,

I've spent 9 hours at this and have had all sorts of weird things going on. I think I've just discovered that I should be using "new Material" instead of "new CustomMaterial" and "baseTex" instead of "texture".

Is that correct?

Also, I'm not sure how to apply textures over the top of one another. The code I have working (sort of) is as follows

new Material(furtwo)
{
mapTo = misc018;

basetex[0] = "game1/data/shapes/DTSshapes/misc019";
shader = dgfur2;
version = 2.0;

};
new Material(furone)
{
mapTo = misc018;

basetex[0] = "game1/data/shapes/DTSshapes/misc017";
shader = dgfur1;
version = 2.0;
pass[0] = furtwo;

};

So my cube has misc018 as a texture. The furone material works away and it puts the misc017 texture on the cube OK, and will animate fine if I put the appropriate commands in. However the furtwo material seems to have no effect. You see I have it mapped to the original texture just to see if it will override the first material, but it doesn't. If I map it to misc017 it does nothing either (I assume because misc017 is not seen by the pipeline other than by the first material when it puts it on the cube).

Do you have any idea how to lay one material over the other using the system above?

Thanks a heap,

Dave.
#6
01/17/2006 (1:38 pm)
Hey dave, When you use Material instead of Custom Material you are telling the shadergen code to build a procedural shader for you (from the params you specify in the def), so shader = is being ignored. I dont think there is support pass[x] in a procedural shader (i could be wrong tho..)

You need to define your material as custom, mapped to your shader (see shaders.cs) and it should work fine. (Just follows brian's post to the letter)

We are using quite a few mutlipass shaders (customMaterial) in our game and what brian posted looks like what works for us..

hope this helps
k
#7
01/17/2006 (5:41 pm)
@Dave - Kevin is correct, you need to be using CustomMaterials if you are using your own shaders.

You should *not* be using the "baseTexture" parameter inside CustomMaterials, you want to use the "texture" parameter.

Yes, you can specify as many textures per pass as your shader needs. Keep in mind each "texture" parameter is mapped directly to the corresponding texture unit in your shader.

ie.

texture[0] = "foo.png";
texture[1] = "bar.png";

In this case foo is mapped to texture unit 0, and bar is mapped to texture unit 1.


As for mapping the texture in the second pass, I'm guessing that you can simply leave the "mapTo" parameter blank and it will work OK.
#8
01/18/2006 (12:23 am)
Kevin, Brian, thanks very much. Looks like it's back to the drawing board for me, I must be doing something dumb somewhere. If I find out what it was I'll post it for any other dodos that come along after me :-)

Brian, I'm not sure I understand what you mean by
"Keep in mind each "texture" parameter is mapped directly to the corresponding texture unit in your shader."
I assume this refers to the shader itself, which I am generating in Render Monkey? Not to the ShaderData that I define?

I can't find a decent HLSL beginners tutorial anywhere that doesn't assume you already know a lot, so please forgive all these questions. I'll be the first to help others when I get this figured out.

Thanks,

Dave.
#9
01/19/2006 (7:04 am)
Well, I seem to have the basics of it figured out. I've managed to create a shader to blend three textures over a cube. Not sure if I've done it the right way, I've just added the textures together in the shader code and then multiplied by 0.33 to get it back to a normal brightness. But I'm happy neough, at least I understand how it all fits together now. Thanks for all the help peeps.

If anyone knows a better or more efficient way of blending textures in a shader, please let me know! There's probably some command for it I haven't found yet.

In case it helps someone in the future, it seems the correct way to do it is to multiply the first two textures and add the third. Don't ask me why, but it works anyway, and you don't need to adjust the brightness afterwards.

Cheers,

Dave.