1번.

Diffuse Warping + NormalMap + Texture

Shader "Custom/WarpedDiffuse"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _RampTex ("Ramp Texture", 2D) = "white" {}
        _NormalMap("Normal Map", 2D) = "bump" {}
        _OutLine("OutLine", Range(0,1)) = 0.2
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf _Warped
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _RampTex;
        sampler2D _NormalMap;
        float _OutLine;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NormalMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            float4 c = tex2D(_MainTex, IN.uv_MainTex);
            float4 d = tex2D(_NormalMap, IN.uv_NormalMap);
            //float3 normal = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
            o.Normal = UnpackNormal(d);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        float4 Lighting_Warped(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
        {
            float4 final;
            float ndotl = dot(s.Normal, lightDir);

            float rim = dot(s.Normal, viewDir);
            if(rim >= _OutLine) rim = 1;
            else rim = 0;

            fixed4 ramp = tex2D(_RampTex, float2(ndotl, 0.5));
            
            final.rgb = s.Albedo.rgb * ramp.    rgb * rim;
            final.a = s.Alpha;

            return final;
        }
        ENDCG

    }
    FallBack "Diffuse"
}

 

2.

1번  + 2Pass 외곽선 + RampTex 적용

Shader "Custom/WarpedDiffuse"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _RampTex ("Ramp Texture", 2D) = "white" {}
        _NormalMap("Normal Map", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf _Warped
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _RampTex;
        sampler2D _NormalMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NormalMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            float4 c = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            float3 normal = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
            o.Normal = normal;
        }

        float4 Lighting_Warped(SurfaceOutput s, float3 lightDir, float atten)
        {
            float ndotl = dot(s.Normal, lightDir);
            float2 uv = float2(ndotl, 0.5);
            float4 c = tex2D(_RampTex, uv);
            return c;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

3.

Fresnel 외곽선 + RampTex

Shader "Custom/WarpedDiffuse"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _RampTex ("Ramp Texture", 2D) = "white" {}
        _NormalMap("Normal Map", 2D) = "bump" {}
        _OutLine("OutLine", Range(0,1)) = 0.2
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
        #pragma surface surf _Warped
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _RampTex;
        sampler2D _NormalMap;
        float _OutLine;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NormalMap;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            float4 c = tex2D(_MainTex, IN.uv_MainTex);
            float4 d = tex2D(_NormalMap, IN.uv_NormalMap);
            //float3 normal = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
            o.Normal = UnpackNormal(d);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        float4 Lighting_Warped(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
        {
            float4 final;
            float ndotl = dot(s.Normal, lightDir);

            float rim = dot(s.Normal, viewDir);
            if(rim >= _OutLine) rim = 1;
            else rim = 0;

            fixed4 ramp = tex2D(_RampTex, float2(ndotl, 0.5));
            
            final.rgb = s.Albedo.rgb * ramp.    rgb * rim;
            final.a = s.Alpha;

            return final;
        }
        ENDCG

    }
    FallBack "Diffuse"
}

 

4번.

2pass + 커스텀 스페큘러

Shader "Custom/WarpedDiffuse"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _RampTex ("Ramp Texture", 2D) = "white" {}
        _NormalMap("Normal Map", 2D) = "bump" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        Cull Front
        CGPROGRAM
        #pragma surface surf _NoLight vertex:vert
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _RampTex;
        sampler2D _NormalMap;

        struct Input
        {
            float4 color : COLOR;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
        }

        void vert(inout appdata_full v){
            v.vertex.xyz  = v.vertex.xyz + v.normal.xyz * 0.01;
            }

        float4 Lighting_NoLight(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
        {
            return float4(0,0,0,1);
        }
        ENDCG
        Cull Back


        CGPROGRAM
        #pragma surface surf _Warped
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _RampTex;
        sampler2D _NormalMap;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NormalMap;
            float4 color : COLOR;
        };

        void surf (Input IN, inout SurfaceOutput o)
        {
            float4 c = tex2D(_MainTex, IN.uv_MainTex);
            float4 d = tex2D(_NormalMap, IN.uv_NormalMap);
            o.Normal = UnpackNormal(d);
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }

        float4 Lighting_Warped(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
        {
            float4 final;

            //half-lambert
            float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;

            //spec
            float3 h = normalize(lightDir + viewDir);
            float spec = saturate(dot(s.Normal,h));
            //spec => pow

            //Ramp
            float4 ramp = tex2D(_RampTex,float2(ndotl, 0.5));

            //final
            final.rgb = s.Albedo.rgb * (ramp.rgb + 0.5) * spec;
            final.a = s.Alpha;



            return final;
        }
        ENDCG

     }
    FallBack "Diffuse"
}

'산대특 > 게임 UIUX 프로그래밍' 카테고리의 다른 글

Shader - triplaner  (1) 2024.02.26
Shader - Cubemap Reflection  (0) 2024.02.22
Shader -Blinn Phong 스펙큘러  (0) 2024.02.22
Shader - Lambert  (0) 2024.02.20
Shader - Vertex  (0) 2024.02.19

+ Recent posts