• Advertisement
Sign in to follow this  

Shader architecture

This topic is 3521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I have a complicated vertex shader which is responsible, say, for depth shadow mapping. What I need to do is create another version of this shader which differs slightly, for example, supportes one extra texture sampler. Is there any way around creating a duplicate of the same shader with just a couple (probably just one) lines modified? Seems to be a very inconvenient way of doing it. Thank you

Share this post


Link to post
Share on other sites
Advertisement
You can use C-style preprocessors:

#ifdef I_WANT_THIS_EXTRA_LINE
// code
#endif


You can either create the #define in the effect file or you can pass it from the application via D3DXINCLUDE or D3DXMACRO structs when compiling the effect (forget exact details).

Or, and my preferred method, is to use uniform parameters:

VS_OUT vs(in VS_IN v, in uniform bool ExtraCode )
{
// ...
if( ExtraCode )
{
// Your additional/different code here
}
// ...
}


technique t0
{
pass
{
VertexShader = compile vs_2_0 vs(true);
}
}

technique t1
{
pass
{
VertexShader = compile vs_2_0 vs(false);
}
}



hth
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement