Skip to content

Add custom projection mode to Camera3D, make Camera3D store its CameraMatrix and expose CameraMatrix to user code #2713

@Astrono2

Description

@Astrono2

Describe the project you are working on

I'm working on a portal plugin.

Describe the problem or limitation you are having in your project

I need to use oblique frustum projection to allow for the portals' cameras to clip content that's behind the portal plane. Which is currently impossible in Godot.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The enhancement would be to add a new projection mode, PROJECTION_CUSTOM to the Camera class, which would allow the developer to directly set the matrix to be used for projection. For my specific case, that would allow me to use oblique frustum projection. It would also address any other projection that any developer could want to use. And it would probably allow for some weird distortion effects as well.
Also, if a new projection is added with a CameraMatrix exposed to the user, it would make sense to migrate the entire Camera class and camera rendering to work with a CameraMatrix object belonging to each Camera instead of calculating the matrices from the Cameras' parameters.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I think this can be done in a few steps:

  1. Make CameraMatrix or other 4x4 matrix type available to user code
    1. Register CameraMatrix so that it is accessible to user code
    2. Add CameraMatrix to the documentation
  2. Change the Camera class to allow for custom matrices
    1. Add a CameraMatrix object to the Camera class (could be named projection_matrix)
    2. Add updating the matrix when a parameter is changed (fov, near, far, etc.) by modifying the appropriate item in the matrix
    3. Add updating the matrix when the projection mode is changed by using the already existing methods in the CameraMatrix struct
    4. Add PROJECTION_CUSTOM to the Projection enum
    5. Add the CameraMatrix to the Camera's properties
  3. Replace steps like this one in the rendering process with getting the camera's projection matrix.
  4. Add necessary methods to either Camera3D or CameraMatrix to replace the functionality that calculating the matrix when necessary provided (e.g. setting the aspect ratio). So that the matrix doesn't have to be completely remade
  5. Update Camera3D and possibly RenderingServer documentation
  6. XR wizardry I cannot comprehend.

Here's a little mockup:
image image
image

If this enhancement will not be used often, can it be worked around with a few lines of script?

Most definitely not

Is there a reason why this should be core and not an add-on in the asset library?

It requires considerable (although not very invasive) changes to two core classes and the rendering system.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    On Hold

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions