cschied / q2vkpt

Real-time path tracer VKPT integrated into q2pro Quake 2 client.
http://brechpunkt.de/q2vkpt
GNU General Public License v2.0
946 stars 76 forks source link

Path-tracing with Nonlinear projections (for wider FOVs) #10

Open shaunlebron opened 5 years ago

shaunlebron commented 5 years ago

Congrats on the project 🎉 I wanted to add that path-tracing isn't just the holy grail for lighting—it also frees the renderer to use different projections for showing wider FOVs without terrible distortion:

Before I jump in—could you weigh in with your thoughts? I imagine this wouldn't be hard to do since each pixel just has to map to a different ray determined by the chosen projection, but I'm not sure if anything in the pipeline assumes the standard projection. Thanks for your thoughts.

cschied commented 5 years ago

This is entirely possible. Care needs to be taken that the forward-projection in is changed accordingly.

The main path tracer lives in , search for global_ubo.VP

Some of the reprojection code and the reconstruction filter might need some fiddling with the epsilons.

shaunlebron commented 5 years ago

Thanks, looks like the call to get_primary_ray is where we can do the projection. 👍

https://github.com/cschied/q2vkpt/blob/a4de8e90ea86a31e0cc8c6f74303c2dd473a56ca/src/refresh/vkpt/shader/path_tracer.h#L484

cschied commented 5 years ago

Yes, you just need to make sure to also change all the code that uses global_ubo.VP

BurningNorth commented 5 years ago

My practical knowledge of path tracing is too limited to be any help here, but as someone who's spent far too much time trying to come up with needlessly clever raster projections to do this in other engines without the post-process step (spoiler alert: haha nope), I'm super excited to see if you can make this work. 😃

shaunlebron commented 5 years ago

vp = vector projection? found this reference: https://github.com/cschied/q2vkpt/blob/a4de8e90ea86a31e0cc8c6f74303c2dd473a56ca/src/refresh/vkpt/shader/asvgf_fwd_project.comp#L90

cschied commented 5 years ago

This is the view-projection matrix, going from world-space to clip-space.

shaunlebron commented 5 years ago

Ah I see now, thanks. Here's a plan, if you wanna check it:

Standard Projection Matrices

These matrices are used for standard projection:

Non-linear projection functions

NOTE: Non-linear projections can't be performed by matrices—it's a linear algebra afterall.

To swap out the standard projection with a non-linear one—any time the above matrices are multipled by a vector, we have to replace them with calls to custom projection functions:

Where to change?

Add projection functions to global_ubo.h:

Modify to use inverse projection (customInvVP) here: https://github.com/cschied/q2vkpt/blob/a4de8e90ea86a31e0cc8c6f74303c2dd473a56ca/src/refresh/vkpt/shader/path_tracer.h#L282

Modify to use forward projection (customVP) here: https://github.com/cschied/q2vkpt/blob/a4de8e90ea86a31e0cc8c6f74303c2dd473a56ca/src/refresh/vkpt/shader/asvgf_fwd_project.comp#L90

cschied commented 5 years ago

The plan looks good! Let me know if you need any additional information. There might be the need to fix some of the reconstruction filter but we'll have to see the results first.