hello
i am working on a watershader,but 1 stuck on some places...
-the first thing is: if i try to make waves, on the sides of the screen parts of the opposite screen part appears..i know why it is so but not how i can solve it
-the second thing is: i want to have reflection and refraction, but there must bean mistake in the part where i lerp both pictures, because there is _nearly_ only refraction visible.
here is a picture you can see what i mean:

and here is the fx file and the bit c-script i use:
Code:
float4x4 matWorld;
float4x4 matWorldViewProj;
float4x4 saturate_mat = { -0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0,-0.5, 0.0,
-0.5,-0.5,-0.5,-1.0};
float4 vecTime;
float4 vecViewDir;
texture entSkin1;
texture entSkin2;
texture mtlSkin1;
sampler2D reflectionMap = sampler_state
{
Texture=<entSkin1>;
};
sampler2D refractionMap = sampler_state
{
Texture=<entSkin2>;
};
sampler2D normalMap = sampler_state
{
Texture=<mtlSkin1>;
AddressU = Wrap;
AddressV = Wrap;
};
void waterVS( in float2 tex :TEXCOORD0,
in float4 pos :POSITION,
in float3 tangent :TEXCOORD2,
in float3 N :NORMAL,
out float4 oPos :POSITION,
out float4 crdPos :TEXCOORD0,
out float2 oTex :TEXCOORD1,
out float3 tangentView :TEXCOORD2)
{
oPos=mul(pos,matWorldViewProj);
crdPos=oPos;
crdPos = mul(crdPos,saturate_mat);
oTex=tex;
float3x3 TBN;
TBN[0]=mul(tangent,matWorld);
TBN[1]=mul(cross(tangent,N),matWorld);
TBN[2]=mul(N,matWorld);
tangentView =normalize(mul(TBN,vecViewDir.xyz));
}
float4 waterPS( in float4 pos :TEXCOORD0,
in float2 texcrd :TEXCOORD1,
in float3 tangentView :TEXCOORD2):COLOR
{
float4 blue = {0.0,1.0,1.5,1.0};
texcrd.x += vecTime.w/1000;
pos += 5*tex2D(normalMap,texcrd);
float4 mix = saturate(dot(2*tex2D(normalMap,texcrd)-1,tangentView));
return lerp(blue*tex2Dproj(refractionMap,pos),tex2Dproj(reflectionMap,pos),mix);
}
technique water
{
pass p0
{
Vertexshader = compile vs_1_0 waterVS();
Pixelshader = compile ps_2_0 waterPS();
}
}
AND the c-script:
Code:
bmap water_bump = <water_bump.tga>;
material water_mtl
{
effect="water.fx";
skin1 = water_bump;
flags="tangent";
}
view refraction
{
flags=noflag1,visible;
}
view mirror
{
flags=visible;
aspect=-1;
}
action water
{
my.passable=on;
my.material=water_mtl;
refraction.bmap = bmap_for_entity(me,2);
mirror.bmap = bmap_for_entity(me,1);
while(1)
{
vec_set(mirror.x,vector(camera.x,camera.y,my.z-(camera.z-my.z)));
vec_Set(mirror.pan,vector(camera.pan,-camera.tilt,camera.roll));
wait(1);
}
}
[...]
vec_set(refraction.x,camera.x);
vec_set(refraction.pan,camera.pan);