셰이더 (Shader)/유니티 쉐이더 스타트업 - 정종필
[Unity/Shader] 파트8-2 : Metalic과 Smoothness
Minkyu Lee
2023. 8. 7. 23:33
기본 코드에서 Metallic과 Smoothness가 어떤 역할을 하는지 설명한다.
코드
Shader "Custom/part8-2"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Metallic ("Metalic", Range(0,1)) = 0
_Smoothness("Smoothness", Range(0,1)) = 0.5
}
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;
float _Metallic;
float _Smoothness;
struct Input
{
float2 uv_MainTex;
};
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Metallic = _Metallic; // 0은 비금속, 1은 금속. 0과 1외의 값을 가급적 쓰지 않는게 물리 법칙에 맞다.
// 0이면 스페큘러 컬러가 흑백, 1이면 albedo 색이 된다. 금속은 고유의 스페큘러 색을 가지기 때문이다.
o.Smoothness = _Smoothness; // Roughness를 뒤집은 것이다.
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}