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));
Yep i have seen this behavior before myself its really weird.
The only thing i can think of is that this is because the actual mouse code we use thru mouse.GetState lags behind what the windows mouse sees as the current position i guess you could try to prove that with regular spritebatch if thats not the reason then i have no idea how or what why it could be.
I don’t think it lags behind though, because even if I pass Vector2.Zero into the shader, it draws it as if it’s “origin” is it’s center left, rather than just the center.
Yea this doesn’t look like a lag issue, it looks like a scale issue. At the edges of the screen, your mouse out-paces where the shader thinks it is.
I notice in your code you’re passing Screen.Size for “res” but you’re using Screen.Width and Screen.Height to calculate “center”. Is there any difference in value between these two?
This looks familiar to me, but it’s late and I can’t put my finger on it. Check your values and math
center.x goes from 0 to 1. UV.x also goes from 0 to 1.
scaled_UV.x doesn’t go from 0 to 1 anymore, because you multiply and shift it. That’s why (scaled_UV - center) doesn’t make much sense anymore.
What if you just use UV everywhere instead of scaled_UV?
(UV - center) will give you the distance from the center in UV-coordinates. As you rightly pointed out, this will be stretched, because the UV-coordinates are stretched. If you just “unstretch” this distance, and use it in your distortion calculations, you should be fine.