Skip to content

Commit

Permalink
r163 (#4738)
Browse files Browse the repository at this point in the history
* r163

* switch to built-in neutral tone mapping
  • Loading branch information
elalish committed Apr 4, 2024
1 parent 501f4e2 commit 99b50ff
Show file tree
Hide file tree
Showing 9 changed files with 1,012 additions and 854 deletions.
1,798 changes: 989 additions & 809 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/model-viewer-effects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ npm install three @google/model-viewer @google/model-viewer-effects
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@^0.160.0/build/three.module.min.js"
"three": "https://cdn.jsdelivr.net/npm/three@^0.163.0/build/three.module.min.js"
}
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions packages/model-viewer-effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/pngjs": "^6.0.1",
"@types/three": "^0.160.0",
"@types/three": "^0.163.0",
"@ungap/event-target": "^0.2.3",
"@web/test-runner": "^0.16.1",
"@web/test-runner-playwright": "^0.10.0",
Expand All @@ -100,10 +100,10 @@
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-polyfill": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"three": "^0.160.0",
"three": "^0.163.0",
"typescript": "4.8.4"
},
"publishConfig": {
"access": "public"
}
}
}
8 changes: 4 additions & 4 deletions packages/model-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@monogrid/gainmap-js": "^3.0.1"
},
"peerDependencies": {
"three": "^0.160.0"
"three": "^0.163.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.1",
Expand All @@ -96,7 +96,7 @@
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/pngjs": "^6.0.1",
"@types/three": "^0.160.0",
"@types/three": "^0.163.0",
"@ungap/event-target": "^0.2.3",
"@web/test-runner": "^0.16.1",
"@web/test-runner-playwright": "^0.10.0",
Expand All @@ -110,9 +110,9 @@
"rollup-plugin-polyfill": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "4.8.4",
"three": "^0.160.0"
"three": "^0.163.0"
},
"publishConfig": {
"access": "public"
}
}
}
12 changes: 7 additions & 5 deletions packages/model-viewer/src/features/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import {property} from 'lit/decorators.js';
import {ACESFilmicToneMapping, AgXToneMapping, CustomToneMapping, Texture} from 'three';
import {ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping, Texture} from 'three';

import ModelViewerElementBase, {$needsRender, $progressTracker, $renderer, $scene, $shouldAttemptPreload} from '../model-viewer-base.js';
import {clamp, Constructor, deserializeUrl} from '../utilities.js';
Expand All @@ -24,7 +24,7 @@ const DEFAULT_SHADOW_INTENSITY = 0.0;
const DEFAULT_SHADOW_SOFTNESS = 1.0;
const DEFAULT_EXPOSURE = 1.0;

export type ToneMappingValue = 'auto'|'aces'|'agx'|'commerce';
export type ToneMappingValue = 'auto'|'aces'|'agx'|'commerce'|'neutral';

export const $currentEnvironmentMap = Symbol('currentEnvironmentMap');
export const $currentBackground = Symbol('currentBackground');
Expand Down Expand Up @@ -88,8 +88,9 @@ export const EnvironmentMixin = <T extends Constructor<ModelViewerElementBase>>(
}

if (changedProperties.has('toneMapping')) {
this[$scene].toneMapping = this.toneMapping === 'commerce' ?
CustomToneMapping :
this[$scene].toneMapping = (this.toneMapping === 'commerce' ||
this.toneMapping === 'neutral') ?
NeutralToneMapping :
this.toneMapping === 'agx' ? AgXToneMapping :
ACESFilmicToneMapping;
this[$needsRender]();
Expand Down Expand Up @@ -125,7 +126,8 @@ export const EnvironmentMixin = <T extends Constructor<ModelViewerElementBase>>(
return;
}

const updateEnvProgress = this[$progressTracker].beginActivity('environment-update');
const updateEnvProgress =
this[$progressTracker].beginActivity('environment-update');

try {
const {environmentMap, skybox} =
Expand Down
28 changes: 2 additions & 26 deletions packages/model-viewer/src/three-components/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {ACESFilmicToneMapping, CustomToneMapping, Event, EventDispatcher, ShaderChunk, Vector2, WebGLRenderer} from 'three';
import {ACESFilmicToneMapping, Event, EventDispatcher, NeutralToneMapping, Vector2, WebGLRenderer} from 'three';

import {$updateEnvironment} from '../features/environment.js';
import {ModelViewerGlobalConfig} from '../features/loading.js';
Expand Down Expand Up @@ -137,30 +137,6 @@ export class Renderer extends
this.canvas3D.id = 'webgl-canvas';
this.canvas3D.classList.add('show');

// Emmett's new 3D Commerce tone mapping function
ShaderChunk.tonemapping_pars_fragment =
ShaderChunk.tonemapping_pars_fragment.replace(
'vec3 CustomToneMapping( vec3 color ) { return color; }', `
float startCompression = 0.8 - 0.04;
float desaturation = 0.15;
vec3 CustomToneMapping( vec3 color ) {
color *= toneMappingExposure;
float x = min(color.r, min(color.g, color.b));
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
color -= offset;
float peak = max(color.r, max(color.g, color.b));
if (peak < startCompression) return color;
float d = 1. - startCompression;
float newPeak = 1. - d * d / (peak + d - startCompression);
color *= newPeak / peak;
float g = 1. - 1. / (desaturation * (peak - newPeak) + 1.);
return mix(color, newPeak * vec3(1, 1, 1), g);
}`);

try {
this.threeRenderer = new WebGLRenderer({
canvas: this.canvas3D,
Expand Down Expand Up @@ -436,7 +412,7 @@ export class Renderer extends
typeof exposure === 'number' && !Number.isNaN(exposure);
const env = element.environmentImage;
const sky = element.skyboxImage;
const compensateExposure = toneMapping === CustomToneMapping &&
const compensateExposure = toneMapping === NeutralToneMapping &&
(env === 'neutral' || env === 'legacy' || (!env && !sky));
this.threeRenderer.toneMappingExposure =
(exposureIsNumber ? exposure : 1.0) *
Expand Down
4 changes: 2 additions & 2 deletions packages/model-viewer/src/three-components/Shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import {BackSide, Box3, Material, Mesh, MeshBasicMaterial, MeshDepthMaterial, Object3D, OrthographicCamera, PlaneGeometry, RGBAFormat, Scene, ShaderMaterial, Vector3, WebGLRenderer, WebGLRenderTarget, WebGLRenderTargetOptions} from 'three';
import {BackSide, Box3, Material, Mesh, MeshBasicMaterial, MeshDepthMaterial, Object3D, OrthographicCamera, PlaneGeometry, RenderTargetOptions, RGBAFormat, Scene, ShaderMaterial, Vector3, WebGLRenderer, WebGLRenderTarget} from 'three';
import {HorizontalBlurShader} from 'three/examples/jsm/shaders/HorizontalBlurShader.js';
import {VerticalBlurShader} from 'three/examples/jsm/shaders/VerticalBlurShader.js';
import {lerp} from 'three/src/math/MathUtils.js';
Expand Down Expand Up @@ -220,7 +220,7 @@ export class Shadow extends Object3D {
}

if (this.renderTarget == null) {
const params: WebGLRenderTargetOptions = {format: RGBAFormat};
const params: RenderTargetOptions = {format: RGBAFormat};
this.renderTarget = new WebGLRenderTarget(width, height, params);
this.renderTargetBlur = new WebGLRenderTarget(width, height, params);

Expand Down
4 changes: 2 additions & 2 deletions packages/modelviewer.dev/examples/postprocessing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@^0.160.0/build/three.module.min.js"
"three": "https://cdn.jsdelivr.net/npm/three@^0.163.0/build/three.module.min.js"
}
}
</script>
Expand Down Expand Up @@ -104,7 +104,7 @@ <h2 class="demo-title">Setup Post Processing</h2>
<script type="importmap-noexecute">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@^0.160.0/build/three.module.min.js"
"three": "https://cdn.jsdelivr.net/npm/three@^0.163.0/build/three.module.min.js"
}
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/render-fidelity-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
"@types/pngjs": "^3.4.0",
"@types/puppeteer": "^5.4.6",
"@types/rimraf": "^3.0.1",
"@types/three": "^0.160.0",
"@types/three": "^0.163.0",
"filament": "1.44.0",
"http-server": "^14.1.1",
"lit": "^2.7.2",
"mkdirp": "^1.0.4",
"pngjs": "^6.0.0",
"puppeteer": "^21.3.4",
"rimraf": "^3.0.2",
"three": "^0.160.0",
"three": "^0.163.0",
"three-gpu-pathtracer": "^0.0.20",
"three-mesh-bvh": "^0.7.3",
"yargs": "^17.7.2"
Expand Down

0 comments on commit 99b50ff

Please sign in to comment.