Jump to content
  • Advertisement
Sign in to follow this  
Noggs

Sharing state between HLSL techniques

This topic is 2879 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

I'm re-writing my lighting pass to take multiple lights per pass, but I need it to work on ps_2 without dynamic branching. So I was thinking pass in an int at compile time, and create a bunch of techniques for one light, two lights, etc.

The problem I have with this approach is that it quickly becomes unwieldy to manage 8 techniques that are identical apart from a single int parameter. This could be alleviated to some degree by being able to share the render state blocks easily. Does anyone know how to do this? Or maybe other ideas on how to implement this?

I did try using a run-time int parameter to the shader but got a compile error related to running out of shader registers. I guess it unrolled the loop too far.


Technique PointLight_1
{
pass Pass0
{
// only write pixel if it passes the test
StencilEnable = true;
StencilMask = 0x1;
StencilRef = 0x1;
StencilPass = KEEP;
StencilFunc = EQUAL;

AlphaBlendEnable = TRUE;
BlendOp = ADD;
SrcBlend = ONE;
DestBlend = ONE;

VertexShader = compile vs_2_0 vs_light();
PixelShader = compile ps_2_0 ps_light( 1 );
}
}
Technique PointLight_2
{
pass Pass0
{
// only write pixel if it passes the test
StencilEnable = true;
StencilMask = 0x1;
StencilRef = 0x1;
StencilPass = KEEP;
StencilFunc = EQUAL;

AlphaBlendEnable = TRUE;
BlendOp = ADD;
SrcBlend = ONE;
DestBlend = ONE;

VertexShader = compile vs_2_0 vs_light();
PixelShader = compile ps_2_0 ps_light( 2 );
}
}
// etc etc

Share this post


Link to post
Share on other sites
Advertisement
With effects you can declare an array of pixel shaders, and then switch between them by setting a sigle int parameter. See the DX9 skinning sample for an example.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!