I’m creating a game that involves you raycasting on objects through a screen distorted by the lens distortion effect from post processing.
However, because it is distorted, the raycast no longer works, because of the warped screen coordinates.
I’m using URP.
How would you guys suggest I fix this?
This is what it looks like:
I think you’ll have to read the lens distortion parameters from the post process volume and perform the same distortion calculation on your screen position to get a “distorted” ray to cast with. This might help:
I have tried that, I’ve implemented the code and it doesn’t work. I’m using the URP post processing so it may be different, how the lens distortion works
“I’ve implemented the code and it doesn’t work.”
I haven’t done anything like that before with shaders, but remember the clicks on screen item hit the distorted position, so shouldn’t you remove the distortion, to get the actual object world or screen position to raycast against?
Maybe add some debug draw lines or OnDrawGizmos to verify your click position and actual object (undistorted) positions match?
im not sure what kind of algorithm it uses, but I might try to use gizmos to see how it distorts
