godot
godot copied to clipboard
Implementation of new Camera3D type: Oblique
Closes: https://github.com/godotengine/godot-proposals/issues/501 Partial solution to this proposal: https://github.com/godotengine/godot-proposals/issues/2713
This PR should not necessarily be a reason to close the proposal 2713, it is merely a straightforward implementation of oblique near plane clipping to implement a portal--or other similar--mechanic.
This PR is essentially an update to my previous PR: https://github.com/godotengine/godot/pull/64876 The main difference is that shadows were fixed.
This other PR attempts to completely solve proposal 2713 mentioned above, but apparently is having issues with shadows. Considering that its commits try to implement custom projections by adding a new camera type like with my PRs, there is a good chance the way I fixed shadows could also work there too: https://github.com/godotengine/godot/pull/84454
The solution was that along with the main Oblique camera projection a separate, normal Perspective camera projection needed to be included with the CameraData
used in the RenderSceneCull::_render_scene()
that was used explicitly for lighting and shadows.
However, regarding the potential question of whether one PR should be included over the other as a solution, clearly the more general solution can see a wider range of uses. However, I believe this implementation of an Oblique Near Plane camera still has merit based on the majority use case of creating a portal mechanic, etc where oblique near clipping is necessary.
This is because the interface for the Oblique camera included in this PR has been simplified so that users are only required to provide at a minimum the transform of the plane they wish to use as the near clipping plane of the camera using set_oblique_plane_from_transform()
.
Additionally, because all of the required math (especially the matrix math) is happening in C++, the effect is as efficient as possible, without requiring steps to first camera.get_projection
, then doing matrix manipulation, then camera.set_projection
all in GDScript.
Alternatively, because the Oblique Near Plane matrix manipulations "... can be applied to any projection matrix, ..." (https://terathon.com/lengyel/Lengyel-Oblique.pdf, pg. 2) it's possible that all camera types (including the other proposed custom projection camera) could benefit from a general is_oblique_near_plane
boolean toggle instead of this dedicated oblique camera which only implements the algorithm for a Perspective projection.
Video 1: Current state of personal portal game mechanic https://youtu.be/A_-2nTyKVkU Notice that the portal viewports are not blocked by the surface the portal is on (the issue with using a standard perspective camera), and that shadows and lighting appear the same when looking through the portal (as evidenced by walking through the portal where a seamless transition occurs).
Video 2: Previous video showcasing dynamically the difference oblique near plane clipping makes https://youtu.be/PipVd6wRnMk?si=lCThReaKyO-smBaP Note that this older video did not properly handle shadows, and the viewport texture color and environment lighting were all wrong giving it that washed out look (both fixed in Video 1).
Image 1: Portal effect using Perspective camera
Image 2: Portal effect using Oblique camera
Image 3: Oblique camera editor interface