Skip to content

Conversation

@MiiBond
Copy link
Contributor

@MiiBond MiiBond commented Oct 31, 2025

This PR adds defines to assist with vertex pulling when the vertex buffers are interleaved.
I'm also including a fix by @Popov72 for IBL shadow voxelization when using bones.

@bjsplat
Copy link
Collaborator

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

1 similar comment
@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 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 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 31, 2025

@deltakosh deltakosh requested a review from Popov72 November 1, 2025 00:15
@MiiBond MiiBond force-pushed the mbond/voxel-shadow-fixes branch from 1cee238 to ce4c445 Compare November 7, 2025 19:31
@MiiBond
Copy link
Contributor Author

MiiBond commented Nov 7, 2025

@Popov72 I've included your fix and also made once that fixes the voxelization when calling it repeatedly.

This allows the voxelization to work with all the animated assets that I've tried.
Though, I suspect an animated asset that moves a lot will pass outside the bounds of the voxelization since the bounds update doesn't take skinning into account.

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 7, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 7, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 7, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 7, 2025

// Calculate offset in float32 elements
const offset = vertexBuffer.effectiveByteOffset / sizeInBytes;
defines[`${upperName}_OFFSET`] = offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

"_COMPONENT_BYTES" is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to uniforms now.

}

// Add vertex buffer metadata defines for proper stride/offset handling
const geometry = renderingMesh.geometry;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want to use the new PrepareDefinesForVertexPullingMetadata function instead?

Also, I think we should pass stride and offset as a byte count instead of a float count, to more easily handle all type conversions we will have to support (for example, type of position could be a (u)byte, (u)short, (u)int, float, and for the integer types, they could be normalized or not - these are type conversions we will have to perform in the shader).

Another thing is that we should probably use uniforms and not defines to pass data, else we will basically generate a new shader for each mesh, as (at least) offset will be different for each mesh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, good idea. I've changed to uniforms now.

@sebavan
Copy link
Member

sebavan commented Nov 19, 2025

@MiiBond fyi cause I think some of the comments went in late :-)

@MiiBond MiiBond force-pushed the mbond/voxel-shadow-fixes branch from ce4c445 to 33b07ed Compare November 21, 2025 20:57
@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 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.

@Popov72
Copy link
Contributor

Popov72 commented Nov 24, 2025

I didn't have time today, but I will review the PR tomorrow.

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 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.

@Popov72
Copy link
Contributor

Popov72 commented Nov 25, 2025

You should remove package-lock.json from the PR.

* @param metadata The vertex pulling metadata
*/
export function BindVertexPullingUniforms(effect: Effect, metadata: Map<string, IVertexPullingMetadata>): void {
if (!metadata || !effect) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If metadata and effect can be null/undefined, you should update their declaration in BindVertexPullingUniforms accordingly.

for (const [attribute, data] of metadata.entries()) {
const uniformName = `vp_${attribute}_info`;
// Pack into vec3: (offset, stride, type)
effect.setVector3(uniformName, new Vector3(data.offset, data.stride, data.type));
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use setFloat3 to avoid creating a new Vector3 for each attribute every frame (you could also use setInt3, if ints are easier to handle than floats in the shader).

// Add vertex buffer metadata defines for proper stride/offset handling
const geometry = renderingMesh.geometry;
if (geometry) {
this._vertexPullingMetadata = PrepareVertexPullingUniforms(geometry);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should normally update the uniforms array passed to createEffect with the names of the new uniforms. I'm not sure why it works without this code...

pos.y = position[index * 3 + 1];
pos.z = position[index * 3 + 2];
return pos;
uniform vp_position_info: vec3f; // (bufferIndex, offset, stride, type)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what bufferIndex refers to?

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.

4 participants