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

Model disappeared when same 3 models pathtraced #668

Open
dongho-shin opened this issue Aug 7, 2024 · 4 comments
Open

Model disappeared when same 3 models pathtraced #668

dongho-shin opened this issue Aug 7, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dongho-shin
Copy link
Contributor

Describe the bug

in three.js editor you can reproduce 100%

  1. Create 1 cube(other models also reproduce)
  2. PathTrace Render(set Realistic upper right)
  3. Create 2 cubes
  4. again PathTrace Render then you can see 2 cubes disappear in pathTraced Scene
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:

  • Device: [Desktop]
  • OS: [MacOS]
  • GPU: [NVidia ??, Radeon ??, ...]
  • Browser: [Chrome]
  • Three.js version: [r167(editor)]
  • Library version: [current library version]
@dongho-shin dongho-shin added the bug Something isn't working label Aug 7, 2024
@gkjohnson
Copy link
Owner

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?

@dongho-shin
Copy link
Contributor Author

@gkjohnson I found a reason but not perfectly digged
this line is a problem
PathTracingSceneGenerator.js in line.217

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

@dongho-shin
Copy link
Contributor Author

Open a pr for check a bug @gkjohnson

@dongho-shin
Copy link
Contributor Author

dongho-shin commented Aug 12, 2024

I found a reason and why it's 3 same model causes a bug
if indirect set true in bvhOptions it causes an error because bvhToTextures not supported Multi root Nodes

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
and in three-mesh-bvh

// 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

bvh: { value: new MeshBVHUniformStruct() },

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

  1. at first PathTrace Rendering
  • this._cachedIndexAttr.count(null) !== indirectBuffer.length(12)
  • this._cachedIndexAttr = BufferAttribute(length 36)
  1. add two BoxGeometry
  • this._cachedIndexAttr.count(36) !== indirectBuffer.length(36) <-- it's same so it Pass update _cachedIndexAttr
    -> there's no update at _cachedIndexAttr it causes a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants