未验证 提交 f9cd9cab 编写于 作者: M Michael Herzog 提交者: GitHub

Add new render target types for 3D and array textures. (#23498)

* Add new render target types for 3D and array textures.

* Rename data textures.

* Examples: Clean up.

* Remove options parameter from new render targets.
上级 97972660
......@@ -66,7 +66,7 @@
// 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>
......
......@@ -66,7 +66,7 @@
// 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>
......
......@@ -310,9 +310,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",
......@@ -809,9 +809,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",
......
......@@ -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;
......
......@@ -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;
......
......@@ -211,7 +211,7 @@
}
class VOXDataTexture3D extends THREE.DataTexture3D {
class VOXData3DTexture extends THREE.Data3DTexture {
constructor( chunk ) {
......@@ -242,7 +242,7 @@
}
THREE.VOXDataTexture3D = VOXDataTexture3D;
THREE.VOXData3DTexture = VOXData3DTexture;
THREE.VOXLoader = VOXLoader;
THREE.VOXMesh = VOXMesh;
......
......@@ -124,7 +124,7 @@
if ( v ) {
const is3dTextureDefine = v.isDataTexture3D ? 1 : 0;
const is3dTextureDefine = v.isData3DTexture ? 1 : 0;
if ( is3dTextureDefine !== material.defines.USE_3DTEXTURE ) {
......@@ -135,7 +135,7 @@
material.uniforms.lutSize.value = v.image.width;
if ( v.isDataTexture3D ) {
if ( v.isData3DTexture ) {
material.uniforms.lut3d.value = v;
......
......@@ -4,7 +4,7 @@ import {
Loader,
FileLoader,
DataTexture,
DataTexture3D,
Data3DTexture,
RGBAFormat,
UnsignedByteType,
ClampToEdgeWrapping,
......@@ -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;
......
......@@ -5,7 +5,7 @@ import {
FileLoader,
Vector3,
DataTexture,
DataTexture3D,
Data3DTexture,
UnsignedByteType,
ClampToEdgeWrapping,
LinearFilter,
......@@ -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;
......
import {
BufferGeometry,
DataTexture3D,
Data3DTexture,
FileLoader,
Float32BufferAttribute,
Loader,
......@@ -266,7 +266,7 @@ class VOXMesh extends Mesh {
}
class VOXDataTexture3D extends DataTexture3D {
class VOXData3DTexture extends Data3DTexture {
constructor( chunk ) {
......@@ -302,4 +302,4 @@ class VOXDataTexture3D extends DataTexture3D {
}
export { VOXLoader, VOXMesh, VOXDataTexture3D };
export { VOXLoader, VOXMesh, VOXData3DTexture };
......@@ -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;
......@@ -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;
......
......@@ -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 );
......@@ -528,7 +528,7 @@ class WebGPUTextures {
let dimension;
if ( texture.isDataTexture3D ) {
if ( texture.isData3DTexture ) {
dimension = GPUTextureDimension.ThreeD;
......
......@@ -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;
......
......@@ -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;
......
......@@ -75,7 +75,7 @@
}
return new THREE.DataTexture3D( data, size, size, size );
return new THREE.Data3DTexture( data, size, size, size );
}
......@@ -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,
......
......@@ -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: {
......@@ -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;
......@@ -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
......
......@@ -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;
......
......@@ -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';
......@@ -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,
......
......@@ -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;
......
......@@ -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 };
......@@ -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 );
}
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';
......@@ -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';
......
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 };
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 };
......@@ -41,18 +41,6 @@ class WebGLRenderTarget extends EventDispatcher {
}
setTexture( texture ) {
texture.image = {
width: this.width,
height: this.height,
depth: this.depth
};
this.texture = texture;
}
setSize( width, height, depth = 1 ) {
if ( this.width !== width || this.height !== height || this.depth !== depth ) {
......
......@@ -1866,7 +1866,7 @@ function WebGLRenderer( parameters = {} ) {
const texture = renderTarget.texture;
if ( texture.isDataTexture3D || texture.isDataTexture2DArray ) {
if ( texture.isData3DTexture || texture.isDataArrayTexture ) {
isRenderTarget3D = true;
......@@ -2081,12 +2081,12 @@ function WebGLRenderer( parameters = {} ) {
const glType = utils.convert( dstTexture.type );
let glTarget;
if ( dstTexture.isDataTexture3D ) {
if ( dstTexture.isData3DTexture ) {
textures.setTexture3D( dstTexture, 0 );
glTarget = _gl.TEXTURE_3D;
} else if ( dstTexture.isDataTexture2DArray ) {
} else if ( dstTexture.isDataArrayTexture ) {
textures.setTexture2DArray( dstTexture, 0 );
glTarget = _gl.TEXTURE_2D_ARRAY;
......@@ -2116,7 +2116,7 @@ function WebGLRenderer( parameters = {} ) {
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );
if ( srcTexture.isDataTexture || srcTexture.isDataTexture3D ) {
if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
_gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
......
import { FloatType, RGBAFormat } from '../../constants.js';
import { DataTexture2DArray } from '../../textures/DataTexture2DArray.js';
import { DataArrayTexture } from '../../textures/DataArrayTexture.js';
import { Vector3 } from '../../math/Vector3.js';
import { Vector2 } from '../../math/Vector2.js';
......@@ -81,7 +81,7 @@ function WebGLMorphtargets( gl, capabilities, textures ) {
const buffer = new Float32Array( width * height * 4 * numberOfMorphTargets );
const texture = new DataTexture2DArray( buffer, width, height, numberOfMorphTargets );
const texture = new DataArrayTexture( buffer, width, height, numberOfMorphTargets );
texture.format = RGBAFormat; // using RGBA since RGB might be emulated (and is thus slower)
texture.type = FloatType;
texture.needsUpdate = true;
......
......@@ -662,8 +662,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
let textureType = _gl.TEXTURE_2D;
if ( texture.isDataTexture2DArray ) textureType = _gl.TEXTURE_2D_ARRAY;
if ( texture.isDataTexture3D ) textureType = _gl.TEXTURE_3D;
if ( texture.isDataArrayTexture ) textureType = _gl.TEXTURE_2D_ARRAY;
if ( texture.isData3DTexture ) textureType = _gl.TEXTURE_3D;
const forceUpload = initTexture( textureProperties, texture );
const source = texture.source;
......@@ -883,7 +883,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
} else if ( texture.isDataTexture2DArray ) {
} else if ( texture.isDataArrayTexture ) {
if ( useTexStorage ) {
......@@ -901,7 +901,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
}
} else if ( texture.isDataTexture3D ) {
} else if ( texture.isData3DTexture ) {
if ( useTexStorage ) {
......@@ -1492,7 +1492,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
const isMultipleRenderTargets = ( renderTarget.isWebGLMultipleRenderTargets === true );
const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
// Setup framebuffer
......@@ -1615,18 +1614,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
let glTextureType = _gl.TEXTURE_2D;
if ( isRenderTarget3D ) {
// Render targets containing layers, i.e: Texture 3D and 2d arrays
if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) {
if ( isWebGL2 ) {
const isTexture3D = texture.isDataTexture3D;
glTextureType = isTexture3D ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
} else {
console.warn( 'THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.' );
console.error( 'THREE.WebGLTextures: THREE.Data3DTexture and THREE.DataArrayTexture only supported with WebGL2.' );
}
......
......@@ -43,12 +43,12 @@
import { CubeTexture } from '../../textures/CubeTexture.js';
import { Texture } from '../../textures/Texture.js';
import { DataTexture2DArray } from '../../textures/DataTexture2DArray.js';
import { DataTexture3D } from '../../textures/DataTexture3D.js';
import { DataArrayTexture } from '../../textures/DataArrayTexture.js';
import { Data3DTexture } from '../../textures/Data3DTexture.js';
const emptyTexture = new Texture();
const emptyTexture2dArray = new DataTexture2DArray();
const emptyTexture3d = new DataTexture3D();
const emptyArrayTexture = new DataArrayTexture();
const empty3dTexture = new Data3DTexture();
const emptyCubeTexture = new CubeTexture();
// --- Utilities ---
......@@ -483,7 +483,7 @@ function setValueT3D1( gl, v, textures ) {
}
textures.setTexture3D( v || emptyTexture3d, unit );
textures.setTexture3D( v || empty3dTexture, unit );
}
......@@ -515,7 +515,7 @@ function setValueT2DArray1( gl, v, textures ) {
}
textures.setTexture2DArray( v || emptyTexture2dArray, unit );
textures.setTexture2DArray( v || emptyArrayTexture, unit );
}
......@@ -718,7 +718,7 @@ function setValueT3DArray( gl, v, textures ) {
for ( let i = 0; i !== n; ++ i ) {
textures.setTexture3D( v[ i ] || emptyTexture3d, units[ i ] );
textures.setTexture3D( v[ i ] || empty3dTexture, units[ i ] );
}
......@@ -750,7 +750,7 @@ function setValueT2DArrayArray( gl, v, textures ) {
for ( let i = 0; i !== n; ++ i ) {
textures.setTexture2DArray( v[ i ] || emptyTexture2dArray, units[ i ] );
textures.setTexture2DArray( v[ i ] || emptyArrayTexture, units[ i ] );
}
......
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
class DataTexture3D extends Texture {
class Data3DTexture extends Texture {
constructor( data = null, width = 1, height = 1, depth = 1 ) {
......@@ -30,6 +30,6 @@ class DataTexture3D extends Texture {
}
DataTexture3D.prototype.isDataTexture3D = true;
Data3DTexture.prototype.isData3DTexture = true;
export { DataTexture3D };
export { Data3DTexture };
import { Texture } from './Texture.js';
import { ClampToEdgeWrapping, NearestFilter } from '../constants.js';
class DataTexture2DArray extends Texture {
class DataArrayTexture extends Texture {
constructor( data = null, width = 1, height = 1, depth = 1 ) {
......@@ -22,6 +22,6 @@ class DataTexture2DArray extends Texture {
}
DataTexture2DArray.prototype.isDataTexture2DArray = true;
DataArrayTexture.prototype.isDataArrayTexture = true;
export { DataTexture2DArray };
export { DataArrayTexture };
......@@ -9,9 +9,6 @@ class DataTexture extends Texture {
this.image = { data: data, width: width, height: height };
this.magFilter = magFilter;
this.minFilter = minFilter;
this.generateMipmaps = false;
this.flipY = false;
this.unpackAlignment = 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册