셰이더 (Shader)/유니티 쉐이더 스타트업 - 정종필
[Unity/Shader] 파트8-4 : Occlusion
Minkyu Lee
2023. 8. 9. 00:08
구석진 부분의 추가 음영이다.
AO (엠비언트 오클루전 = 환경차폐)이라고도 불린다.
매우 구석져있어 환경광도 닿지 못하는 아주 어두운 부분이다.
코드
Shader "Custom/part8-2"
{
Properties
{
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Metallic("Metalic", Range(0,1)) = 0
_Smoothness("Smoothness", Range(0,1)) = 0.5
_BumpMap("Normalmap", 2D) = "bump"{}
_Occlusion("Occlusion", 2D) = "white" {} // *
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _Occlusion; // *
float _Metallic;
float _Smoothness;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
};
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Occlusion = tex2D(_Occlusion, IN.uv_MainTex);
// Occlusion맵은 독립된 UV를 받으면 에러가 난다. 반드시 _MainTex와 같은 UV를 넣는다.
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Smoothness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}