2
0
Эх сурвалжийг харах

ViewportNode revision (#27096)

* ViewportNode revision

* remove depth

* Revert "remove depth"

This reverts commit d20b0f7f643352eeef0fbc4cfc62ee79f49e5017.

* revision shadowmap

* fix screenshot
sunag 1 жил өмнө
parent
commit
79cc152ddf

+ 11 - 2
examples/jsm/nodes/accessors/TextureNode.js

@@ -117,7 +117,10 @@ class TextureNode extends UniformNode {
 
 	generate( builder, output ) {
 
-		const { uvNode, levelNode } = builder.getNodeProperties( this );
+		const properties = builder.getNodeProperties( this );
+
+		let { uvNode } = properties;
+		const { levelNode } = properties;
 
 		const compareNode = this.compareNode;
 		const texture = this.value;
@@ -128,6 +131,12 @@ class TextureNode extends UniformNode {
 
 		}
 
+		if ( builder.isFlipY() && ( texture.isFramebufferTexture === true || texture.isDepthTexture === true ) ) {
+
+			uvNode = uvNode.setY( uvNode.y.fract().oneMinus() );
+
+		}
+
 		const textureProperty = super.generate( builder, 'property' );
 
 		if ( output === 'sampler' ) {
@@ -212,7 +221,7 @@ class TextureNode extends UniformNode {
 		textureNode.levelNode = levelNode;
 
 		return context( textureNode, {
-			getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode
+			getMIPLevelAlgorithmNode: ( reqTextureNode, levelNode ) => levelNode
 		} );
 
 	}

+ 5 - 8
examples/jsm/nodes/display/ViewportNode.js

@@ -21,7 +21,7 @@ class ViewportNode extends Node {
 
 	getNodeType() {
 
-		return this.scope === ViewportNode.COORDINATE || this.scope === ViewportNode.VIEWPORT ? 'vec4' : 'vec2';
+		return this.scope === ViewportNode.VIEWPORT ? 'vec4' : 'vec2';
 
 	}
 
@@ -55,7 +55,7 @@ class ViewportNode extends Node {
 
 	}
 
-	setup( builder ) {
+	setup( /*builder*/ ) {
 
 		const scope = this.scope;
 
@@ -73,10 +73,7 @@ class ViewportNode extends Node {
 
 		} else {
 
-			const coordinateNode = vec2( new ViewportNode( ViewportNode.COORDINATE ) );
-			const resolutionNode = new ViewportNode( ViewportNode.RESOLUTION );
-
-			output = coordinateNode.div( resolutionNode );
+			output = viewportCoordinate.div( viewportResolution );
 
 			let outX = output.x;
 			let outY = output.y;
@@ -102,9 +99,9 @@ class ViewportNode extends Node {
 
 				// follow webgpu standards
 
-				const resolution = viewportResolution.build( builder );
+				const resolution = builder.getNodeProperties( viewportResolution ).outputNode.build( builder );
 
-				coord = `${ builder.getType( 'vec2' ) }( ${ coord }.x, ${ resolution}.y - ${ coord }.y )`;
+				coord = `${ builder.getType( 'vec2' ) }( ${ coord }.x, ${ resolution }.y - ${ coord }.y )`;
 
 			}
 

+ 8 - 13
examples/jsm/nodes/lighting/AnalyticLightNode.js

@@ -74,25 +74,20 @@ class AnalyticLightNode extends LightingNode {
 				.and( shadowCoord.y.lessThanEqual( 1 ) )
 				.and( shadowCoord.z.lessThanEqual( 1 ) );
 
+			let coordZ = shadowCoord.z.add( bias );
 
 			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 )
-				);
+				coordZ = coordZ.mul( 2 ).sub( 1 ); // WebGPU: Convertion [ 0, 1 ] to [ - 1, 1 ]
 
 			}
 
+			shadowCoord = vec3(
+				shadowCoord.x,
+				shadowCoord.y.oneMinus(), // follow webgpu standards
+				coordZ
+			);
+
 			const textureCompare = ( depthTexture, shadowCoord, compare ) => texture( depthTexture, shadowCoord ).compare( compare );
 			//const textureCompare = ( depthTexture, shadowCoord, compare ) => compare.step( texture( depthTexture, shadowCoord ) );
 

+ 1 - 1
examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -484,7 +484,7 @@ ${ flowData.code }
 
 	getFragCoord() {
 
-		return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>', 'fragment' );
+		return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>', 'fragment' ) + '.xy';
 
 	}
 

BIN
examples/screenshots/webgpu_depth_texture.jpg