Sign in to follow this  

Confusion around shaders and .fx files

This topic is 4344 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! I've just started to wrap my head around HLSL shaders and effect files using DX. I have a few questions though: 1. If I've got a scene where all objects are supposed to be lit using some light function defined in a .fx file, and then I wan't a few of those objects to be affected by other shaders in some other .fx file. How do I go about achieving this? Do I have to change that other effect to also contain the light computations and use two diffrent effects depending on if the object uses that other effect or just normally lit? Or is there a way to to draw objects using effects defined in two diffrent .fx files? Basically, If I have an effect that are used on many objects, how do I combine that with some other effect? 2. How do I typically render a scene where all object use shaders? Should I sort by effect and draw all objects that use a certain effect, go to the next effect and draw all objects using that and so on..? Or should I sort by object and draw it using the effect that particular object is specified to use? A scene graph is not needed at the moment... 3. Does .x files support effects? I.e. can materials in the .x files reference to some .fx file, or do I have to specify that manually in the application code? I've understood that "Effect instances" can somewhat help with this...? Any insight on these questions are apreciated! Thanks in advance!

Share this post


Link to post
Share on other sites
Hey bud,

1. Not confident in answering that.

2. Sort by effect, batching the render calls etc.

3. So long as the effect gets the information about the geometry it needs, it doesn't matter where it comes from. An XFile has no direct link to teh shader.

Dave

Share this post


Link to post
Share on other sites
1) You can have two effects that are largely the same, draw all objects that need one, switch state and draw all objects that need both. You could also draw all objects that need one, switch to a shader that does only the extra stuff, and draw all those objects again with blending on (if the available blend equations work for you). You could also explore more advanced concepts like shader fragment linking to combine "parts" of shaders.

2) Yes. For optimum performance you want to minimize state changes by sorting by states (effect, texture, etc), but ultimately what tends to bottleneck you is the number of draw submission calls (DrawPimitive*), so the best state to sort and batch on is the one that will help you reduce submission calls the most.

3) .X files CAN have references to .fx files in "effect instances" as you mentioned. One of the D3D SDK samples ("Mesh with Effect Instance" or some such) illustates that.

Share this post


Link to post
Share on other sites

This topic is 4344 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.

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