Following Riemers tutorials for creating a water effect, I came across a function device.ClipPlane which does not exist in XNA 4. I googled a bit and found this effect that someone wrote for clipping a plane.
float4x4 World;
float4x4 View;
float4x4 Projection;
float4 ClipPlane0;
void vs(inout float4 position : POSITION0, out float4 clipDistances : TEXCOORD0)
{
clipDistances.y = 0;
clipDistances.z = 0;
clipDistances.w = 0;
position = mul(mul(mul(position, World), View), Projection);
clipDistances.x = dot(position, ClipPlane0);
}
float4 ps(float4 clipDistances : TEXCOORD0) : COLOR0
{
clip(clipDistances);
return float4(0, 0, 0, 0); // TODO: whatever other shading logic you want
}
technique
{
pass
{
VertexShader = compile vs_2_0 vs();
PixelShader = compile ps_2_0 ps();
}
}
The result is supposed to show a saved picture of my refraction texture, but nothing is clipped.
public void DrawRefractionMap(Effect clipEffect, Camera camera, GraphicsDevice device)
{
Plane refractionPlane = CreatePlane(waterHeight + 1.5f, new Vector3(0, -1, 0), camera, false);
clipEffect.Parameters["ClipPlane0"].SetValue(new Vector4(refractionPlane.Normal, refractionPlane.D));
device.SetRenderTarget(refractionRenderTarget);
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1, 0);
foreach (EffectPass pass in clipEffect.CurrentTechnique.Passes)
{
pass.Apply();
DrawTerrain(clipEffect, camera, device);
}
device.SetRenderTarget(null);
refractionTexture = (Texture2D)refractionRenderTarget;
FileStream stream = File.OpenWrite("Screenshot3333.png");
refractionTexture.SaveAsJpeg(stream, refractionTexture.Width, refractionTexture.Height);
}
Is there something wrong within the shader? I am not getting any errors or warnings