Skip to content

IBL Shadows - Init passes only after voxelization #16527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MiiBond
Copy link
Contributor

@MiiBond MiiBond commented Apr 24, 2025

Okay, I've been investigating the issue where the shadow accumulation isn't working initially after loading the IBL Shadow Demo playground. On some loads, the shadows will appear noisy and not accumulate over multiple frames. Note that this issue never happens if you have Spector.js enabled, which is why I had such a hard time reproducing it originally.
The actual issue is that the uniform, accumulationParameters fails to be set with
WebGL: INVALID_OPERATION: uniform4f: location is not from the associated program

Even though this fails, the uniform value is still cached and Babylon doesn't set the uniform again until the value changes. That is why accumulation appears to be disabled until you move the camera (which causes the uniform to change and update).
I have not been able to figure out why the uniform set fails in the first place. It seems to be consistently the 3rd render that fails. Before that, the uniform is set successfully and, as far as I can tell, the shader program isn't updated after that point. And after the failure, the uniform can be set again.

The one thing that I was able to change to make the issue seem to go away was to put enough of a delay on the rendering of the accumulation pass. I've added logic to only start rendering the accumulation pass once the first voxelization is complete. This is fine since we can't render shadows until this is done anyway but I don't know why it should fix the problem.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 24, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@@ -199,6 +203,10 @@ export class _IblShadowsSpatialBlurPass {
width: Math.max(1.0, Math.floor(this._engine.getRenderWidth() * scaleFactor)),
height: Math.max(1.0, Math.floor(this._engine.getRenderHeight() * scaleFactor)),
};
// Don't resize if the size is the same as the current size.
if (this._outputTexture.getSize().width === newSize.width && this._outputTexture.getSize().height === newSize.height) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added logic to prevent resizing if the size hasn't actually changed. I assume that resizing the procedural texture may result in the shader program needing to be recreated so I was trying to prevent this from happening.

// onAfterRenderTargetsRenderObservable is called twice during a frame and we only want to render
// on the second call, after the scene has been rendered to the GBuffer.
this._scene.onAfterRenderTargetsRenderObservable.add(() => {
if (++counter == 2) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't like this counter logic and I feel like it might be related to the problem. The onAfterRenderTargetsRenderObservable fires twice during a frame and I only want to run these passes once, after the geometry buffer is rendered and before the main render. Is there a better way to do this?

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 24, 2025

I think I've verified that the uniform does exist by doing a gl.getUniform before the render that results in the error so I'm really at a loss.

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 24, 2025

Another thing to note is that I can't reproduce this issue in Firefox or Safari. It only seems to happen in Chrome and Edge.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 24, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 24, 2025

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