Fix incorrect projection matrix for GI#108628
Conversation
BastiaanOlij
left a comment
There was a problem hiding this comment.
Ran into this while investigating #117303 and this also fixes that issue when frustum camera mode is used.
There is one more related bug around this when stereo render is enabled and it would be great if you could include it (else I'm fixing this as part of a bigger PR of mine), could you change this line in gi.glsl:
pos.z = texelFetch(sampler2D(depth_buffer, linear_sampler), screen_pos, 0).r * 2.0 - 1.0;
to:
pos.z = texelFetch(sampler2D(depth_buffer, linear_sampler), screen_pos, 0).r;
|
Ok, doing some more testing on this I found additional issues. One clue that likely explains why your fix didn't work properly for the other screenspace effects is that our matrix unproject code results in an inverted-y. In the GI code you'll find that this is only applied after Unfortunately this is incorrect for stereo rendering. Whomever changed this though it would be enough to remove the y-flip from our projections depth correction, but sadly all sorts of funky things go wrong when you do this. I'll raise a PR on top of yours with my fixes that make SDFGI work in all scenarios I've tested. |
|
Superseded by #117619. Thanks for the contribution! |
so I think this problem was a lot simpler than I thought. it looks like when these lines were written originally, the column order was backwards.
[0][2]and[1][2]are both always 0.0 in my testing, unused elements of the matrix as far as I can tell, while[2][0]and[2][1]appear to be the intended ones.note that this fixes voxel GI and SDFGI, but not screen space effects. thus, this is only a partial fix for #108508. these exact same lines also exist in
ss_effects.cpp, and applying the same fix here does fix the X axis, but it does not fix the Y axis, so I'm leaving it as-is for someone else to tackle, because I think at least SSR might need more work than just this projection fixed in order to support an offset frustum.