Skip to content

Commit 3e01a32

Browse files
authored
Merge pull request #732 from TheBlek/master
Extend _bvhClosestPointToPoint to accept maxDistance
2 parents 0bcbc7a + ae7607b commit 3e01a32

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,18 +1136,29 @@ Dispose of the associated textures.
11361136
### shaderStructs
11371137

11381138
```js
1139+
BVHShaderGLSL.bvh_struct_definitions : string
1140+
1141+
or equivalent, legacy:
1142+
11391143
shaderStructs : string
11401144
```
11411145

1142-
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.
1146+
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.
11431147

11441148
### shaderFunctions
11451149

11461150
```js
1147-
shaderFunctions : string
1151+
BVHShaderGLSL.bvh_distance_functions : string
1152+
BVHShaderGLSL.bvh_ray_functions : string
1153+
BVHShaderGLSL.common_functions : string
1154+
1155+
or equivalent, bundled for specific usage (legacy):
1156+
1157+
shaderDistanceFunction : string
1158+
shaderIntersectFunction : string
11481159
```
11491160

1150-
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.
1161+
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.
11511162

11521163
## Gotchas
11531164

example/utils/GenerateSDFMaterial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class GenerateSDFMaterial extends ShaderMaterial {
6464
float side;
6565
float rayDist;
6666
vec3 outPoint;
67-
float dist = bvhClosestPointToPoint( bvh, point.xyz, faceIndices, faceNormal, barycoord, side, outPoint );
67+
float dist = bvhClosestPointToPoint( bvh, point.xyz, 100000.0, faceIndices, faceNormal, barycoord, side, outPoint );
6868
6969
// This currently causes issues on some devices when rendering to 3d textures and texture arrays
7070
#if USE_SHADER_RAYCAST

src/gpu/glsl/bvh_distance_functions.glsl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ float distanceSqToBVHNodeBoundsPoint( vec3 point, sampler2D bvhBounds, uint curr
115115
#define\
116116
bvhClosestPointToPoint(\
117117
bvh,\
118-
point, faceIndices, faceNormal, barycoord, side, outPoint\
118+
point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint\
119119
)\
120120
_bvhClosestPointToPoint(\
121121
bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents,\
122-
point, faceIndices, faceNormal, barycoord, side, outPoint\
122+
point, maxDistance, faceIndices, faceNormal, barycoord, side, outPoint\
123123
)
124124
125125
float _bvhClosestPointToPoint(
126126
// bvh info
127127
sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents,
128128
129129
// point to check
130-
vec3 point,
130+
vec3 point, float maxDistance,
131131
132132
// output variables
133133
inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
@@ -140,7 +140,7 @@ float _bvhClosestPointToPoint(
140140
uint stack[ BVH_STACK_DEPTH ];
141141
stack[ 0 ] = 0u;
142142
143-
float closestDistanceSquared = pow( 100000.0, 2.0 );
143+
float closestDistanceSquared = maxDistance * maxDistance;
144144
bool found = false;
145145
while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) {
146146

0 commit comments

Comments
 (0)