Sign in to follow this  
tokaplan

Shader architecture

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this