-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
Model disappeared when same 3 models pathtraced #668
Comments
Can you reproduce in a jsfiddle or smaller example? Something like initializing / rendering the initial scene with 1 cube and then 1 second later (ore pressing a button) adding two more cubes? |
@gkjohnson I found a reason but not perfectly digged if ( result.changeType === GEOMETRY_REBUILT ) {
const bvhOptions = {
strategy: SAH,
maxLeafTris: 1,
indirect: true, //<-- this options causes a problem
onProgress,
...this.bvhOptions,
}; because most(react three fiber, etc...) of indirect option is false as default, but PathTracingSceneGenerator this.generateBVH true as a default so MeshBVH instantiates indirectBuffer at PathTracingSceneGenerator constructor, and MeshBVH's indirect check like below code (MeshBVH line.111) get indirect() {
return ! ! this._indirectBuffer;
} so it causes a bug. it affects many codes ex. MeshBVHUniformStruct updateFrom // indirect false but true |
Open a pr for check a bug @gkjohnson |
I found a reason and why it's 3 same model causes a bug function bvhToTextures( bvh, boundsTexture, contentsTexture ) {
const roots = bvh._roots;
if ( roots.length !== 1 ) {
//if indirect false this error occurred
throw new Error( 'MeshBVHUniformStruct: Multi-root BVHs not supported.' );
} https://github.com/gkjohnson/three-mesh-bvh/blob/9718501eee2619f1015fa332d7bddafaf6cf562a/src/gpu/MeshBVHUniformStruct.js#L52 // dereference a new index attribute if we're using indirect storage
if ( bvh.indirect ) {
const indirectBuffer = bvh._indirectBuffer;
if (
this._cachedIndexAttr === null ||
this._cachedIndexAttr.count !== indirectBuffer.length
) {
if ( geometry.index ) {
this._cachedIndexAttr = geometry.index.clone();
} else {
const array = getIndexArray( getVertexCount( geometry ) );
this._cachedIndexAttr = new BufferAttribute( array, 1, false );
}
}
dereferenceIndex( geometry, indirectBuffer, this._cachedIndexAttr );
this.index.updateFrom( this._cachedIndexAttr );
} MeshUniformBVHStruct is a struct that in PhysicalPathTracingMaterial
focus on here if ( bvh.indirect ) {
const indirectBuffer = bvh._indirectBuffer;
if (
this._cachedIndexAttr === null ||
this._cachedIndexAttr.count !== indirectBuffer.length
) {
if ( geometry.index ) {
this._cachedIndexAttr = geometry.index.clone();
} in BoxGeometry case
|
Describe the bug
in three.js editor you can reproduce 100%
2024-08-07.8.13.15-1.mov
Only this scenario reproduce this bug
add 1 model -> pathTrace render -> add same model of two -> PathTrace render
Expected behavior
all 3 cubes rendered in realistic
Platform:
The text was updated successfully, but these errors were encountered: