Sign in to follow this  

HLSL - how many shader files to have

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

Hey, was just wondering how many shader files you would use in a graphics engine. At the moment I am making a graphical engine which uses shaders using the HLSL. What would you guys recommend, using just the one shader file for the whole engine and using different techniques. Or using say a shader file for xfiles, one for terrain etc... Or breaking it down further to having say one for rendering terrain using a blend map, and one for rendering terrain with custom rules etc... Any thoughts or advice on this from anyone who has encountered this situation would be great. I'm trying to make my engine generic but still able to have flexibility.

Share this post


Link to post
Share on other sites
I don't think it matters whether you have all your techniques in one file or accross seperate files. You can use '#include' to share similar stuff between them. Working with one file could be painfull though because everytime you make a change, you will have to recompile the whole effect.

EDIT:
I had experience with loops taking ages to compile in effects because the effect compiler was unrolling the loops. I would keep this in a seperate file because I don't want to have to compile it over and over again.

Share this post


Link to post
Share on other sites
Thanks for the reply.

Didn't know you could compile effects files. Guess that would take away the pain of having to include them in the finished product as assets.

How do you compile effects files?
And would this change the techniques for loading and using the effects file?

Share this post


Link to post
Share on other sites
Every time you load an effect, the API will compile it for you if it's not compiled already. So you gonna have to include them anyways. By compiling it as part of pre-processing, you just make it faster lo load since it's already in binary bytecode form and no more processing needs to take place.
To compile effects and shaders use the HLSL compliler tool shipped with DX. fxc.exe IIRC.

You can make a DWORD array version of the compiled effect, usung fxc.exe, that can be included in the C++ code but that's overkill for large projects.

Share this post


Link to post
Share on other sites
I have several .fx files for different types of objects, with a common.fxh which is included by all .fx files. The common.fxh contains routines for lighting and shadowing and necessary constant definitions. When building, the .fx files are compiled into .fxo binaries using fxc.exe from DXSDK.

Share this post


Link to post
Share on other sites
Thanks for all of the advice. I like the idea of using one for lighting, and one for shadows and a general one for generic functions. Seems like that would keep the flexibility and allow the shaders to still be generic.

At the moment I have my effects file (just a txt file renamed), and I load it using say :
D3DXCreateEffectFromFile(d3dDevice, "Shader.fx", 0, 0, D3DXSHADER_DEBUG, 0, &FX, &errors);

Would I use the same on a compiled file, or would I have to do something different?

Share this post


Link to post
Share on other sites

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