Skip to content

Commit

Permalink
Merge pull request #732 from TheBlek/master
Browse files Browse the repository at this point in the history
Extend _bvhClosestPointToPoint to accept maxDistance
  • Loading branch information
gkjohnson authored Jan 21, 2025
2 parents 0bcbc7a + ae7607b commit 3e01a32
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1136,18 +1136,29 @@ Dispose of the associated textures.
### shaderStructs

```js
BVHShaderGLSL.bvh_struct_definitions : string

or equivalent, legacy:

shaderStructs : string
```

Set of shaders structs and defined constants used for interacting with the packed BVH in a shader. See [src/gpu/shaderFunctions.js](https://github.com/gkjohnson/three-mesh-bvh/blob/master/src/gpu/shaderFunctions.js) for full implementations and declarations.
Set of shaders structs and defined constants used for interacting with the packed BVH in a shader. See [src/gpu/bvh_struct_definitions.glsl.js](https://github.com/gkjohnson/three-mesh-bvh/blob/master/src/gpu/bvh_struct_definitions.glsl.js) for full implementations and declarations.

### shaderFunctions

```js
shaderFunctions : string
BVHShaderGLSL.bvh_distance_functions : string
BVHShaderGLSL.bvh_ray_functions : string
BVHShaderGLSL.common_functions : string

or equivalent, bundled for specific usage (legacy):

shaderDistanceFunction : string
shaderIntersectFunction : string
```

Set of shader functions used for interacting with the packed BVH in a shader and sampling [VertexAttributeTextures](#VertexAttributeTexture). See [src/gpu/shaderFunctions.js](https://github.com/gkjohnson/three-mesh-bvh/blob/master/src/gpu/shaderFunctions.js) for full implementations and declarations.
Set of shader functions used for interacting with the packed BVH in a shader and sampling [VertexAttributeTextures](#VertexAttributeTexture). See [src/gpu/glsl](https://github.com/gkjohnson/three-mesh-bvh/tree/master/src/gpu/glsl) for full implementations and declarations.

## Gotchas

Expand Down
2 changes: 1 addition & 1 deletion example/utils/GenerateSDFMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class GenerateSDFMaterial extends ShaderMaterial {
float side;
float rayDist;
vec3 outPoint;
float dist = bvhClosestPointToPoint( bvh, point.xyz, faceIndices, faceNormal, barycoord, side, outPoint );
float dist = bvhClosestPointToPoint( bvh, point.xyz, 100000.0, faceIndices, faceNormal, barycoord, side, outPoint );
// This currently causes issues on some devices when rendering to 3d textures and texture arrays
#if USE_SHADER_RAYCAST
Expand Down
8 changes: 4 additions & 4 deletions src/gpu/glsl/bvh_distance_functions.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ float distanceSqToBVHNodeBoundsPoint( vec3 point, sampler2D bvhBounds, uint curr
#define\
bvhClosestPointToPoint(\
bvh,\
point, faceIndices, faceNormal, barycoord, side, outPoint\
point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint\
)\
_bvhClosestPointToPoint(\
bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents,\
point, faceIndices, faceNormal, barycoord, side, outPoint\
point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint\
)
float _bvhClosestPointToPoint(
// bvh info
sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents,
// point to check
vec3 point,
vec3 point, float maxDistance,
// output variables
inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
Expand All @@ -140,7 +140,7 @@ float _bvhClosestPointToPoint(
uint stack[ BVH_STACK_DEPTH ];
stack[ 0 ] = 0u;
float closestDistanceSquared = pow( 100000.0, 2.0 );
float closestDistanceSquared = maxDistance * maxDistance;
bool found = false;
while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) {
Expand Down

0 comments on commit 3e01a32

Please sign in to comment.