Skip to content

Commit

Permalink
Add StorageTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Sep 15, 2023
1 parent fbc28ae commit 178f7b7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
4 changes: 1 addition & 3 deletions examples/jsm/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class Bindings extends DataMap {

if ( binding.isSampledTexture ) {

const store = binding.store === true;

this.textures.updateTexture( binding.texture, { store } );
this.textures.updateTexture( binding.texture );

} else if ( binding.isStorageBuffer ) {

Expand Down
19 changes: 19 additions & 0 deletions examples/jsm/renderers/common/StorageTexture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Texture, LinearFilter } from 'three';

class StorageTexture extends Texture {

constructor( width = 1, height = 1 ) {

super();

this.image = { width, height };

this.magFilter = LinearFilter;
this.minFilter = LinearFilter;

this.isStorageTexture = true;

}
}

export default StorageTexture;
4 changes: 1 addition & 3 deletions examples/jsm/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ class Textures extends DataMap {

//

if ( isRenderTarget || options.store === true ) {

//if ( options.store === true ) options.levels = 1; /* no mipmaps? */
if ( isRenderTarget || texture.isStorageTexture === true ) {

backend.createSampler( texture );
backend.createTexture( texture, options );
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class WebGPUTextureUtils {

let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC;

if ( options.store === true ) {
if ( texture.isStorageTexture === true ) {

usage |= GPUTextureUsage.STORAGE_BINDING;

Expand Down
6 changes: 2 additions & 4 deletions examples/webgpu_compute_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import WebGPU from 'three/addons/capabilities/WebGPU.js';
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js';
import StorageTexture from 'three/addons/renderers/common/StorageTexture.js';

let camera, scene, renderer;

Expand All @@ -57,10 +58,7 @@

const width = 512, height = 512;

const storageTexture = new THREE.Texture();
storageTexture.image = { width, height };
storageTexture.magFilter = THREE.LinearFilter;
storageTexture.minFilter = THREE.LinearFilter;
const storageTexture = new StorageTexture( width, height );

// create function

Expand Down

0 comments on commit 178f7b7

Please sign in to comment.