Ver Fonte

StorageTexture: Mipmaps (#27332)

* StorageTexture: Mipmaps

* revision

* use texture.generateMipmaps
sunag há 1 ano atrás
pai
commit
4c7912c7b4

+ 20 - 0
examples/jsm/renderers/common/Bindings.js

@@ -124,6 +124,8 @@ class Bindings extends DataMap {
 
 			} else if ( binding.isSampledTexture ) {
 
+				const texture = binding.texture;
+
 				if ( binding.needsBindingsUpdate ) needsBindingsUpdate = true;
 
 				const updated = binding.update();
@@ -134,6 +136,24 @@ class Bindings extends DataMap {
 
 				}
 
+				if ( texture.isStorageTexture === true ) {
+
+					const textureData = this.get( texture );
+
+					if ( binding.store === true ) {
+
+						textureData.needsMipmap = true;
+
+					} else if ( texture.generateMipmaps === true && this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) {
+
+						this.backend.generateMipmaps( texture );
+
+						textureData.needsMipmap = false;
+
+					}
+
+				}
+
 			}
 
 		}

+ 6 - 0
examples/jsm/renderers/common/Renderer.js

@@ -352,6 +352,12 @@ class Renderer {
 
 	}
 
+	getMaxAnisotropy() {
+
+		return this.backend.getMaxAnisotropy();
+
+	}
+
 	getActiveCubeFace() {
 
 		return this._activeCubeFace;

+ 1 - 0
examples/jsm/renderers/common/StorageTexture.js

@@ -14,6 +14,7 @@ class StorageTexture extends Texture {
 		this.isStorageTexture = true;
 
 	}
+
 }
 
 export default StorageTexture;

+ 9 - 1
examples/jsm/renderers/webgl/WebGLBackend.js

@@ -8,6 +8,7 @@ import WebGLState from './utils/WebGLState.js';
 import WebGLUtils from './utils/WebGLUtils.js';
 import WebGLTextureUtils from './utils/WebGLTextureUtils.js';
 import WebGLExtensions from './utils/WebGLExtensions.js';
+import WebGLCapabilities from './utils/WebGLCapabilities.js';
 
 //
 
@@ -34,6 +35,7 @@ class WebGLBackend extends Backend {
 		this.gl = glContext;
 
 		this.extensions = new WebGLExtensions( this );
+		this.capabilities = new WebGLCapabilities( this );
 		this.attributeUtils = new WebGLAttributeUtils( this );
 		this.textureUtils = new WebGLTextureUtils( this );
 		this.state = new WebGLState( this );
@@ -877,12 +879,18 @@ class WebGLBackend extends Backend {
 
 	}
 
-	hasFeature( name ) {
+	hasFeature( /*name*/ ) {
 
 		return true;
 
 	}
 
+	getMaxAnisotropy() {
+
+		return this.capabilities.getMaxAnisotropy();
+
+	}
+
 	copyFramebufferToTexture( texture, renderContext ) {
 
 		const { gl } = this;

+ 36 - 0
examples/jsm/renderers/webgl/utils/WebGLCapabilities.js

@@ -0,0 +1,36 @@
+class WebGLCapabilities {
+
+	constructor( backend ) {
+
+		this.backend = backend;
+
+		this.maxAnisotropy = null;
+
+	}
+
+	getMaxAnisotropy() {
+
+		if ( this.maxAnisotropy !== null ) return this.maxAnisotropy;
+
+		const gl = this.backend.gl;
+		const extensions = this.backend.extensions;
+
+		if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
+
+			const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
+
+			this.maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
+
+		} else {
+
+			this.maxAnisotropy = 0;
+
+		}
+
+		return this.maxAnisotropy;
+
+	}
+
+}
+
+export default WebGLCapabilities;

+ 11 - 1
examples/jsm/renderers/webgl/utils/WebGLExtensions.js

@@ -7,11 +7,21 @@ class WebGLExtensions {
 		this.gl = this.backend.gl;
 		this.availableExtensions = this.gl.getSupportedExtensions();
 
+		this.extensions = {};
+
 	}
 
 	get( name ) {
 
-		return this.gl.getExtension( name );
+		let extension = this.extensions[ name ];
+
+		if ( extension === undefined ) {
+
+			extension = this.gl.getExtension( name );
+
+		}
+
+		return extension;
 
 	}
 

+ 6 - 0
examples/jsm/renderers/webgpu/WebGPUBackend.js

@@ -1056,6 +1056,12 @@ class WebGPUBackend extends Backend {
 
 	// utils public
 
+	getMaxAnisotropy() {
+
+		return 16;
+
+	}
+
 	hasFeature( name ) {
 
 		const adapter = this.adapter || _staticAdapter;

+ 1 - 1
examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js

@@ -220,7 +220,7 @@ class WebGPUBindingUtils {
 
 					const aspectGPU = GPUTextureAspect.All;
 
-					resourceGPU = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU } );
+					resourceGPU = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU, mipLevelCount: binding.store ? 1 : textureData.mipLevelCount } );
 
 				}
 

+ 1 - 0
examples/webgpu_compute_texture.html

@@ -56,6 +56,7 @@
 				const width = 512, height = 512;
 
 				const storageTexture = new StorageTexture( width, height );
+				//storageTexture.minFilter = THREE.LinearMipMapLinearFilter;
 
 				// create function