ID3DXEffect manager design?

Started by
7 comments, last by DieterVW 13 years, 7 months ago
I've already asked this before, but I don't think I was very clear on what I was asking at the time.


Anyway, I really need help, guys.

I need to design and develop an effect manager for ID3DXEffect to store and allow for the rendering of effects on 3D data. I've scoured the net and have found very little information, and the info I have found doesn't relate to what I'm trying to do.

Basically, I'm currently in school, and the professor tasked us with building a simple game engine. My group, the graphics group, was required to design the graphics core to be able to run any shader passed to it.

My major problem is that I can't figure out a means to make it so that the Effect Manager is autonomous.

Rules on the design:
-I don't know what variables will be used within the effect file
-I don't know what information will be available with the mesh data


I really need a lot of help guys, my head is about to explode, and despite how hard I've been trying to figure this problem out, my group mates are really starting to get angry at me for not living up to my part of the project.
Advertisement
I probably don't know enough about this to give you advice, but still I'd like to understand your problem a little better.

Quote:-I don't know what variables will be used within the effect file


Does this mean that the manager should pass the effect any variables it needs automatically? I think you can do something like this with HLSL semantics/annotations. Don't know if this is the best way, but it might be something to look into.

Quote:-I don't know what information will be available with the mesh data


Can you give more details? Maybe some examples?

BTW, you can try looking at Ogre's source code, I think it contains some similar functionality. At least it might give you some ideas.
Quote:Original post by Gage64
I probably don't know enough about this to give you advice, but still I'd like to understand your problem a little better.

Quote:-I don't know what variables will be used within the effect file


Does this mean that the manager should pass the effect any variables it needs automatically? I think you can do something like this with HLSL semantics/annotations. Don't know if this is the best way, but it might be something to look into.

Quote:-I don't know what information will be available with the mesh data


Can you give more details? Maybe some examples?

BTW, you can try looking at Ogre's source code, I think it contains some similar functionality. At least it might give you some ideas.


I've considered using semantics; however, they start to cause problems if an effect file that's very different from normal use is applied. For example, one of my teammates developed a terrain renderer using texture blending. Naturally, I could create 4 different texture semantics; however, what if someone wanted to use more, it becomes a bit complicated.

I'll probably end up using semantics in the end anyway (I'm already using them for camera variables.)


As to the information. Obviously, each model would have at least a texture map; however, it may or may not have specular data, light map, emissivity map, etc.

Ultimately, I'm trying to find the best solution for developing this class. I've already rewritten it 4 times, and would really only like to write it one last time.

edit: I should give a further example.

Say I have an object that uses a shader with 3 texture, and has 3 textures stored. What if the programmer using the engine decides to change the shader that object uses to one that uses 4 textures. Obviously, for this case, the data passing cannot be hard-coded and must somehow be made dynamic. My confusing hit a wall here. How to make it dynamic.

I've tried creating a "passing" struct, but that blew up in my face.
Have a look at the example of SDK called statemanagement
This sample shows an example implementation of the ID3DXEffectStateManager interface. this inteface can be used to implement custom state-change handling for the D3DX effects system
Quote:Original post by monkeyboi
Have a look at the example of SDK called statemanagement
This sample shows an example implementation of the ID3DXEffectStateManager interface. this inteface can be used to implement custom state-change handling for the D3DX effects system


I have taken a glimpse of that; however, I wasn't too sure as to how I would go about actually using it.
Look at the documentation.
There should be a constant table for you to use.
And for meshes.. you can grab the vertex declaration.
When information is collected, connect all nodes in the "data graph".

Btw, you should know that it's quite pointless to try to match any vertex shader to any vertex declaration with one exception. And that is - when you convert a mesh to a vertex declaration that fills all of the commonly used members of a vertex data stream -- if mesh's vertices don't have a NORMAL0 data stream member, you add it to every vertex and fill them with vertex normals.

EDIT: if it's possible to avoid all that "universalism" then do that. You should really have a solid format for connections between different data (like mesh material descriptors <=> effect file). It's definitely not a good idea to throw any data at the renderer and just look if it works or blows up.
I'll take a deeper look at the documentation. I'll probably be back later with more questions, though.
Quote:Original post by Ncyphe
Say I have an object that uses a shader with 3 texture, and has 3 textures stored. What if the programmer using the engine decides to change the shader that object uses to one that uses 4 textures. Obviously, for this case, the data passing cannot be hard-coded and must somehow be made dynamic. My confusing hit a wall here. How to make it dynamic.


There could be an annotation specifying the number of textures, that would make it more dynamic.

This thread seems to contain useful information.
Obviously if the shader isn't supplied all of the data it needs then it's not going to function correctly. However, that isn't necessarily bad since people can go in a fix models or add textures quite easily if given proper feedback.

Normally there are some basic requirements in a game, for instance most objects will all fit some min spec, including vertex data, normals, texture coords, and a set of diffuse/specular textures. So this would be a min bar for a model. Models with more info would still work with any shaders coded for the min bar.

Then there would be a file that linked everything needed for a model. It would specify the geometry and the textures that go with it. If there are special shaderes for a model, those would also be specified. Consider using xml. But the model would fulfill the min bar. If a model needs to go below the min bar, then it would have to have a custom shader to go with it as the general engine shaders wouldn't work. Add error message that point out if a model doesn't meet the requirements. If data is needed that isn't available, provide it automatically with zeros. Objects will still render if a texture is missing. Those texture lookups will return zero. This is fine. If a model needs normals, generate a buffer of normals (bogus ones) just so that it will draw and work with the pipeline. Print an error message so that the artist knows what needs fixing when the rendering is wrong.

Use differed lighting and or deferred rendering. This will separate the lighting from the material properties rendering. Basically the first render step will be to get all objects into a universal format that your lighting can run on. This will simplify most object rendering and lighting.

Have the engine know about common semantics/annotations like model, view, projection, inverse model view matrices etc. Then all shaders should be written to use those inputs which your engine will know how to auto connect. Shader writers should all use the same set of semantics/annotations for common information.

Custom inputs can be added to models too. Have a map of semantic/annotation names -> function callback for getting the relevant data. Then when a shader is loaded that needs custom data, you can query the objects map for the semantic/annotation and then use the function to fill the memory location with the required data. If the data doesn't exist, print and error message and fill the space with zeros. The object will still be drawn, but that attribute info will just be zero.

This topic is closed to new replies.

Advertisement