Skip to content

Commit

Permalink
WebGPURenderer: Revision texture filtering and rain example (#28682)
Browse files Browse the repository at this point in the history
* revision of tsl filtered textures

* fix example
  • Loading branch information
sunag authored Jun 17, 2024
1 parent 8a7848a commit 2328b0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
} from '../../renderers/common/nodes/NodeUniform.js';

import { REVISION, RenderTarget, Color, Vector2, Vector3, Vector4, IntType, UnsignedIntType, Float16BufferAttribute } from 'three';
import {
REVISION, RenderTarget, Color, Vector2, Vector3, Vector4, IntType, UnsignedIntType, Float16BufferAttribute,
LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter
} from 'three';

import { stack } from './StackNode.js';
import { getCurrentStack, setCurrentStack } from '../shadernode/ShaderNode.js';
Expand Down Expand Up @@ -246,6 +249,13 @@ class NodeBuilder {

}

isFilteredTexture( texture ) {

return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
texture.minFilter === LinearFilter || texture.minFilter === LinearMipmapNearestFilter || texture.minFilter === NearestMipmapLinearFilter || texture.minFilter === LinearMipmapLinearFilter );

}

addChain( node ) {

/*
Expand Down
12 changes: 10 additions & 2 deletions examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ class WGSLNodeBuilder extends NodeBuilder {

}

} else {
} else if ( this.isFilteredTexture( texture ) ) {

return this.generateFilteredTexture( texture, textureProperty, uvSnippet );

} else {

return this.generateTextureLod( texture, textureProperty, uvSnippet, '0' );

}

}
Expand All @@ -213,10 +217,14 @@ class WGSLNodeBuilder extends NodeBuilder {

return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;

} else {
} else if ( this.isFilteredTexture( texture ) ) {

return this.generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet );

} else {

return this.generateTextureLod( texture, textureProperty, uvSnippet, levelSnippet );

}

}
Expand Down
2 changes: 2 additions & 0 deletions examples/webgpu_compute_particles_rain.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@

collisionPosRT = new THREE.RenderTarget( 1024, 1024 );
collisionPosRT.texture.type = THREE.HalfFloatType;
collisionPosRT.texture.magFilter = THREE.NearestFilter;
collisionPosRT.texture.minFilter = THREE.NearestFilter;

collisionPosMaterial = new MeshBasicNodeMaterial();
collisionPosMaterial.colorNode = positionWorld;
Expand Down

0 comments on commit 2328b0a

Please sign in to comment.