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: Transmission - Backdrop 3/3 #27880

Merged
merged 50 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2bde431
WebGPURenderer: Apply fog before tonemapping and encoding
sunag Feb 29, 2024
51a9567
TSL: Add `rendererReference`
sunag Mar 3, 2024
fa358a4
PassNode: Add `getViewZNode()`
sunag Mar 3, 2024
7669377
FogNode: Add `.getViewZNode()`, removed `mixAssign()`
sunag Mar 3, 2024
d0e4571
TSL: Add `toneMappingExposure`
sunag Mar 3, 2024
0d7d848
PostProcessing: Add `.renderAsync()`
sunag Mar 3, 2024
7fb4f28
Add `webgpu_custom_fog_background` example
sunag Mar 3, 2024
eaecbd2
cleanup
sunag Mar 3, 2024
35e49c1
cleanup
sunag Mar 3, 2024
a174963
improve description
sunag Mar 3, 2024
1e7f19f
update example
sunag Mar 5, 2024
6ee0c2d
Merge branch 'dev' into dev-postprocessing
sunag Mar 6, 2024
f0206bb
Transmission - WIP
sunag Mar 7, 2024
e468957
rename
sunag Mar 7, 2024
f5873dc
Revert
sunag Mar 7, 2024
9e7b47d
Merge branch 'dev' into dev-postprocessing
sunag Mar 13, 2024
b517944
Merge branch 'dev' into dev-postprocessing
sunag Mar 26, 2024
3ff31f4
Merge branch 'dev' into dev-postprocessing
sunag Mar 27, 2024
7ba9e25
Introduce singleViewportMipTexture for tests and revisions
sunag Mar 27, 2024
2255334
revision
sunag Mar 27, 2024
31628cd
cleanup
sunag Mar 27, 2024
723d286
fix circular deps
sunag Mar 27, 2024
2253e91
update screenshot `webgpu_skinning`
sunag Mar 27, 2024
cecf20f
Merge branch 'dev' into dev-postprocessing
sunag Mar 28, 2024
d0458d0
revision
sunag Mar 29, 2024
b5f3c8a
copyFramebufferToTexture(): Added support for multisampling
sunag Apr 2, 2024
47b8aca
revision
sunag Apr 2, 2024
6c6494b
revision
sunag Apr 3, 2024
23367a8
revision
sunag Apr 3, 2024
3a90200
cleanup
sunag Apr 3, 2024
9c209d0
Merge branch 'dev-postprocessing' of https://github.com/sunag/three.j…
sunag Apr 3, 2024
5f01967
Fix faceDirection in WebGLBackend if used BackSide
sunag Apr 3, 2024
f8f57e7
Added frontFaceCW
sunag Apr 3, 2024
3cdd80e
Added webgpu_materials_transmission
sunag Apr 3, 2024
def795d
cleanup
sunag Apr 3, 2024
94eea4d
update
sunag Apr 3, 2024
33c4083
revision
sunag Apr 4, 2024
b5742e6
update webgpu_skinning
sunag Apr 4, 2024
2fb6882
revision getVolumeTransmissionRay
sunag Apr 5, 2024
a5e48cd
revision
sunag Apr 5, 2024
be9d5d9
revision
sunag Apr 5, 2024
01936db
revision
sunag Apr 5, 2024
c8ac9b9
update screenshot
sunag Apr 5, 2024
f4bde63
cleanup
sunag Apr 5, 2024
c8f5bdf
Merge branch 'dev' into dev-postprocessing
sunag Apr 11, 2024
e07a6ee
update `webgpu_loader_gltf_anisotropy` example
sunag Apr 11, 2024
80a8d37
cleanup
sunag Apr 11, 2024
2a9c9cb
Update webgpu_compute_geometry.jpg
sunag Apr 11, 2024
1009652
update screenshots
sunag Apr 12, 2024
cfa2925
add material.*Node transmission properties
sunag Apr 12, 2024
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
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
"webgpu_cubemap_dynamic",
"webgpu_cubemap_mix",
"webgpu_custom_fog",
"webgpu_custom_fog_background",
"webgpu_depth_texture",
"webgpu_equirectangular",
"webgpu_instance_mesh",
Expand Down
1 change: 1 addition & 0 deletions examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export { default as CubeTextureNode, cubeTexture } from './accessors/CubeTexture
export { default as InstanceNode, instance } from './accessors/InstanceNode.js';
export { default as MaterialNode, materialAlphaTest, materialColor, materialShininess, materialEmissive, materialOpacity, materialSpecularColor, materialSpecularStrength, materialReflectivity, materialRoughness, materialMetalness, materialNormal, materialClearcoat, materialClearcoatRoughness, materialClearcoatNormal, materialRotation, materialSheen, materialSheenRoughness, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineWidth, materialLineDashOffset, materialPointWidth } from './accessors/MaterialNode.js';
export { default as MaterialReferenceNode, materialReference } from './accessors/MaterialReferenceNode.js';
export { default as RendererReferenceNode, rendererReference } from './accessors/RendererReferenceNode.js';
export { default as MorphNode, morphReference } from './accessors/MorphNode.js';
export { default as TextureBicubicNode, textureBicubic } from './accessors/TextureBicubicNode.js';
export { default as ModelNode, modelDirection, modelViewMatrix, modelNormalMatrix, modelWorldMatrix, modelPosition, modelViewPosition, modelScale } from './accessors/ModelNode.js';
Expand Down
70 changes: 70 additions & 0 deletions examples/jsm/nodes/accessors/MaterialNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@

}

} else if ( scope === MaterialNode.SPECULAR_INTENSITY ) {

const specularIntensity = this.getFloat( scope );

if ( material.specularMap ) {

node = specularIntensity.mul( this.getTexture( scope ).a );

} else {

node = specularIntensity;

}

} else if ( scope === MaterialNode.SPECULAR_INTENSITY ) {
Fixed Show fixed Hide fixed

const specularIntensity = this.getFloat( scope );

if ( material.specularMap ) {

node = specularIntensity.mul( this.getTexture( scope ).a );

} else {

node = specularIntensity;

}

} else if ( scope === MaterialNode.ROUGHNESS ) { // TODO: cleanup similar branches

const roughnessNode = this.getFloat( scope );
Expand Down Expand Up @@ -241,6 +269,34 @@

}

} else if ( scope === MaterialNode.TRANSMISSION ) {

const transmissionNode = this.getFloat( scope );

if ( material.transmissionMap ) {

node = transmissionNode.mul( this.getTexture( scope ).r );

} else {

node = transmissionNode;

}

} else if ( scope === MaterialNode.THICKNESS ) {

const thicknessNode = this.getFloat( scope );

if ( material.thicknessMap ) {

node = thicknessNode.mul( this.getTexture( scope ).g );

} else {

node = thicknessNode;

}

} else {

const outputType = this.getNodeType( builder );
Expand All @@ -261,6 +317,8 @@
MaterialNode.SHININESS = 'shininess';
MaterialNode.SPECULAR_COLOR = 'specular';
MaterialNode.SPECULAR_STRENGTH = 'specularStrength';
MaterialNode.SPECULAR_INTENSITY = 'specularIntensity';
MaterialNode.SPECULAR_COLOR2 = 'specularColor';
MaterialNode.REFLECTIVITY = 'reflectivity';
MaterialNode.ROUGHNESS = 'roughness';
MaterialNode.METALNESS = 'metalness';
Expand All @@ -275,6 +333,10 @@
MaterialNode.IRIDESCENCE = 'iridescence';
MaterialNode.IRIDESCENCE_IOR = 'iridescenceIOR';
MaterialNode.IRIDESCENCE_THICKNESS = 'iridescenceThickness';
MaterialNode.TRANSMISSION = 'transmission';
MaterialNode.THICKNESS = 'thickness';
MaterialNode.ATTENUATION_DISTANCE = 'attenuationDistance';
MaterialNode.ATTENUATION_COLOR = 'attenuationColor';
MaterialNode.LINE_SCALE = 'scale';
MaterialNode.LINE_DASH_SIZE = 'dashSize';
MaterialNode.LINE_GAP_SIZE = 'gapSize';
Expand All @@ -290,6 +352,10 @@
export const materialEmissive = nodeImmutable( MaterialNode, MaterialNode.EMISSIVE );
export const materialOpacity = nodeImmutable( MaterialNode, MaterialNode.OPACITY );
export const materialSpecularColor = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_COLOR );

export const materialSpecularIntensity = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_INTENSITY );
export const materialSpecularColor2 = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_COLOR2 );

export const materialSpecularStrength = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_STRENGTH );
export const materialReflectivity = nodeImmutable( MaterialNode, MaterialNode.REFLECTIVITY );
export const materialRoughness = nodeImmutable( MaterialNode, MaterialNode.ROUGHNESS );
Expand All @@ -304,6 +370,10 @@
export const materialIridescence = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE );
export const materialIridescenceIOR = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_IOR );
export const materialIridescenceThickness = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_THICKNESS );
export const materialTransmission = nodeImmutable( MaterialNode, MaterialNode.TRANSMISSION );
export const materialThickness = nodeImmutable( MaterialNode, MaterialNode.THICKNESS );
export const attenuationDistance = nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_DISTANCE );
export const attenuationColor = nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_COLOR );
export const materialLineScale = nodeImmutable( MaterialNode, MaterialNode.LINE_SCALE );
export const materialLineDashSize = nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_SIZE );
export const materialLineGapSize = nodeImmutable( MaterialNode, MaterialNode.LINE_GAP_SIZE );
Expand Down
29 changes: 29 additions & 0 deletions examples/jsm/nodes/accessors/RendererReferenceNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ReferenceNode from './ReferenceNode.js';
import { addNodeClass } from '../core/Node.js';
import { nodeObject } from '../shadernode/ShaderNode.js';

class RendererReferenceNode extends ReferenceNode {

constructor( property, inputType, renderer = null ) {

super( property, inputType, renderer );

this.renderer = renderer;

}

setReference( state ) {

this.reference = this.renderer !== null ? this.renderer : state.renderer;

return this.reference;

}

}

export default RendererReferenceNode;

export const rendererReference = ( name, type, renderer ) => nodeObject( new RendererReferenceNode( name, type, renderer ) );

addNodeClass( 'RendererReferenceNode', RendererReferenceNode );
2 changes: 1 addition & 1 deletion examples/jsm/nodes/accessors/TextureSizeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TextureSizeNode extends Node {
const textureProperty = this.textureNode.build( builder, 'property' );
const levelNode = this.levelNode.build( builder, 'int' );

return builder.format( `${builder.getMethod( 'textureDimensions' )}( ${textureProperty}, ${levelNode} )`, this.getNodeType( builder ), output );
return builder.format( `${ builder.getMethod( 'textureDimensions' ) }( ${ textureProperty }, ${ levelNode } )`, this.getNodeType( builder ), output );

}

Expand Down
1 change: 0 additions & 1 deletion examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class NodeBuilder {
this.lightsNode = null;
this.environmentNode = null;
this.fogNode = null;
this.toneMappingNode = null;

this.clippingContext = null;

Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/nodes/core/OutputStructNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class OutputStructNode extends Node {

super();

this.isOutputStructNode = true;
this.members = members;

this.isOutputStructNode = true;

}

setup( builder ) {
Expand Down
1 change: 1 addition & 0 deletions examples/jsm/nodes/core/PropertyNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default PropertyNode;
export const property = ( type, name ) => nodeObject( new PropertyNode( type, name ) );
export const varyingProperty = ( type, name ) => nodeObject( new PropertyNode( type, name, true ) );

//export const baseColor = nodeImmutable( PropertyNode, 'vec4', 'BaseColor' );
export const diffuseColor = nodeImmutable( PropertyNode, 'vec4', 'DiffuseColor' );
export const roughness = nodeImmutable( PropertyNode, 'float', 'Roughness' );
export const metalness = nodeImmutable( PropertyNode, 'float', 'Metalness' );
Expand Down
18 changes: 17 additions & 1 deletion examples/jsm/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PassNode extends TempNode {
this._depthTextureNode = nodeObject( new PassTextureNode( this, depthTexture ) );

this._depthNode = null;
this._viewZNode = null;
this._cameraNear = uniform( 0 );
this._cameraFar = uniform( 0 );

Expand All @@ -91,14 +92,29 @@ class PassNode extends TempNode {

}

getViewZNode() {

if ( this._viewZNode === null ) {

const cameraNear = this._cameraNear;
const cameraFar = this._cameraFar;

this._viewZNode = perspectiveDepthToViewZ( this._depthTextureNode, cameraNear, cameraFar );

}

return this._viewZNode;

}

getDepthNode() {

if ( this._depthNode === null ) {

const cameraNear = this._cameraNear;
const cameraFar = this._cameraFar;

this._depthNode = viewZToOrthographicDepth( perspectiveDepthToViewZ( this._depthTextureNode, cameraNear, cameraFar ), cameraNear, cameraFar );
this._depthNode = viewZToOrthographicDepth( this.getViewZNode(), cameraNear, cameraFar );

}

Expand Down
12 changes: 8 additions & 4 deletions examples/jsm/nodes/display/ToneMappingNode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import TempNode from '../core/TempNode.js';
import { addNodeClass } from '../core/Node.js';
import { tslFn, nodeObject, float, mat3, vec3 } from '../shadernode/ShaderNode.js';

import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping } from 'three';
import { addNodeElement, tslFn, nodeObject, float, mat3, vec3 } from '../shadernode/ShaderNode.js';
import { rendererReference } from '../accessors/RendererReferenceNode.js';
import { clamp, log2, max, pow } from '../math/MathNode.js';
import { mul } from '../math/OperatorNode.js';

import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping } from 'three';

// exposure only
const LinearToneMappingNode = tslFn( ( { color, exposure } ) => {

Expand Down Expand Up @@ -127,7 +128,7 @@ const toneMappingLib = {

class ToneMappingNode extends TempNode {

constructor( toneMapping = NoToneMapping, exposureNode = float( 1 ), colorNode = null ) {
constructor( toneMapping = NoToneMapping, exposureNode = toneMappingExposure, colorNode = null ) {

super( 'vec3' );

Expand Down Expand Up @@ -180,5 +181,8 @@ class ToneMappingNode extends TempNode {
export default ToneMappingNode;

export const toneMapping = ( mapping, exposure, color ) => nodeObject( new ToneMappingNode( mapping, nodeObject( exposure ), nodeObject( color ) ) );
export const toneMappingExposure = rendererReference( 'toneMappingExposure', 'float' );

addNodeElement( 'toneMapping', ( color, mapping, exposure ) => toneMapping( mapping, exposure, color ) );

addNodeClass( 'ToneMappingNode', ToneMappingNode );
9 changes: 4 additions & 5 deletions examples/jsm/nodes/fog/FogExp2Node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import FogNode from './FogNode.js';
import { positionView } from '../accessors/PositionNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';

Expand All @@ -15,12 +14,12 @@ class FogExp2Node extends FogNode {

}

setup() {
setup( builder ) {

const depthNode = positionView.z.negate();
const densityNode = this.densityNode;
const viewZ = this.getViewZNode( builder );
const density = this.densityNode;

return densityNode.mul( densityNode, depthNode, depthNode ).negate().exp().oneMinus();
return density.mul( density, viewZ, viewZ ).negate().exp().oneMinus();

}

Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/nodes/fog/FogNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Node, { addNodeClass } from '../core/Node.js';
import { mix } from '../math/MathNode.js';
import { positionView } from '../accessors/PositionNode.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';

class FogNode extends Node {
Expand All @@ -15,9 +15,9 @@ class FogNode extends Node {

}

mixAssign( outputNode ) {
getViewZNode( builder ) {

return mix( outputNode, this.colorNode, this );
return ( builder.context.viewZ || positionView.z ).negate();

}

Expand Down
7 changes: 4 additions & 3 deletions examples/jsm/nodes/fog/FogRangeNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import FogNode from './FogNode.js';
import { smoothstep } from '../math/MathNode.js';
import { positionView } from '../accessors/PositionNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';

Expand All @@ -17,9 +16,11 @@ class FogRangeNode extends FogNode {

}

setup() {
setup( builder ) {

return smoothstep( this.nearNode, this.farNode, positionView.z.negate() );
const viewZ = this.getViewZNode( builder );

return smoothstep( this.nearNode, this.farNode, viewZ );

}

Expand Down