Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[pull] dev from mrdoob:dev #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Three.WebGPU.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export { default as PostProcessing } from './renderers/common/PostProcessing.js'
import * as RendererUtils from './renderers/common/RendererUtils.js';
export { RendererUtils };
export { default as StorageTexture } from './renderers/common/StorageTexture.js';
export { default as Storage3DTexture } from './renderers/common/Storage3DTexture.js';
export { default as StorageArrayTexture } from './renderers/common/StorageArrayTexture.js';
export { default as StorageBufferAttribute } from './renderers/common/StorageBufferAttribute.js';
export { default as StorageInstancedBufferAttribute } from './renderers/common/StorageInstancedBufferAttribute.js';
export { default as IndirectStorageBufferAttribute } from './renderers/common/IndirectStorageBufferAttribute.js';
Expand Down
79 changes: 79 additions & 0 deletions src/renderers/common/Storage3DTexture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Texture } from '../../textures/Texture.js';
import { LinearFilter, ClampToEdgeWrapping } from '../../constants.js';

/**
* This special type of texture is intended for compute shaders.
* It can be used to compute the data of a texture with a compute shader.
*
* Note: This type of texture can only be used with `WebGPURenderer`
* and a WebGPU backend.
*
* @augments Texture
*/
class Storage3DTexture extends Texture {

/**
* Constructs a new storage texture.
*
* @param {number} [width=1] - The storage texture's width.
* @param {number} [height=1] - The storage texture's height.
* @param {number} [depth=1] - The storage texture's depth.
*/
constructor( width = 1, height = 1, depth = 1 ) {

super();

//inherited from texture. Must be false for 3DTexture
this.isArrayTexture = false;

/**
* The image object which just represents the texture's dimension.
*
* @type {{width: number, height: number, depth: number}}
*/
this.image = { width, height, depth };

/**
* The default `magFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.magFilter = LinearFilter;

/**
* The default `minFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.minFilter = LinearFilter;

/**
* This defines how the texture is wrapped in the depth direction and corresponds to
* *W* in UVW mapping.
*
* @type {number}
*/
this.wrapR = ClampToEdgeWrapping;

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isStorageTexture = true;

/**
* Indicates whether this texture is a 3D texture.
*
* @type {boolean}
*
*/
this.is3DTexture = true;

}

}

export default Storage3DTexture;
63 changes: 63 additions & 0 deletions src/renderers/common/StorageArrayTexture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Texture } from '../../textures/Texture.js';
import { LinearFilter } from '../../constants.js';

/**
* This special type of texture is intended for compute shaders.
* It can be used to compute the data of a texture with a compute shader.
*
* Note: This type of texture can only be used with `WebGPURenderer`
* and a WebGPU backend.
*
* @augments Texture
*/
class StorageArrayTexture extends Texture {

/**
* Constructs a new storage texture.
*
* @param {number} [width=1] - The storage texture's width.
* @param {number} [height=1] - The storage texture's height.
* @param {number} [depth=1] - The storage texture's depth.
*/
constructor( width = 1, height = 1, depth = 1 ) {

super();

//inherited from texture
this.isArrayTexture = true;

/**
* The image object which just represents the texture's dimension.
*
* @type {{width: number, height: number, depth: number}}
*/
this.image = { width, height, depth };

/**
* The default `magFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.magFilter = LinearFilter;

/**
* The default `minFilter` for storage textures is `THREE.LinearFilter`.
*
* @type {number}
*/
this.minFilter = LinearFilter;

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isStorageTexture = true;

}

}

export default StorageArrayTexture;
2 changes: 1 addition & 1 deletion src/renderers/common/nodes/NodeSampledTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class NodeSampledTexture3D extends NodeSampledTexture {
* @readonly
* @default true
*/
this.isSampledTexture3D = true;
this.is3DTexture = true;

}

Expand Down
25 changes: 15 additions & 10 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,24 +1701,29 @@ ${ flowData.code }

}

} else if ( texture.isArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
} else if ( uniform.node.isStorageTextureNode === true ) {

textureType = 'texture_2d_array<f32>';
const format = getFormat( texture );
const access = this.getStorageAccess( uniform.node, shaderStage );

} else if ( texture.isVideoTexture === true ) {
const is3D = uniform.node.value.is3DTexture;
const isArrayTexture = uniform.node.value.isArrayTexture;

textureType = 'texture_external';
const dimension = is3D ? '3d' : `2d${ isArrayTexture ? '_array' : '' }`;

} else if ( texture.isData3DTexture === true ) {
textureType = `texture_storage_${ dimension }<${ format }, ${ access }>`;

textureType = 'texture_3d<f32>';
} else if ( texture.isArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {

} else if ( uniform.node.isStorageTextureNode === true ) {
textureType = 'texture_2d_array<f32>';

const format = getFormat( texture );
const access = this.getStorageAccess( uniform.node, shaderStage );
} else if ( texture.is3DTexture === true || texture.isData3DTexture === true ) {

textureType = `texture_storage_2d<${ format }, ${ access }>`;
textureType = 'texture_3d<f32>';

} else if ( texture.isVideoTexture === true ) {

textureType = 'texture_external';

} else {

Expand Down
14 changes: 12 additions & 2 deletions src/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class WebGPUBindingUtils {

}

if ( binding.texture.isArrayTexture ) {

storageTexture.viewDimension = GPUTextureViewDimension.TwoDArray;

} else if ( binding.texture.is3DTexture ) {

storageTexture.viewDimension = GPUTextureViewDimension.ThreeD;

}

bindingGPU.storageTexture = storageTexture;

} else if ( binding.isSampledTexture ) {
Expand Down Expand Up @@ -206,7 +216,7 @@ class WebGPUBindingUtils {

texture.viewDimension = GPUTextureViewDimension.TwoDArray;

} else if ( binding.isSampledTexture3D ) {
} else if ( binding.texture.is3DTexture ) {

texture.viewDimension = GPUTextureViewDimension.ThreeD;

Expand Down Expand Up @@ -428,7 +438,7 @@ class WebGPUBindingUtils {

dimensionViewGPU = GPUTextureViewDimension.Cube;

} else if ( binding.isSampledTexture3D ) {
} else if ( binding.texture.is3DTexture ) {

dimensionViewGPU = GPUTextureViewDimension.ThreeD;

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgpu/utils/WebGPUTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ class WebGPUTextureUtils {

let dimension;

if ( texture.isData3DTexture ) {
if ( texture.is3DTexture || texture.isData3DTexture ) {

dimension = GPUTextureDimension.ThreeD;

Expand Down