   Why is my HLSL clip function giving me this effect?
  OK so first I will post the image to show what I'm getting and maybe you've had this issue before and may know right away...I'm trying to clip everything above 5 on the y plane, hence why the bottom of the texture is clear, but what is supposed to be clipped is coming out only partially clipped<br /><br />Here is my code for creating the refraction mapprivate void DrawTempPlane(Matrix viewMatrix)   {  effect.CurrentTechnique = effect.Techniques["Clip"];  Matrix worldMatrix = Matrix.Identity;  effect.Parameters["xWorld"].SetValue(worldMatrix);  effect.Parameters["xView"].SetValue(viewMatrix);  effect.Parameters["xProjection"].SetValue(projectionMatrix);  effect.Parameters["ClipPlane0"].SetValue(new Vector4(refractionplane.Normal, refractionplane.D));  device.SetRenderTarget(refractionRenderTarget);  device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);  foreach (EffectPass pass in effect.CurrentTechnique.Passes)  { pass.Apply(); // This is where the draw code will be placed device.Indices = terrainIndexBuffer; int noVertices = terrainVertexBuffer.VertexCount; int noTriangles = terrainIndexBuffer.IndexCount / 3; device.SetVertexBuffer(terrainVertexBuffer); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, noVertices, 0, noTriangles);  }    DrawTerrain(viewMatrix);  device.SetRenderTarget(null);  refractionMap = refractionRenderTarget;  FileStream fs = new System.IO.FileStream(@"refraction.png", System.IO.FileMode.OpenOrCreate);  refractionMap.SaveAsJpeg(fs, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);   }Here is my DrawTerrain functionprivate void DrawTerrain(Matrix currentViewMatrix)   {  effect.CurrentTechnique = effect.Techniques["MultiTextured"];  effect.Parameters["xTexture0"].SetValue(sandTexture);  effect.Parameters["xTexture1"].SetValue(grassTexture);  effect.Parameters["xTexture2"].SetValue(rockTexture);  effect.Parameters["xTexture3"].SetValue(snowTexture);  Matrix worldMatrix = Matrix.Identity;  effect.Parameters["xWorld"].SetValue(worldMatrix);  effect.Parameters["xView"].SetValue(currentViewMatrix);  effect.Parameters["xProjection"].SetValue(projectionMatrix);  effect.Parameters["xTexture"].SetValue(grassTexture);  effect.Parameters["xEnableLighting"].SetValue(true);  effect.Parameters["xAmbient"].SetValue(0.4f);  effect.Parameters["xLightDirection"].SetValue(new Vector3(-0.5f, -1, -0.5f));  foreach (EffectPass pass in effect.CurrentTechnique.Passes)  { pass.Apply(); // This is where the draw code will be placed device.Indices = terrainIndexBuffer; int noVertices = terrainVertexBuffer.VertexCount; int noTriangles = terrainIndexBuffer.IndexCount / 3; device.SetVertexBuffer(terrainVertexBuffer); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, noVertices, 0, noTriangles);  }   }And here is my HLSL clip techniquevoid Clipvs(inout float4 position : POSITION0, out float4 clipDistances : TEXCOORD0){clipDistances.x = 0;clipDistances.y = dot(position, ClipPlane0);clipDistances.z = 0;clipDistances.w = 0;    position = mul(mul(mul(position, xWorld), xView), xProjection);}  float4 Clipps(float4 clipDistances : TEXCOORD0) : COLOR0 {  clip(clipDistances.y);    return float4(0,0,0,0); // TODO: whatever other shading logic you want }  technique Clip{ pass Pass0    {    VertexShader = compile vs_2_0 Clipvs();    PixelShader = compile ps_2_0 Clipps();} } Any help on this topic would be great!!
  the function clip.. . . .Use this function to simulate clipping planes if each component of the x parameter represents the distance from a plane. Discards the current pixel if the specified value is less than zero.if you want to clip all pixels with a y (world space) greater than 5, its pretty easyvoid Clipvs(inout float4 position : POSITION0, out float4 clipDistances : TEXCOORD0){    float4 pos = mul(position, xWorld);    clipDistances.x = pos.y-5;// subtract 5 because if the height is 6, it will be one, and will not get clipped in the pixel shader.. done dealposition = mul(mul(pos, xView), xProjection);} float4 Clipps(float4 clipDistances : TEXCOORD0) : COLOR0 {  clip(clipDistances.x);    return float4(0,0,0,0); // TODO: whatever other shading logic you want } ;  Just tried it and its giving me the exact same result...   