campfire/Assets/Shaders/CampFog.shader

73 lines
2.1 KiB
Plaintext

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Unlit/CampFog"
{
Properties
{
_FogColor ("Color", Color) = (1, 0, 0, 1)
_Intensity ("Intensity", Float) = 2.5
_Transparency ("Transparency", Float) = 1
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 screenpos : TEXCOORD1;
float4 center : TEXCOORD2;
float4 orig : TEXCOORD3;
};
float4 _FogColor;
float _Intensity;
float _Transparency;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos (v.vertex);
o.orig = v.vertex;
o.screenpos = ComputeScreenPos(o.vertex);
o.center = ComputeScreenPos (UnityObjectToClipPos(fixed3(0, 0, 0)));
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 pos = (i.screenpos.xy/i.screenpos.w);
float2 center = (i.center.xy/i.center.w);
float2 distance = center - pos;
if (_ScreenParams.y > _ScreenParams.x) {
distance.y /= (_ScreenParams.x / _ScreenParams.y);
} else {
distance.x /= (_ScreenParams.y / _ScreenParams.x);
}
float value = length(distance) / length(unity_ObjectToWorld[0].xyz);
value = 1 - value * i.center.w * _Intensity;
fixed4 col = fixed4(_FogColor.xyz * value, value * _Transparency);
return col;
}
ENDCG
}
}
}