PDA

View Full Version : Water mapping



^DaNiEl^
01-25-2004, 08:37 PM
Hi, i'm currently doing a water demo with render to texture, ut i don't know how to map correctly the reflection and the refraction map to the water plane. Help me please !!

Here's the Cg code:


struct vpin
{
float4 Position : POSITION;
float3 TexCoord0 : TEXCOORD0;
float2 TexCoord1 : TEXCOORD1;
float2 TexCoord2 : TEXCOORD2;
};

struct vpout
{
float4 Position : POSITION;
float2 TexCoord0 : TEXCOORD0;
float2 TexCoord1 : TEXCOORD1;
float2 TexCoord2 : TEXCOORD2;
};


vpout main ( vpin IN,
uniform float4x4 ModelViewProj )
{
vpout OUT;

OUT.Position = mul( ModelViewProj, IN.Position );

OUT.TexCoord0 = IN.TexCoord0;

OUT.TexCoord1 = IN.TexCoord1;

OUT.TexCoord2 = IN.TexCoord2;

return OUT;
}

struct fpin
{
float3 TexCoord0 : TEXCOORD0;
float2 TexCoord1 : TEXCOORD1;
float2 TexCoord2 : TEXCOORD2;
};


struct fpout
{
float4 Color : COLOR;
};


fpout main ( fpin IN,
uniform sampler2D OffsetMap,
uniform sampler2D ReflectMap,
uniform sampler2D RefractMap,
uniform float4 OffsetValues )
{
fpout OUT;

float4 OffsetTex = tex2D( OffsetMap, IN.TexCoord0 );

float4 ReflectTex = tex2D( ReflectMap, IN.TexCoord1 + OffsetValues.xy * OffsetTex.xx + OffsetValues.zw * OffsetTex.yy );

float4 RefractTex = tex2D( RefractMap, IN.TexCoord2 + OffsetValues.xy * OffsetTex.xx + OffsetValues.zw * OffsetTex.yy );

float4 ReflectColor = float4( 1.0, 1.0, 1.0, 1.0 );

float4 RefractColor = float4( 0.3, 0.3, 0.4, 1.0 );

OUT.Color = ( ReflectTex * ReflectColor ) + ( RefractTex * RefractColor );

OUT.Color.a = 1.0;

return OUT;
}