Skip to content

Commit

Permalink
ViewportNode revision (#27096)
Browse files Browse the repository at this point in the history
* ViewportNode revision

* remove depth

* Revert "remove depth"

This reverts commit d20b0f7.

* revision shadowmap

* fix screenshot
  • Loading branch information
sunag committed Nov 1, 2023
1 parent 5a25a00 commit 79cc152
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
13 changes: 11 additions & 2 deletions examples/jsm/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' ) {
Expand Down Expand Up @@ -212,7 +221,7 @@ class TextureNode extends UniformNode {
textureNode.levelNode = levelNode;

return context( textureNode, {
getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode
getMIPLevelAlgorithmNode: ( reqTextureNode, levelNode ) => levelNode
} );

}
Expand Down
13 changes: 5 additions & 8 deletions examples/jsm/nodes/display/ViewportNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}

Expand Down Expand Up @@ -55,7 +55,7 @@ class ViewportNode extends Node {

}

setup( builder ) {
setup( /*builder*/ ) {

const scope = this.scope;

Expand All @@ -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;
Expand All @@ -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 )`;

}

Expand Down
21 changes: 8 additions & 13 deletions examples/jsm/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ ${ flowData.code }

getFragCoord() {

return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>', 'fragment' );
return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>', 'fragment' ) + '.xy';

}

Expand Down
Binary file modified examples/screenshots/webgpu_depth_texture.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 79cc152

Please sign in to comment.