Skip to content

Conversation

MiiBond
Copy link
Contributor

@MiiBond MiiBond commented Oct 10, 2025

This changes the voxelization strategy for WebGPU to allow it to be done in a single pass (though, generation of mips still takes additional steps). This is possible using textureStore to write to arbitrary texels in a 3D texture. It also uses vertex pulling to correctly determine the provoking vertex for each triangle and retrieve adjacent vertices so that we can calculate the triangle's normal. This is used to swizzle the xyz components to maximize the rasterized area and not miss voxels.

Anywho, this makes updating shadows for animated meshes much more plausible. I'm not sure the best way to do this but currently, in my playground, I'm doing this:

const frameSkip = 1;
let frame = 0;
scene.onAfterAnimationsObservable.add(() => {
    if (enableIblShadows) {
        if (frame == 0 && scene.animatables.find((anim) => !anim.paused)) {
            iblShadowsPipeline.updateVoxelization();
            iblShadowsPipeline.resetAccumulation();
        }
        if (frame === frameSkip) {
            frame = 0;
        } else {
            frame++;
        }
    }
});

Is there a better way to query whether there is currently an animation happening?

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 10, 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.

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 10, 2025

@Popov72
Copy link
Contributor

Popov72 commented Oct 13, 2025

This changes the voxelization strategy for WebGPU to allow it to be done in a single pass (though, generation of mips still takes additional steps). This is possible using textureStore to write to arbitrary texels in a 3D texture. It also uses vertex pulling to correctly determine the provoking vertex for each triangle and retrieve adjacent vertices so that we can calculate the triangle's normal. This is used to swizzle the xyz components to maximize the rasterized area and not miss voxels.

Anywho, this makes updating shadows for animated meshes much more plausible. I'm not sure the best way to do this but currently, in my playground, I'm doing this:

const frameSkip = 1;
let frame = 0;
scene.onAfterAnimationsObservable.add(() => {
    if (enableIblShadows) {
        if (frame == 0 && scene.animatables.find((anim) => !anim.paused)) {
            iblShadowsPipeline.updateVoxelization();
            iblShadowsPipeline.resetAccumulation();
        }
        if (frame === frameSkip) {
            frame = 0;
        } else {
            frame++;
        }
    }
});

Is there a better way to query whether there is currently an animation happening?

In a real-world scenario, I think we would let the user decide when to update the voxelization (meshes can also be moved without using animation, a custom vertex shader can apply deformation, etc.). But for a test PG, I think this is fine.

Let us know when the PR is ready for review!

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.

3 participants