45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
// 파일명: FogHeightMask.shader
|
|
Shader "Custom/FogHeightMask"
|
|
{
|
|
Properties { _MainColor ("Fog Color", Color) = (0,0,0,1) }
|
|
SubShader {
|
|
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
|
|
Blend SrcAlpha OneMinusSrcAlpha // 투명도 사용 설정
|
|
ZWrite Off
|
|
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
|
|
struct v2f {
|
|
float4 vertex : SV_POSITION;
|
|
float3 worldPos : TEXCOORD0;
|
|
};
|
|
|
|
sampler2D _GlobalFogTex;
|
|
float _FogWorldSize;
|
|
float _GroundLevelY; // 매니저가 보내줄 높이값
|
|
float4 _MainColor;
|
|
|
|
v2f vert (appdata_base v) {
|
|
v2f o;
|
|
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag (v2f i) : SV_Target {
|
|
// [핵심 로직] 현재 픽셀의 높이가 지상 레벨보다 높으면 투명하게!
|
|
if (i.worldPos.y > _GroundLevelY) return fixed4(0,0,0,0);
|
|
|
|
float2 uv = i.worldPos.xz / _FogWorldSize + 0.5;
|
|
fixed4 fogData = tex2D(_GlobalFogTex, uv);
|
|
|
|
return fixed4(_MainColor.rgb, fogData.a); // 안개 텍스처의 알파값(검정 정도) 적용
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
} |