BastiaanOlij / RERadialSunRays

Demo project for Rendering Effects in Godot
MIT License
34 stars 3 forks source link

Something seems to be wrong with the sun disk position when the camera is rotated #3

Open digi-chris opened 6 days ago

digi-chris commented 6 days ago

Hi,

Thanks for this great example! It's been interesting seeing what's possible with the new compositor.

I'm not 100% sure if I'm just misunderstanding something, but I think the calculation deciding where the sun disk is located is doing something unexpected.

I created a video showing the issue, it also happens in the example but the effect is less pronounced:

https://vimeo.com/1019383187

It seems to me that when looking directly at the sun, the position is correct. As the camera is rotated, especially on the x-axis, the sun disk seems to get higher or lower than the actual sun position. Turning around the face the other way also shows the sun in the opposite direction to where it really is (demonstrated a bit quickly at then end of the video).

I'm not sure if I'm just not setting the sun location correctly, or it's not supposed to work with a dynamically-moving sun and moving camera, but since the example is exhibiting the same behavior I wondered if it's a bug?

Thanks,

Chris.

digi-chris commented 3 days ago

I figured it out... it's on this line:

https://github.com/BastiaanOlij/RERadialSunRays/blob/78dea14e07d2b7487d09511edb1017a2f9995c5c/radial_sky_rays/radial_sky_rays.gd#L183

I'm not entirely sure why, but you have to reverse the sun_proj.y value like this:

var sun_pos : Vector2 = Vector2(sun_proj.x / sun_proj.w, -sun_proj.y / sun_proj.w)

That seems to resolve it.

The other problem with seeing the sun disk when facing away from the camera is of course because the sun is behind the camera. Technically the calculated position is correct. I think this is fairly simple to fix (something to do with the .w coordinate?) but I haven't had a chance to look yet.

BastiaanOlij commented 20 hours ago

Hey @digi-chris ,

Good find, there was a recent change around the projection matrices as the flip only happens when loading those into the GPU struct we use. We're working on direct access to those.

And indeed, when the sun is behind us that will give issues, I believe we can evaluate the sign of sun_proj.z/sun_proj.w, from memory if that is negative, the sun will be behind us.