Jump to content
  • Advertisement
Sign in to follow this  
ELgitaro

[Beginner to shader programming] A general question.

This topic is 3983 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 guys, I am learning shader programming from a book now. I was wondering how shaders are associated with each material. I mean, for instance, the textures are specified in .X file. How about shaders? Say I have a character and I want to apply a shader, but I also want to apply a shader to the environment. What is the general way to apply different shaders to each object or objects in the scene? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Shaders are used like any other render state, texture or parameter: you set it at some time and it will be used with all following draw calls until you set another shader. So using different shaders for different scene parts is done simply by setting one shader, drawing one object, setting another shader, drawing another object and so on.

Share this post


Link to post
Share on other sites
In general, a material is associated with a particular shader and a set of parameters. These parameters are usually a set of shader constants that will be set when the material's shader are applied, and can be of varying types. So for example say you had a material called "Brick" with a simple phong normal-mapped shader. You'd probably have a string name for the diffuse texture, a string name for the normal-map texture, a 3-float vector with the specular color, and a single float for the specular power.

X-files provide some built-in functionality for this, called Effect Instances. When you load a mesh, you can get an array of Effect Instance structs (1 per parameter). Each one will have string name that corresponds to the name of the parameter in the HLSL code, an enum that indicates what type the data is (typically string, FLOAT, or INT), a void pointer to the actual data, and an integer indicating the size of the data. The idea is that for a particular material on a mesh, you loop through these instances and set the shader constants using the data available to you.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!