Skip to content

Commit

Permalink
WebGPURenderer: Introduce RenderTarget3D and RenderTargetArray (#30155)
Browse files Browse the repository at this point in the history
* WebGPURenderer: Introduce RenderTarget3D and RenderTargetArray

* Fix TextureHelperGPU

* revert WebGL3DRenderTarget.js

* cleanup

* simplify example

* cleanup

* revert screenshot

* improve example

* update example

* refactor renderContext to support renderTarget not rendered yet and fix clear in webgpubackend

* ignore example

* Fix flip UV of texture3D FBO in WebGL

* update screenshot

* use build in example

* cleanup example

* feedbacks clear/load

* small cleanup syntax

* Improved example

* rename example

* update puppeeteer
  • Loading branch information
RenaudRohlinger authored Dec 23, 2024
1 parent f9c4319 commit 05dbc5d
Show file tree
Hide file tree
Showing 17 changed files with 556 additions and 59 deletions.
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
"webgpu_procedural_texture",
"webgpu_reflection",
"webgpu_refraction",
"webgpu_rendertarget_2d-array_3d",
"webgpu_rtt",
"webgpu_sandbox",
"webgpu_shadertoy",
Expand Down
20 changes: 15 additions & 5 deletions examples/jsm/helpers/TextureHelperGPU.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import {
NodeMaterial,
BoxGeometry,
BufferAttribute,
Mesh,
PlaneGeometry,
DoubleSide,
Vector3,
} from 'three';
import { NodeMaterial, texture as textureNode, cubeTexture, texture3D, float, vec4 } from 'three/tsl';
import { texture as textureNode, cubeTexture, texture3D, float, vec4, attribute } from 'three/tsl';
import { mergeGeometries } from '../utils/BufferGeometryUtils.js';

class TextureHelper extends Mesh {

constructor( texture, width = 1, height = 1, depth = 1 ) {

const material = new NodeMaterial();
material.side = DoubleSide;
material.transparent = true;
material.name = 'TextureHelper';

let colorNode;

const uvw = attribute( 'uvw' );

if ( texture.isCubeTexture ) {

colorNode = cubeTexture( texture );
colorNode = cubeTexture( texture ).sample( uvw );

} else if ( texture.isData3DTexture || texture.isCompressed3DTexture ) {

colorNode = texture3D( texture );
colorNode = texture3D( texture ).sample( uvw );

} else if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {

colorNode = textureNode( texture ).sample( uvw.xy ).depth( uvw.z );

} else {

Expand Down Expand Up @@ -122,7 +132,7 @@ function createCubeGeometry( width, height, depth ) {
}

geometry.deleteAttribute( 'uv' );
geometry.setAttribute( 'uv', uvw );
geometry.setAttribute( 'uvw', uvw );

return geometry;

Expand Down Expand Up @@ -162,7 +172,7 @@ function createSliceGeometry( texture, width, height, depth ) {
}

geometry.deleteAttribute( 'uv' );
geometry.setAttribute( 'uv', uvw );
geometry.setAttribute( 'uvw', uvw );

geometries.push( geometry );

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_textures_2d-array_compressed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"webgpu_postprocessing_ssaa": [ "msaa", "multisampled" ],
"webgpu_refraction": [ "water" ],
"webgpu_rtt": [ "renderTarget", "texture" ],
"webgpu_rendertarget_2d-array_3d": [ "renderTarget", "2d-array", "3d" ],
"webgpu_sky": [ "sun" ],
"webgpu_tonemapping": [ "gltf" ],
"webgpu_tsl_compute_attractors_particles": [ "gpgpu" ],
Expand Down
Loading

0 comments on commit 05dbc5d

Please sign in to comment.