Skip to content

Commit

Permalink
Web viewer HDRI improvements
Browse files Browse the repository at this point in the history
- Load HDR images in half-float format, improving render performance and browser compatibility.
- Clarify HDR image names.
  • Loading branch information
jstone-lucasfilm committed Dec 17, 2023
1 parent 20022bc commit 1ef4619
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions javascript/MaterialXView/source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ function init()
const hdrLoader = viewer.getHdrLoader();
const fileLoader = viewer.getFileLoader();
Promise.all([
new Promise(resolve => hdrLoader.setDataType(THREE.FloatType).load('Lights/san_giuseppe_bridge_split.hdr', resolve)),
new Promise(resolve => hdrLoader.load('Lights/san_giuseppe_bridge_split.hdr', resolve)),
new Promise(resolve => hdrLoader.load('Lights/irradiance/san_giuseppe_bridge_split.hdr', resolve)),
new Promise(resolve => fileLoader.load('Lights/san_giuseppe_bridge_split.mtlx', resolve)),
new Promise(resolve => hdrLoader.setDataType(THREE.FloatType).load('Lights/irradiance/san_giuseppe_bridge_split.hdr', resolve)),
new Promise(function (resolve) {
MaterialX().then((module) => {
resolve(module);
});
})
]).then(async ([loadedRadianceTexture, loadedLightSetup, loadedIrradianceTexture, mxIn]) =>
]).then(async ([radianceTexture, irradianceTexture, lightRigXml, mxIn]) =>
{
// Initialize viewer + lighting
await viewer.initialize(mxIn, renderer, loadedRadianceTexture, loadedLightSetup, loadedIrradianceTexture);
await viewer.initialize(mxIn, renderer, radianceTexture, irradianceTexture, lightRigXml);

// Load geometry
let scene = viewer.getScene();
Expand Down
16 changes: 8 additions & 8 deletions javascript/MaterialXView/source/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ export class Viewer
// Create shader generator, generation context and "base" document which
// contains the standard definition libraries and lighting elements.
//
async initialize(mtlxIn, renderer, loadedRadianceTexture, loadedLightSetup, loadedIrradianceTexture)
async initialize(mtlxIn, renderer, radianceTexture, irradianceTexture, lightRigXml)
{
this.mx = mtlxIn;

Expand All @@ -1047,30 +1047,30 @@ export class Viewer
this.stdlib = this.mx.loadStandardLibraries(this.genContext);
this.document.importLibrary(this.stdlib);

this.initializeLighting(renderer, loadedRadianceTexture, loadedLightSetup, loadedIrradianceTexture);
this.initializeLighting(renderer, radianceTexture, irradianceTexture, lightRigXml);

loadedRadianceTexture.mapping = THREE.EquirectangularReflectionMapping;
this.getScene().setBackgroundTexture(loadedRadianceTexture);
radianceTexture.mapping = THREE.EquirectangularReflectionMapping;
this.getScene().setBackgroundTexture(radianceTexture);
}

//
// Load in lighting rig document and register lights with generation context
// Initialize environment lighting (IBLs).
//
async initializeLighting(renderer, loadedRadianceTexture, loadedLightSetup, loadedIrradianceTexture)
async initializeLighting(renderer, radianceTexture, irradianceTexture, lightRigXml)
{
// Load lighting setup into document
const mx = this.getMx();
this.lightRigDoc = mx.createDocument();
await mx.readFromXmlString(this.lightRigDoc, loadedLightSetup);
await mx.readFromXmlString(this.lightRigDoc, lightRigXml);
this.document.importLibrary(this.lightRigDoc);

// Register lights with generation context
this.lights = findLights(this.document);
this.lightData = registerLights(mx, this.lights, this.genContext);

this.radianceTexture = prepareEnvTexture(loadedRadianceTexture, renderer.capabilities);
this.irradianceTexture = prepareEnvTexture(loadedIrradianceTexture, renderer.capabilities);
this.radianceTexture = prepareEnvTexture(radianceTexture, renderer.capabilities);
this.irradianceTexture = prepareEnvTexture(irradianceTexture, renderer.capabilities);
}

getEditor() {
Expand Down

0 comments on commit 1ef4619

Please sign in to comment.