Skip to content
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
1 change: 1 addition & 0 deletions examples/jsm/utils/TextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function decompress( texture, maxTextureSize = Infinity, renderer = null
readableTexture.magFilter = texture.magFilter;
readableTexture.wrapS = texture.wrapS;
readableTexture.wrapT = texture.wrapT;
readableTexture.colorSpace = texture.colorSpace;
Copy link
Collaborator Author

@Mugen87 Mugen87 Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better for consistency if the color space property of the original texture is retained.

readableTexture.name = texture.name;

if ( _renderer ) {
Expand Down
63 changes: 63 additions & 0 deletions examples/jsm/utils/TextureUtilsGPU.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
QuadMesh,
NodeMaterial,
WebGPURenderer,
CanvasTexture
} from 'three';
import { texture, uv } from 'three/tsl';

let _renderer;
const _quadMesh = /*@__PURE__*/ new QuadMesh();

export async function decompress( blitTexture, maxTextureSize = Infinity, renderer = null ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new decompress() function is now async since an internal WebGPURenderer has to call init() before performing the decompression.


if ( renderer === null ) {

renderer = _renderer = new WebGPURenderer();
await renderer.init();

}

const material = new NodeMaterial();
material.fragmentNode = texture( blitTexture ).uv( uv().flipY() );

const width = Math.min( blitTexture.image.width, maxTextureSize );
const height = Math.min( blitTexture.image.height, maxTextureSize );

const currentOutputColorSpace = renderer.outputColorSpace;

renderer.setSize( width, height );
renderer.outputColorSpace = blitTexture.colorSpace;

_quadMesh.material = material;
_quadMesh.render( renderer );

renderer.outputColorSpace = currentOutputColorSpace;

const canvas = document.createElement( 'canvas' );
const context = canvas.getContext( '2d' );

canvas.width = width;
canvas.height = height;

context.drawImage( renderer.domElement, 0, 0, width, height );

const readableTexture = new CanvasTexture( canvas );

readableTexture.minFilter = blitTexture.minFilter;
readableTexture.magFilter = blitTexture.magFilter;
readableTexture.wrapS = blitTexture.wrapS;
readableTexture.wrapT = blitTexture.wrapT;
readableTexture.colorSpace = blitTexture.colorSpace;
readableTexture.name = blitTexture.name;

if ( _renderer !== null ) {

_renderer.dispose();
_renderer = null;

}

return readableTexture;

}