CG Clips
CG Program fragment write between Cgprogram and ENDCG
Fragments at the beginning can be compiled as #pragma statements
Pass { //... the usual pass state setup ... Cgprogram //compilation directives for this snippet, e.g.: #pragma vertex vert #pragma fragment Frag // The CG/HLSL code itself ENDCG //... the rest of the pass setup ... } Http://i.cnblogs.com/EditPosts.aspx?opt=1
#pragma vertex name----------------compilation vertex shader for a function named by name
#pragma fragment name------------compilation fragment shader for a function with name
#pragma Geometry name------------compilation DX10 Geometry shader shader
#pragma hull name-----------------compiling DX11 hull material
#pragma domain name-------------compiling DX11 field material
Other compilation directives
#pragma target name--------------compile the destination shader
Shader #pragma only_renderers space separated names-------------compiled by default shader compiles all renderers
#pragma exclude_renderers space separated names shader does not compile by default shader compiles all renderers
#pragma multi_compile names--------------------------------for multiple materials
Each fragment must contain at least one vertex program and one fragment program. So # pragma vertices and # pragma fragment directives are required.
Shader Target
by default, Unity compiles shaders into approximately equal to 2.0 material models #pragma target 2.0 (default)---- Shading Model 2.0 Direct3D 9--- ----limited arithmetic and material descriptions, no vertex texture sampling, no derivatives in fragment shaders
#pragma target 3.0--------------compiling a Shading Model 3.0
#pragma target 4.0-------------- compiling DX10 Shader Model 4.0 This goal currently only supports DirectX 11 and XBOXONE/PS4 platforms
#pragma target 5.0-------------- compiling DX10 Shader model 5.0 This goal currently only supports DirectX 11 and XBOXONE/PS4 platforms
All Opengl-like platforms (including mobile phones) are considered to be "shaded model 3.0" capabilities. The WP8/WINRT platform (DX11 feature Level 9. x) is considered to be only capable of coloring Model 2.0.
Render Platform
Unity supports a variety of rendering APIs (such as Direct3D 9 and OpenGL), and by default all shader programs are compiled into all supported renderers. You can point out the shader that needs to be compiled by #pragma only_renderers or #pragma exclude_ renderers directive
This is primarily useful in this case, you are explicitly using some material language features on some platforms that you know are impossible on some platforms
- D3d9 -Direct3D 9.
- D3d11 -Direct3D 11.
- OpenGL -OpenGL.
- gles -OpenGL ES 2.0.
- gles3 -OpenGL ES 3.0.
- Metal -IOS metal.
- d3d11_9x -Direct3D 9.x feature level, as commonly used on WSA/WP8 platforms.
- Xbox360 -Xbox 360.
- Xboxone -Xbox One.
- PS3 -PlayStation 3.
- PS4 -PlayStation 4.
- psp2 -PlayStation Vita.
For example, this line will only compile the material to D3D 9 mode:
- D3d9-direct3d 9.
- D3d11-direct3d 11.
- Opengl-opengl.
- Gles-opengl ES 2.0.
- Gles3-opengl ES 3.0.
- Metal-ios Metal.
- D3d11_9x-direct3d 9.x feature level, as commonly used on WSA/WP8 platforms.
- Xbox360-xbox 360.
- Xboxone-xbox one.
- Ps3-playstation 3.
- Ps4-playstation 4.
- Psp2-playstation Vita.
Unity CG Vertex and fragment shaders (i)