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
71 changes: 40 additions & 31 deletions examples/js/loaders/EquiangularToCubeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
* @author Richard M. / https://github.com/richardmonette
*/

THREE.EquiangularToCubeGenerator = function( sourceTexture, resolution ) {
THREE.EquiangularToCubeGenerator = function ( sourceTexture, resolution ) {

this.sourceTexture = sourceTexture;
this.resolution = resolution;

this.views = [
{ t: [1.0, 0.0, 0.0 ], u: [0.0, -1.0, 0.0] },
{ t: [-1.0, 0.0, 0.0], u: [0.0, -1.0, 0.0] },
{ t: [0.0, 1.0, 0.0], u: [0.0, 0.0, 1.0] },
{ t: [0.0, -1.0, 0.0], u: [0.0, 0.0, -1.0] },
{ t: [0.0, 0.0, 1.0], u: [0.0, -1.0, 0.0] },
{ t: [0.0, 0.0, -1.0], u: [0.0, -1.0, 0.0] },
{ t: [ 1, 0, 0 ], u: [ 0, - 1, 0 ] },
{ t: [ - 1, 0, 0 ], u: [ 0, - 1, 0 ] },
{ t: [ 0, 1, 0 ], u: [ 0, 0, 1 ] },
{ t: [ 0, - 1, 0 ], u: [ 0, 0, - 1 ] },
{ t: [ 0, 0, 1 ], u: [ 0, - 1, 0 ] },
{ t: [ 0, 0, - 1 ], u: [ 0, - 1, 0 ] },
];

this.camera = new THREE.PerspectiveCamera( 90, 1, 0.1, 10 );
Expand All @@ -22,49 +22,47 @@ THREE.EquiangularToCubeGenerator = function( sourceTexture, resolution ) {
this.scene = new THREE.Scene();
this.scene.add( this.boxMesh );

};
var params = {
format: THREE.RGBAFormat,
magFilter: this.sourceTexture.magFilter,
minFilter: this.sourceTexture.minFilter,
type: this.sourceTexture.type,
generateMipmaps: this.sourceTexture.generateMipmaps,
anisotropy: this.sourceTexture.anisotropy,
encoding: this.sourceTexture.encoding
};

THREE.EquiangularToCubeGenerator.prototype = {
this.renderTarget = new THREE.WebGLRenderTargetCube( this.resolution, this.resolution, params );

constructor : THREE.EquiangularToCubeGenerator,
};

generate: function( renderer ) {
THREE.EquiangularToCubeGenerator.prototype = {

var params = {
format: THREE.RGBAFormat,
magFilter: this.sourceTexture.magFilter,
minFilter: this.sourceTexture.minFilter,
type: this.sourceTexture.type,
generateMipmaps: this.sourceTexture.generateMipmaps,
anisotropy: this.sourceTexture.anisotropy,
encoding: this.sourceTexture.encoding
};
constructor: THREE.EquiangularToCubeGenerator,

var renderTarget = new THREE.WebGLRenderTargetCube( this.resolution, this.resolution, params );
update: function ( renderer ) {

for ( var i = 0; i < 6; i++ ) {
for ( var i = 0; i < 6; i ++ ) {

renderTarget.activeCubeFace = i;
this.renderTarget.activeCubeFace = i;

var v = this.views[i];
var v = this.views[ i ];

this.camera.position.set( 0, 0, 0 );
this.camera.up.set( v.u[ 0 ], v.u[ 1 ], v.u[ 2 ] );
this.camera.lookAt( v.t[ 0 ], v.t[ 1 ], v.t[ 2 ] );

this.camera.updateProjectionMatrix();

renderer.render( this.scene, this.camera, renderTarget, true );
renderer.render( this.scene, this.camera, this.renderTarget, true );

}

return renderTarget.texture;
return this.renderTarget.texture;

},

getShader: function() {
getShader: function () {

return new THREE.ShaderMaterial( {
var shaderMaterial = new THREE.ShaderMaterial( {

uniforms: {
"equirectangularMap": { value: this.sourceTexture },
Expand Down Expand Up @@ -107,7 +105,18 @@ THREE.EquiangularToCubeGenerator.prototype = {

} );

shaderMaterial.type = 'EquiangularToCubeGenerator';

return shaderMaterial;

},

dispose: function () {

this.boxMesh.geometry.dispose();
this.boxMesh.material.dispose();
this.renderTarget.dispose();

}

};

17 changes: 15 additions & 2 deletions examples/js/pmrem/PMREMCubeUVPacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
* The arrangement of the faces is fixed, as assuming this arrangement, the sampling function has been written.
*/

THREE.PMREMCubeUVPacker = function ( cubeTextureLods, numLods ) {
THREE.PMREMCubeUVPacker = function ( cubeTextureLods ) {

this.cubeLods = cubeTextureLods;
this.numLods = numLods;
var size = cubeTextureLods[ 0 ].width * 4;

var sourceTexture = cubeTextureLods[ 0 ].texture;
Expand Down Expand Up @@ -189,8 +188,22 @@ THREE.PMREMCubeUVPacker.prototype = {

} );

shaderMaterial.type = 'PMREMCubeUVPacker';

return shaderMaterial;

},

dispose: function () {

for ( var i = 0, l = this.objects.length; i < l; i ++ ) {

this.objects[ i ].material.dispose();

}

this.objects[ 0 ].geometry.dispose();

}

};
19 changes: 18 additions & 1 deletion examples/js/pmrem/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ THREE.PMREMGenerator.prototype = {

getShader: function () {

return new THREE.ShaderMaterial( {
var shaderMaterial = new THREE.ShaderMaterial( {

defines: {
"SAMPLES_PER_LEVEL": 20,
Expand Down Expand Up @@ -269,6 +269,23 @@ THREE.PMREMGenerator.prototype = {

} );

shaderMaterial.type = 'PMREMGenerator';

return shaderMaterial;

},

dispose: function () {

for ( var i = 0, l = this.cubeLods.length; i < l; i ++ ) {

this.cubeLods[ i ].dispose();

}

this.planeMesh.geometry.dispose();
this.planeMesh.material.dispose();

}

};
16 changes: 13 additions & 3 deletions examples/webgl_materials_envmaps_exr.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
document.body.appendChild( container );

camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0.0, 0, 120 );
camera.position.set( 0, 0, 120 );

scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
Expand Down Expand Up @@ -107,7 +107,7 @@
texture.encoding = THREE.LinearEncoding;

var cubemapGenerator = new THREE.EquiangularToCubeGenerator( texture, 512 );
var cubeMapTexture = cubemapGenerator.generate( renderer );
var cubeMapTexture = cubemapGenerator.update( renderer );

var pmremGenerator = new THREE.PMREMGenerator( cubeMapTexture );
pmremGenerator.update( renderer );
Expand All @@ -117,14 +117,19 @@

exrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;

texture.dispose();
cubemapGenerator.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();

} );

new THREE.TextureLoader().load( 'textures/equiangular.png', function ( texture ) {

texture.encoding = THREE.sRGBEncoding;

var cubemapGenerator = new THREE.EquiangularToCubeGenerator( texture, 512 );
var cubeMapTexture = cubemapGenerator.generate( renderer );
var cubeMapTexture = cubemapGenerator.update( renderer );

var pmremGenerator = new THREE.PMREMGenerator( cubeMapTexture );
pmremGenerator.update( renderer );
Expand All @@ -134,6 +139,11 @@

pngCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;

texture.dispose();
cubemapGenerator.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();

} );

renderer.setPixelRatio( window.devicePixelRatio );
Expand Down
15 changes: 13 additions & 2 deletions examples/webgl_materials_envmaps_hdr.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
document.body.appendChild( container );

camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 0.0, 0, 120 );
camera.position.set( 0, 0, 120 );

scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
Expand All @@ -77,7 +77,6 @@
renderer.toneMapping = THREE.LinearToneMapping;

standardMaterial = new THREE.MeshStandardMaterial( {
map: null,
color: 0xffffff,
metalness: params.metalness,
roughness: params.roughness
Expand Down Expand Up @@ -119,6 +118,10 @@

hdrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;

hdrCubeMap.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();

} );

var ldrUrls = genCubeUrls( './textures/cube/pisa/', '.png' );
Expand All @@ -134,6 +137,10 @@

ldrCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;

ldrCubeMap.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();

} );


Expand All @@ -150,6 +157,10 @@

rgbmCubeRenderTarget = pmremCubeUVPacker.CubeUVRenderTarget;

rgbmCubeMap.dispose();
pmremGenerator.dispose();
pmremCubeUVPacker.dispose();

} );

renderer.setPixelRatio( window.devicePixelRatio );
Expand Down