Jump to content
  • Advertisement
Sign in to follow this  
Quat

FX HLSL conditional statements

This topic is 4830 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 have something like in a .fx file: static float DIR= 1; static float POINT= 2; static float SPOT= 3; Light L; // parameter In a function: if( L.type == POINT) { ... } else if( L.type == SPOT) { ... } Light is a structure I set as an effect parameter. I have a corresponding structure definition in the .fx file to match it. Then I use SetValue to set the whole thing. For some reason, both the if and else if part are getting executed. Any ideas why? I'm using VS 2.0.

Share this post


Link to post
Share on other sites
Advertisement
Ok, I think I found the problem. It looks like each data member in a structure gets its own 4D vector slot. Thus, the memory layout of my C++ structure does not match the memory layout of the HLSL structure. Thus the copy gets fouled up. I fixed this by augmenting everything to 4D vectors in the C++ application. Is this the usual fix? Or am I missing something?

Share this post


Link to post
Share on other sites
Nevermind, it was working because I switched to VS 3.0. Is what I am trying to do considered dynamic branching?

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
Nevermind, it was working because I switched to VS 3.0. Is what I am trying to do considered dynamic branching?

Yes. Generally prior to 3.0, both if and else blocks are executed and the compiler inserts some clever code to choose the appropriate result.

Share this post


Link to post
Share on other sites
Quote:

Generally, prior to 3.0 both if and else blocks are executed and the compiler inserts some clever code to choose the appropriate result.


Any idea why it is not choosing the appropriate one in Shader version 2.0?

Basically I am just trying to implement D3D lighting in a vertex shader, and I want to write a "one function that does it all" based on the light's "type" data member. These parameters are set inbetween draw calls--I thought shader version 2.0 could do static branching.

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!