Original Post
Hello!
I'm getting strange results after implementing this algorithm as a post process shader. Instead of the correct result of "waves" radiating, the image just smears diagonally down to the right while fading out.
Here's my HLSL code:
and my rendering process:
Its pretty straight forward, and this isn't a tricky effect, so I don't know where I'm going wrong. I've tried not clearing either currBuffer or lastBuffer, additively blending the two buffers, and a few other small things I can't recall immediately.
Well, there you have it. I appreciate any advice you may be able to pass my way. Thanks for reading!
I'm getting strange results after implementing this algorithm as a post process shader. Instead of the correct result of "waves" radiating, the image just smears diagonally down to the right while fading out.
Here's my HLSL code:
texture lastFrame;
sampler LastFrameSmplr = sampler_state
{
Texture = <lastFrame>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};
float4 DoWater(float2 texCoord : TEXCOORD0) : COLOR
{
float2 n = float2(texCoord.x, texCoord.y - 0.002f);
float2 s = float2(texCoord.x, texCoord.y + 0.002f);
float2 e = float2(texCoord.x + 0.002f, texCoord.y);
float2 w = float2(texCoord.x - 0.002f, texCoord.y);
float3 nP = tex2D(LastFrameSmplr, n);
float3 sP = tex2D(LastFrameSmplr, s);
float3 eP = tex2D(LastFrameSmplr, e);
float3 wP = tex2D(LastFrameSmplr, w);
float3 cP = tex2D(LastFrameSmplr, texCoord);
float3 retval = (nP + sP + eP + wP) / 4 - cP;
retval *= 0.99f;
return float4(retval + cP, 1.0f);
}
and my rendering process:
Create Buffer1 and Buffer2 as render targets
Pull Surface1 and Surface2 from their respective Buffers
currBuffer = Buffer1
currSurface = surface1
lastBuffer = Buffer2
lastSurface = Surface2
loop
if the spaceBar is pressed
clear z buffer
render a sphere into lastSurface (effectively lastBuffer)
end if
render to currBuffer
clear z buffer and color buffer
set technique to my water algorithm
set the texture to lastBuffer
render a quad that covers the entire surface of currBuffer
end render
render currBuffer to BackBuffer
swap currBuffer and lastBuffer
swap currSurface and lastSurface
end loop
Its pretty straight forward, and this isn't a tricky effect, so I don't know where I'm going wrong. I've tried not clearing either currBuffer or lastBuffer, additively blending the two buffers, and a few other small things I can't recall immediately.
Well, there you have it. I appreciate any advice you may be able to pass my way. Thanks for reading!