three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Reverse-Z state problem

Open eXponenta opened this issue 1 year ago • 4 comments

Description

Reverse Z PR not fully correctly implement reverse-Z.

Problem in state: https://github.com/mrdoob/three.js/blob/0c7cf78a64a724c24fcca51500b8f3d1b9931af5/src/renderers/webgl/WebGLCapabilities.js#L100

This flag applied in capabilities that persistent after initialisation, that is wrong due to context sharing.

ThreeJS state can be flushed for some specific cases like a 1 contex for N-renderers or libs. For ex: Three + PIXI, Three + WebXR emulator, Three+potree.

WebGLState has reset for that: https://github.com/mrdoob/three.js/blob/0c7cf78a64a724c24fcca51500b8f3d1b9931af5/src/renderers/webgl/WebGLState.js#L1152

Because clipControl is context-related three also should reset this state and change it when needed back

@CodyJasonBennett can you apply some changes and move call of clipControl into WebGLLState instead of WebGLCapabilities?

@Mugen87 what you think about that?

Reproduction steps

Code

Live example

Screenshots

No response

Version

r169

Device

No response

Browser

No response

OS

No response

eXponenta avatar Oct 07 '24 14:10 eXponenta

Also we have state problem with clearDepth:

Reverse Z upgrade depth inside renderer: https://github.com/mrdoob/three.js/blob/0c7cf78a64a724c24fcca51500b8f3d1b9931af5/src/renderers/WebGLRenderer.js#L597

BUT Three has state for that: https://github.com/mrdoob/three.js/blob/0c7cf78a64a724c24fcca51500b8f3d1b9931af5/src/renderers/webgl/WebGLState.js#L190 ReversedZ will broke state upgrade, because clear value will always 0 or 1.

eXponenta avatar Oct 07 '24 15:10 eXponenta

This flag applied in capabilities that persistent after initialisation, that is wrong due to context sharing.

ThreeJS state can be flushed for some specific cases like a 1 contex for N-renderers or libs. For ex: Three + PIXI, Three + WebXR emulator, Three+potree.

How could this happen? Do they have a different WebGL implementation than the browser or are still using WebGL 1?

Because clipControl is context-related three also should reset this state and change it when needed back

I can agree with this and your changes in #29579. I would much prefer if renderer.capabilities had some hint as to what the context supports. Not sure anyone is using that though since this feature is so new.

CodyJasonBennett avatar Oct 07 '24 20:10 CodyJasonBennett

How could this happen? Do they have a different WebGL implementation than the browser or are still using WebGL 1?

Simple case: Potree is outdated library that use parts of threejs with manual state switch, it not know about reverse-Z at all. For potree to important use valid depth info because it use postprocess for resolve dom lighting.

https://github.com/potree/potree/blob/develop/src/materials/shaders/edl.fs#L38

But in general a reverseZ must have for BIMs ( cad system ), because BIMs have billions of near placed polygons on non-normalized space( about 10000x10000 metres with step in 10sm ). Without reverseZ we to tired use hacks that reducing z-fights.

eXponenta avatar Oct 08 '24 04:10 eXponenta

/fyi @m-schuetz

mrdoob avatar Oct 09 '24 03:10 mrdoob