KEMBAR78
Working with Shader with Unity | PPTX
Working with shader
What is a Shader ?
A shader is a program that runs in the graphics
pipeline in CPU and tells the computer how to
render each pixel.
These programs are called shaders because
they're often used to control lighting and
shading, but they also can handle other special
effects.
Minecraft before and after shader
Graphic rendering pipeline
Consists of six stages:
1. Per-Vertex Operation
2. Primitive Assembly
3. Primitive Processing
4. Rasterization
5. Fragment Processing
Per-Vertex Operation
Transform from the local coordinate
system to the 3d world coordinate
system. A model of a teapot in
abstract is placed in the coordinate
system of the 3d world.
Vertex shader comes here.
Per Vertex Operation - Lighting and shading is programmable
Primitive Assembly
Traditionally this is done using
triangles, as a result a primitive is
assembled, e.g. a triangle.
Primitive Assembly
Primitive Processing
Geometric primitives that now fall
completely outside of the viewing
frustum will not be visible and are
discarded at this stage.
Primitive Processing
Rasterization
Primitives are then broken down into
smaller units, corresponding to pixels
in the framebuffer. Each of these
smaller units are called Fragments.
Fragment shader comes after here.
Rasterization
Fragment Processing
Once the primitive has been
rasterized, color/texture is applied to
the geometry.
Fragment Processing
Per-Fragment Operation
Fragments are submitted to tests:
1. Pixel Ownership - not customizable by applications
2. Scissor - fails if fragment is outside of a specified rectangle
3. Alpha - outcome depends on alpha of the fragment
4. Stencil - outcome depends on value in stencil buffer
5. Depth - outcome depends on depth of fragment
6. Blending - outcome depends on fragment color
7. Dithering - not customizable by applications
8. Logical operations - outcome depends on color of
fragment
Per-Fragment Operation - usually configurable but not programmable
The ultimate goal of the Vertex Shader is to
provide the final transformation of the mesh
vertices to the rendering pipeline.
Vertex Shader
Vertex Shader pipeline
The goal of the Fragment shader is to provide
Coloring and Texture data to each pixel
heading to the framebuffer.
A framebuffer is a bitmap that is used to
refresh a display from a memory buffer
containing a complete frame of data.
Fragment/Pixel Shader
Pixel shader pipeline
MSAA - each pixel at the edge of a polygon is sampled multiple times. For each
sample-pass, a slight offset is applied to all screen coordinates.

Working with Shader with Unity

  • 1.
  • 2.
    What is aShader ? A shader is a program that runs in the graphics pipeline in CPU and tells the computer how to render each pixel. These programs are called shaders because they're often used to control lighting and shading, but they also can handle other special effects.
  • 3.
  • 4.
    Graphic rendering pipeline Consistsof six stages: 1. Per-Vertex Operation 2. Primitive Assembly 3. Primitive Processing 4. Rasterization 5. Fragment Processing
  • 5.
    Per-Vertex Operation Transform fromthe local coordinate system to the 3d world coordinate system. A model of a teapot in abstract is placed in the coordinate system of the 3d world. Vertex shader comes here.
  • 6.
    Per Vertex Operation- Lighting and shading is programmable
  • 7.
    Primitive Assembly Traditionally thisis done using triangles, as a result a primitive is assembled, e.g. a triangle.
  • 8.
  • 9.
    Primitive Processing Geometric primitivesthat now fall completely outside of the viewing frustum will not be visible and are discarded at this stage.
  • 10.
  • 11.
    Rasterization Primitives are thenbroken down into smaller units, corresponding to pixels in the framebuffer. Each of these smaller units are called Fragments. Fragment shader comes after here.
  • 12.
  • 13.
    Fragment Processing Once theprimitive has been rasterized, color/texture is applied to the geometry.
  • 14.
  • 15.
    Per-Fragment Operation Fragments aresubmitted to tests: 1. Pixel Ownership - not customizable by applications 2. Scissor - fails if fragment is outside of a specified rectangle 3. Alpha - outcome depends on alpha of the fragment 4. Stencil - outcome depends on value in stencil buffer 5. Depth - outcome depends on depth of fragment 6. Blending - outcome depends on fragment color 7. Dithering - not customizable by applications 8. Logical operations - outcome depends on color of fragment
  • 16.
    Per-Fragment Operation -usually configurable but not programmable
  • 17.
    The ultimate goalof the Vertex Shader is to provide the final transformation of the mesh vertices to the rendering pipeline. Vertex Shader
  • 18.
  • 19.
    The goal ofthe Fragment shader is to provide Coloring and Texture data to each pixel heading to the framebuffer. A framebuffer is a bitmap that is used to refresh a display from a memory buffer containing a complete frame of data. Fragment/Pixel Shader
  • 20.
  • 21.
    MSAA - eachpixel at the edge of a polygon is sampled multiple times. For each sample-pass, a slight offset is applied to all screen coordinates.