Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need a hand troubleshooting this shader

Started by DrunkMonkey25 Jul 7, 2011 at 10:06 PM 0 replies 1.5k views
Original Post
DrunkMonkey25
DrunkMonkey25
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:


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!
GraphicsDude
GraphicsDude
If this is a DX9 app, the smearing sounds like your not taking into account the half pixel offset when doing post effects.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.