Question

I'm writting a small graphics program using directx9 which imports some model files created using blender from .x files. So far so good.

The models have materials which have textures and it's simple to get the texture names and properly render the objects however I'd like to use different effect (shader) files on some of the materials but I can't find any way to embed the information about what shader to use in the model in the .x file.

The best idea I had was to look at the texture filename in my d3d9 application and hardcode a lookup table of texture name to effect file. But that doesn't seem elegant, and also means that I'd end up copying and renaming textures just so I could use the same texture with different shaders.

I feel I must be missing an easier way to do this, any suggestions?

Was it helpful?

Solution

Unlike texture image files, specifying a shader program can be very complicated. You need the shader text as well as the specifications for the parameters it needs and a way for whoever reads the file to know which values to set for the parameters and how. Some shaders require in turn textures a parameters and sometimes these texutres needs to be generated by the application (for instance in the case of a Perlin noise 3D texture).
In short, there is no way to come up with a standard way to generically specify shaders which can be fully integreted in a file format such as .x. Your only choice is to come up with something ad-hoc for your application. The method you suggest in the question is as good as any.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top