게임개발/게임 그래픽 프로그래밍

커스텀 라이트 만들기

pudding81 2024. 2. 20. 11:40

 

 

 

 

 

 

 

Shader "Custom/CustomLambert"
{
    Properties
    {
        _BumpMap("Normalmap",2D) ="bump"{}
        
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        CGPROGRAM
       
        #pragma surface surf _MyLambert //noamient

        
        #pragma target 3.0

        sampler2D _BumpMap;
       

        struct Input
        {
            float4 color:COLOR;
             float2 uv_BumpMap;

        };

       

        void surf (Input IN, inout SurfaceOutput o)
        {
           

             //노멀맵 
            fixed4 n =tex2D (_BumpMap, IN.uv_BumpMap);
              fixed3 normal =UnpackNormal(n);
              o.Normal =normal;
            o.Albedo =1;
        }

        float4 Lighting_MyLambert(SurfaceOutput s,float3 lightDir, float atten)
        {
          //  return float4(1,0,0,1);
          //조명벡터와 노멀벡터를 내적해라 
          float ndotl =dot(s.Normal,lightDir); //색을 의미 -1~1
          
          //0~1을 반환
          float4 final = saturate(ndotl);
          return final;

        }
        ENDCG
    }
    FallBack "Diffuse"
}

 

Shader "Custom/head2"
{
    Properties
    {
       
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpMap("Normalmap",2D) ="bump"{}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
       
        CGPROGRAM
       
        #pragma surface surf Lambert     
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            
        };

      

       
        void surf (Input IN, inout SurfaceOutput o)
        {
           
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);

            fixed4 n =tex2D(_BumpMap,IN.uv_MainTex); // IN.uv_MainTex
            fixed3 normal =UnpackNormal(n);
            o.Normal =normal;

            o.Albedo = c.rgb;
          
          
        }

        float4 Lighting_MyLambert(SurfaceOutput s, float3 lightDir, float atten)
        { // return float4(1,0,0,1);

            float ndotl =dot(s.Normal,lightDir)*0.5+0.5; //색을 의미 -1~1
          float powNdotl=pow(ndotl,3); //3제곱

          //0~1을 반환
          float4 final = saturate(powNdotl);
          final.rgb=powNdotl*s.Albedo*_LightColor0.rgb*atten;

          return final;

            }
        ENDCG
    }
    FallBack "Diffuse"
}