Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewportNode revision #27096

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does viewportResolution.build( builder ) not work? (Possibly it could be fixed with one of the changes from my PR -- introducing Node.fullBuild(), which runs all builds from all build stages on a node)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ping @sunag


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.