Wednesday, April 25, 2012

ShaderLab Day(2) (Passes)



Day 2 learning all of this stuff, just as a recap of what I did the yesterday

I have learned about Properties and how they should be implemented.
Syntax
Properties
{
     Available parameters
     Float, Color, Vector, Range, 2D, Cube, and Rect
}
Subshaders are essentially used for rendering and it is required for the graphics card to read all of passes that make the shader what it is.

OKAY so new lesson today..

PASSES
The Pass block causes the geometry of an object to be rendered once.
Syntax:
  • Pass
    {
         [Name and Tags] Reference: Name and PassTags
         [RenderSetup]
         [TextureSetup]
    }
This basic pass command contains an optional list of render setup commands, optionally followed by a list of textures to use

Name and Tags:
A pass can define it's Name and arbitrary number of pass tags - name/value strings that communicate Pass intent to the rendering engine

Render Set up
A pass sets up various states of the graphics hardware, for example
Should alpha blending be turned on?
Should fog be used?
Here are the possible components that can be used:
  • Material { Material Block }
    Defines a material to use in a vertex lighting pipeline. 
    • Materials include:
      • Diffuse Color
        Object's base color
      • Ambient Color
        The ambient color component. This is the color the object has when it's hit by the ambient light set in the RenderSettings!
      • Specular color
        The color of the object's specular highlight
      • Shininess Number
        The sharpness of the highlight, between 0 and 1. At 0 you get a huge highlight that looks a lot like diffuse lighting, at 1 you get a tiny speck.
      • Emission Color
        The color of the object when it is not hit by any light
    • Examples can be found here  Materials
  • Lighting ON | OFF
    Turn vertex lighting on or off. 
    Reference: Materials
  • Cull Back | Font | Off
    Set polygon culling mode.
  • ZTest ( Less | Greater | LEqual | GEqual | Equal | NotEqual | Always)
    Set depth testing mode
  • ZWrite ON | OFF
    Set depth writing mode.
  • Fog { Fog Block}
    Set fog parameters.
  • AlphaTest  ( Less | Greater | LEqual | GEqual | Equal | NotEqual | Always CutoffValue
    Turns on alpha testing.
  • Blend SourceBlendMode DestBlendMode
    Sets alpha blending modes:
    SourceBlendMode
    DestBlendMode
  • Color Color value
    Sets color to use if vertex lighting is turned off
  • ColorMask RGB | A | 0 | any combination of R, G, B, A
    Set color writing mask, Writing ColorMask 0 turns off rendering to all color channels
  • Offset OffsetFactor, Offset Units
    Set depth offset. Note that this command intentionally only accepts constrants
    (Not really sure what this does yet... )
  • SeparateSpecular ON | OFF
    Turns separate specular color for vertex lighting on or off 
  • ColorMaterial AmbiendAndDiffuse | Emission 
Texture Setup
After the render state setup, we want to specify a number of textures and their combining modes to apply using SetTexture commands:

SetTexture 
texture property {[combine options]}
The texture setup configures fixed function multitexturing pipeline, and is ignored if custom fragmend shaders are used. Reference: Custom Fragment Shaders


Details:
Per-pixel Lighting
The per-pixel lighting pipeline works by rendering objects in multiple passes. Unity renders the object once to get ambient and any vertex lights in. Then it renders each pixel lighting affecting object in a separate addictive pass. Reference: Rendering Pilepine



Per-vertex Lighting
Per-vertex lighting is the standard Direct3D/OpenGL lighting model that is computed for each vertex. Lighting On turns it on. Lighting is affected by Material ColorMaterial and SeparateSpecular commands.


There are other variations of passes that are similar to the Pass command but different.


UsePass
The UsePass command uses named passes from another shader.
Syntax
UsePass "Shader/Name"
This inserts all passes with a given name from a given shader. Shader/Name contains the name of the shader and the name of the pass, separated by a slash character


Some of the shaders could reuse existing passes from other shaders, reducing code duplication. For example, in most pixel lit shaders the ambient or vertex lighting passes are the same as in the corresponding VertexLit shaders. The UsePass command includes a given pass from another shader.
Example:
UsePass "Specular/BASE"

Name "MyPassName"


No comments:

Post a Comment