diff --git a/files/water/water.cg b/files/water/water.cg index 6d5df987d..70d3339b1 100644 --- a/files/water/water.cg +++ b/files/water/water.cg @@ -6,6 +6,7 @@ void main_vp , out float4 oPos : POSITION , out float3 oScreenCoords : TEXCOORD0 , out float2 oUv : TEXCOORD1 + , out float oDepth : TEXCOORD2 , uniform float4x4 wvpMat ) @@ -13,6 +14,7 @@ void main_vp oPos = mul(wvpMat, iPos); oUv = iUv * 10; // uv scale + oDepth = oPos.z; float4x4 scalemat = float4x4( 0.5, 0, 0, 0.5, 0, -0.5, 0, 0.5, @@ -28,11 +30,14 @@ void main_fp , in float3 iScreenCoords : TEXCOORD0 , in float2 iUv : TEXCOORD1 + , in float iDepth : TEXCOORD2 , uniform float renderTargetFlipping , uniform sampler2D reflectionMap : register(s0) , uniform sampler2D normalMap : register(s1) , uniform float time + , uniform float4 fogParams + , uniform float4 fogColour ) { @@ -51,6 +56,7 @@ void main_fp float4 reflection = tex2D(reflectionMap, screenCoords); - oColor.xyz = reflection.xyz; + float fogValue = saturate((iDepth - fogParams.y) * fogParams.w); + oColor.xyz = lerp(reflection.xyz, fogColour, fogValue); oColor.a = 0.45; } diff --git a/files/water/water.material b/files/water/water.material index 8f8f72df0..abd5ad80e 100644 --- a/files/water/water.material +++ b/files/water/water.material @@ -52,6 +52,8 @@ material Water fragment_program_ref Water_FP { param_named_auto time time 0.1 + param_named_auto fogColour fog_colour + param_named_auto fogParams fog_params } texture_unit reflectionMap