docs.unity3d.com
    目次を表示する/隠す

    Rounded Polygon ノード

    説明

    入力 UV に基づいて、入力 Width および Height に指定されたサイズの、角を丸めたポリゴン形状を生成します。入力 Sides は辺の数を指定し、入力 Roundness は各角の丸みを指定します。

    Tiling And Offset ノード を接続すると、生成された形状のオフセットやタイル化が可能です。UV 空間内でのシェイプのオフセット機能を維持するため、タイル化の際にシェイプは自動的に反復されないようになっています。角を丸めたポリゴンの反復効果を作り出すには、まず Fraction ノード を使って入力を接続してください。

    Rounded Polygon ノードは、Fragment (フラグメント) シェーダーステージ でのみ使用可能です。

    ポート

    Name Direction タイプ バインディング 説明
    UV 入力 Vector 2 UV 入力 UV 値
    Width 入力 Vector 1 なし 角を丸めたポリゴンの幅
    Height 入力 Vector 1 なし 角を丸めたポリゴンの高さ
    Sides 入力 Vector 1 なし ポリゴンの辺の数
    Roundness 入力 Vector 1 なし 角の丸み
    Out 出力 Vector 1 なし 出力値

    生成されるコードの例

    以下のサンプルコードは、このノードの出力の一例を示したものです。

    void RoundedPolygon_Func_float(float2 UV, float Width, float Height, float Sides, float Roundness, out float Out)
    {
        UV = UV * 2. + float2(-1.,-1.);
        float epsilon = 1e-6;
        UV.x = UV.x / ( Width + (Width==0)*epsilon);
        UV.y = UV.y / ( Height + (Height==0)*epsilon);
        Roundness = clamp(Roundness, 1e-6, 1.);
        float i_sides = floor( abs( Sides ) );
        float fullAngle = 2. * PI / i_sides;
        float halfAngle = fullAngle / 2.;
        float opositeAngle = HALF_PI - halfAngle;
        float diagonal = 1. / cos( halfAngle );
        // 面取りの値
        float chamferAngle = Roundness * halfAngle; // 面取りの角度
        float remainingAngle = halfAngle - chamferAngle; // 残る角度
        float ratio = tan(remainingAngle) / tan(halfAngle); // これは、ポリゴンの三角形の長さと、面取りの中心からポリゴンの中心までの距離の比率です
        // 面取りの弧の中心
        float2 chamferCenter = float2(
            cos(halfAngle) ,
            sin(halfAngle)
        )* ratio * diagonal;
        // 面取りの弧の開始点
        float2 chamferOrigin = float2(
            1.,
            tan(remainingAngle)
        );
        // アル・カーシーの代数学を使用して以下を特定します:
        // 面取りの中心からポリゴンの中心までの距離 (辺 A)
        float distA = length(chamferCenter);
        // 面取りの半径 (辺 B)
        float distB = 1. - chamferCenter.x;
        // 辺 C の基準長さ (つまり面取りの開始点までの距離)
        float distCref = length(chamferOrigin);
        // これにより、面取りされたポリゴンが、UV 空間に合わせてスケーリングされます
        // diagonal = length(chamferCenter) + distB;
        float uvScale = diagonal;
        UV *= uvScale;
        float2 polaruv = float2 (
            atan2( UV.y, UV.x ),
            length(UV)
        );
        polaruv.x += HALF_PI + 2*PI;
        polaruv.x = fmod( polaruv.x + halfAngle, fullAngle );
        polaruv.x = abs(polaruv.x - halfAngle);
        UV = float2( cos(polaruv.x), sin(polaruv.x) ) * polaruv.y;
        // アル・カーシーの代数学に必要とされる角度を計算します
        float angleRatio = 1. - (polaruv.x-remainingAngle) / chamferAngle;
        // ポリゴンの中心から面取りの端までの距離を計算します
        float distC = sqrt( distA*distA + distB*distB - 2.*distA*distB*cos( PI - halfAngle * angleRatio ) );
        Out = UV.x;
        float chamferZone = ( halfAngle - polaruv.x ) < chamferAngle;
        Out = lerp( UV.x, polaruv.y / distC, chamferZone );
        // この出力は、距離フィールドではなくその形状のマスクを作成します
        Out = saturate((1 - Out) / fwidth(Out));
    }
    
    トップに戻る
    Copyright © 2023 Unity Technologies — 商標と利用規約
    • 法律関連
    • プライバシーポリシー
    • クッキー
    • 私の個人情報を販売または共有しない
    • Your Privacy Choices (Cookie Settings)