After, finally, completed the shadow volume example, now, before make a journey in long shadow mapping way, i would like to make a little water example.
I'm reading the ShaderX2 article, i will explain you what am i doing, hoping that someone will find the error.
Quote
We want to simulate a close-to-reality view into the water. The seabed and objects
like fish or plants should be distortable by faked bumps (see the section “Animated
Surface Bumping”). So, we have to render the underwater scene view each
frame again into a render-target texture. For this job, we use the original camera.
A clip plane cuts off the invisible part of the scene above the water surface
For this, i created another texture and, after getting the backbuffer, i made a CopyResource and it works. So, no render target it's needed (i hope)
The second pass it's the
Modifications Dependent on Water Depth
It say to use a vertex and pixel shader, but i did not understand where. On the water-grid mesh? Anyway, if i use it, i can't see the plane on the screen.
The shader is
// VERTEX SHADER (for DX9 hardware and better) VS-1 // FUNCTION: Modifies underwater scene texture // // INPUT: // v0 = position (3 floats) // c0 - c3 = world/view/proj matrix // version instruction vs 2 0 210 Advanced Water Effects Figure 4: Reduction formula exp ( –d * ) // declare registers dcl position v0 // transform position into projection space dp4 oPos.x, v0, c0 // c0 = first row of transposed world/view/proj-matrix. dp4 oPos.y, v0, c1 // c1 = second row of transposed world/view/proj-matrix. dp4 oPos.z, v0, c2 // c2 = third row of transposed world/view/proj-matrix. dp4 oPos.w, v0, c3 // c3 = forth row of transposed world/view/proj-matrix. // transfer position to pixel shader mov oT0, v0 // We pass the vertex position to the pixel shader as tex coord.
I traslated it in this way.
float4x4 ViewMatrix;
float4x4 WorldMatrix;
float4x4 ProjMatrix;
float4 LightDirection;
float4 MaterialColor;
float3 EyePosition;
texture2D Texture;
texture2D CurrentBackbuffer;
SamplerState SamplText
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Tex : TEXCOORD;
float3 Nor : NORMAL;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 WorldPos: WORLDPOSITION;
float3 Tex : TEXCOORD;
float3 Nor : NORMAL;
};
PS_INPUT vs_main(VS_INPUT Input)
{
PS_INPUT Out = (PS_INPUT)0;
Out.Pos = mul(mul(mul(Input.Pos,WorldMatrix),ViewMatrix),ProjMatrix);
Out.WorldPos = mul(Input.Pos,WorldMatrix);
Out.Tex = Input.Tex;
Out.Nor = mul(Input.Nor,WorldMatrix);
return Out;
}
PS_INPUT vs_plane(VS_INPUT input)
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul(input.Pos, transpose(WorldMatrix));
output.Pos = mul(output.Pos, transpose(ViewMatrix));
output.Pos = mul(output.Pos, transpose(ProjMatrix));
output.Nor = mul( input.Nor, WorldMatrix );
output.Tex = float3(output.Pos.x,output.Pos.y,output.Pos.z);
return output;
}
float4 ps_plane(PS_INPUT input) : SV_TARGET
{
return CurrentBackbuffer.Sample(SamplText,saturate(input.Tex));
}
float4 ps_main(PS_INPUT In) : SV_TARGET
{
return Texture.Sample(SamplText,In.Tex);
}
technique10 WaterEffect
{
Pass PositionTextured
{
SetVertexShader( CompileShader( vs_4_0, vs_main() ) );
SetGeometryShader(NULL);
SetPixelShader( CompileShader( ps_4_0, ps_main() ) );
}
Pass Plane
{
SetVertexShader( CompileShader( vs_4_0, vs_plane() ) );
SetGeometryShader(NULL);
SetPixelShader( CompileShader( ps_4_0, ps_plane() ) );
}
}
The second part of the article say modification of the texture depend of water depth.
Ok, but where have i to apply the texture? On the grid plane mesh?
Anyway, if yes or not, the second pass make this, but it seems to not work.
Hints?















