Game Development Community

Torque 3D - Multiple Passes / Shaders with CustomMats

by Shawn Kennedy · in Torque 3D Professional · 02/23/2011 (8:19 am) · 4 replies

Hello,

I'm currently trying to implement multiple passes / shaders on an object with Custom Materials, but I'm not quite sure how to do the multiple passes. Here is the syntax that I'm currently using:

singleton ShaderData( Shader1 )
{
   DXVertexShaderFile 	= "shaders/shaderV1.hlsl";
   DXPixelShaderFile 	= "shaders/shaderP1.hlsl";   
   
   pixVersion = 2.0;
};

singleton ShaderData( Shader2 )
{
   DXVertexShaderFile 	= "shaders/shaderV2.hlsl";
   DXPixelShaderFile 	= "shaders/shaderP2.hlsl";   
   
   pixVersion = 2.0;
};

singleton CustomMaterial( two )
{
   mapTo = "object_material";
 	
   texture[0] = "#rendertarget4";
   texture[1] = "#rendertarget1";
   texture[2] = "#rendertarget2";
   
   shader = Shader2;   
};

singleton CustomMaterial( one )
{
   mapTo = "#rendertarget4";
 	
   texture[0] = "#rendertarget1";
   texture[1] = "#rendertarget2";
   texture[2] = "#rendertarget3";
   texture[3] = "#rendertarget4";
   
   shader = Shader1;   
	
   pass[0] = two;
};

This object is set up to have multiple render targets in code, and I figured I could use the mapTo parameter to "output" the texture from one shader into the next, but it isn't working.

I just need to know how to "chain" these custom materials together correctly. Any help is appreciated.

Thanks.

#1
02/23/2011 (8:39 am)
have a look at the water shader setup and the blur shader setup, exactly what you talk about, I suggest reading those, you'll get it.
#2
02/23/2011 (9:23 am)
Hmm, thank you for the suggestion, but I'm not quite sure where you want me to look. I'm looking for multiple passes through custom materials, but can't find anywhere that custom materials are used for a water or blur shader.

Any chance you could be more specific?

Thanks.
#3
02/23/2011 (11:55 am)
look at dof.cs in game\core\scripts\client\postFx

singleton PostEffect( DOFCalcCoC )
{
   shader = PFX_DOFCalcCoCShader;
   stateBlock = PFX_DOFCalcCoCStateBlock;
   texture[0] = "#shrunk";
   texture[1] = "#largeBlur";
   target = "$outTex";
};

DOFPostEffect.add( DOFCalcCoc );
  
singleton PostEffect( DOFSmallBlur )
{
   shader = PFX_DOFSmallBlurShader;
   stateBlock = PFX_DefaultDOFStateBlock;
   texture[0] = "$inTex";
   target = "$outTex";
};

that kind of thing, no?
#4
02/25/2011 (8:18 am)
Thanks again deepscratch. I think I've solved the issue of outputting from one shader pass into another, but now I'm not even sure if my passes are being recognized.

Is pass[x] the proper syntax for adding passes in Torque 3D Custom Mats? I couldn't find a "pass" field identified in the code anywhere... so now I think I've been mistaken.