HLSL - how many shader files to have

Started by
5 comments, last by p0is0n 15 years, 9 months ago
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.
Advertisement
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.
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?
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.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
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.
The best thing would be a big fx files with all techniques you need.
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?

This topic is closed to new replies.

Advertisement