From 36fd9b9f263c7c4f4fc9df759253b96785121cdf Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 5 Apr 2012 10:39:22 +0200 Subject: [PATCH] shore transition test --- files/water/water.cg | 17 ++++++++++++----- files/water/water.material | 6 ++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/files/water/water.cg b/files/water/water.cg index 88515c3e8..c8156d9ce 100644 --- a/files/water/water.cg +++ b/files/water/water.cg @@ -35,8 +35,10 @@ void main_fp , uniform sampler2D reflectionMap : register(s0) , uniform sampler2D refractionMap : register(s1) - , uniform sampler2D normalMap : register(s2) + , uniform sampler2D depthMap : register(s2) + , uniform sampler2D normalMap : register(s3) , uniform float time + , uniform float far , uniform float4 fogParams , uniform float4 fogColour ) @@ -45,6 +47,9 @@ void main_fp float2 screenCoords = iScreenCoords.xy / iScreenCoords.z; screenCoords.y = (1-saturate(renderTargetFlipping))+renderTargetFlipping*screenCoords.y; + float depth1 = tex2D(depthMap, screenCoords).r * far - iDepth; + depth1 = saturate(depth1 / 500.f); + float2 uv1 = iUv + time * float2(0.5, 0); float2 uv2 = iUv + time * float2(0, 0.5); float2 uv3 = iUv + time * float2(-0.5, 0); @@ -53,12 +58,14 @@ void main_fp float4 normal = tex2D(normalMap, uv1) + tex2D(normalMap, uv2) + tex2D(normalMap, uv3) + tex2D(normalMap, uv4); normal = normal / 4.f; normal = 2*normal - 1; - screenCoords += normal.yx * 0.05; - float4 reflection = tex2D(reflectionMap, screenCoords); - float4 refraction = tex2D(refractionMap, screenCoords); + float2 screenCoords_reflect = screenCoords + normal.yx * 0.05; + float2 screenCoords_refract = screenCoords + normal.yx * 0.1 * depth1; + + float4 reflection = tex2D(reflectionMap, screenCoords_reflect); + float4 refraction = tex2D(refractionMap, screenCoords_refract); - oColor.xyz = lerp(reflection.xyz, refraction.xyz, 1); + oColor.xyz = lerp(refraction.xyz, reflection.xyz, depth1); float fogValue = saturate((iDepth - fogParams.y) * fogParams.w); oColor.xyz = lerp(oColor.xyz, fogColour, fogValue); diff --git a/files/water/water.material b/files/water/water.material index c964e9ae4..dd01af405 100644 --- a/files/water/water.material +++ b/files/water/water.material @@ -55,6 +55,7 @@ material Water param_named_auto fogColour fog_colour param_named_auto fogParams fog_params param_named_auto renderTargetFlipping render_target_flipping + param_named_auto far far_clip_distance } texture_unit reflectionMap @@ -68,6 +69,11 @@ material Water tex_address_mode clamp } + texture_unit depthMap + { + tex_address_mode clamp + } + texture_unit normalMap { texture WaterNormal2.tga