Matcap
Unity3D/Shader 2020. 12. 23. 17:01반응형
Shader "Custom/Matcap"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Matcap ("Matcap", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf _NoLight noambient
sampler2D _MainTex;
sampler2D _Matcap;
struct Input
{
float2 uv_MainTex;
float3 worldNormal;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
//UNITY_MATRIX_V : view 좌표계 메트릭스
float3 viewNormal = mul((float3x3)UNITY_MATRIX_V, IN.worldNormal.rgb); //메트릭스 곱셈
//o.Emission = IN.worldNormal; //색이 변함
//o.Emission = viewNormal; //왼쪽이 항상 파랑
//o.Emission = viewNormal.x;
//viewNormal의 x, y를 u, v로 사용가능
float2 matcapUV = viewNormal.xy * 0.5 + 0.5; //normal uv 0 ~ 1 을 -1 ~ 1로 만듬
//o.Emission = float3(matcapUV, 0);
o.Emission = tex2D(_Matcap, matcapUV) * c.rgb;
o.Alpha = c.a;
}
float4 Lighting_NoLight(SurfaceOutput s, float3 lightDir, float atten){
return float4(0, 0, 0, s.Alpha);
}
ENDCG
}
FallBack "Diffuse"
}
반응형
'Unity3D > Shader' 카테고리의 다른 글
water (0) | 2020.12.23 |
---|---|
Refraction (0) | 2020.12.23 |
흔들리는 풀 (0) | 2020.12.23 |
Unity Unlit Shader (vertex & fragment shader) (0) | 2020.12.22 |
Diffuse Warping (0) | 2020.12.21 |