Skip to content
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

BatchedMesh: update example, fix depth conversion & auxiliary buffer #27228

Merged
merged 4 commits into from Nov 23, 2023

Conversation

sciecode
Copy link
Collaborator

@sciecode sciecode commented Nov 21, 2023

Related issue: #27202, #27213

SortUtils: minor changes - smaller memory footprint.
webgl_mesh_batch: converts depth to uint32 by bit-cast instead of normalization.
webgl_mesh_batch: correctly maintains auxiliary buffer between calls, based on geometry count.

Simply normalizing the float depth is not enough to correctly sort, as the fractional part gets truncated - producing incorrect ties. If float values are strictly positive, a simple bit-cast is sufficient to solve this. If negative values are possible you can use the following conversion:

const f32 = new Float32Array( 1 );
const u32 = new Uint32Array( f32.buffer );
const convert = (val) => {
   f32[0] = val;
   return u32[0] ^ ( - ( val >>> 31 ) | 0x80000000 );
}

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>
Copy link
Collaborator

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes! I added a couple comments.

examples/webgl_mesh_batch.html Outdated Show resolved Hide resolved
examples/webgl_mesh_batch.html Outdated Show resolved Hide resolved
@gkjohnson gkjohnson added this to the r159 milestone Nov 22, 2023
@sciecode
Copy link
Collaborator Author

Thanks for the fixes! I added a couple comments.

Addressed both comments, let me know what you prefer. I'll make the changes.

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>
Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>
Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>
@sciecode
Copy link
Collaborator Author

Should be good to go.
@gkjohnson

@gkjohnson
Copy link
Collaborator

Awesome, thanks!

@gkjohnson gkjohnson merged commit 8c524e9 into mrdoob:dev Nov 23, 2023
11 checks passed
@sciecode sciecode deleted the dev-radix branch November 23, 2023 02:18
AdaRoseCannon pushed a commit to AdaRoseCannon/three.js that referenced this pull request Jan 15, 2024
…rdoob#27228)

* BatchedMesh: bit-cast depth f32 to u32 & fix auxiliary array

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>

* webgl_mesh_batch: make custom sort self-contained

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>

* webgl_mesh_batch: remove global auxiliary buffer

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>

* clean-up / lint

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>

---------

Signed-off-by: Guilherme Avila <3927951+sciecode@users.noreply.github.com>
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.

None yet

2 participants