shaderlab

  • Syntax

    Properties { Property [ Property ...] }
    Defines the property block. Inside braces multiple properties are defined as follows.
    name (" display name", Range ( min, max)) = number
    Defines a float property, represented as a slider from min to maxin the inspector.
    name (" display name", Color) = ( number, number, number, number)
    Defines a color property.
    name (" display name", 2D) = " name" { options}
    Defines a 2D texture property.
    name (" display name", Rect) = " name" { options}
    Defines a rectangle (non power of 2) texture property.
    name (" display name", Cube) = " name" { options}
    Defines a cubemap texture property.
    name (" display name", Float) = number
    Defines a float property.
    name (" display name", Vector) = ( number, number, number, number)
    Defines a four component vector property.
  • Syntax

    Subshader { [ Tags] [ CommonState] Passdef [ Passdef ...] }
  • ShaderLab syntax: Pass

    The Pass block causes the geometry of an object to be rendered once.

    Syntax

    Pass { [Name and Tags] [RenderSetup] [TextureSetup] }
    The 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 its Name and arbitrary number of Tags - name/value strings that communicate Pass' intent to the rendering engine.

    Render Setup

    A pass sets up various states of the graphics hardware, for example should alpha blending be turned on, should fog be used, and so on. The commands are these:

    Material { Material Block }
    Defines a material to use in a vertex lighting pipeline. See material pagefor details.
    LightingOn | Off
    Turn vertex lighting on or off. See material pagefor details.
    CullBack | Front | Off
    Set polygon culling mode.
    ZTest(Less | Greater | LEqual | GEqual | Equal | NotEqual | Always)
    Set depth testing mode.
    ZWriteOn | 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 mode.
    Color Color value
    Sets color to use if vertex lighting is turned off.
    ColorMaskRGB | A | 0 | any combination of R, G, B, A
    Set color writing mask. Writing ColorMask 0turns off rendering to all color channels.
    Offset OffsetFactor , OffsetUnits
    Set depth offset.
    SeparateSpecularOn | Off
    Turns separate specular color for vertex lighting on or off. See material pagefor details.
    ColorMaterialAmbientAndDiffuse | Emission
    Uses per-vertex color when computing vertex lighting. See material page for details.

    Texture Setup

    After the render state setup, you can 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 fragment shaders are used.

    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 light affecting the object in a separate additive pass. See Render Pipeline for details.

    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 block, ColorMaterial and SeparateSpecular commands. See material page for details.

  • -----------------------------------------------------------------------------------------------
  • Syntax

    The top level commands control whether to use fixed function lighting or not, and some configuration options. The main setup is in the Material Block, detailed further below.

    Color Color
    Sets the object to a solid color. A color is either four RGBA values in parenthesis, or a color property name in square brackets.
    Material { Material Block }
    The Material block is used to define the material properties of the object.
    LightingOn | Off
    For the settings defined in the Material block to have any effect, you must enable Lighting with the Lighting On command. If lighting is off instead, the color is taken straight from the Colorcommand.
    SeparateSpecularOn | Off
    This command makes specular lighting be added to the end of the shader pass, so specular lighting is unaffected by texturing. Only has effect when Lighting Onis used.
    ColorMaterialAmbientAndDiffuse | Emission
    makes per-vertex color be used instead of the colors set in the material. AmbientAndDiffuse replaces Ambient and Diffuse values of the material; Emission replaces Emission value of the material.

    Material Block

    This contains settings for how the material reacts to the light. Any of these properties can be left out, in which case they default to black (i.e. have no effect).

    Diffuse Color
    The diffuse color component. This is an 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.

    The full color of lights hitting the object is:

      Ambient * RenderSettings ambient setting +
    
      (Light Color * Diffuse + Light Color * Specular) + Emission
    
    

    The light parts of the equation (within parenthesis) is repeated for all lights that hit the object.

    Typically you want to keep the Diffuse and Ambient colors the same (all builtin Unity shaders do this).

  • ----------------------------------------------------------------------------------------------------------------

  • Syntax

    CullBack | Front | Off
    Controls which sides of polygons should be culled (not drawn)
    Back Don't render polygons facing away from the viewer (default).
    Front Don't render polygons facing towards the viewer. Used for turning objects inside-out.
    Off Disables culling - all faces are drawn. Used for special effects.
    ZWriteOn | Off
    Controls whether pixels from this object are written to the depth buffer (default is On). If you're drawng solid objects, leave this on. If you're drawing semitransparent effects, switch to ZWrite Off. For more details read below.
    ZTestLess | Greater | LEqual | GEqual | Equal | NotEqual | Always
    How should depth testing be performed. Default is LEqual(draw objects in from or at the distance as existing objects; hide objects behind them).
    Offset Factor , Units
    Allows you specify a depth offset with two parameters. factor and units. Factor scales the maximum Z slope, with respect to X or Y of the polygon, and units scale the minimum resolvable depth buffer value. This allows you to force one polygon to be drawn on top of another although they are actually in the same position. For example Offset 0, -1 pulls the polygon closer to the camera ignoring the polygon's slope, whereas Offset -1, -1 will pull the polygon even closer when looking at a grazing angle
     ----------------------------------------------------------------------------------------------------------
  • float4 vertexis the vertex position
  • float3 normalis the vertex normal
  • float4 texcoordis the first UV coordinate
  • float4 texcoord1is the second UV coordinate
  • float4 tangentis the tangent vector (used for normal mapping)
  • float4 color is per-vertex color
  • appdata_base: vertex consists of position, normal and one texture coordinate.
  • appdata_tan: vertex consists of position, tangent, normal and one texture coordinate.
  • Built-in matrices

    Matrices (float4x4) supported:

    UNITY_MATRIX_MVP
    Current model*view*projection matrix
    UNITY_MATRIX_MV
    Current model*view matrix
    UNITY_MATRIX_P
    Current projection matrix
    UNITY_MATRIX_T_MV
    Transpose of model*view matrix
    UNITY_MATRIX_IT_MV
    Inverse transpose of model*view matrix
    UNITY_MATRIX_TEXTURE0 to UNITY_MATRIX_TEXTURE3
    Texture transformation matrices

    Built-in vectors

    Vectors (float4) supported:

    UNITY_LIGHTMODEL_AMBIENT
    Current ambient color.

你可能感兴趣的:(sha)