Added fog fading

This commit is contained in:
raccoon
2025-05-17 03:57:13 +05:00
parent 1c0673d551
commit bef0dce786

View File

@@ -25,12 +25,18 @@ Shader "Custom/CloudsShader"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
half _MainTexScrollX;
half _MainTexScrollY;
sampler2D _NoiseTex;
float4 _NoiseTex_ST;
half _NoiseTexScrollX;
half _NoiseTexScrollY;
@@ -47,15 +53,20 @@ Shader "Custom/CloudsShader"
float2 uv1 : TEXCOORD0;
float2 uv2 : TEXCOORD1;
float4 vertex : SV_POSITION;
UNITY_FOG_COORDS(2)
};
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
// Textures scrolling
o.uv1 = v.uv + float2(_MainTexScrollX, _MainTexScrollY) * _Time.y;
o.uv2 = v.uv + float2(_NoiseTexScrollX, _NoiseTexScrollY) * _Time.y;
o.uv1 = TRANSFORM_TEX(v.uv, _MainTex) + float2(_MainTexScrollX, _MainTexScrollY) * _Time.y;
o.uv2 = TRANSFORM_TEX(v.uv, _NoiseTex) + float2(_NoiseTexScrollX, _NoiseTexScrollY) * _Time.y;
UNITY_TRANSFER_FOG(o, o.vertex);
return o;
}
@@ -63,7 +74,22 @@ Shader "Custom/CloudsShader"
{
fixed4 tex1 = tex2D(_MainTex, i.uv1);
fixed4 tex2 = tex2D(_NoiseTex, i.uv2);
return tex1 * tex2 * _Color;
fixed4 col = tex1 * tex2 * _Color;
// fixed4 col = _Color;
fixed4 fog = fixed4(0, 0, 0, 1);
/*
// Subtractive fog effect — fade to black
float dist = distance(_WorldSpaceCameraPos, i.worldPos);
float fogFactor = 1.0 - exp(-_FogDensity * dist);
fogFactor = saturate(fogFactor);
col.rgb *= (1.0 - fogFactor); // Fade to black
*/
// Apply the fog
// UNITY_APPLY_FOG(i.fogCoord, fog);
//col.rgb -= ; // Fade to black
return col;
}
ENDCG
}