一:标准库里的常用.cginc文件
HLSLSupport.cginc-(automatically included)Helper macros and definitions for cross-platform shader compilation.
HLSLSupport.cginc :(自动包含)跨平台着色器编译帮助宏和定义
UnityCG.cginc- commonly used global variables and helper functions.
UnityCG.cginc :常用的全局变量和辅助函数
AutoLight.cginc- lighting & shadowing functionality, e.g.surface shadersuse this file internally.
AutoLight.cginc :灯光和阴影功能,例如surface shaders 内在地使用此文件。
Lighting.cginc- standardsurface shaderlighting models; automatically included when you're writing surface shaders.
Lighting.cginc :标准surface shader 灯光模型,当你写表面着色器时自动包含。
TerrainEngine.cginc- helper functions for Terrain & Vegetation shaders.
TerrainEngine.cginc : 地形和植被着色器的辅助函数。
二:辅助函数
Generic helper functions in UnityCG.cginc 在UnityCG.cginc中的通用辅助函数
float3 WorldSpaceViewDir (float4 v)- returns world space direction (not normalized) from given object space vertex position towards the camera.
float3 WorldSpaceViewDir (float4 v):根据给定的局部空间顶点位置到相机返回世界空间的方向(非规范化的)
float3 ObjSpaceViewDir (float4 v)- returns object space direction (not normalized) from given object space vertex position towards the camera.
float3 ObjSpaceViewDir (float4 v):根据给定的局部空间顶点位置到相机返回局部空间的方向(非规范化的)
float2 ParallaxOffset (half h, half height, half3 viewDir)- calculates UV offset for parallax normal mapping.
float2 ParallaxOffset (half h, half height, half3 viewDir):为视差法线贴图计算UV偏移
fixed Luminance (fixed3 c)- converts color to luminance (grayscale).
fixed Luminance (fixed3 c):将颜色转换为亮度(灰度)
fixed3 DecodeLightmap (fixed4 color)- decodes color from Unity lightmap (RGBM or dLDR depending on platform).
fixed3 DecodeLightmap (fixed4 color):从Unity光照贴图解码颜色(基于平台为RGBM 或dLDR)
float4 EncodeFloatRGBA (float v)- encodes [0..1) range float into RGBA color, for storage in low precision render target.
float4 EncodeFloatRGBA (float v):为储存低精度的渲染目标,编码[0..1)范围的浮点数到RGBA颜色。
float DecodeFloatRGBA (float4 enc)- decodes RGBA color into a float.
float DecodeFloatRGBA (float4 enc):解码RGBA颜色到float。
Similarly,float2 EncodeFloatRG (float v)andfloat DecodeFloatRG (float2 enc)that use two color channels.
同样的,float2 EncodeFloatRG (float v) 和float DecodeFloatRG (float2 enc)使用的是两个颜色通道。
float2 EncodeViewNormalStereo (float3 n)- encodes view space normal into two numbers in 0..1 range.
float2 EncodeViewNormalStereo (float3 n):编码视图空间法线到在0到1范围的两个数。
float3 DecodeViewNormalStereo (float4 enc4)- decodes view space normal from enc4.xy.
float3 DecodeViewNormalStereo (float4 enc4):从enc4.xy解码视图空间法线
Forward rendering helper functions in UnityCG.cginc
UnityCG.cginc正向渲染辅助函数
These functions are only useful when using forward rendering (ForwardBase or ForwardAdd pass types).
这些函数只有当使用forward rendering(ForwardBase 或 ForwardAdd通道类型)时才有效。
float3 WorldSpaceLightDir (float4 v)- computes world space direction (not normalized) to light, given object space vertex position.
根据局部空间顶点位置计算世界空间灯光方向(非规范化的)。
float3 ObjSpaceLightDir (float4 v)- computes object space direction (not normalized) to light, given object space vertex position.
根据局部空间顶点位置计算局部空间灯光方向(非规范化的)。
float3 Shade4PointLights (...)- computes illumination from four point lights, with light data tightly packed into vectors. Forward rendering uses this to compute per-vertex lighting.
从4个点光源计算亮度,来将光照数据牢固的装入向量中。正向渲染使用此来计算逐顶点光照。
Vertex-lit helper functions in UnityCG.cginc
UnityCG.cginc中的顶点光照辅助函数
These functions are only useful when using per-vertex lit shaders ("Vertex" pass type).
这些函数只在当使用逐顶点光照着色器(“顶点”通道类型)时才有效。
float3 ShadeVertexLights (float4 vertex, float3 normal)- computes illumination from four per-vertex lights and ambient, given object space position & normal.
根据局部空间位置和法线,从4个逐顶点灯光和环境光计算亮度。
三:内置变量http://docs.unity3d.com/Manual/SL-UnityShaderVariables.html
unity_SpecCube0,unity_SpecCube0_HDRfrom thebuilt-in shader variables. unity_SpecCube0 contains data for the active reflection probe. //unity_SpecCube0包含了现在激活的反射探头, unity_SpecCube0_HDR是其HDR颜色数据。