当前位置:网站首页>Use partial derivatives to display normals in unity

Use partial derivatives to display normals in unity

2022-07-07 22:09:00 qq_ fifty-seven million two hundred and fifty-one thousand thre

One 、 Using partial derivatives , stay Unity It shows the normal

// ddx ddy  Calculating normals 
Shader "lcl/ddxddy/CalculateNormal"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float3 worldPos : TEXCOORD0;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float3 normalDir = normalize(cross(ddy(i.worldPos),ddx(i.worldPos)));
                
                return fixed4(normalDir,1);
            }
            ENDCG
        }
    }
}

kUnity Shader - ddx/ddy Partial derivative test , Realization : sharpening 、 Height map 、Flat shading application _Jave.Lin Learning notes of -CSDN Blog _unity sharpening q

Tangent line

Unity Shader - Normal mapping application in tangent space (T2W & W2T)_Jave.Lin Learning notes of -CSDN Blog _unity Tangent line

Normal mapping and tangent space _ Six days -CSDN Blog _ Tangent space normal and object space normal

原网站

版权声明
本文为[qq_ fifty-seven million two hundred and fifty-one thousand thre]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130608248940.html