I’m trying to make a distortion shader for water in my game. I have a rendertarget I render everything to, and the water mask, and I’m try to simply capture the pixels underneath the mask, but I can’t get it to work. When I pass the textures, it’s as if they’re both completely transparent. What could I be doing wrong?
Shader:
texture Screen;
texture Mask;
float2 Offset;
sampler ScreenSampler = sampler_state
{
Texture = <Screen>;
};
sampler MaskSampler = sampler_state
{
Texture = <Mask>;
};
float4 PixelShaderFunction(float2 texCoord: TEXCOORD0) : COLOR
{
float4 mask = tex2D(MaskSampler, texCoord);
float4 color = tex2D(ScreenSampler, texCoord + Offset);
if (mask.a > 0)
{
return color;
}
return mask;
}
technique Technique0
{
pass Pass0
{
PixelShader = compile ps_4_0 PixelShaderFunction();
}
}
Render target:
Doldrums.Game.Graphics.GraphicsDevice.SetRenderTarget(renderTargetDistortion);
Doldrums.Game.Graphics.GraphicsDevice.Clear(Color.Transparent);
waterEffect.Parameters["Screen"].SetValue(Doldrums.RenderTarget);
waterEffect.Parameters["Mask"].SetValue(renderTargetWater);
waterEffect.Parameters["Offset"].SetValue(Doldrums.Camera.ToScreen(renderTargetPosition));
sprites.Begin(SpriteSortMode.Deferred, null, null, null, null, waterEffect);
sprites.Draw(renderTargetWater, Vector2.Zero, Color.White);
sprites.End();
Finally, rendering the rendertarget:
sprites.Draw(renderTargetDistortion, renderTargetPosition, Color.White);
PLEASE HELP - I was up until 4 am and nearly missed school cause of this. Holy shit shaders are difficult.