# Difference between Material and Shader

In games, materials often only influence the visual appearance of objects. The visual appearance is effected by shaders. So regarding to terminology is there a difference between materials and shaders? Should you write one shader for one material?

• I've seen a few engines where a material is a shader + diffuse texture + bumpmap, but I don't think there is one concise definition. Dec 19, 2012 at 13:02
• @RoyT. Those engines would be misusing terminology. A material isn't equivalent to a shader -- a shader is a program, a material is a bunch of data values. 2 different shader programs can render the same material and get different results. Dec 19, 2012 at 17:33
• @bobobobo Or more commonly, a single shader would be used to render many materials, by plugging in different textures, parameter values and such. Dec 19, 2012 at 23:38

A material is a combination of attributes which describe how a surface of the given material should look like.

Some engines use different shaders for different materials, in which case a material definition could look like this:

[Material]
Texture1=Rock.png
Texture2=RockNormal.png
Texture3=RockSpecular.png


Other engines use one shader for all objects (or rather the engines decides what shader to use dependent on the parameters, the capabilities of the GPU and other factors such as distance), in which case a material would look more like this:

[Material]
Ambient=0.5
Specularity=0.7
DiffuseMap=Rock.png
NormalMap=RockNormal.png
SpecularMap=RockSpecular.png

• couldn't one extend the definition of a material to every senses supported by the game engine? For instance, the sounds that the material will produce when hit, stepped upon, etc. , or its friction parameters? Jun 25, 2013 at 0:46

A material specifies how an object responds to light.

There are a couple of common parameters:

• Kd: Diffuse response to light
• Ks: Specular response to light
• Ns: "Shininess"
• map_Kd: Texture

Now say you have a triangle rendered with material M. M has Kd=(1,0,0) (red diffuse response), Ks=(1,1,1) (white specular response), Ns=25 (specular highlight will be quite sharp and not fuzzed out) and no map_Kd (no texture).

The job of the shader is to use math to take the vertex positions of triangle, the position of the light, the material color values, and figure out what color the triangle should appear. A vertex shader does this "shading computation" once at each vertex and interpolates the color across the triangle.

A common operation in a shader to compute the diffuse response at a vertex is:

// hlsl
float3 vertexToLight = normalize( lightPos.xyz - vertexPos.xyz ) ;

float3 diffuseColor = max( dot( vertexToLight, vertexNormal ), 0.0 ) * kd * lightColor ;


A material is what you apply to geometry to give it a colour and pattern. A texture is a component of a material.

A shader is a small program that allows this material to be rendered at runtime. The nice thing about shaders is that you can do everything from simply rendering the material, to adding dynamic effects like specular highlights and reflections all the way up to extremely clever things such as rendering fake holes through walls where a bullet has hit.

so in answer to your question - yes there is a difference, there is a little overlap too - you could either make a red material or write a shader to render things as red, but both of them also allow you to a lot of things you could not with the other.

and no, you don't need one shader per material. although a material requires a shader to be rendered, you could have one for all you materials if you wanted. they do specific things so if you wanted everything to be shiny for example, you could just write one.

A nice example of shaders is in gears of war. there is one set of materials for the scene, but when you press a button to switch to tactical view, the shaders that are rendering these materials change so things look outlined and generally different. The same thing happens in batman: arkham's 'detective mode'.

• Technically a texture isn't really a material on it's own, it's usually part of a material. Dec 19, 2012 at 17:26

Although late, there is a "cheat" which can help you understand better.

A material is everything that is attached to a certain shader for that draw call.

For example, in the above answer, you have this material: [Material] Shader=NormalMappedSpecular.glsl Texture1=Rock.png Texture2=RockNormal.png Texture3=RockSpecular.png

which translated that you will be rendering with a shader that does a normal map and a specular computation, and it will use the 3 textures inside that shader.

Later on, you can re-use the same shader, with different other 3 textures (like car, carNormal and carSpecular), you will do a different draw call with a different material, just because you changed the shader parameters.

All in all, a material is everything that uniquely creates a draw call using the same shader with the same parameters (textures, uniforms, attributes).

I hope this helps to better visualize it

• is it something like: the shader is the class, but the material is the instance? Nov 13, 2018 at 15:25