From add4ebe4458fa57e8584bc3db1901a12bb1b2c0c Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 5 Apr 2012 12:59:56 +0200 Subject: [PATCH] fresnel effect --- files/gbuffer/gbuffer.compositor | 1 + files/water/water.cg | 10 ++++++---- files/water/water.material | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/files/gbuffer/gbuffer.compositor b/files/gbuffer/gbuffer.compositor index a81ad18c3..fb12b8bf4 100644 --- a/files/gbuffer/gbuffer.compositor +++ b/files/gbuffer/gbuffer.compositor @@ -11,6 +11,7 @@ compositor gbuffer input none pass clear { + // make sure to set this to the viewport background color from outside colour_value 0 0 0 1 } pass render_scene diff --git a/files/water/water.cg b/files/water/water.cg index bd18286bc..10b42eec0 100644 --- a/files/water/water.cg +++ b/files/water/water.cg @@ -64,7 +64,6 @@ 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; - //normal = normalize(normal); float2 screenCoords_reflect = screenCoords + normal.yx * 0.05; float2 screenCoords_refract = screenCoords + normal.yx * 0.1 * depth1; @@ -72,11 +71,14 @@ void main_fp float4 reflection = tex2D(reflectionMap, screenCoords_reflect); float4 refraction = tex2D(refractionMap, screenCoords_refract); + // tangent to object space + normal.xyz = normal.xzy; + // fresnel - //float facing = 1.0 - max(abs(dot(iEyeVector.xyz, normal.xyz)), 0); - //float reflectionFactor = saturate(0.3 + 0.7 * pow(facing, 2)); + float facing = 1.0 - max(abs(dot(normalize(iEyeVector.xyz), normal.xyz)), 0); + float reflectionFactor = saturate(0.3 + 0.7 * pow(facing, 2)); - oColor.xyz = lerp(refraction.xyz, reflection.xyz, depth1); + oColor.xyz = lerp(refraction.xyz, reflection.xyz, depth1 * reflectionFactor); 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 ffd813e16..95a0aef78 100644 --- a/files/water/water.material +++ b/files/water/water.material @@ -48,7 +48,7 @@ material Water vertex_program_ref Water_VP { - //param_named_auto camPosObjSpace camera_position_object_space + param_named_auto camPosObjSpace camera_position_object_space } fragment_program_ref Water_FP {