Hi everyone, I’m working on a radial distortion shader but for some reason, even though I’m passing it the coordinates of my mouse, the distortion area moves slightly slower than the mouse is, as you can see in this video.
Here’s the code where I pass in parameters for the shader:
shockwave.Parameters["res"].SetValue(Screen.Size.ToVector2()); shockwave.Parameters["center"].SetValue(new Vector2(mouse.X / Screen.Width, mouse.Y / Screen.Height));
And here’s the code for the pixel shader function:
float4 PixelShaderFunction(float2 UV : TEXCOORD0) : COLOR0
{
float ratio = res.x / res.y;
float2 scaled_UV = (UV - float2(0.5, 0)) * float2(ratio, 1) + float2(0.5, 0);
float mask = (1 - smoothstep(radius - feather, radius, length(scaled_UV - center))) *
smoothstep(radius - thickness - feather, radius - thickness, length(scaled_UV - center));
float2 disp = normalize(scaled_UV - center) * force * mask;
float4 color = tex2D(samp, UV - disp);
return color;
}
If anyone knows why it’s not following the mouse correctly I’d really appreciate that!