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; 하면 밝아진다.

 

유니티 쉐이더 스타트업 자료(정종필저)

'Unity > Surface Shader' 카테고리의 다른 글

OUTLINE  (0) 2020.05.17
프레넬 공식  (0) 2020.05.17
라이팅구조  (0) 2020.05.17
Vertex color  (0) 2020.05.17
texture  (0) 2020.05.16