Unity built-in shader variables, auxiliary functions, etc.

Source: Internet
Author: User

One: Commonly used. cginc files in the standard library

    • HLSLSupport.cginc- (automatically included) Helper macros and definitions for Cross-platform shader compilation.
      Hlslsupport.cginc: (automatically included) cross-platform shader compilation help macros and definitions
    • UnityCG.cginc-Commonly used global variables and helper functions.
      Unitycg.cginc: Common global variables and auxiliary functions
    • AutoLight.cginc-Lighting & shadowing functionality, e.g. surface shaders use this file internally.
      Autolight.cginc: Lighting and shading features, such as surface shaders, use this file internally.
    • Lighting.cginc-Standard surface shader lighting models; Automatically included when you ' re writing surface shaders.
      Lighting.cginc: Standard surface shader light model that is automatically included when you write a surface shader.
    • TerrainEngine.cginc-Helper functions for Terrain & vegetation shaders.
      TERRAINENGINE.CGINC: Auxiliary functions for terrain and vegetation shaders.

Second: auxiliary function

Generic helper functions in Unitycg.cginc General helper function in 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): The direction (denormalized) of the camera's return to world space based on the given local space vertex position
    • float3 ObjSpaceViewDir (float4 v)-Returns object space direction (not normalized) from given object space vertex position towards the camera.
      FLOAT3 Objspaceviewdir (Float4 v): The direction of the camera's return to the local space (denormalized) based on the given local space vertex position
    • float2 ParallaxOffset (half h, half height, half3 viewDir)-Calculates UV offset for parallax normal mapping.
      Float2 Parallaxoffset (half h, half height, half3 viewdir): Calculate UV offsets for parallax normal maps
    • fixed Luminance (fixed3 c)-Converts color to luminance (grayscale).
      Fixed luminance (fixed3 C): Convert color to brightness (grayscale)
    • fixed3 DecodeLightmap (fixed4 color)-Decodes color from Unity lightmap (RGBM or Dldr depending on platform).
      Fixed3 decodelightmap (fixed4 color): Decode colors from Unity Illumination Map (platform-based RGBM or DLDR)
    • float4 EncodeFloatRGBA (float v)-encodes [0..1) range float into RGBA color, for storage with low precision render target.
      Float4 Encodefloatrgba (float v): For storing low-precision render targets, encode the [0..1] range of floating-point numbers to the RGBA color.
    • float DecodeFloatRGBA (float4 enc)-Decodes RGBA color into a float.
      Float Decodefloatrgba (float4 enc): Decodes the Rgba color to float.
    • Similarly, and that use both float2 EncodeFloatRG (float v) float DecodeFloatRG (float2 enc) color channels.
      Similarly, Float2 ENCODEFLOATRG (float v) and float DECODEFLOATRG (FLOAT2 enc) use two color channels.
    • float2 EncodeViewNormalStereo (float3 n)-Encodes view space normal into double numbers in 0..1 range.
      Float2 Encodeviewnormalstereo (float3 N): Encodes the view space normals to two numbers in the range 0 to 1.
    • float3 DecodeViewNormalStereo (float4 enc4)-Decodes view space normal from Enc4.xy.
      FLOAT3 Decodeviewnormalstereo (float4 enc4): Decode view space normals from Enc4.xy
Forward Rendering helper functions in Unitycg.cginc
Unitycg.cginc Forward Rendering helper function

These functions is only useful when using forward rendering (forwardbase or Forwardadd pass types).

These functions are valid only if you are using forward rendering (Forwardbase or Forwardadd channel types).

      • float3 WorldSpaceLightDir (float4 v)-Computes world space direction (not normalized) to light, given object space vertex position.
        Calculates the World Space Light Direction (denormalized) based on the local space vertex position.
      • float3 ObjSpaceLightDir (float4 v)-Computes object space direction (not normalized) to light, given object space vertex position.
        Calculates the local space light direction (non-normalized) based on the local 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.
        Calculates the brightness from 4 point light sources to securely load the light data into the vector. Forward rendering uses this to calculate per-vertex lighting.
Vertex-lit helper functions in Unitycg.cginc
The Vertex illumination helper function in Unitycg.cginc

These functions is only useful when using Per-vertex lit shaders ("vertex" pass type).

These functions are only valid when using the vertex-per-vertex illumination shader (the vertices channel type).

      • float3 ShadeVertexLights (float4 vertex, float3 normal)-computes illumination from four per-vertex lights and ambient, given object space position & normal.
        Calculates the brightness from 4 vertex-wise lights and ambient light based on the local space position and normals.

Three: Built-in variable http://docs.unity3d.com/Manual/SL-UnityShaderVariables.html

Unity built-in shader variables, auxiliary functions, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.