diff --git a/src/materials/LineBasicMaterial.js b/src/materials/LineBasicMaterial.js index efd1e3201ee499..b6cc7be93afff5 100644 --- a/src/materials/LineBasicMaterial.js +++ b/src/materials/LineBasicMaterial.js @@ -21,8 +21,6 @@ class LineBasicMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -42,8 +40,6 @@ class LineBasicMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/MeshBasicMaterial.js b/src/materials/MeshBasicMaterial.js index 4fe13367e7e48c..b9f7c2b5706fdf 100644 --- a/src/materials/MeshBasicMaterial.js +++ b/src/materials/MeshBasicMaterial.js @@ -38,8 +38,6 @@ class MeshBasicMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -74,8 +72,6 @@ class MeshBasicMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/MeshLambertMaterial.js b/src/materials/MeshLambertMaterial.js index 3e1a8a4098a248..a7c3b05053b85c 100644 --- a/src/materials/MeshLambertMaterial.js +++ b/src/materials/MeshLambertMaterial.js @@ -56,8 +56,6 @@ class MeshLambertMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -109,8 +107,6 @@ class MeshLambertMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/MeshMatcapMaterial.js b/src/materials/MeshMatcapMaterial.js index 95004ab57a72e1..84030dcae04ab2 100644 --- a/src/materials/MeshMatcapMaterial.js +++ b/src/materials/MeshMatcapMaterial.js @@ -38,8 +38,6 @@ class MeshMatcapMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -74,8 +72,6 @@ class MeshMatcapMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/MeshPhongMaterial.js b/src/materials/MeshPhongMaterial.js index 3fe95f00546cf1..6dfe9e46c27c0d 100644 --- a/src/materials/MeshPhongMaterial.js +++ b/src/materials/MeshPhongMaterial.js @@ -58,8 +58,6 @@ class MeshPhongMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -113,8 +111,6 @@ class MeshPhongMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/MeshStandardMaterial.js b/src/materials/MeshStandardMaterial.js index 9195b95907469d..1821cf2ffa446a 100644 --- a/src/materials/MeshStandardMaterial.js +++ b/src/materials/MeshStandardMaterial.js @@ -60,8 +60,6 @@ class MeshStandardMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -117,8 +115,6 @@ class MeshStandardMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/MeshToonMaterial.js b/src/materials/MeshToonMaterial.js index d894c49b15c628..2f9b2f9e273b5e 100644 --- a/src/materials/MeshToonMaterial.js +++ b/src/materials/MeshToonMaterial.js @@ -50,8 +50,6 @@ class MeshToonMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -95,8 +93,6 @@ class MeshToonMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/PointsMaterial.js b/src/materials/PointsMaterial.js index c689a7339b16c3..8ca5500d6ee124 100644 --- a/src/materials/PointsMaterial.js +++ b/src/materials/PointsMaterial.js @@ -22,8 +22,6 @@ class PointsMaterial extends Material { this.fog = true; - this.occlusion = true; - this.setValues( parameters ); } @@ -43,8 +41,6 @@ class PointsMaterial extends Material { this.fog = source.fog; - this.occlusion = source.occlusion; - return this; } diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index ebb2d5ed2b9f4c..c3370a67f11617 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -80,8 +80,6 @@ class ShaderMaterial extends Material { this.lights = source.lights; this.clipping = source.clipping; - this.occlusion = source.occlusion; - this.extensions = Object.assign( {}, source.extensions ); this.glslVersion = source.glslVersion; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 58c53e6d53f9fa..35f5a6bab853a7 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -210,7 +210,6 @@ class WebGLRenderer { const _vector3 = new Vector3(); const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true }; - let _occlusion = null; function getTargetPixelRatio() { @@ -416,20 +415,6 @@ class WebGLRenderer { }; - this.setOcclusion = function ( value ) { - - if ( value === undefined ) return; - - _occlusion = value; - - }; - - this.clearOcclusion = function () { - - _occlusion = null; - - }; - this.getSize = function ( target ) { return target.set( _width, _height ); @@ -1149,7 +1134,7 @@ class WebGLRenderer { // Rendering - this.render = function ( scene, camera ) { + this.render = function ( scene, camera, renderingOcclusion ) { if ( camera !== undefined && camera.isCamera !== true ) { @@ -1226,6 +1211,12 @@ class WebGLRenderer { background.render( currentRenderList, scene ); + if ( xr.enabled === true && xr.getOcclusionScene() && ! renderingOcclusion ) { + + this.render( xr.getOcclusionScene(), camera, true ); + + } + // render scene currentRenderState.setupLights( _this._useLegacyLights ); @@ -1615,7 +1606,7 @@ class WebGLRenderer { const lightsStateVersion = lights.state.version; - const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object, _occlusion ); + const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object ); const programCacheKey = programCache.getProgramCacheKey( parameters ); let programs = materialProperties.programs; @@ -1855,10 +1846,6 @@ class WebGLRenderer { needsProgramChange = true; - } else if ( material.occlusion === true ) { - - needsProgramChange = true; - } else if ( materialProperties.numClippingPlanes !== undefined && ( materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection ) ) { @@ -2073,12 +2060,6 @@ class WebGLRenderer { } - if ( _occlusion && material.occlusion === true ) { - - materials.refreshOcclusionUniforms( m_uniforms, _occlusion ); - - } - materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget ); WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures ); diff --git a/src/renderers/shaders/ShaderChunk.js b/src/renderers/shaders/ShaderChunk.js index 33e6f15fd8919e..a943c12965170c 100644 --- a/src/renderers/shaders/ShaderChunk.js +++ b/src/renderers/shaders/ShaderChunk.js @@ -75,8 +75,6 @@ import normal_pars_fragment from './ShaderChunk/normal_pars_fragment.glsl.js'; import normal_pars_vertex from './ShaderChunk/normal_pars_vertex.glsl.js'; import normal_vertex from './ShaderChunk/normal_vertex.glsl.js'; import normalmap_pars_fragment from './ShaderChunk/normalmap_pars_fragment.glsl.js'; -import occlusion_fragment from './ShaderChunk/occlusion_fragment.glsl.js'; -import occlusion_pars_fragment from './ShaderChunk/occlusion_pars_fragment.glsl.js'; import clearcoat_normal_fragment_begin from './ShaderChunk/clearcoat_normal_fragment_begin.glsl.js'; import clearcoat_normal_fragment_maps from './ShaderChunk/clearcoat_normal_fragment_maps.glsl.js'; import clearcoat_pars_fragment from './ShaderChunk/clearcoat_pars_fragment.glsl.js'; @@ -204,8 +202,6 @@ export const ShaderChunk = { normal_pars_vertex: normal_pars_vertex, normal_vertex: normal_vertex, normalmap_pars_fragment: normalmap_pars_fragment, - occlusion_fragment: occlusion_fragment, - occlusion_pars_fragment: occlusion_pars_fragment, clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin, clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps, clearcoat_pars_fragment: clearcoat_pars_fragment, diff --git a/src/renderers/shaders/ShaderChunk/occlusion_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/occlusion_fragment.glsl.js deleted file mode 100644 index 62b7b59603efb4..00000000000000 --- a/src/renderers/shaders/ShaderChunk/occlusion_fragment.glsl.js +++ /dev/null @@ -1,20 +0,0 @@ -export default /* glsl */` -#ifdef USE_OCCLUSION - if (gl_FragColor.a > 0.0) { - int arrayIndex = 0; - vec2 depthUv; - if (gl_FragCoord.x>=depthWidth) { - arrayIndex = 1; - depthUv = vec2((gl_FragCoord.x-depthWidth)/depthWidth, gl_FragCoord.y/depthHeight); - } else { - depthUv = vec2(gl_FragCoord.x/depthWidth, gl_FragCoord.y/depthHeight); - } - float assetDepthM = gl_FragCoord.z; - - //float occlusion = Depth_GetOcclusion(depthColor, depthUv, assetDepthM, arrayIndex); - float occlusion = Depth_GetBlurredOcclusionAroundUV(depthColor, depthUv, assetDepthM, arrayIndex); - - gl_FragColor *= 1.0 - occlusion; - } -#endif -`; diff --git a/src/renderers/shaders/ShaderChunk/occlusion_pars_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/occlusion_pars_fragment.glsl.js deleted file mode 100644 index b1441c71a10302..00000000000000 --- a/src/renderers/shaders/ShaderChunk/occlusion_pars_fragment.glsl.js +++ /dev/null @@ -1,97 +0,0 @@ -export default /* glsl */` -#ifdef USE_OCCLUSION - uniform sampler2DArray depthColor; - uniform float depthWidth; - uniform float depthHeight; - - float Depth_GetCameraDepthInMeters(const sampler2DArray depthTexture, - const vec2 depthUv, int arrayIndex) { - return texture(depthColor, vec3(depthUv.x, depthUv.y, arrayIndex)).r; - } - - float Depth_GetOcclusion(const sampler2DArray depthTexture, const vec2 depthUv, float assetDepthM, int arrayIndex) { - float depthMm = Depth_GetCameraDepthInMeters(depthTexture, depthUv, arrayIndex); - - // Instead of a hard z-buffer test, allow the asset to fade into the - // background along a 2 * kDepthTolerancePerM * assetDepthM - // range centered on the background depth. - const float kDepthTolerancePerM = 0.001; - return clamp(1.0 - - 0.5 * (depthMm - assetDepthM) / - (kDepthTolerancePerM * assetDepthM) + - 0.5, 0.0, 1.0); - } - - float Depth_GetBlurredOcclusionAroundUV(const sampler2DArray depthTexture, const vec2 uv, float assetDepthM, int arrayIndex) { - // Kernel used: - // 0 4 7 4 0 - // 4 16 26 16 4 - // 7 26 41 26 7 - // 4 16 26 16 4 - // 0 4 7 4 0 - const float kKernelTotalWeights = 269.0; - float sum = 0.0; - - const float kOcclusionBlurAmount = 0.0005; - vec2 blurriness = - vec2(kOcclusionBlurAmount, kOcclusionBlurAmount /** u_DepthAspectRatio*/); - - float current = 0.0; - - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-1.0, -2.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+1.0, -2.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-1.0, +2.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+1.0, +2.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-2.0, +1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+2.0, +1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-2.0, -1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+2.0, -1.0) * blurriness, assetDepthM, arrayIndex); - sum += current * 4.0; - - current = 0.0; - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-2.0, -0.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+2.0, +0.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+0.0, +2.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-0.0, -2.0) * blurriness, assetDepthM, arrayIndex); - sum += current * 7.0; - - current = 0.0; - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-1.0, -1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+1.0, -1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-1.0, +1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+1.0, +1.0) * blurriness, assetDepthM, arrayIndex); - sum += current * 16.0; - - current = 0.0; - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+0.0, +1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-0.0, -1.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(-1.0, -0.0) * blurriness, assetDepthM, arrayIndex); - current += Depth_GetOcclusion( - depthTexture, uv + vec2(+1.0, +0.0) * blurriness, assetDepthM, arrayIndex); - sum += current * 26.0; - - sum += Depth_GetOcclusion(depthTexture, uv, assetDepthM, arrayIndex) * 41.0; - - return sum / kKernelTotalWeights; - } -#endif -`; diff --git a/src/renderers/shaders/ShaderLib.js b/src/renderers/shaders/ShaderLib.js index 1e80a37a41c655..0ed7018ee9577c 100644 --- a/src/renderers/shaders/ShaderLib.js +++ b/src/renderers/shaders/ShaderLib.js @@ -16,8 +16,7 @@ const ShaderLib = { UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, - UniformsLib.fog, - UniformsLib.occlusion + UniformsLib.fog ] ), vertexShader: ShaderChunk.meshbasic_vert, @@ -39,7 +38,6 @@ const ShaderLib = { UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, - UniformsLib.occlusion, { emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) } } @@ -64,7 +62,6 @@ const ShaderLib = { UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, - UniformsLib.occlusion, { emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) }, specular: { value: /*@__PURE__*/ new Color( 0x111111 ) }, @@ -92,7 +89,6 @@ const ShaderLib = { UniformsLib.metalnessmap, UniformsLib.fog, UniformsLib.lights, - UniformsLib.occlusion, { emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) }, roughness: { value: 1.0 }, @@ -119,7 +115,6 @@ const ShaderLib = { UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, - UniformsLib.occlusion, { emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) } } @@ -138,7 +133,6 @@ const ShaderLib = { UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, - UniformsLib.occlusion, { matcap: { value: null } } @@ -153,8 +147,7 @@ const ShaderLib = { uniforms: /*@__PURE__*/ mergeUniforms( [ UniformsLib.points, - UniformsLib.fog, - UniformsLib.occlusion + UniformsLib.fog ] ), vertexShader: ShaderChunk.points_vert, @@ -198,7 +191,6 @@ const ShaderLib = { UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, - UniformsLib.occlusion, { opacity: { value: 1.0 } } diff --git a/src/renderers/shaders/ShaderLib/linedashed.glsl.js b/src/renderers/shaders/ShaderLib/linedashed.glsl.js index e76ae6b041ffcf..42bfbb39ac9ff5 100644 --- a/src/renderers/shaders/ShaderLib/linedashed.glsl.js +++ b/src/renderers/shaders/ShaderLib/linedashed.glsl.js @@ -45,7 +45,6 @@ varying float vLineDistance; #include #include #include -#include void main() { @@ -71,7 +70,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/meshbasic.glsl.js b/src/renderers/shaders/ShaderLib/meshbasic.glsl.js index 51eb75f1022238..72c611e1934267 100644 --- a/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshbasic.glsl.js @@ -67,7 +67,6 @@ uniform float opacity; #include #include #include -#include void main() { @@ -112,7 +111,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/meshlambert.glsl.js b/src/renderers/shaders/ShaderLib/meshlambert.glsl.js index 3ec9e2cfb3aaa4..c6f4c6249ad94d 100644 --- a/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshlambert.glsl.js @@ -81,7 +81,6 @@ uniform float opacity; #include #include #include -#include void main() { @@ -120,7 +119,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js b/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js index 82c7e70def4684..be310c28767acf 100644 --- a/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js @@ -68,7 +68,6 @@ varying vec3 vViewPosition; #include #include #include -#include void main() { @@ -108,7 +107,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/meshnormal.glsl.js b/src/renderers/shaders/ShaderLib/meshnormal.glsl.js index 66a8ce777802aa..09d91eda04534f 100644 --- a/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshnormal.glsl.js @@ -64,7 +64,6 @@ uniform float opacity; #include #include #include -#include void main() { @@ -81,7 +80,5 @@ void main() { #endif - #include - } `; diff --git a/src/renderers/shaders/ShaderLib/meshphong.glsl.js b/src/renderers/shaders/ShaderLib/meshphong.glsl.js index 0ece36414439e5..61ccad801f90c1 100644 --- a/src/renderers/shaders/ShaderLib/meshphong.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshphong.glsl.js @@ -83,7 +83,6 @@ uniform float opacity; #include #include #include -#include void main() { @@ -122,7 +121,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/meshphysical.glsl.js b/src/renderers/shaders/ShaderLib/meshphysical.glsl.js index c8d81acb853e7e..0708b112d2552a 100644 --- a/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshphysical.glsl.js @@ -154,7 +154,6 @@ varying vec3 vViewPosition; #include #include #include -#include void main() { @@ -220,7 +219,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/meshtoon.glsl.js b/src/renderers/shaders/ShaderLib/meshtoon.glsl.js index 6743093ff73694..1df200691efe01 100644 --- a/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +++ b/src/renderers/shaders/ShaderLib/meshtoon.glsl.js @@ -77,7 +77,6 @@ uniform float opacity; #include #include #include -#include void main() { @@ -114,7 +113,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/ShaderLib/points.glsl.js b/src/renderers/shaders/ShaderLib/points.glsl.js index 63991f52de3ab6..be07fd06ed84f4 100644 --- a/src/renderers/shaders/ShaderLib/points.glsl.js +++ b/src/renderers/shaders/ShaderLib/points.glsl.js @@ -60,7 +60,6 @@ uniform float opacity; #include #include #include -#include void main() { @@ -82,7 +81,6 @@ void main() { #include #include #include - #include } `; diff --git a/src/renderers/shaders/UniformsLib.js b/src/renderers/shaders/UniformsLib.js index 62ae7bcd898f62..9b23c3f73d884c 100644 --- a/src/renderers/shaders/UniformsLib.js +++ b/src/renderers/shaders/UniformsLib.js @@ -197,12 +197,6 @@ const UniformsLib = { }, - occlusion: { - depthColor: { value: null }, - depthWidth: {}, - depthHeight: {} - }, - points: { diffuse: { value: /*@__PURE__*/ new Color( 0xffffff ) }, diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index 30186a09e4f545..2c2cc1ab585fe6 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -32,14 +32,6 @@ function WebGLMaterials( renderer, properties ) { } - function refreshOcclusionUniforms( uniforms, occlusion ) { - - uniforms.depthColor.value = occlusion.depthColor; - uniforms.depthWidth.value = occlusion.depthWidth; - uniforms.depthHeight.value = occlusion.depthHeight; - - } - function refreshMaterialUniforms( uniforms, material, pixelRatio, height, transmissionRenderTarget ) { if ( material.isMeshBasicMaterial ) { @@ -567,8 +559,7 @@ function WebGLMaterials( renderer, properties ) { return { refreshFogUniforms: refreshFogUniforms, - refreshMaterialUniforms: refreshMaterialUniforms, - refreshOcclusionUniforms: refreshOcclusionUniforms + refreshMaterialUniforms: refreshMaterialUniforms }; } diff --git a/src/renderers/webgl/WebGLProgram.js b/src/renderers/webgl/WebGLProgram.js index b35d0fb43961c3..6285e619df47c2 100644 --- a/src/renderers/webgl/WebGLProgram.js +++ b/src/renderers/webgl/WebGLProgram.js @@ -550,8 +550,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', - parameters.occlusion ? '#define USE_OCCLUSION' : '', - parameters.map ? '#define USE_MAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapModeDefine : '', @@ -767,8 +765,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', - parameters.occlusion ? '#define USE_OCCLUSION' : '', - parameters.map ? '#define USE_MAP' : '', parameters.matcap ? '#define USE_MATCAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', diff --git a/src/renderers/webgl/WebGLPrograms.js b/src/renderers/webgl/WebGLPrograms.js index 1006f24d37ff5c..d153ff64514406 100644 --- a/src/renderers/webgl/WebGLPrograms.js +++ b/src/renderers/webgl/WebGLPrograms.js @@ -44,7 +44,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities } - function getParameters( material, lights, shadows, scene, object, occlusion ) { + function getParameters( material, lights, shadows, scene, object ) { const fog = scene.fog; const geometry = object.geometry; @@ -162,8 +162,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities const HAS_ATTRIBUTE_UV2 = !! geometry.attributes.uv2; const HAS_ATTRIBUTE_UV3 = !! geometry.attributes.uv3; - const HAS_OCCLUSION = !! occlusion; - let toneMapping = NoToneMapping; if ( material.toneMapped ) { @@ -255,8 +253,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities combine: material.combine, - occlusion: HAS_OCCLUSION, - // mapUv: HAS_MAP && getChannel( material.map.channel ), @@ -306,10 +302,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities useFog: material.fog === true, fogExp2: ( !! fog && fog.isFogExp2 ), - useOcclusion: material.occlusion === true, - - useOcclusion: material.occlusion === true, - flatShading: material.flatShading === true, sizeAttenuation: material.sizeAttenuation === true, @@ -414,7 +406,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities } array.push( parameters.customProgramCacheKey ); - array.push( parameters.occlusion ); return array.join(); diff --git a/src/renderers/webxr/WebXRManager.js b/src/renderers/webxr/WebXRManager.js index be290d5ebe1e5d..f57ce9ea48679f 100644 --- a/src/renderers/webxr/WebXRManager.js +++ b/src/renderers/webxr/WebXRManager.js @@ -10,8 +10,39 @@ import { WebGLAnimation } from '../webgl/WebGLAnimation.js'; import { WebGLRenderTarget } from '../WebGLRenderTarget.js'; import { WebXRController } from './WebXRController.js'; import { DepthTexture } from '../../textures/DepthTexture.js'; +import { ShaderMaterial } from '../../materials/ShaderMaterial.js'; +import { PlaneGeometry } from '../../geometries/PlaneGeometry.js'; +import { Mesh } from '../../objects/Mesh.js'; +import { Scene } from '../../scenes/Scene.js'; import { DepthFormat, DepthStencilFormat, RGBAFormat, UnsignedByteType, UnsignedIntType, UnsignedInt248Type } from '../../constants.js'; +const _occlusion_vertex = ` +void main() { + + gl_Position = vec4(position, 1.0); + +}`; + +const _occlusion_fragment = ` +uniform sampler2DArray depthColor; +uniform float depthWidth; +uniform float depthHeight; + +void main() { + + int arrayIndex = 0; + vec2 depthUv; + if (gl_FragCoord.x>=depthWidth) { + arrayIndex = 1; + depthUv = vec2((gl_FragCoord.x-depthWidth)/depthWidth, gl_FragCoord.y/depthHeight); + } else { + depthUv = vec2(gl_FragCoord.x/depthWidth, gl_FragCoord.y/depthHeight); + } + + gl_FragDepthEXT = texture(depthColor, vec3(depthUv.x, depthUv.y, arrayIndex)).r; + +}`; + class WebXRManager extends EventDispatcher { constructor( renderer, gl ) { @@ -38,6 +69,10 @@ class WebXRManager extends EventDispatcher { let _nearOverride = 0; let _farOverride = 0; let xrFrame = null; + + let _occlusionDepthTexture = null; + let _occlusionScene = null; + const attributes = gl.getContextAttributes(); let initialRenderTarget = null; let newRenderTarget = null; @@ -168,11 +203,12 @@ class WebXRManager extends EventDispatcher { _currentDepthNear = null; _currentDepthFar = null; _depthTexture = null; + _occlusionDepthTexture = null; + _occlusionScene = null; // restore framebuffer/rendering state renderer.setRenderTarget( initialRenderTarget ); - renderer.clearOcclusion(); glBaseLayer = null; glProjLayer = null; @@ -659,9 +695,9 @@ class WebXRManager extends EventDispatcher { }; - this.getDepthTexture = function ( ) { + this.getOcclusionScene = function () { - return _depthTexture; + return _occlusionScene; }; @@ -764,14 +800,14 @@ class WebXRManager extends EventDispatcher { } - if ( depthData && depthData.isValid ) { + if ( depthData && depthData.isValid && depthData.texture ) { - if ( _depthTexture === null ) { + if ( _occlusionDepthTexture === null ) { _depthTexture = depthData.texture; - const depthTexture = new Texture(); - const texProps = renderer.properties.get( depthTexture ); + _occlusionDepthTexture = new Texture(); + const texProps = renderer.properties.get( _occlusionDepthTexture ); texProps.__webglTexture = _depthTexture; if ( ( depthData.depthNear != session.renderState.depthNear ) || ( depthData.depthFar != session.renderState.depthFar ) ) { @@ -781,15 +817,8 @@ class WebXRManager extends EventDispatcher { } - const viewport = cameraXR.cameras[ 0 ].viewport; - renderer.setOcclusion( { depthColor: depthTexture, depthWidth: viewport.z, depthHeight: viewport.w } ); - } - } else { - - _depthTexture = null; - } } @@ -809,6 +838,30 @@ class WebXRManager extends EventDispatcher { } + if ( _occlusionDepthTexture ) { + + if ( ! _occlusionScene ) { + + const viewport = cameraXR.cameras[ 0 ].viewport; + const occlusionMaterial = new ShaderMaterial( { + vertexShader: _occlusion_vertex, + fragmentShader: _occlusion_fragment, + uniforms: { + depthColor: { value: _occlusionDepthTexture }, + depthWidth: { value: viewport.z }, + depthHeight: { value: viewport.w } + } + } ); + + occlusionMaterial.extensions.fragDepth = true; + + _occlusionScene = new Scene(); + _occlusionScene.add( new Mesh( new PlaneGeometry( 20, 20 ), occlusionMaterial ) ); + + } + + } + if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame ); if ( frame.detectedPlanes ) {