Unity Shader Study06 : Legacy shader (Lambert)

 //*0.5 +0.5 가 음영을 부드럽게 만든다.
float ndot1 = dot(s.Normal, lightDir)*0.5 +0.5;

  //s.Albedo는 입력받은 텍스쳐 입니다. Lambert라이트와 연산되어 Diffuse가 됩니다.
  //_LightColor0.rgb 이전 ndot1은 조명과 노멀 각도를 표현한 것 뿐이고 색상이나 강도는 이 내장 변수에서 가져옵니다.
  //atten :빛의 감쇠현상을 시뮬레이트 합니다. atten을 계산하지 않으면 다음의 과정이 일어나지 않습니다.
  //1. Self Shadow 가 생기지 않습니다. 자기 자신의 그림자가 생기지 안습니다
  //2. receive shadow
  //조명의 감쇠 현상이 일어나지 안습니다. 멀어질수록 빛이 약해지도록 만드는 것이 atten입니다.

Legacy shader/ Bumped Diffuse와 같은 쉐이더 입니다.

Shader "Custom/Shader08_CustomLight" {
 Properties {
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
     _BumpMap ("NormalMap", 2D) = "bump"{}
 }
 SubShader {
  Tags { "RenderType"="Opaque" }
  LOD 200

  CGPROGRAM
  // Physically based Standard lighting model, and enable shadows on all light types
  #pragma surface surf Test
  // Use shader model 3.0 target, to get nicer looking lighting
  #pragma target 3.0
  sampler2D _MainTex;
     sampler2D _BumpMap;
  struct Input {
   float2 uv_MainTex;
   float2 uv_BumpMap;
  };

  // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  // #pragma instancing_options assumeuniformscaling
  UNITY_INSTANCING_CBUFFER_START(Props)
   // put more per-instance properties here
  UNITY_INSTANCING_CBUFFER_END
  void surf (Input IN, inout SurfaceOutput o) {
   // Albedo comes from a texture tinted by color
   fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
   o.Albedo = c.rgb;
   o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
   o.Alpha = c.a;
  }
  float4 LightingTest(SurfaceOutput s, float3 lightDir, float atten) {
   float ndot1 = saturate(dot(s.Normal, lightDir));
   float4 final;
   final.rgb = ndot1 * s.Albedo * _LightColor0.rgb * atten;
   final.a = s.Alpha;
   return final;
  }
  ENDCG
 }
 FallBack "Diffuse"
}

댓글

이 블로그의 인기 게시물

About AActor!!! "UObject" has no member "BeginPlay"

UNREAL Android build information

Shader informations nice blog ~ ~