Jump to content
  • Advertisement
Sign in to follow this  
dustamulet

Confusion over 'Materials' and 'Shaders'

This topic is 4455 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, I was wondering if anyone could explain to me what the difference between 'material' and 'shaders' are referring to. I can create an object, give it a texture, give it a material, and render it with lights on using the fixed function pipeline. I can also create a shader and send the shader a texture, and render the object. I see people talking about 'materials' and 'shaders' and wasn't really sure what they mean by the difference between them. If you don't use any fixed function pipeline and render everything with shaders, does this eliminate the need to use the 'fixed function' materials? Could you give me an example of how I would do this? Thanks if you can help :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by dustamulet
I was wondering if anyone could explain to me what the difference between 'material' and 'shaders' are referring to.

If you're referring to vertex and pixel shaders, there's a huge difference. But you can supply material information to shaders, so I guess the use of shaders can make built in materials obsolete.

Quote:
If you don't use any fixed function pipeline and render everything with shaders, does this eliminate the need to use the 'fixed function' materials?

Pretty much, yep.

Shaders are just programming code. The code is used to process individual vertices (vertex shader) or individual pixels (pixel shader). I don't have any experience with pixel shaders, but I can explain vertex shaders. You can control any attribute that is owned by a vertex. You can generate dynamic changes in vertex positions, normals, colors, texture coordinates, etc. For example, you could create water wave patterns by cycling vertex positions and texture coordinates. Or you could feed the shader other data, and that data can be used to influence the changes in vertices. In the shader code, most of the programming is non-conditional. That means little use of if-else. But you can work with every attribute that you put into your vertices, and you can return (to the graphics hardware renderer) brand new generated attributes in your vertices.

There's a lot to explain, and my project just finished compiling, but feel free to ask specific questions :)

Share this post


Link to post
Share on other sites
A Material defines how a specific piece of geometry is to be rendered by specifing passes, and specifying how these passes are to be rendered ( for example by specifying a shader for the pass ) The border between Material and Pass may get a little blurry if you only think about simple materials that only have one Pass. But in general, a Material is something more generic than a shader.

Example:

Material Definition:
This Material has 2 Passes ( so 2 Drawcalls have to be executed for this piece of Geometry )
In the First Pass, Use Shader A with Textures "bla.jpg" and "hello.bmp", also disable backface culling for this pass.
In the Second Pass, Use Shader B with Texture "blub.jpg", also enable alpha blending for this pass.

The Pass description of the Material could also contain information which uniforms/constants the engine needs to pass to the Shader. For example a lightPosition or something

Hope that helped

Share this post


Link to post
Share on other sites
A shader is a way of rendering something. For example, you might have a shader that uses the fresnel term to control the alpha of the output (e.g. a water shader), or a shader that calculates the amount of light recieved by a pixel using per-pixel normals and a list of lights.

A material can be loosely thought of as all the information needed to render a particular thing - a shader, plus data for the shader. You might have a shader that applies a specular effect to your polygon; the material data would contain a reference to that shader, plus the name of the specific specular map to use, plus the strength of the specular effect to apply. It's like wrapping up a function + that function's arguments.

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!