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

WebGPURenderer: DepthTexture #25766

Merged
merged 20 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions examples/jsm/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TextureNode extends UniformNode {

constructor( value, uvNode = null, levelNode = null ) {

super( value, 'vec4' );
super( value );

this.isTextureNode = true;

Expand All @@ -24,6 +24,14 @@ class TextureNode extends UniformNode {

}

getNodeType( /*builder*/ ) {

if ( this.value.isDepthTexture === true ) return 'float';

return 'vec4';

}

getInputType( /*builder*/ ) {

return 'texture';
Expand Down Expand Up @@ -81,7 +89,7 @@ class TextureNode extends UniformNode {

}

const textureProperty = super.generate( builder, 'texture' );
const textureProperty = super.generate( builder, 'property' );

if ( output === 'sampler' ) {

Expand All @@ -93,32 +101,29 @@ class TextureNode extends UniformNode {

} else {

const nodeType = this.getNodeType( builder );
const nodeData = builder.getDataFromNode( this );

let propertyName = nodeData.propertyName;

if ( propertyName === undefined ) {

const uvSnippet = uvNode.build( builder, 'vec2' );
const nodeVar = builder.getVarFromNode( this, 'vec4' );
const nodeVar = builder.getVarFromNode( this, nodeType );

propertyName = builder.getPropertyName( nodeVar );

let snippet = null;

if ( texture.isVideoTexture === true ) {

snippet = builder.getVideoTexture( textureProperty, uvSnippet );

} else if ( levelNode && levelNode.isNode === true ) {
if ( levelNode && levelNode.isNode === true ) {

const levelSnippet = levelNode.build( builder, 'float' );

snippet = builder.getTextureLevel( textureProperty, uvSnippet, levelSnippet );
snippet = builder.getTextureLevel( texture, textureProperty, uvSnippet, levelSnippet );

} else {

snippet = builder.getTexture( textureProperty, uvSnippet );
snippet = builder.getTexture( texture, textureProperty, uvSnippet );

}

Expand All @@ -129,7 +134,7 @@ class TextureNode extends UniformNode {

}

return builder.format( propertyName, 'vec4', output );
return builder.format( propertyName, nodeType, output );

}

Expand Down
9 changes: 5 additions & 4 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ class NodeBuilder {
constructor( object, renderer, parser ) {

this.object = object;
this.material = object.material || null;
this.geometry = object.geometry || null;
this.material = object && ( object.material || null );
this.geometry = object && ( object.geometry || null );
this.renderer = renderer;
this.parser = parser;

this.nodes = [];
this.updateNodes = [];
this.hashNodes = {};

this.scene = null;
this.lightsNode = null;
this.environmentNode = null;
this.fogNode = null;
this.toneMappingNode = null;

this.vertexShader = null;
this.fragmentShader = null;
Expand All @@ -63,7 +64,7 @@ class NodeBuilder {

this.context = {
keywords: new NodeKeywords(),
material: object.material,
material: this.material,
getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode.mul( maxMipLevel( textureNode ) )
};

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/fog/FogExp2Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FogExp2Node extends FogNode {
const depthNode = positionView.z.negate();
const densityNode = this.densityNode;

this.factorNode = densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().oneMinus();
return densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().oneMinus();

}

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/fog/FogNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class FogNode extends Node {

}

generate( builder ) {
construct() {

return this.factorNode.build( builder, 'float' );
return this.factorNode;

}

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/fog/FogRangeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FogRangeNode extends FogNode {

construct() {

this.factorNode = smoothstep( this.nearNode, this.farNode, positionView.z.negate() );
return smoothstep( this.nearNode, this.farNode, positionView.z.negate() );

}

Expand Down
64 changes: 7 additions & 57 deletions examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Material, ShaderMaterial, NoToneMapping } from 'three';
import { Material, ShaderMaterial } from 'three';
import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js';
import { attribute } from '../core/AttributeNode.js';
import { diffuseColor } from '../core/PropertyNode.js';
Expand All @@ -8,13 +8,8 @@ import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js';
import { transformedNormalView } from '../accessors/NormalNode.js';
import { instance } from '../accessors/InstanceNode.js';
import { positionLocal } from '../accessors/PositionNode.js';
import { reference } from '../accessors/ReferenceNode.js';
import { skinning } from '../accessors/SkinningNode.js';
import { texture } from '../accessors/TextureNode.js';
import { cubeTexture } from '../accessors/CubeTextureNode.js';
import { toneMapping } from '../display/ToneMappingNode.js';
import { rangeFog } from '../fog/FogRangeNode.js';
import { densityFog } from '../fog/FogExp2Node.js';
import { lightsWithoutWrap } from '../lighting/LightsNode.js';
import AONode from '../lighting/AONode.js';
import EnvironmentNode from '../lighting/EnvironmentNode.js';
Expand Down Expand Up @@ -161,28 +156,7 @@ class NodeMaterial extends ShaderMaterial {

constructLights( builder ) {

let lightsNode = this.lightsNode || builder.lightsNode;
let envNode = this.envNode || builder.scene.environmentNode;

if ( envNode === undefined && builder.scene.environment ) {

const environment = builder.scene.environment;

if ( environment.isCubeTexture === true ) {

envNode = cubeTexture( environment );

} else if ( environment.isTexture === true ) {

envNode = texture( environment );

} else {

console.error( 'NodeMaterial: Unsupported environment configuration.', environment );

}

}
const envNode = this.envNode || builder.environmentNode;

const materialLightsNode = [];

Expand All @@ -198,6 +172,8 @@ class NodeMaterial extends ShaderMaterial {

}

let lightsNode = this.lightsNode || builder.lightsNode;

if ( materialLightsNode.length > 0 ) {

lightsNode = lightsWithoutWrap( [ ...lightsNode.lightNodes, ...materialLightsNode ] );
Expand Down Expand Up @@ -251,15 +227,9 @@ class NodeMaterial extends ShaderMaterial {

// TONE MAPPING

let toneMappingNode = renderer.toneMappingNode;

if ( ! toneMappingNode && renderer.toneMapping !== NoToneMapping ) {
const toneMappingNode = builder.toneMappingNode;

toneMappingNode = toneMapping( renderer.toneMapping, reference( 'toneMappingExposure', 'float', renderer ), outgoingLight );

}

if ( toneMappingNode && toneMappingNode.isNode === true ) {
if ( toneMappingNode ) {

outgoingLight = toneMappingNode.context( { color: outgoingLight } );

Expand All @@ -275,27 +245,7 @@ class NodeMaterial extends ShaderMaterial {

// FOG

let fogNode = builder.fogNode;

if ( ( fogNode && fogNode.isNode !== true ) && builder.scene.fog ) {

const fog = builder.scene.fog;

if ( fog.isFogExp2 ) {

fogNode = densityFog( reference( 'color', 'color', fog ), reference( 'density', 'float', fog ) );

} else if ( fog.isFog ) {

fogNode = rangeFog( reference( 'color', 'color', fog ), reference( 'near', 'float', fog ), reference( 'far', 'float', fog ) );

} else {

console.error( 'NodeMaterial: Unsupported fog configuration.', fog );

}

}
const fogNode = builder.fogNode;

if ( fogNode ) outputNode = vec4( fogNode.mixAssign( outputNode.rgb ), outputNode.a );

Expand Down
Loading