Skip to content

Commit

Permalink
Examples: Simplified webgl_loader_texture_hdrjpg example.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Mar 27, 2024
1 parent 66f7aa8 commit 156cb35
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 66 deletions.
Binary file not shown.
29 changes: 0 additions & 29 deletions examples/textures/gainmap/spruit_sunrise_4k.json

This file was deleted.

Binary file removed examples/textures/gainmap/spruit_sunrise_4k.webp
Binary file not shown.
47 changes: 10 additions & 37 deletions examples/webgl_loader_texture_hdrjpg.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';

import { GainMapLoader, HDRJPGLoader } from '@monogrid/gainmap-js';
import { HDRJPGLoader } from '@monogrid/gainmap-js';

const params = {
envMap: 'HDR JPG',
Expand All @@ -68,10 +68,9 @@
let camera, scene, renderer, controls;
let torusMesh, planeMesh;
let hdrJpg, hdrJpgPMREMRenderTarget, hdrJpgEquirectangularMap;
let gainMap, gainMapPMREMRenderTarget, gainMapBackground;
let hdrPMREMRenderTarget, hdrEquirectangularMap;


const fileSizes = {};
const resolutions = {};

Expand Down Expand Up @@ -127,14 +126,15 @@


hdrJpg = new HDRJPGLoader( renderer )
.load( 'textures/gainmap/spruit_sunrise_4k.jpg', function ( ) {
.load( 'textures/equirectangular/spruit_sunrise_4k.hdr.jpg', function ( ) {

resolutions[ 'HDR JPG' ] = hdrJpg.width + 'x' + hdrJpg.height;

displayStats( 'HDR JPG' );

hdrJpgEquirectangularMap = hdrJpg.renderTarget.texture;
hdrJpgPMREMRenderTarget = pmremGenerator.fromEquirectangular( hdrJpgEquirectangularMap );

hdrJpgEquirectangularMap.mapping = THREE.EquirectangularReflectionMapping;
hdrJpgEquirectangularMap.needsUpdate = true;

Expand All @@ -143,37 +143,14 @@
}, function ( progress ) {

fileSizes[ 'HDR JPG' ] = humanFileSize( progress.total );

} );

gainMap = new GainMapLoader( renderer )
.load( [
'textures/gainmap/spruit_sunrise_4k.webp',
'textures/gainmap/spruit_sunrise_4k-gainmap.webp',
'textures/gainmap/spruit_sunrise_4k.json'
], function ( ) {

resolutions[ 'Webp Gain map (separate)' ] = gainMap.width + 'x' + gainMap.height;

gainMapBackground = gainMap.renderTarget.texture;
gainMapPMREMRenderTarget = pmremGenerator.fromEquirectangular( gainMapBackground );

gainMapBackground.mapping = THREE.EquirectangularReflectionMapping;
gainMapBackground.needsUpdate = true;

gainMap.dispose();

}, function ( progress ) {

fileSizes[ 'Webp Gain map (separate)' ] = humanFileSize( progress.total );

} );

hdrEquirectangularMap = new RGBELoader()
.load( 'textures/gainmap/spruit_sunrise_1k.hdr', function ( ) {
.load( 'textures/equirectangular/spruit_sunrise_1k.hdr', function ( ) {

resolutions[ 'HDR' ] = hdrEquirectangularMap.image.width + 'x' + hdrEquirectangularMap.image.height;

hdrPMREMRenderTarget = pmremGenerator.fromEquirectangular( hdrEquirectangularMap );

hdrEquirectangularMap.mapping = THREE.EquirectangularReflectionMapping;
Expand Down Expand Up @@ -202,13 +179,13 @@

const gui = new GUI();

gui.add( params, 'envMap', [ 'HDR JPG', 'Webp Gain map (separate)', 'HDR' ] ).onChange( displayStats );
gui.add( params, 'envMap', [ 'HDR JPG', 'HDR' ] ).onChange( displayStats );
gui.add( params, 'roughness', 0, 1, 0.01 );
gui.add( params, 'metalness', 0, 1, 0.01 );
gui.add( params, 'exposure', 0, 2, 0.01 );
gui.add( params, 'debug' );
gui.open();

function displayStats( value ) {

lbl.innerHTML = value + ' size : ' + fileSizes[ value ] + ', Resolution: ' + resolutions[ value ];
Expand Down Expand Up @@ -281,10 +258,6 @@
pmremRenderTarget = hdrJpgPMREMRenderTarget;
equirectangularMap = hdrJpgEquirectangularMap;
break;
case 'Webp Gain map (separate)':
pmremRenderTarget = gainMapPMREMRenderTarget;
equirectangularMap = gainMapBackground;
break;
case 'HDR':
pmremRenderTarget = hdrPMREMRenderTarget;
equirectangularMap = hdrEquirectangularMap;
Expand Down

0 comments on commit 156cb35

Please sign in to comment.