SurfaceOutput기본에
|
SubShader { Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Test noambient
sampler2D _MainTex; sampler2D _BumpMap;
struct Input { float2 uv_MainTex; float2 uv_BumpMap; };
void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb; o.Normal = UnpackNormal(tex2D(_BumpMap,IN.uv_BumpMap)); o.Alpha = c.a; }
|
//#pragma surface surf Lambert noambient (Lambert를 test로 바꿔서 해봄. 커스텀을 만들기 위함인듯)
noambient는 엠비언트를 제거하여 lambert를 확실하게 보기 위함이라고 함
|
라이트를 넣어서 구현
|
float4 LightingTest (SurfaceOutput s, float3 lightDir, float atten) {
float ndotl = dot(s.Normal, lightDir)*0.5+0.5; // halp Lambert 연산 만들기 return ndotl;
}
ENDCG }
|
float4 LightingTest (SurfaceOutput s, float3 lightDir, float atten) Test라는 라이팅을 float4로 셋팅하겠다.(SurfaceOutput구조체를 쓰겠다 그리고 s라고 하겠다. float3으로 조명을셋팅하겠다. float atten으로 감쇠조명을 만들겠다.)
//Lighting+Test 붙여야함.
// return 값이 있어야 결과가 출력됨. ndotl=N(노멀)+L(라이트)+dot(닷) //float ndotl = dot(s.Normal, lightDir); //float ndotl = saturate(dot(s.Normal, lightDir)); //saturate 함수는 0보다 낮은 값은 0으로 1보다 높은 값은 1로 //float ndotl = max(0.2,dot(s.Normal, lightDir)); //max 한쪽의 값을 0.2으로 하면, 0.2보다 작은 다른쪽 값을 무조건 0으로 출력 //float ndotl = dot(s.Normal, lightDir)*0.5+0.5; // halp Lambert 연산 만들기
여기에 출력되는 return ndotl; 에 return ndotl+0.5; 하면 더 밝아진다.
|