surface shader Custom Light 예제 따라하기~

 

 

 

==================================================================================================================

심플 램버트 라이트.....내장 램버트 라이트를 따라한 커스텀 라이트

 

Shader "DY/surf_Diffuse" {
 Properties{
  _MainTex("Diffuse",2D)="white"{}
 }
 SubShader{
  Tags {"RanderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf SimpleLambert
  
  half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten){
   half NdotL = dot(s.Normal, lightDir);
   half4 c;
   c.rgb = s.Albedo * _LightColor0.rgb *(NdotL * atten *2);
   c.a = s.Alpha;
   return c;
  }
  //커스텀 램버트 라이트

 


  struct Input{
   float2 uv_MainTex;
  };
  
  sampler2D _MainTex;
  
  void surf (Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
  }
  
  ENDCG
 }
 Fallback"Diffuse"
}

 

 

 

 

==================================================================================================================

 

하프 램버트 라이트.....밸브의 하프 램버트를 구현한 커스텀 라이트

 

Shader "DY/surf_wraf" {
 Properties{
  _MainTex("Diffuse",2D)="white"{}
 }
 SubShader{
  Tags {"RanderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf WrafLambert
  
  half4 LightingWrafLambert(SurfaceOutput s, half3 lightDir, half atten){
   half NdotL = dot(s.Normal, lightDir);
   half diff = NdotL*0.5+0.5;
   half4 c;
   c.rgb = s.Albedo * _LightColor0.rgb *(diff * atten *2);
   c.a = s.Alpha;
   return c;
  }
  //커스텀 하프램버트 라이트

  //half diff = NdotL*0.5+0.5;

 


  struct Input{
   float2 uv_MainTex;
  };
  
  sampler2D _MainTex;
  
  void surf (Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
  }
  
  ENDCG
 }
 Fallback"Diffuse"
}

 

 

 

 

 

==================================================================================================================

 

컬러 텍스쳐를 활용한 커스텀 툰 라이팅.........텍스쳐 메모리 때문에 아마 사용할 일은 없을듯 

 

Shader "DY/Toon Ramp" {
 Properties{
  _MainTex("Diffuse",2D)="white"{}
  _Ramp("shading Ramp",2D)="gray"{}
 }
 SubShader{
  Tags {"RanderType"="Opaque"}
  
  CGPROGRAM
  #pragma surface surf Ramp
  
  sampler2D _Ramp;
  
  half4 LightingRamp(SurfaceOutput s, half3 lightDir, half atten){
   half NdotL = dot(s.Normal, lightDir);
   half diff = NdotL*0.5+0.5;
   half3 ramp = tex2D(_Ramp, float2(diff)).rgb;
   half4 c;
   c.rgb = s.Albedo * _LightColor0.rgb *ramp*(atten *2);
   c.a = s.Alpha;
   return c;
  }

//툰 램프 커스텀 라이트
//half3 ramp = tex2D(_Ramp, float2(diff)).rgb;

 

  struct Input{
   float2 uv_MainTex;
  };
  
  sampler2D _MainTex;
  
  void surf (Input IN, inout SurfaceOutput o){
   o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
  }
  
  ENDCG
 }
 Fallback"Diffuse"
}

 

 

 

 

=======================================================================================================================

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted by 프리랜서 디자이너