docs.unity3d.com
    Show / Hide Table of Contents

    Normal From Height Node

    Description

    Creates a normal map from a height value defined by input Input with a strength defined by input Strength.

    Ports

    Name Direction Type Description
    In Input Float Input height value
    Strength Input Float The strength of the output normal. Considered in real-world units, recommended range is 0 - 0.1 .
    Out Output Vector 3 Output value

    Controls

    Name Type Options Description
    Output Space Dropdown Tangent, World Sets the coordinate space of the output normal.

    Generated Code Example

    The following example code represents one possible outcome of this node per Output Space mode.

    Tangent

    void Unity_NormalFromHeight_Tangent_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out)
    {
        float3 worldDerivativeX = ddx(Position);
        float3 worldDerivativeY = ddy(Position);
    
        float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX);
        float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz);
        float d = dot(worldDerivativeX, crossY);
        float sgn = d < 0.0 ? (-1.0f) : 1.0f;
        float surface = sgn / max(0.000000000000001192093f, abs(d));
    
        float dHdx = ddx(In);
        float dHdy = ddy(In);
        float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX);
        Out = normalize(TangentMatrix[2].xyz - (Strength * surfGrad));
        Out = TransformWorldToTangent(Out, TangentMatrix);
    }
    

    World

    void Unity_NormalFromHeight_World_float(float In, float Strength, float3 Position, float3x3 TangentMatrix, out float3 Out)
    {
        float3 worldDerivativeX = ddx(Position);
        float3 worldDerivativeY = ddy(Position);
    
        float3 crossX = cross(TangentMatrix[2].xyz, worldDerivativeX);
        float3 crossY = cross(worldDerivativeY, TangentMatrix[2].xyz);
        float d = dot(worldDerivativeX, crossY);
        float sgn = d < 0.0 ? (-1.0f) : 1.0f;
        float surface = sgn / max(0.000000000000001192093f, abs(d));
    
        float dHdx = ddx(In);
        float dHdy = ddy(In);
        float3 surfGrad = surface * (dHdx*crossY + dHdy*crossX);
        Out = normalize(TangentMatrix[2].xyz - (Strength * surfGrad));
    }
    
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023