Unity 內置Shader變量、輔助函數等


一:標准庫里的常用.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 shaders use this file internally. 
      AutoLight.cginc :燈光和陰影功能,例如surface shaders 內在地使用此文件。
    • Lighting.cginc - standard surface shader lighting 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) and float 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_SpecCube0unity_SpecCube0_HDR from the built-in shader variables. unity_SpecCube0 contains data for the active reflection probe. //unity_SpecCube0包含了現在激活的反射探頭, unity_SpecCube0_HDR是其HDR顏色數據。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM