프레넬 공식

     
     

Shader "Custom/20_Lambert_lim1"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RimColor ("RimColor", Color) = (1,1,1,1)
_RimPower ("RimPower", Range(1,10)) = 3

}

 

SubShader
{
Tags { "RenderType"="Opaque" }

CGPROGRAM

#pragma surface surf Lambert noambient


sampler2D _MainTex;

struct Input
{
float2 uv_MainTex;
float3 viewDir; //
버텍스가 카메라 방향을 보는 방향
};

 

SubShader
{
Tags { "RenderType"="Opaque" }

CGPROGRAM

#pragma surface surf Lambert noambient


sampler2D _MainTex;
float4 _RimColor;
float _RimPower;

struct Input
{
float2 uv_MainTex;
float3 viewDir; //
버텍스가 카메라 방향을 보는 방향
};

 

void surf (Input IN, inout SurfaceOutput o)
{

fixed4 c = tex2D (_MainTex, IN.uv_MainTex);

float rim = dot(o.Normal, IN.viewDir);

o.Emission = pow(1- rim, 3);

o.Albedo = c.rgb;
//0
으로 놓고 하면 까만 초기 상태가 된다.
o.Alpha = c.a;
}

o.Emission = 1- rim 이렇게 하면 그래프로 보면 직각이된다.


그래서 pow(exponet, 지수) 써서 그래프가 산모양으로 되게 만들어서
굵기를 얇게 하는것이다.

pow
연산은 비교적 무겁다.

void surf (Input IN, inout SurfaceOutput o)
{

fixed4 c = tex2D (_MainTex, IN.uv_MainTex);

o.Albedo = 0;//0
으로 놓고 하면 까만 초기 상태가 된다.
float rim = dot(o.Normal, IN.viewDir);
o.Emission = pow(1- rim, _RimPower)*_RimColor.rgb;
o.Alpha = c.a;
}

 

ENDCG
}
FallBack "Diffuse"
}

 

ENDCG
}
FallBack "Diffuse"
}

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

 

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

RampTexture  (0) 2020.05.21
OUTLINE  (0) 2020.05.17
Lambert 공식  (0) 2020.05.17
라이팅구조  (0) 2020.05.17
Vertex color  (0) 2020.05.17