Normal From Texture Node | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Normal From Texture Node

    Description

    Converts a height map defined by input Texture into a normal map. UV values and sampler state can be defined by inputs UV and Sampler respectively. If nothing is connected to these ports they will use default values from the inputs. See Port Bindings for more information.

    The strength of the created normal map can be defined by inputs Offset and Strength, where Offset defines the maximum distance of a normal detail and Strength acts as a multiplier to the result.

    Ports

    Name Direction Type Binding Description
    Texture Input Texture None Height map
    UV Input Vector 2 UV Texture coordinates
    Sampler Input Sampler State None Sampler for Texture
    Offset Input Vector 1 None Amount to offset samples
    Strength Input Vector 1 None Strength multiplier
    Out Output Vector 3 None Output value

    Generated Code Example

    The following example code represents one possible outcome of this node.

    void Unity_NormalFromTexture_float(Texture texture, SamplerState Sampler, float2 UV, float Offset, float Strength, out float3 Out)
    {
        Offset = pow(Offset, 3) * 0.1;
        float2 offsetU = float2(UV.x + Offset, UV.y);
        float2 offsetV = float2(UV.x, UV.y + Offset);
        float normalSample = Texture.Sample(Sampler, UV);
        float uSample = Texture.Sample(Sampler, offsetU);
        float vSample = Texture.Sample(Sampler, offsetV);
        float3 va = float3(1, 0, (uSample - normalSample) * Strength);
        float3 vb = float3(0, 1, (vSample - normalSample) * Strength);
        Out = normalize(cross(va, vb));
    }
    
    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