Skip to content

Commit

Permalink
WebGPURenderer: Compute Snow Example (#27400)
Browse files Browse the repository at this point in the history
* NodeMaterial: Check toneMapped=true

* Renderer: overrideMaterial compatible with positionNode

* GaussianBlurNode: Added resolution

* add `webgpu_compute_particles_snow` example

* update

* fix scale offset collision

* update initial pos y
  • Loading branch information
sunag committed Dec 19, 2023
1 parent 73fafde commit 74ca7d8
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
"webgpu_compute_audio",
"webgpu_compute_particles",
"webgpu_compute_particles_rain",
"webgpu_compute_particles_snow",
"webgpu_compute_points",
"webgpu_compute_texture",
"webgpu_compute_texture_pingpong",
Expand Down
5 changes: 5 additions & 0 deletions examples/jsm/nodes/display/GaussianBlurNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ class GaussianBlurNode extends TempNode {

this.updateBeforeType = NodeUpdateType.RENDER;

this.resolution = new Vector2( 1, 1 );

}

setSize( width, height ) {

width = Math.max( Math.round( width * this.resolution.x ), 1 );
height = Math.max( Math.round( height * this.resolution.y ), 1 );

this._invSize.value.set( 1 / width, 1 / height );
this._horizontalRT.setSize( width, height );
this._verticalRT.setSize( width, height );
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class NodeMaterial extends ShaderMaterial {

const toneMappingNode = builder.toneMappingNode;

if ( toneMappingNode ) {
if ( this.toneMapped === true && toneMappingNode ) {

outputNode = vec4( toneMappingNode.context( { color: outputNode.rgb } ), outputNode.a );

Expand Down
28 changes: 27 additions & 1 deletion examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ class Renderer {

renderObject( object, scene, camera, geometry, material, group, lightsNode ) {

material = scene.overrideMaterial !== null ? scene.overrideMaterial : material;
let overridePositionNode;

//

Expand All @@ -951,6 +951,24 @@ class Renderer {

//

if ( scene.overrideMaterial !== null ) {

const overrideMaterial = scene.overrideMaterial;

if ( material.positionNode && material.positionNode.isNode ) {

overridePositionNode = overrideMaterial.positionNode;

overrideMaterial.positionNode = material.positionNode;

}

material = overrideMaterial;

}

//

if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {

material.side = BackSide;
Expand All @@ -969,6 +987,14 @@ class Renderer {

//

if ( overridePositionNode !== undefined ) {

scene.overrideMaterial.positionNode = overridePositionNode;

}

//

object.onAfterRender( this, scene, camera, geometry, material, group );

}
Expand Down
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 74ca7d8

Please sign in to comment.