Jump to content
  • Advertisement
Sign in to follow this  
D3DXVECTOR3

How to handle different shaders!?

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

Different shaders have different parameters to be set and I was wondering what I need to do to handle all sort of shaders. for example some shaders need the model and view matrix, some need the model, view and view-inverse matrix and other need model*view*proj. etc For some shaders you need to set a parameter for example time (0.0f ~1.0f) How do I read/work with this!? I was thinking to do it via the parameter semantics!? I was thinking to do all matrix calculation in the shaders (inverse, matrixA*MatrixB, transpose) it this a smart thing to do!? How can I calculate inverse and transpose in the shader!? many question I know :(

Share this post


Link to post
Share on other sites
Advertisement
You need to read a tutorial or description of how the shaders work, and that might make a lot more sense, but basically registers and constant registers can be set. If it's a common thing needed by every vertex shader, there may be a declared register for it that is set automatically, such as the position value from the vertex buffer. If it's specific to your shader, you have a set of constant registers you can use for anything you want. Matrix computations are a smart thing to do in a shader, if it makes sense. If it's a one time calculation that you do each frame, it doesn't make sense though. There are many functions available, but they differ based on what version shader you are using. Again, there are some books or tutorials that will tell you what is available in each shader version (probably MSDN has this info).

See this link for more details:Click Here.

Good luck,
Chris

Share this post


Link to post
Share on other sites
Correct me if I'm wrong, but can't you just create mulitple Effect (or shader) interfaces and set each one before you render?

Share this post


Link to post
Share on other sites
^^ Yes but every shaders is different and recuire different matrices. I was thinking about setting the World, View, projection (if recuired) and calculate all others in the shader itself.

I checked the link you posted Supernat02 but his code is written for the specified shaders. What I want to do it have the ability to use different shaders that have different parameters.

Share this post


Link to post
Share on other sites
I'm not quite sure what you're after, but it sounds like you want some sort of automatic system?
You could make a mapping between engine-variables and shaders, and use some sort of declarator-file. In the engine, in you SetShader()-function, you'd check the mapping and put all the values in their constant-registers.
Now, I must say this is usually a bad idea. The person making the shader will know what input it needs, and should be responsible for documenting it enough so others can use it if necessary. Automatic systems like this one are usually much too complicated compared to what you gain from them, and they can also be a massive speed-hit once you have a few shaders loaded.

Share this post


Link to post
Share on other sites
I'm using half-automatic system. I'm simply setting the most common parameters (matrices of all kinds, lights, materials and eye position, maybe time). Now, at load time, I check if those parameters are in a shader via standard semantics (read about it in DX SDK documentation). Those are standard for .fx files, but I bet you are using/would want to use them anyway.

Before rendering, I'm setting only those parameters that are needed, and voila!

As for non-standard parameters, you've got to know about them in the program anyway, so I think there's no easy(automatic) way aroud this.

Cheers.
~def

Share this post


Link to post
Share on other sites
^^ ah yes standard semantics thats what I was refering to0.

""...I'm simply setting the most common parameters (matrices of all kinds, lights, materials and eye position, maybe time). Now, at load time, I check if those parameters are in a shader via standard semantics..."

Sounds like the way I want it. thx I think I have the info I was looking for.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!