diff --git a/examples/jsm/nodes/lighting/AnalyticLightNode.js b/examples/jsm/nodes/lighting/AnalyticLightNode.js index a85cc17797e607..bef0f6481b9657 100644 --- a/examples/jsm/nodes/lighting/AnalyticLightNode.js +++ b/examples/jsm/nodes/lighting/AnalyticLightNode.js @@ -7,6 +7,7 @@ import { reference } from '../accessors/ReferenceNode.js'; import { texture } from '../accessors/TextureNode.js'; import { positionWorld } from '../accessors/PositionNode.js'; import { normalWorld } from '../accessors/NormalNode.js'; +import { WebGPUCoordinateSystem } from 'three'; //import { add } from '../math/OperatorNode.js'; import { Color, DepthTexture, NearestFilter, LessCompare } from 'three'; @@ -73,11 +74,24 @@ class AnalyticLightNode extends LightingNode { .and( shadowCoord.y.lessThanEqual( 1 ) ) .and( shadowCoord.z.lessThanEqual( 1 ) ); - shadowCoord = vec3( - shadowCoord.x, - shadowCoord.y.oneMinus(), // WebGPU: Flip Y - shadowCoord.z.add( bias ).mul( 2 ).sub( 1 ) // WebGPU: Convertion [ 0, 1 ] to [ - 1, 1 ] - ); + + if ( builder.renderer.coordinateSystem === WebGPUCoordinateSystem ) { + + shadowCoord = vec3( + shadowCoord.x, + shadowCoord.y.oneMinus(), // WebGPU: Flip Y + shadowCoord.z.add( bias ).mul( 2 ).sub( 1 ) // WebGPU: Convertion [ 0, 1 ] to [ - 1, 1 ] + ); + + } else { + + shadowCoord = vec3( + shadowCoord.x, + shadowCoord.y, + shadowCoord.z.add( bias ) + ); + + } const textureCompare = ( depthTexture, shadowCoord, compare ) => texture( depthTexture, shadowCoord ).compare( compare ); //const textureCompare = ( depthTexture, shadowCoord, compare ) => compare.step( texture( depthTexture, shadowCoord ) ); diff --git a/examples/jsm/renderers/webgl/WebGLBackend.js b/examples/jsm/renderers/webgl/WebGLBackend.js index bada50d7a24ae3..ec80edf0bfa191 100644 --- a/examples/jsm/renderers/webgl/WebGLBackend.js +++ b/examples/jsm/renderers/webgl/WebGLBackend.js @@ -41,6 +41,7 @@ class WebGLBackend extends Backend { this.defaultTextures = {}; this.extensions.get( 'EXT_color_buffer_float' ); + this._currentContext = null; } @@ -53,9 +54,13 @@ class WebGLBackend extends Backend { beginRender( renderContext ) { const { gl } = this; + const renderContextData = this.get( renderContext ); // + renderContextData.previousContext = this._currentContext; + this._currentContext = renderContext; + this._setFramebuffer( renderContext ); let clear = 0; @@ -103,8 +108,6 @@ class WebGLBackend extends Backend { if ( occlusionQueryCount > 0 ) { - const renderContextData = this.get( renderContext ); - // Get a reference to the array of objects with queries. The renderContextData property // can be changed by another render pass before the async reading of all previous queries complete renderContextData.currentOcclusionQueries = renderContextData.occlusionQueries; @@ -121,6 +124,29 @@ class WebGLBackend extends Backend { finishRender( renderContext ) { + const renderContextData = this.get( renderContext ); + const previousContext = renderContextData.previousContext; + + this._currentContext = previousContext; + + if ( previousContext !== null ) { + + this._setFramebuffer( previousContext ); + + if ( previousContext.viewport ) { + + this.updateViewport( previousContext ); + + } else { + + const gl = this.gl; + + gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight ); + + } + + } + const occlusionQueryCount = renderContext.occlusionQueryCount; if ( occlusionQueryCount > 0 ) { diff --git a/examples/screenshots/webgpu_shadowmap.jpg b/examples/screenshots/webgpu_shadowmap.jpg index 001fe203e0b94e..6539397f372b2e 100644 Binary files a/examples/screenshots/webgpu_shadowmap.jpg and b/examples/screenshots/webgpu_shadowmap.jpg differ diff --git a/examples/webgpu_shadowmap.html b/examples/webgpu_shadowmap.html index 6efb5df3803093..3eb4f3e534939d 100644 --- a/examples/webgpu_shadowmap.html +++ b/examples/webgpu_shadowmap.html @@ -26,6 +26,8 @@ import * as THREE from 'three'; import WebGPU from 'three/addons/capabilities/WebGPU.js'; + import WebGL from 'three/addons/capabilities/WebGL.js'; + import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js'; import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; @@ -38,11 +40,11 @@ function init() { - if ( WebGPU.isAvailable() === false ) { + if ( WebGPU.isAvailable() === false && WebGL.isWebGL2Available() === false ) { document.body.appendChild( WebGPU.getErrorMessage() ); - throw new Error( 'No WebGPU support' ); + throw new Error( 'No WebGPU or WebGL2 support' ); } diff --git a/test/e2e/puppeteer.js b/test/e2e/puppeteer.js index 0ac630d2c038e1..bfc7d60605d073 100644 --- a/test/e2e/puppeteer.js +++ b/test/e2e/puppeteer.js @@ -124,7 +124,6 @@ const exceptionList = [ 'webgpu_materials_video', 'webgpu_sandbox', 'webgpu_shadertoy', - 'webgpu_shadowmap', 'webgpu_sprites', 'webgpu_tsl_editor', 'webgpu_tsl_transpiler',