Skip to content

Commit

Permalink
fix formatting for TextureUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Mar 27, 2023
1 parent fafd9ac commit 74223fa
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions examples/jsm/utils/TextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import {
Scene,
WebGLRenderer,
Texture,
sRGBEncoding
sRGBEncoding
} from 'three';

let temporaryRenderer;
let fullscreenQuadGeometry;
let fullscreenQuadMaterial;
let fullscreenQuad;

function decompress( texture, maxTextureSize, renderer ) {
export function decompress( texture, maxTextureSize, renderer ) {

if ( !fullscreenQuadGeometry ) fullscreenQuadGeometry = new PlaneGeometry( 2, 2, 1, 1 );
if ( !fullscreenQuadMaterial ) fullscreenQuadMaterial = new ShaderMaterial( {
uniforms: { blitTexture: new Uniform( texture ) },
vertexShader: `
if ( ! fullscreenQuadGeometry ) fullscreenQuadGeometry = new PlaneGeometry( 2, 2, 1, 1 );
if ( ! fullscreenQuadMaterial ) fullscreenQuadMaterial = new ShaderMaterial( {
uniforms: { blitTexture: new Uniform( texture ) },
vertexShader: `
varying vec2 vUv;
void main(){
vUv = uv;
gl_Position = vec4(position.xy * 1.0,0.,.999999);
}`,
fragmentShader: `
fragmentShader: `
uniform sampler2D blitTexture;
varying vec2 vUv;
Expand All @@ -44,42 +44,45 @@ function decompress( texture, maxTextureSize, renderer ) {
gl_FragColor = texture2D( blitTexture, vUv);
#endif
}`
} );
} );

fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
fullscreenQuadMaterial.defines.IS_SRGB = texture.encoding == sRGBEncoding;
fullscreenQuadMaterial.needsUpdate = true;
fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
fullscreenQuadMaterial.defines.IS_SRGB = texture.encoding == sRGBEncoding;
fullscreenQuadMaterial.needsUpdate = true;

if ( !fullscreenQuad ) {
if ( ! fullscreenQuad ) {

fullscreenQuad = new Mesh( fullscreenQuadGeometry, fullscreenQuadMaterial );
fullscreenQuad.frustrumCulled = false;
fullscreenQuad = new Mesh( fullscreenQuadGeometry, fullscreenQuadMaterial );
fullscreenQuad.frustrumCulled = false;

}
}

const temporaryCam = new PerspectiveCamera();
const temporaryScene = new Scene();
temporaryScene.add( fullscreenQuad );
const temporaryCam = new PerspectiveCamera();
const temporaryScene = new Scene();
temporaryScene.add( fullscreenQuad );

if ( !renderer ) {
if ( ! renderer ) {

if ( !temporaryRenderer )
temporaryRenderer = new WebGLRenderer( { antialias: false } );
if ( ! temporaryRenderer )
temporaryRenderer = new WebGLRenderer( { antialias: false } );

renderer = temporaryRenderer;
renderer = temporaryRenderer;

}
}

renderer.setSize( Math.min(texture.image.width, maxTextureSize), Math.min(texture.image.height, maxTextureSize) );
renderer.clear();
renderer.render( temporaryScene, temporaryCam );
renderer.setSize( Math.min( texture.image.width, maxTextureSize ), Math.min( texture.image.height, maxTextureSize ) );
renderer.clear();
renderer.render( temporaryScene, temporaryCam );

const readableTexture = new Texture( renderer.domElement );
readableTexture.userData.mimeType = 'image/png';
return readableTexture;
const readableTexture = new Texture( renderer.domElement );

}
readableTexture.minFilter = texture.minFilter;
readableTexture.magFilter = texture.magFilter;
readableTexture.wrapS = texture.wrapS;
readableTexture.wrapT = texture.wrapT;
readableTexture.name = texture.name;

readableTexture.userData.mimeType = 'image/png';
return readableTexture;

export {
decompress
}
}

0 comments on commit 74223fa

Please sign in to comment.