• Advertisement
Sign in to follow this  

Setting Shader per Object or independently?

This topic is 3291 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 everyone, I just started with Shaders and i am a bit confused on how to manage them? So far i have this following setup: I have a Skin manager that manages all the Skins a Object could have. Each Skin hast Information about Alpha blending, the Material and Texture in it. So when i render I read the Skin for every object and set the Render states accordingly as well as the material and the Texture. Now my question is should i add Information about the Shader in the Skin too? Like which Shader an Object wants to use? Or should i use a separate Shader Manager that just sets a new active shader? And how do i go about different input parameters for different shaders? Wouldn't my objects need the input-paramaters that every possible shader can have? You see i am a bit lost with the structuring of all this. I read Game Engine Programming by Stefan Zerbst but i don't really like the approach he takes with setting shaders and renderstates. So if anyone had some ideas for me i would be really happy:-) Thx a lot in advance for any hints you guys can share!

Share this post


Link to post
Share on other sites
Advertisement
Hopefully I did not misunderstood your problem.

My take would be it depends on how you want to design your system. You could have them separated from your Skin. However, there must be some other place that at least matches the skin to the respective shader to be used. Your objects will need to update the parameters that the skin required. If skins are unique to each object, then you may possibly store the input parameters in the skin, since I suppose 1 Skin can only have 1 Shader.

The approach that I took was to not make the Shader have a direct dependent for the required input values. This allows swaping of shader which won't break the drawing.

For example if the new shader requires a new SPECULAR input variable, it will try to obtain this value from the object, if it can't get the value, it will get a system default.

This was what I have done, I am sure there are other better solutions out there. It was just an idea that I thought about and coded it to try it out. It may probably not be the efficient solution you are seeking.

Just my opinion, hope it helps

Share this post


Link to post
Share on other sites
Sounds interesting:-)

Could you show me an example of how you obtain the System Variable if no input is available?

Thx again

Share this post


Link to post
Share on other sites
For my case, the system default is declared two ways. (I am not sure which part of obtaining the system value are you interested in, but here is a generally brief of how it works)

1. It is a static data declared by the user of the engine. E.g They may set DIFFUSECOLOR to be always (0.0, 0.0, 1.0, 1.0)

2. The default data is dynamic. A callback function or script is declared by the user. When the shader queries it, this function is called to generate the default system value. For example: OscillationAmount may probably be define as a callback function that takes the current app time and return the sin of it.

Hope this helps

Share this post


Link to post
Share on other sites
Is there a way to find out in C++ code what input parameters are required by a certain shader?

Cause my main problem right now is setting the input parameters dynamically.

If there is no way to find out in c++, how am i to know dynamically in source which shader needs which input?

Thx for your reply so far:-)

Share this post


Link to post
Share on other sites
You can get the input parameters that is used by the effect, by calling ID3D10Effect::GetDesc() to obtain the number of variables. Next, you obtain each variable through the function ID3D10Effect::GetVariableByIndex(). The variables that you obtain will then reflect its Name, semantic etc.

Share this post


Link to post
Share on other sites
I have materials that are created by an effect when it is loaded.

1) The effect class queries the directx effect for effect variable names and types.
2) The effect class fills the material class' std::maps of each variable type by variable name that the effect uses.
3) A copy of that material object is then obtainable from the effect object.
4) The application then asks for a copy of the material object and fills in its own values.
5) That copy is stored in my polygon set
6) At render time the material is obtained from the poygon set being rendered.
7) The effect object sets the directx effect variables with the values in the material object. (if they vary from the material used last render)

So, the effect sets up the contents of the material that the effect uses and the application fills in the values. There are a ton of little details that are important, but that is the idea.

The same material class is used no matter what shader I am using.
The same effect class is used no matter what the shader code.

I very much disliked hard coding a set of material attributes and for each effects. The majority of code I saw on the net did this and had to make seperate material classes for every rendering method the engine used. I found that very limiting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement