Skip to content

Conversation

@sciecode
Copy link
Contributor

@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 );
}

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.

@gkjohnson gkjohnson added this to the r159 milestone Nov 22, 2023
@sciecode
Copy link
Contributor Author

Thanks for the fixes! I added a couple comments.

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

@sciecode
Copy link
Contributor Author

Should be good to go.
@gkjohnson

@gkjohnson
Copy link
Collaborator

Awesome, thanks!

@gkjohnson gkjohnson merged commit 8c524e9 into mrdoob:dev Nov 23, 2023
@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 <[email protected]>

* webgl_mesh_batch: make custom sort self-contained

Signed-off-by: Guilherme Avila <[email protected]>

* webgl_mesh_batch: remove global auxiliary buffer

Signed-off-by: Guilherme Avila <[email protected]>

* clean-up / lint

Signed-off-by: Guilherme Avila <[email protected]>

---------

Signed-off-by: Guilherme Avila <[email protected]>
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