ソースを参照

WebGPURenderer: Revision texture filtering and rain example (#28682)

* revision of tsl filtered textures

* fix example
sunag 1 年間 前
コミット
2328b0a75c

+ 11 - 1
examples/jsm/nodes/core/NodeBuilder.js

@@ -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';
@@ -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 ) {
 
 		/*

+ 10 - 2
examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -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' );
+
 		}
 
 	}
@@ -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 );
+
 		}
 
 	}

+ 2 - 0
examples/webgpu_compute_particles_rain.html

@@ -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;