Unity Shader (2)

1, to take the name shader, can be inserted in order to facilitate management '/' separator in the name to a MenuItem layered with meaning.

Shader "NewMenu/colorMaterialShader" {}

2, Properties (Properties) is in communication with the media Shader material, which is an optional attribute

Properties

{

    Name ("display name", PropertyType) = DefaultValue

    ......

}

Name is used in the code, display name attribute editor panel display is used, PropertyType data type

 For Int, Float, Range (min, max) for both types of numeric attributes; for Color, Vector composite digital these types of properties, a default value surrounded by parentheses; 2D, Default Cube, 3D textures of these types of usually a string followed by a brace, the string is either empty or is the name of a built-textured, curly braces specify some texture attributes apply to these contents are removed after Unity 5.0.

 

3, SubShader is implemented a set of code blocks to achieve the effect provided for a different environment, SubShader group is a meaning. When Unity to load the shader, will start from scratch through all SubShader group Pass, select the first code to successfully execute on the target platform (hardware support) to achieve, we will not use Fallback (this is a spare tire ah).

SubShader

{

    [Tag]

    [RenderSetup]

    Pass {}

    Pass {}

    ......

}

RenderSetup some rendering pipeline state setting instruction, the same applies to all blocks Pass SubShader a group, when the Pass is to distinguish between the need to set these in the respective Pass, culling, depth testing, mixing and the like

Tags are key-value pairs arranged rendering, rendering forward, like the control rendering order

4, Pass is a specific goal of rendering, Pass can UsePass "Shader_Name / Pass_Name" is called (Unity will Pass internal names are converted to uppercase) by the other shader

Pass

{

   [Name]

   [Tags]

   [RenderSetup]

   ......//imp code

}

Like RenderSetup in the SubShader

Tags are also set to render relevant content

5, FallBack "Shader_Name" indicated when other codes can not be used to achieve the effect, this is the last choice, but this can not spare tire  FallBack Off

 

6, Unity Shader said the public is not OpenGL, Shader on the DirectX sense, since the jurisdiction of the Unity Shader include a set number of rendering state, but also hides a lot of details on the implementation, but also for segments such as shaders, geometry shader support is not enough.

 

7, GL / HLSL, GLSL ShaderLab can be embedded, it is necessary nested CGPROGRAM, ENDCG and GLSLPROGRAM, between ENDGLSL

Pass

{

    ...... // set the content of the rendering state, tags, etc.

    CGPROGRAM

    #pragram vertex vert

    #pragram fragment frag

    ......

    ENDCG

    ...... // write some of the other content

}

 

8, Unity Shader there is a unique shader type, surface shader (Surface Shader ), its main function is to hide the details of implementation of many lighting convenience we use light. The other two are the vertices (vertex shader) and the fragment (fragment shader) shader.

 

Guess you like

Origin www.cnblogs.com/haihuahuang/p/12507165.html