Skip to content

Commit e8af82a

Browse files
Upgrade three.js from r152 to r183
This changelist upgrades the three.js dependency in the MaterialX Web Viewer from r152 to r183, adapting to API changes across the intervening releases. A new `hwEmitVersionDirective` option has been added to GenOptions, allowing the Web Viewer to skip the `#version` directive in generated shaders, as three.js now manages this detail on its own.
1 parent b05f0b3 commit e8af82a

12 files changed

Lines changed: 54 additions & 26 deletions

File tree

javascript/MaterialXView/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13+
"fflate": "^0.8.2",
1314
"lil-gui": "^0.19.2",
14-
"three": "^0.152.2"
15+
"three": "^0.183.0"
1516
},
1617
"devDependencies": {
1718
"copy-webpack-plugin": "^14.0.0",

javascript/MaterialXView/source/dropHandling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as THREE from 'three';
2-
import * as fflate from 'three/examples/jsm/libs/fflate.module.js';
2+
import * as fflate from 'fflate';
33

44
const debugFileHandling = false;
55
let loadingCallback = null;

javascript/MaterialXView/source/helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ function getWrapping(mode)
212212
*/
213213
function getMinFilter(type, generateMipmaps)
214214
{
215-
const filterType = generateMipmaps ? THREE.LinearMipMapLinearFilter : THREE.LinearFilter;
215+
let filterType = generateMipmaps ? THREE.LinearMipmapLinearFilter : THREE.LinearFilter;
216216
if (type === 0)
217217
{
218-
filterType = generateMipmaps ? THREE.NearestMipMapNearestFilter : THREE.NearestFilter;
218+
filterType = generateMipmaps ? THREE.NearestMipmapNearestFilter : THREE.NearestFilter;
219219
}
220220
return filterType;
221221
}

javascript/MaterialXView/source/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function init()
9797
// Set up renderer
9898
renderer = new THREE.WebGLRenderer({ antialias: true, canvas });
9999
renderer.setSize(window.innerWidth, window.innerHeight);
100+
renderer.outputColorSpace = THREE.SRGBColorSpace;
100101
renderer.debug.checkShaderErrors = false;
101102

102103
window.addEventListener('resize', onWindowResize);

javascript/MaterialXView/source/viewer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//
55

66
import * as THREE from 'three';
7-
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
8-
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
7+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
8+
import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
99

1010
import { prepareEnvTexture, getLightRotation, findLights, registerLights, getUniformValues } from './helper.js'
1111
import { Group } from 'three';
@@ -36,7 +36,6 @@ export class Scene
3636
{
3737
this._scene = new THREE.Scene();
3838
this._scene.background = new THREE.Color(this.#_backgroundColor);
39-
this._scene.background.convertSRGBToLinear();
4039

4140
const aspectRatio = window.innerWidth / window.innerHeight;
4241
const cameraNearDist = 0.05;
@@ -416,7 +415,6 @@ export class Scene
416415
return this.#_backgroundTexture;
417416
}
418417
var color = new THREE.Color(this.#_backgroundColor);
419-
color.convertSRGBToLinear();
420418
return color;
421419
}
422420

@@ -964,6 +962,7 @@ export class Material
964962
uniforms: uniforms,
965963
vertexShader: vShader,
966964
fragmentShader: fShader,
965+
glslVersion: THREE.GLSL3,
967966
transparent: isTransparent,
968967
blendEquation: THREE.AddEquation,
969968
blendSrc: THREE.OneMinusSrcAlphaFactor,
@@ -1526,7 +1525,7 @@ export class Viewer
15261525
this.materials.push(new Material());
15271526

15281527
this.fileLoader = new THREE.FileLoader();
1529-
this.hdrLoader = new RGBELoader();
1528+
this.hdrLoader = new HDRLoader();
15301529
}
15311530

15321531
//
@@ -1540,6 +1539,7 @@ export class Viewer
15401539
// Initialize base document
15411540
this.generator = this.mx.EsslShaderGenerator.create();
15421541
this.genContext = new this.mx.GenContext(this.generator);
1542+
this.genContext.getOptions().hwEmitVersionDirective = false;
15431543

15441544
this.document = this.mx.createDocument();
15451545
this.stdlib = this.mx.loadStandardLibraries(this.genContext);

javascript/package-lock.json

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/JsMaterialX/JsMaterialXGenShader/JsGenOptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ EMSCRIPTEN_BINDINGS(GenOptions)
5252
.property("hwWriteAlbedoTable", &mx::GenOptions::hwWriteAlbedoTable)
5353
.property("hwWriteEnvPrefilter", &mx::GenOptions::hwWriteEnvPrefilter)
5454
.property("hwImplicitBitangents", &mx::GenOptions::hwImplicitBitangents)
55+
.property("hwEmitVersionDirective", &mx::GenOptions::hwEmitVersionDirective)
5556
;
5657
}

source/MaterialXGenGlsl/EsslShaderGenerator.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ EsslShaderGenerator::EsslShaderGenerator(TypeSystemPtr typeSystem) :
2323
_syntax->registerReservedWords(reservedWords);
2424
}
2525

26-
void EsslShaderGenerator::emitDirectives(GenContext&, ShaderStage& stage) const
26+
void EsslShaderGenerator::emitDirectives(GenContext& context, ShaderStage& stage) const
2727
{
28-
emitLine("#version " + getVersion(), stage, false);
29-
emitLineBreak(stage);
28+
if (context.getOptions().hwEmitVersionDirective)
29+
{
30+
emitLine("#version " + getVersion(), stage, false);
31+
emitLineBreak(stage);
32+
}
33+
3034
// ESSL 3.0+ is used where highp float is considered mandatory.
3135
// (See https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)
3236
emitLine("precision highp float", stage);

source/MaterialXGenGlsl/GlslShaderGenerator.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,13 @@ void GlslShaderGenerator::emitTransmissionRender(GenContext& context, ShaderStag
243243
emitLineBreak(stage);
244244
}
245245

246-
void GlslShaderGenerator::emitDirectives(GenContext&, ShaderStage& stage) const
246+
void GlslShaderGenerator::emitDirectives(GenContext& context, ShaderStage& stage) const
247247
{
248-
emitLine("#version " + getVersion(), stage, false);
249-
emitLineBreak(stage);
248+
if (context.getOptions().hwEmitVersionDirective)
249+
{
250+
emitLine("#version " + getVersion(), stage, false);
251+
emitLineBreak(stage);
252+
}
250253
}
251254

252255
void GlslShaderGenerator::emitConstants(GenContext& context, ShaderStage& stage) const

source/MaterialXGenGlsl/VkShaderGenerator.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ VkShaderGenerator::VkShaderGenerator(TypeSystemPtr typeSystem) :
2424
_resourceBindingCtx = std::make_shared<MaterialX::VkResourceBindingContext>(0);
2525
}
2626

27-
void VkShaderGenerator::emitDirectives(GenContext&, ShaderStage& stage) const
27+
void VkShaderGenerator::emitDirectives(GenContext& context, ShaderStage& stage) const
2828
{
29-
emitLine("#version " + getVersion(), stage, false);
30-
emitLineBreak(stage);
29+
if (context.getOptions().hwEmitVersionDirective)
30+
{
31+
emitLine("#version " + getVersion(), stage, false);
32+
emitLineBreak(stage);
33+
}
3134
}
3235

3336
void VkShaderGenerator::emitInputs(GenContext& context, ShaderStage& stage) const

0 commit comments

Comments
 (0)