Unity内置的shader include files

Unity内置的shader include files:这些文件都以.cninc结尾,
  HLSLSupport.cginc:自动包含,一些跨平台编译相关的宏和定义。

  UnityShaderVariables.cginc:自动包含,常用的全局变量。
  UnityCG.cginc:常用的全局变量和函数。
  AutoLight.cginc:光影相关帮助函数,surface shader内部使用此文件。
  Lighting.cginc:surface shader自动包含,定义了标准的光照模式。
  TerrainEngin.cginc:地形和植被shader相关的帮助函数。

UnityGC.cginc数据结构:
  appdata_base / appdata_tan / appdata_full / appdata_img

UnityGC.cginc通用帮助函数:
  float3 WorldSpaceViewDir (float4 v):
  返回从顶点位置到camera位置的世界空间(world space)的朝向,not normailzed。
  参数v:object space vertex position,即顶点的局部空间坐标。
  float3 ObjSpaceViewDir (float4 v):
  返回从顶点位置到camera位置的局部空间(object space)的朝向,not normailzed。
  参数v:object space vertex position,即顶点的局部空间坐标。
  float2 ParallaxOffset (half h, half height, half3 viewDir):
  parallax normal mapping时计算UV offset。
  fixed Luminance (fixed3 c):
  颜色转换亮度(灰度)。

  // Converts color to luminance (grayscale)
  inline fixed Luminance( fixed3 c )
  {
    return dot( c, fixed3(0.22, 0.707, 0.071) );
  }

  fixed3 DecodeLightmap (fixed4 color):
  解码lightmap颜色值,根据不同平台返回RGBM或dLDR。
  float4 EncodeFloatRGBA (float v)/float DecodeFloatRGBA (float4 enc):
  编码/解码[0, 1)float <--> 8bit/channel RGBA,注意1.0的编解码会有问题。
  EncodeFloatRG (float v)/DecodeFloatRG (float2 enc):
  编码/解码[0.0,1.0)float <--> 8bit/channel RG,注意1.0的编解码会有问题。
  float2 EncodeViewNormalStereo (float3 n):
  float3 DecodeViewNormalStereo (float4 enc4):
  编码/解码view space noramls <--> 2D 0..1 vector
  Decode函数是对nec4.xy进行解码。

UnityGC.cginc前向渲染帮助函数:(只有在前向渲染时有用,ForwardBase或ForwardAdd pass types)
  float3 WorldSpaceLightDir (float4 v):
  计算world空间光照方向,从顶点位置到光源位置,not normalized。
  float3 ObjSpaceLightDir (float4 v):
  计算object空间光照方向,从顶点位置到光源位置,not normalized。
  float3 Shade4PointLights (...):
  计算四个点光源的光照,前向渲染中会使用此函数来计算逐顶点光照。

UnityGC.cginc和vertex-lit相关的帮助函数:(只有在使用per-vertex lit时有用,Vertex pass types)
  float3 ShadeVertexLights (float4 vertex, float3 normal):
  计算顶点光照,来自4个per-vertex light和ambient。
  参数vertex和normal:局部空间的位置和法线。

UNITY_INITIALIZE_OUTPUT(Input,o);
  初始化输入参数,全部置为0
  #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;

 

posted @ 2015-08-08 23:56  斯芬克斯  阅读(1922)  评论(0编辑  收藏  举报