Skip to content

Easymode Projection Setters #875

@bjornbytes

Description

@bjornbytes

I get a sinking feeling every time I want to change the projection matrix. I can never remember the argument order for Mat4:orthographic (even though it was recently changed to take just 2 width/height arguments!), and if I'm trying to set up the cameras to render to a cubemap I have to go copy the code from somewhere else.

It might be nice to have easier ways to set the projection. Maybe there could be a ProjectionMode that represents all the different ways to do it:

  • ortho or 2d
  • fov (takes vertical FOV, aspect, near, far)
  • fov4 (4 FOV values for an asymmetric projection like for VR)
  • cube (sets a 90 degree perspective matrix for rendering a cubemap face/faces)

We could also make the view index optional now (we can't do that right now because we can't tell the difference between a numeric projection param and a view index).

Here are some examples:

pass:setProjection('ortho') --> set orthographic projection for first camera, using canvas size and default near/far
pass:setProjection('ortho', w, h) --> set ortho matrix with custom size
pass:setProjection('ortho', w, h, n, f)
pass:setProjection('cube') --> set up to 6 cameras to the 90 degree perspective matrix
pass:setProjection(i, 'fov4', lovr.headset.getViewAngles(i)) --> assigning projection based on headset views
pass:setProjection('fov', math.rad(50)) --> super easy way to change the FOV if you don't care about anything

Near/far would be optional like they currently are, and default to 1cm near and 0 far (infinite reverse Z).
You can always put a view index before the ProjectionMode, but if you leave it off then it defaults to 1.

Also as a bonus for the cube mode we should be able to do Pass:setViewPose('cube') to just splat all 6 camera poses.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions