Shaders
Ehsan Ehrari
1
Materials, Shaders & Textures
• Rendering in Unity uses Materials, Shaders and Textures. All three
have a close relationship.
2
Materials
• Materials define how a surface should be rendered, by including
references to the Textures it uses, tiling information, Color tints and
more. The available options for a Material depend on which Shader
the Material is using.
3
Textures
• Textures are bitmap images. A Material can contain references to
textures, so that the Material’s Shader can use the textures while
calculating the surface color of a GameObject. In addition to basic
Color (Albedo) of a GameObject’s surface, Textures can represent
many other aspects of a Material’s surface such as its reflectivity or
roughness.
4
Shader
• Small scripts that contain the mathematical calculations and
algorithms for calculating the Color of each pixel rendered, based on
the lighting input and the Material configuration.
• A program specifically made to run on a GPU
• Post processing
5
3D models
• a collection of 3D coordinates called vertices
• Triangles
• Each vertices can contain few other information's color , direction
• Models cannot be rendered without a material
• Materials are wrappers which contain a shader and the values for its
properties.
• Hence, different materials can share the same shader
6
Diagram
7
Anatomy of a shaders
• Unity has two different types of shaders
• surface shaders
• fragment and vertex shaders
• fixed function shaders
8
Anatomy of a shaders
• multiple SubShader sections
• actual instructions for the GPU
• Unity execute in order until it finds one that is compatible with your
graphics
• different platforms
9
The properties
• equivalent to the public fields in a C# script
• changes made to the properties of a material while the game is
running in the editor are permanent.
10
The properties
11
The surface VS Vertex and fragment
• Whenever the material you want to simulate needs to be affected by lights
in a realistic way, chances are you’ll need a surface shader
• Surface shaders hide the calculations of how light is reflected and allows to
specify “intuitive” properties such as the albedo, the normals, the
reflectivity and so on in a function called surf.
• Vertex and fragment shaders work close to the way the GPU renders
triangles, and have no built-in concept of how light should behave. The
geometry of your model is first passed through a function called vert which
can alter its vertices. Then, individual triangles are passed through another
function called frag which decides the final RGB colour for every pixel. They
are useful for 2D effects, postprocessing and special 3D effects which are
too complex to be expressed as surface shaders.
12
Unity Standard Shader
• built-in shader
• “real-world” objects
• wide range of shader types and combinations
• enabled or disabled by simply using or not using
• Incorporate PBS
13
Physics Base Shading
• Simulates the interactions between materials and light in a way that
mimics reality.
• Only recently become possible in real-time graphics
• It works at its best in situations where lighting and materials need to
exist together intuitively and realistically.
• Advance lighting model
14
Standard Shader
• The Standard Shader is designed with hard surfaces in mind (also
known as “architectural materials”), and can deal with most real-
world materials like stone, glass, ceramics, brass, silver or rubber. It
will even do a decent job with non-hard materials like skin, hair and
cloth.
• With the Standard Shader, a large range of shader types (such as
Diffuse, Specular, Bumped Specular, Reflective) are combined into a
single shader intended to be used across all material types.
15
Rendered using the standard shader on all models
16
Material Parameters
17
Rendering Mode
• Opaque
• Cutout
• Transparent
• Fade
18
Opaque
• Opaque - Is the default, and suitable for normal solid objects with no
transparent areas.
19
Cutout
• Cutout - Allows you to create a transparent effect that has hard edges
between the opaque and transparent areas. In this mode, there are
no semi-transparent areas, the texture is either 100% opaque, or
invisible. This is useful when using transparency to create the shape
of materials such as leaves, or cloth with holes and tatters.
20
Transparent
• Transparent - Suitable for rendering realistic transparent materials
such as clear plastic or glass.
21
Fade
• Fade - Allows the transparency values to entirely fade an object out,
including any specular highlights or reflections it may have. This mode
is useful if you want to animate an object fading in or out. It is not
suitable for rendering realistic transparent materials such as clear
plastic or glass because the reflections and highlights will also be
faded out.
22
Albedo Color
• The Albedo parameter controls the base color of the
surface.
• More common to assign a texture map for the
Albedo parameter
• Albedo texture should not contain any lighting
23
Albedo Transparency
• The alpha value of the Albedo colour controls the transparency level
for the material. This only has an effect if the Rendering
Mode for the material is set to one of the transparent mode, and
not Opaque.
24
Specular mode: Specular parameter
• Standard (Specular setup):
Choose this shader for the
classic approach. A Specular
color is used to control the
color and strength of
specular reflections in the
material.
25
Metallic mode: Metallic Parameter
• When working in the Metallic
workflow (as opposed to the
Specular workflow), the the
reflectivity and light response of
the surface are modified by the
Metallic level and
the Smoothness level.
26
Metallic
27
Smoothness
• The smoothness of the material is controlled by a slider. This slider
allows you to control the “microsurface detail” or smoothness across
a surface
28
Normal Maps
• Normal maps are a type of Bump Map. They are a special kind of
texture that allow you to add surface detail such as bumps, grooves,
and scratches to a model which catch the light as if they are
represented by real geometry.
29
Normal Map
30
Height Map
• Height mapping (also known as parallax mapping) is a similar concept
to normal mapping, however this technique is more complex - and
therefore also more performance-expensive.
31
Occlusion Map
• The occlusion map is used to provide information about which areas
of the model should receive high or low indirect lighting.
32
Emission
• Emission controls the color and intensity of light emitted from the
surface. When you use an emissive Material in your Scene, it appears
as a visible source of light. The GameObject appears to be self-
illuminated.
33
Thank You
34

Shaders & Standard Shader In Unity

  • 1.
  • 2.
    Materials, Shaders &Textures • Rendering in Unity uses Materials, Shaders and Textures. All three have a close relationship. 2
  • 3.
    Materials • Materials definehow a surface should be rendered, by including references to the Textures it uses, tiling information, Color tints and more. The available options for a Material depend on which Shader the Material is using. 3
  • 4.
    Textures • Textures arebitmap images. A Material can contain references to textures, so that the Material’s Shader can use the textures while calculating the surface color of a GameObject. In addition to basic Color (Albedo) of a GameObject’s surface, Textures can represent many other aspects of a Material’s surface such as its reflectivity or roughness. 4
  • 5.
    Shader • Small scriptsthat contain the mathematical calculations and algorithms for calculating the Color of each pixel rendered, based on the lighting input and the Material configuration. • A program specifically made to run on a GPU • Post processing 5
  • 6.
    3D models • acollection of 3D coordinates called vertices • Triangles • Each vertices can contain few other information's color , direction • Models cannot be rendered without a material • Materials are wrappers which contain a shader and the values for its properties. • Hence, different materials can share the same shader 6
  • 7.
  • 8.
    Anatomy of ashaders • Unity has two different types of shaders • surface shaders • fragment and vertex shaders • fixed function shaders 8
  • 9.
    Anatomy of ashaders • multiple SubShader sections • actual instructions for the GPU • Unity execute in order until it finds one that is compatible with your graphics • different platforms 9
  • 10.
    The properties • equivalentto the public fields in a C# script • changes made to the properties of a material while the game is running in the editor are permanent. 10
  • 11.
  • 12.
    The surface VSVertex and fragment • Whenever the material you want to simulate needs to be affected by lights in a realistic way, chances are you’ll need a surface shader • Surface shaders hide the calculations of how light is reflected and allows to specify “intuitive” properties such as the albedo, the normals, the reflectivity and so on in a function called surf. • Vertex and fragment shaders work close to the way the GPU renders triangles, and have no built-in concept of how light should behave. The geometry of your model is first passed through a function called vert which can alter its vertices. Then, individual triangles are passed through another function called frag which decides the final RGB colour for every pixel. They are useful for 2D effects, postprocessing and special 3D effects which are too complex to be expressed as surface shaders. 12
  • 13.
    Unity Standard Shader •built-in shader • “real-world” objects • wide range of shader types and combinations • enabled or disabled by simply using or not using • Incorporate PBS 13
  • 14.
    Physics Base Shading •Simulates the interactions between materials and light in a way that mimics reality. • Only recently become possible in real-time graphics • It works at its best in situations where lighting and materials need to exist together intuitively and realistically. • Advance lighting model 14
  • 15.
    Standard Shader • TheStandard Shader is designed with hard surfaces in mind (also known as “architectural materials”), and can deal with most real- world materials like stone, glass, ceramics, brass, silver or rubber. It will even do a decent job with non-hard materials like skin, hair and cloth. • With the Standard Shader, a large range of shader types (such as Diffuse, Specular, Bumped Specular, Reflective) are combined into a single shader intended to be used across all material types. 15
  • 16.
    Rendered using thestandard shader on all models 16
  • 17.
  • 18.
    Rendering Mode • Opaque •Cutout • Transparent • Fade 18
  • 19.
    Opaque • Opaque -Is the default, and suitable for normal solid objects with no transparent areas. 19
  • 20.
    Cutout • Cutout -Allows you to create a transparent effect that has hard edges between the opaque and transparent areas. In this mode, there are no semi-transparent areas, the texture is either 100% opaque, or invisible. This is useful when using transparency to create the shape of materials such as leaves, or cloth with holes and tatters. 20
  • 21.
    Transparent • Transparent -Suitable for rendering realistic transparent materials such as clear plastic or glass. 21
  • 22.
    Fade • Fade -Allows the transparency values to entirely fade an object out, including any specular highlights or reflections it may have. This mode is useful if you want to animate an object fading in or out. It is not suitable for rendering realistic transparent materials such as clear plastic or glass because the reflections and highlights will also be faded out. 22
  • 23.
    Albedo Color • TheAlbedo parameter controls the base color of the surface. • More common to assign a texture map for the Albedo parameter • Albedo texture should not contain any lighting 23
  • 24.
    Albedo Transparency • Thealpha value of the Albedo colour controls the transparency level for the material. This only has an effect if the Rendering Mode for the material is set to one of the transparent mode, and not Opaque. 24
  • 25.
    Specular mode: Specularparameter • Standard (Specular setup): Choose this shader for the classic approach. A Specular color is used to control the color and strength of specular reflections in the material. 25
  • 26.
    Metallic mode: MetallicParameter • When working in the Metallic workflow (as opposed to the Specular workflow), the the reflectivity and light response of the surface are modified by the Metallic level and the Smoothness level. 26
  • 27.
  • 28.
    Smoothness • The smoothnessof the material is controlled by a slider. This slider allows you to control the “microsurface detail” or smoothness across a surface 28
  • 29.
    Normal Maps • Normalmaps are a type of Bump Map. They are a special kind of texture that allow you to add surface detail such as bumps, grooves, and scratches to a model which catch the light as if they are represented by real geometry. 29
  • 30.
  • 31.
    Height Map • Heightmapping (also known as parallax mapping) is a similar concept to normal mapping, however this technique is more complex - and therefore also more performance-expensive. 31
  • 32.
    Occlusion Map • Theocclusion map is used to provide information about which areas of the model should receive high or low indirect lighting. 32
  • 33.
    Emission • Emission controlsthe color and intensity of light emitted from the surface. When you use an emissive Material in your Scene, it appears as a visible source of light. The GameObject appears to be self- illuminated. 33
  • 34.