Skip to content

Fix Iris matrices when rendering sublevels#326

Open
djefrey wants to merge 1 commit intoryanhcode:mainfrom
djefrey:fix-iris-normals
Open

Fix Iris matrices when rendering sublevels#326
djefrey wants to merge 1 commit intoryanhcode:mainfrom
djefrey:fix-iris-normals

Conversation

@djefrey
Copy link
Copy Markdown
Contributor

@djefrey djefrey commented Apr 21, 2026

Iris replaces ShaderInstance with ExtendedShader.
When ExtendedShader.apply() is called, modelViewInverse and normalMatrix are updated using MODEL_VIEW_MATRIX value.

However, in VanillaChunkedSubLevelRenderData.renderChunkedSubLevel(), MODEL_VIEW_MATRIX.set() is called after apply() has already been called. This leaves the Iris matrices in an incorrect state.

This can be fixed by delaying the apply() call until just before rendering.

Before:
2026-04-21_15 27 15

After:
2026-04-21_15 26 13

Iris replaces ShaderInstance with ExtendedShader.
When ExtendedShader.apply() is called, modelViewInverse and
normalMatrix are updated using MODEL_VIEW_MATRIX value.

However, in VanillaChunkedSubLevelRenderData.renderChunkedSubLevel(),
MODEL_VIEW_MATRIX.set() is called after apply() has already been called.
This leaves the Iris matrices in an incorrect state.

This is fixed by delaying the apply() call until just before rendering.
@ryanhcode
Copy link
Copy Markdown
Owner

tested, awesome! What's with the dynamic effects uniforms not needing to be uploaded anymore?

@ryanhcode
Copy link
Copy Markdown
Owner

oh, is it because the apply is afterwards now and uploads them anyway? yeah okay

@djefrey
Copy link
Copy Markdown
Contributor Author

djefrey commented Apr 21, 2026

I made the change when I removed the now useless uploads. However, as I'm reading the code again, I'm not sure if this is actually correct.

@ryanhcode
Copy link
Copy Markdown
Owner

will this have any more noticeable impact than just uploading the individual uniforms like we were doing before?

@djefrey
Copy link
Copy Markdown
Contributor Author

djefrey commented Apr 21, 2026

I've done a simple benchmark: 354 sublevels on a flat world, no shaderpack.
This commit: ~760fps
With uploads readded: ~725fps
So it seems there's a small gain to prevent unnecessary uploads.

However, I noticed that this commit introduces a significant performance regression, as the previous version is around ~1400fps. This regression is caused by apply() reupload every uniforms, as the dirty flag in Uniform is ignored.
The only fix I see would be to compute and update manually modelViewInverse and normalMatrix if shader is an ExtendedShader instance.

@ryanhcode
Copy link
Copy Markdown
Owner

With those numbers, I think it's worth it to have explicit compatibility with Iris here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants