docs.unity3d.com
    Show / Hide Table of Contents

    Rounded Rectangle Node

    Description

    Generates a rounded rectangle shape based on input UV at the size specified by inputs Width and Height. The radius of each corner is defined by input Radius. The generated shape can be offset or tiled by connecting a Tiling And Offset Node. Note that in order to preserve the ability to offset the shape within the UV space the shape will not automatically repeat if tiled. To achieve a repeating rounded rectangle effect first connect your input through a Fraction Node.

    NOTE: This Node can only be used in the Fragment Shader Stage.

    Ports

    Name Direction Type Binding Description
    UV Input Vector 2 UV Input UV value
    Width Input Float None Rounded Rectangle width
    Height Input Float None Rounded Rectangle height
    Radius Input Float None Corner radius
    Out Output Float None Output value

    Generated Code Example

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

    void Unity_RoundedRectangle_float(float2 UV, float Width, float Height, float Radius, out float Out)
    {
        Radius = max(min(min(abs(Radius * 2), abs(Width)), abs(Height)), 1e-5);
        float2 uv = abs(UV * 2 - 1) - float2(Width, Height) + Radius;
        float d = length(max(0, uv)) / Radius;
        Out = saturate((1 - d) / fwidth(d));
    }
    
    In This Article
    • Description
    • Ports
    • Generated Code Example
    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