Skip to content

Commit

Permalink
Add new render target types for 3D and array textures. (mrdoob#23498)
Browse files Browse the repository at this point in the history
* Add new render target types for 3D and array textures.

* Rename data textures.

* Examples: Clean up.

* Remove options parameter from new render targets.
  • Loading branch information
Mugen87 authored and donmccurdy committed Mar 10, 2022
1 parent 607575b commit 19ebec6
Show file tree
Hide file tree
Showing 33 changed files with 126 additions and 89 deletions.
File renamed without changes.
Expand Up @@ -66,7 +66,7 @@ <h2>Code Example</h2>

// used the buffer to create a [name]

const texture = new THREE.DataTexture2DArray( data, width, height, depth );
const texture = new THREE.DataArrayTexture( data, width, height, depth );
texture.needsUpdate = true;
</code>

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/api/zh/textures/DataTexture2DArray.html
Expand Up @@ -66,7 +66,7 @@ <h2>代码示例</h2>

// used the buffer to create a [name]

const texture = new THREE.DataTexture2DArray( data, width, height, depth );
const texture = new THREE.DataArrayTexture( data, width, height, depth );
texture.needsUpdate = true;
</code>

Expand Down
8 changes: 4 additions & 4 deletions docs/list.json
Expand Up @@ -311,9 +311,9 @@
"CanvasTexture": "api/en/textures/CanvasTexture",
"CompressedTexture": "api/en/textures/CompressedTexture",
"CubeTexture": "api/en/textures/CubeTexture",
"Data3DTexture": "api/en/textures/Data3DTexture",
"DataArrayTexture": "api/en/textures/DataArrayTexture",
"DataTexture": "api/en/textures/DataTexture",
"DataTexture2DArray": "api/en/textures/DataTexture2DArray",
"DataTexture3D": "api/en/textures/DataTexture3D",
"DepthTexture": "api/en/textures/DepthTexture",
"FramebufferTexture": "api/en/textures/FramebufferTexture",
"Source": "api/en/textures/Source",
Expand Down Expand Up @@ -810,9 +810,9 @@
"CanvasTexture": "api/zh/textures/CanvasTexture",
"CompressedTexture": "api/zh/textures/CompressedTexture",
"CubeTexture": "api/zh/textures/CubeTexture",
"DataArrayTexture": "api/zh/textures/DataArrayTexture",
"Data3DTexture": "api/zh/textures/Data3DTexture",
"DataTexture": "api/zh/textures/DataTexture",
"DataTexture2DArray": "api/zh/textures/DataTexture2DArray",
"DataTexture3D": "api/zh/textures/DataTexture3D",
"DepthTexture": "api/zh/textures/DepthTexture",
"FramebufferTexture": "api/zh/textures/FramebufferTexture",
"Source": "api/zh/textures/Source",
Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/LUT3dlLoader.js
Expand Up @@ -110,7 +110,7 @@
texture.wrapT = THREE.ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;
const texture3D = new THREE.DataTexture3D();
const texture3D = new THREE.Data3DTexture();
texture3D.image.data = data;
texture3D.image.width = size;
texture3D.image.height = size;
Expand Down
2 changes: 1 addition & 1 deletion examples/js/loaders/LUTCubeLoader.js
Expand Up @@ -109,7 +109,7 @@
texture.wrapT = THREE.ClampToEdgeWrapping;
texture.generateMipmaps = false;
texture.needsUpdate = true;
const texture3D = new THREE.DataTexture3D();
const texture3D = new THREE.Data3DTexture();
texture3D.image.data = data;
texture3D.image.width = size;
texture3D.image.height = size;
Expand Down
4 changes: 2 additions & 2 deletions examples/js/loaders/VOXLoader.js
Expand Up @@ -211,7 +211,7 @@

}

class VOXDataTexture3D extends THREE.DataTexture3D {
class VOXData3DTexture extends THREE.Data3DTexture {

constructor( chunk ) {

Expand Down Expand Up @@ -242,7 +242,7 @@

}

THREE.VOXDataTexture3D = VOXDataTexture3D;
THREE.VOXData3DTexture = VOXData3DTexture;
THREE.VOXLoader = VOXLoader;
THREE.VOXMesh = VOXMesh;

Expand Down
4 changes: 2 additions & 2 deletions examples/js/postprocessing/LUTPass.js
Expand Up @@ -124,7 +124,7 @@

if ( v ) {

const is3dTextureDefine = v.isDataTexture3D ? 1 : 0;
const is3dTextureDefine = v.isData3DTexture ? 1 : 0;

if ( is3dTextureDefine !== material.defines.USE_3DTEXTURE ) {

Expand All @@ -135,7 +135,7 @@

material.uniforms.lutSize.value = v.image.width;

if ( v.isDataTexture3D ) {
if ( v.isData3DTexture ) {

material.uniforms.lut3d.value = v;

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/loaders/LUT3dlLoader.js
Expand Up @@ -4,7 +4,7 @@ import {
Loader,
FileLoader,
DataTexture,
DataTexture3D,
Data3DTexture,
RGBAFormat,
UnsignedByteType,
ClampToEdgeWrapping,
Expand Down Expand Up @@ -125,7 +125,7 @@ export class LUT3dlLoader extends Loader {
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new DataTexture3D();
const texture3D = new Data3DTexture();
texture3D.image.data = data;
texture3D.image.width = size;
texture3D.image.height = size;
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/loaders/LUTCubeLoader.js
Expand Up @@ -5,7 +5,7 @@ import {
FileLoader,
Vector3,
DataTexture,
DataTexture3D,
Data3DTexture,
UnsignedByteType,
ClampToEdgeWrapping,
LinearFilter,
Expand Down Expand Up @@ -125,7 +125,7 @@ export class LUTCubeLoader extends Loader {
texture.generateMipmaps = false;
texture.needsUpdate = true;

const texture3D = new DataTexture3D();
const texture3D = new Data3DTexture();
texture3D.image.data = data;
texture3D.image.width = size;
texture3D.image.height = size;
Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/loaders/VOXLoader.js
@@ -1,6 +1,6 @@
import {
BufferGeometry,
DataTexture3D,
Data3DTexture,
FileLoader,
Float32BufferAttribute,
Loader,
Expand Down Expand Up @@ -266,7 +266,7 @@ class VOXMesh extends Mesh {

}

class VOXDataTexture3D extends DataTexture3D {
class VOXData3DTexture extends Data3DTexture {

constructor( chunk ) {

Expand Down Expand Up @@ -302,4 +302,4 @@ class VOXDataTexture3D extends DataTexture3D {

}

export { VOXLoader, VOXMesh, VOXDataTexture3D };
export { VOXLoader, VOXMesh, VOXData3DTexture };
4 changes: 2 additions & 2 deletions examples/jsm/postprocessing/LUTPass.js
Expand Up @@ -117,7 +117,7 @@ class LUTPass extends ShaderPass {

if ( v ) {

const is3dTextureDefine = v.isDataTexture3D ? 1 : 0;
const is3dTextureDefine = v.isData3DTexture ? 1 : 0;
if ( is3dTextureDefine !== material.defines.USE_3DTEXTURE ) {

material.defines.USE_3DTEXTURE = is3dTextureDefine;
Expand All @@ -126,7 +126,7 @@ class LUTPass extends ShaderPass {
}

material.uniforms.lutSize.value = v.image.width;
if ( v.isDataTexture3D ) {
if ( v.isData3DTexture ) {

material.uniforms.lut3d.value = v;

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/renderers/webgpu/WebGPUTextures.js
Expand Up @@ -349,7 +349,7 @@ class WebGPUTextures {

// transfer texture data

if ( texture.isDataTexture || texture.isDataTexture2DArray || texture.isDataTexture3D ) {
if ( texture.isDataTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {

this._copyBufferToTexture( image, format, textureGPU );

Expand Down Expand Up @@ -528,7 +528,7 @@ class WebGPUTextures {

let dimension;

if ( texture.isDataTexture3D ) {
if ( texture.isData3DTexture ) {

dimension = GPUTextureDimension.ThreeD;

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl2_materials_texture2darray.html
Expand Up @@ -107,7 +107,7 @@
const zip = unzipSync( new Uint8Array( data ) );
const array = new Uint8Array( zip[ 'head256x256x109' ].buffer );

const texture = new THREE.DataTexture2DArray( array, 256, 256, 109 );
const texture = new THREE.DataArrayTexture( array, 256, 256, 109 );
texture.format = THREE.RedFormat;
texture.needsUpdate = true;

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl2_materials_texture3d.html
Expand Up @@ -97,7 +97,7 @@
// THREEJS will select R32F (33326) based on the THREE.RedFormat and THREE.FloatType.
// Also see https://www.khronos.org/registry/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE
// TODO: look the dtype up in the volume metadata
const texture = new THREE.DataTexture3D( volume.data, volume.xLength, volume.yLength, volume.zLength );
const texture = new THREE.Data3DTexture( volume.data, volume.xLength, volume.yLength, volume.zLength );
texture.format = THREE.RedFormat;
texture.type = THREE.FloatType;
texture.minFilter = texture.magFilter = THREE.LinearFilter;
Expand Down
4 changes: 2 additions & 2 deletions examples/webgl2_materials_texture3d_partialupdate.html
Expand Up @@ -75,7 +75,7 @@

}

return new THREE.DataTexture3D( data, size, size, size );
return new THREE.Data3DTexture( data, size, size, size );

}

Expand Down Expand Up @@ -115,7 +115,7 @@

// Texture

const texture = new THREE.DataTexture3D(
const texture = new THREE.Data3DTexture(
new Uint8Array( INITIAL_CLOUD_SIZE * INITIAL_CLOUD_SIZE * INITIAL_CLOUD_SIZE ).fill( 0 ),
INITIAL_CLOUD_SIZE,
INITIAL_CLOUD_SIZE,
Expand Down
14 changes: 4 additions & 10 deletions examples/webgl2_rendertarget_texture2darray.html
Expand Up @@ -138,13 +138,8 @@
const postProcessScene = new THREE.Scene();
const postProcessCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );

const renderTargetTexture = new THREE.DataTexture2DArray();
renderTargetTexture.format = THREE.RedFormat;
renderTargetTexture.type = THREE.UnsignedByteType;

const renderTarget = new THREE.WebGLRenderTarget( DIMENSIONS.width, DIMENSIONS.height );
renderTarget.depth = DIMENSIONS.depth;
renderTarget.setTexture( renderTargetTexture );
const renderTarget = new THREE.WebGLArrayRenderTarget( DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth );
renderTarget.texture.format = THREE.RedFormat;

const postProcessMaterial = new THREE.ShaderMaterial( {
uniforms: {
Expand Down Expand Up @@ -207,7 +202,7 @@
var zip = unzipSync( new Uint8Array( data ) );
const array = new Uint8Array( zip[ 'head256x256x109' ].buffer );

const texture = new THREE.DataTexture2DArray( array, DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth );
const texture = new THREE.DataArrayTexture( array, DIMENSIONS.width, DIMENSIONS.height, DIMENSIONS.depth );
texture.format = THREE.RedFormat;
texture.needsUpdate = true;

Expand Down Expand Up @@ -282,8 +277,7 @@

function render() {

// Step 1 - Render the input DataTexture2DArray into a
// DataTexture2DArray render target.
// Step 1 - Render the input DataArrayTexture into render target
renderTo2DArray();

// Step 2 - Renders the scene containing the plane with a material
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl2_volume_cloud.html
Expand Up @@ -104,7 +104,7 @@

}

const texture = new THREE.DataTexture3D( data, size, size, size );
const texture = new THREE.Data3DTexture( data, size, size, size );
texture.format = THREE.RedFormat;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
Expand Down
4 changes: 2 additions & 2 deletions examples/webgl2_volume_instancing.html
Expand Up @@ -27,7 +27,7 @@
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { VOXLoader, VOXDataTexture3D } from './jsm/loaders/VOXLoader.js';
import { VOXLoader, VOXData3DTexture } from './jsm/loaders/VOXLoader.js';

import WebGL from './jsm/capabilities/WebGL.js';

Expand Down Expand Up @@ -182,7 +182,7 @@
const material = new THREE.RawShaderMaterial( {
glslVersion: THREE.GLSL3,
uniforms: {
map: { value: new VOXDataTexture3D( chunk ) },
map: { value: new VOXData3DTexture( chunk ) },
cameraPos: { value: new THREE.Vector3() }
},
vertexShader,
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl2_volume_perlin.html
Expand Up @@ -85,7 +85,7 @@

}

const texture = new THREE.DataTexture3D( data, size, size, size );
const texture = new THREE.Data3DTexture( data, size, size, size );
texture.format = THREE.RedFormat;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
Expand Down
16 changes: 16 additions & 0 deletions src/Three.Legacy.js
Expand Up @@ -77,6 +77,8 @@ import { ImageUtils } from './extras/ImageUtils.js';
import { Shape } from './extras/core/Shape.js';
import { CubeCamera } from './cameras/CubeCamera.js';
import { Scene } from './scenes/Scene.js';
import { DataArrayTexture } from './textures/DataArrayTexture.js';
import { Data3DTexture } from './textures/Data3DTexture.js';

export { MathUtils as Math };

Expand Down Expand Up @@ -1994,3 +1996,17 @@ export function WebGLMultisampleRenderTarget( width, height, options ) {
return renderTarget;

}

export function DataTexture2DArray( data, width, height, depth ) {

console.warn( 'THREE.DataTexture2DArray has been renamed to DataArrayTexture.' );
return new DataArrayTexture( data, width, height, depth );

}

export function DataTexture3D( data, width, height, depth ) {

console.warn( 'THREE.DataTexture3D has been renamed to Data3DTexture.' );
return new Data3DTexture( data, width, height, depth );

}
6 changes: 4 additions & 2 deletions src/Three.js
@@ -1,5 +1,7 @@
import { REVISION } from './constants.js';

export { WebGLArrayRenderTarget } from './renderers/WebGLArrayRenderTarget.js';
export { WebGL3DRenderTarget } from './renderers/WebGL3DRenderTarget.js';
export { WebGLMultipleRenderTargets } from './renderers/WebGLMultipleRenderTargets.js';
export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js';
export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js';
Expand Down Expand Up @@ -27,8 +29,8 @@ export { Group } from './objects/Group.js';
export { VideoTexture } from './textures/VideoTexture.js';
export { FramebufferTexture } from './textures/FramebufferTexture.js';
export { DataTexture } from './textures/DataTexture.js';
export { DataTexture2DArray } from './textures/DataTexture2DArray.js';
export { DataTexture3D } from './textures/DataTexture3D.js';
export { DataArrayTexture } from './textures/DataArrayTexture.js';
export { Data3DTexture } from './textures/Data3DTexture.js';
export { CompressedTexture } from './textures/CompressedTexture.js';
export { CubeTexture } from './textures/CubeTexture.js';
export { CanvasTexture } from './textures/CanvasTexture.js';
Expand Down
22 changes: 22 additions & 0 deletions src/renderers/WebGL3DRenderTarget.js
@@ -0,0 +1,22 @@
import { WebGLRenderTarget } from './WebGLRenderTarget.js';
import { Data3DTexture } from '../textures/Data3DTexture.js';

class WebGL3DRenderTarget extends WebGLRenderTarget {

constructor( width, height, depth ) {

super( width, height );

this.depth = depth;

this.texture = new Data3DTexture( null, width, height, depth );

this.texture.isRenderTargetTexture = true;

}

}

WebGL3DRenderTarget.prototype.isWebGL3DRenderTarget = true;

export { WebGL3DRenderTarget };
22 changes: 22 additions & 0 deletions src/renderers/WebGLArrayRenderTarget.js
@@ -0,0 +1,22 @@
import { WebGLRenderTarget } from './WebGLRenderTarget.js';
import { DataArrayTexture } from '../textures/DataArrayTexture.js';

class WebGLArrayRenderTarget extends WebGLRenderTarget {

constructor( width, height, depth ) {

super( width, height );

this.depth = depth;

this.texture = new DataArrayTexture( null, width, height, depth );

this.texture.isRenderTargetTexture = true;

}

}

WebGLArrayRenderTarget.prototype.isWebGLArrayRenderTarget = true;

export { WebGLArrayRenderTarget };

0 comments on commit 19ebec6

Please sign in to comment.