Unexpected DhApiRenderParam#dhProjectionMatrix content with Iris enabled

I'm grabbing the projection matrix from the DhApiAfterRenderEvent and use it to perform a depth test in one of my shaders. And this works fine as long as no Iris shaders are active. Usually the projection matrix contains "normal" values, e.g.:
4,702E-1 0,000E+0 0,000E+0 -0,000E+0
0,000E+0 8,541E-1 0,000E+0 -0,000E+0
-0,000E+0 -0,000E+0 -1,014E+0 -4,908E+1
-0,000E+0 -0,000E+0 -1,000E+0 -0,000E+0
4,702E-1 0,000E+0 0,000E+0 -0,000E+0
0,000E+0 8,541E-1 0,000E+0 -0,000E+0
-0,000E+0 -0,000E+0 -1,014E+0 -4,908E+1
-0,000E+0 -0,000E+0 -1,000E+0 -0,000E+0
But when an Iris shader is active (in this case BSL but I don't think it matters) the values seem wrong:
1,000E+0 0,000E+0 0,000E+0 0,000E+0
0,000E+0 1,000E+0 0,000E+0 0,000E+0
0,000E+0 0,000E+0 -1,014E+0 -4,908E+1
0,000E+0 0,000E+0 0,000E+0 1,000E+0
1,000E+0 0,000E+0 0,000E+0 0,000E+0
0,000E+0 1,000E+0 0,000E+0 0,000E+0
0,000E+0 0,000E+0 -1,014E+0 -4,908E+1
0,000E+0 0,000E+0 0,000E+0 1,000E+0
In earlier version of DH and Iris (1.x on 1.20.1 for example) this wasn't an issue. It seems to me that DH is not providing the correct projection matrix, which is causing the depth test in my shader to produce wrong results. I'm using: - DH 2.1.2-a - Iris 1.7.2 - Indium 1.0.33 - Sodium 0.5.9 and trying to update the DH compatibility of my mod "Better Clouds"
29 Replies
Miki_P98
Miki_P986mo ago
I hope you will find a fix!
Wendelin
WendelinOP6mo ago
bump
Puhpine
Puhpine6mo ago
as @James Seibel (GMT-6) was the only one who could help you here: https://discord.com/channels/881614130614767666/1211290858134052894 i assume he's also the only one who can here you with this new problem
Wendelin
WendelinOP6mo ago
Yes, probably. But I'm sure he has a lot to do.
BackSun
BackSun6mo ago
Thanks for the info I didn't realize there was a problem. Hmmm... Iris must be modifying the matrix, which is causing it to change when passed along. I have an idea on how to fix it, I'll add this to my todo list.
Wendelin
WendelinOP6mo ago
Thanks! Do you think it would be better to wait for the fix or look for a workaround on my end?
BackSun
BackSun6mo ago
I just pushed a fix, please let me know if you're still having issues.
Wendelin
WendelinOP6mo ago
Awesome! Do you have a dev-build at hand so I can test it out?
BackSun
BackSun6mo ago
The latest nightly build has it
Wendelin
WendelinOP6mo ago
Oh, sorry I didn't realize you had nightly builds
BackSun
BackSun6mo ago
No worries, just grab a build from #links-n-downloads
Wendelin
WendelinOP6mo ago
I can't test it out for now since Iris hasn't updated to the new DhApi version (afaik) and crashes since the math types have been renamed.
BackSun
BackSun6mo ago
Makes sense, IMS has a test build for shader devs but I'm guessing it isn't public yet.
Wendelin
WendelinOP6mo ago
I'll try to make a local build of Iris which uses the new dh api I've managed to patch iris and fix a crash related to the new LOD Clouds but using the 13363ff3 nightly build the projection matrix still isn't correct:
1,000E+0 0,000E+0 0,000E+0 0,000E+0
0,000E+0 1,000E+0 0,000E+0 0,000E+0
0,000E+0 0,000E+0 -1,022E+0 -7,885E+1
0,000E+0 0,000E+0 0,000E+0 1,000E+0
1,000E+0 0,000E+0 0,000E+0 0,000E+0
0,000E+0 1,000E+0 0,000E+0 0,000E+0
0,000E+0 0,000E+0 -1,022E+0 -7,885E+1
0,000E+0 0,000E+0 0,000E+0 1,000E+0
Update: just tested with todays nightly build afddf416 and the issue is still the same I've finally had time to look deeper into the issue. Here are my findings: renderLods calls renderLodLayer with the proper mcProjectionMatrix. DhApiBeforeRenderEvent is fired DhApiAfterRenderEvent is not fired because Delayed.renderProxy.getDeferTransparentRendering() is false. renderDeferredLods calls renderLodLayer with an identity matrix for mcProjectionMatrix DhApiBeforeRenderEvent is fired DhApiAfterRenderEvent is fired using a dhProjectionMatrix derived from the identity matrix, which results in a not-really-useful matrix. I can't tell if thats right or wrong. To fix my issue it seems that I can switch to DhApiBeforeRenderEvent and grab the projection matrix from there, since it contains the right projection matrix during the opaque rendering pass. However I'm not sure the code in renderLodLayer is behaving correctly. It seems odd to me that there are two DhApiBeforeRenderEvent but only one DhApiAfterRenderEvent fired during a frame.
BackSun
BackSun6mo ago
Very interesting... Since the matrices are correct for the opaque layer, but not the deferred layer I'm going to assume that Iris is messing with the projection matrix before DH pulls it in. Not sure why that would be though. When you say that the DhApiBeforeRenderEvent is fired twice, do you mean the exact DhApiBeforeRenderEvent event is fired twice? When deferred rendering is active the DhApiBeforeRenderEvent should fire for the opaque layer, then then the DhApiBeforeDeferredRenderEvent should fire for the transparent layer.
Wendelin
WendelinOP6mo ago
oh, I missed the "Deferred" part of DhApiBeforeDeferredRenderEvent and thought it was also a DhApiBeforeRenderEvent. So corrected: Two "before render" events are fired, one DhApiBeforeRenderEvent in the opauqe path and one DhApiBeforeDeferredRenderEvent in the transparent path. However only a single DhApiAfterRenderEvent is fired in the transparent path.
Wendelin
WendelinOP6mo ago
mcProjectionMatrix is an identity matrix because you explicitly pass in one.
No description
BackSun
BackSun6mo ago
Ok, good that's exactly how it should be done. The DhApiAfterRenderEvent should only be called after all rendering is done.
Wendelin
WendelinOP6mo ago
Alright, I guess that makes sense, but the discrepancy between the DhApiRenderParam of the before and after event is still quite odd
BackSun
BackSun6mo ago
Oh dang it. I forgot about that. I think in MC 1.21 the renderSectionLayer started merging the model view and projection matricies, so that's why they're the same. I remember that being quite annoying the first time I delt with that...
Wendelin
WendelinOP6mo ago
Maybe the DhApiAfterRenderEvent shouldn't contain the DhApiRenderParam at all, or both. But none would be easier and less confusing. As I understand is know this is the intended meaning of the events: 1. Opaque pass start 2. Transparent pass start 3. Rendering end But the actual information of the events is: 1. Opaque pass start (using ABC params) 2. Transparent pass start (using XYZ params) 3. Transparent pass end (using XYZ params) So the values passed to the after render event handlers doesn't match their "definition". Sorry it's difficult to express what I mean by that.
BackSun
BackSun6mo ago
What do you mean bye ABC/XYZ params?
Wendelin
WendelinOP6mo ago
The DhApiRenderParam used for that pass
BackSun
BackSun6mo ago
What's an ABC RenderParam? I think I'm missing something
Wendelin
WendelinOP6mo ago
Changing the DhApiAfterRenderEvent definetly isn't required since it's really not a big issue once you know about it, but it would definietly be worth noting in the docs. ABC as a name for the values contained in DhApiRenderParam, like renderPass and mcProjectionMatrix.
BackSun
BackSun6mo ago
Oh, you're just saying the values are different, gotcha
Wendelin
WendelinOP6mo ago
yeah
BackSun
BackSun6mo ago
Having thought about it, I think you're right. Including a RenderParam for the ending event is more likely to cause confusion than anything since the parameters can change if deferred rendering is enabled. I've removed the parameters and I'll be pushing my changes soon. Thanks for the help and sorry for the confusion
Wendelin
WendelinOP6mo ago
No worries
Want results from more Discord servers?
Add your server