Skip to content

Commit 6326321

Browse files
Add exposure and tone mapping to the renderer and flat shaded material (#5029)
1 parent 79a91ab commit 6326321

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

docs/components/material.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ such as images or videos. Set `shader` to `flat`:
238238
| height | Height of video (in pixels), if defining a video texture. | 360 |
239239
| repeat | How many times a texture (defined by `src`) repeats in the X and Y direction. | 1 1 |
240240
| src | Image or video texture map. Can either be a selector to an `<img>` or `<video>`, or an inline URL. | None |
241+
| toneMapped | Whether to ignore toneMapping, set to false you are using renderer.toneMapping and an element should appear to emit light. | true |
241242
| width | Width of video (in pixels), if defining a video texture. | 640 |
242243
| wireframe | Whether to render just the geometry edges. | false |
243244
| wireframeLinewidth | Width in px of the rendered line. | 2 |

docs/components/renderer.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ It also configures presentation attributes when entering WebVR/WebXR.
3737
| maxCanvasWidth | Maximum canvas width. Uses the size multiplied by device pixel ratio. Does not limit canvas width if set to -1. | 1920 |
3838
| maxCanvasHeight | Maximum canvas height. Behaves the same as maxCanvasWidth. | 1920 |
3939
| logarithmicDepthBuffer | Whether to use a logarithmic depth buffer. | auto |
40-
| precision | Fragment shader [precision][precision] : low, medium or high. | high |
40+
| precision | Fragment shader [precision][precision] : low, medium or high. | high |
4141
| alpha | Whether the canvas should contain an alpha buffer. | true |
42+
| toneMapping | Type of toneMapping to use, one of: 'no', 'ACESFilmic', 'linear', 'reinhard', 'cineon' | 'no' |
43+
| exposure | When any toneMapping other than "no" is used this can be used to make the overall scene brighter or darker | 1 |
4244

43-
> **NOTE:** Once the scene is initialized, these properties may no longer be changed.
45+
> **NOTE:** Once the scene is initialized, none of these properties may no longer be changed apart from "exposure" and "toneMapping" which can be set dynamically.
4446
4547
### antialias
4648

src/shaders/flat.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports.Shader = registerShader('flat', {
1515
src: {type: 'map'},
1616
width: {default: 512},
1717
wireframe: {default: false},
18-
wireframeLinewidth: {default: 2}
18+
wireframeLinewidth: {default: 2},
19+
toneMapped: {default: true}
1920
},
2021

2122
/**
@@ -63,6 +64,7 @@ function getMaterialData (data, materialData) {
6364
materialData.color.set(data.color);
6465
materialData.fog = data.fog;
6566
materialData.wireframe = data.wireframe;
67+
materialData.toneMapped = data.toneMapped;
6668
materialData.wireframeLinewidth = data.wireframeLinewidth;
6769
return materialData;
6870
}

src/systems/renderer.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module.exports.System = registerSystem('renderer', {
1616
maxCanvasWidth: {default: 1920},
1717
maxCanvasHeight: {default: 1920},
1818
physicallyCorrectLights: {default: false},
19+
exposure: {default: 1, if: {toneMapping: ['ACESFilmic', 'linear', 'reinhard', 'cineon']}},
20+
toneMapping: {default: 'no', oneOf: ['no', 'ACESFilmic', 'linear', 'reinhard', 'cineon']},
1921
precision: {default: 'high', oneOf: ['high', 'medium', 'low']},
2022
sortObjects: {default: false},
2123
colorManagement: {default: false},
@@ -27,10 +29,12 @@ module.exports.System = registerSystem('renderer', {
2729
init: function () {
2830
var data = this.data;
2931
var sceneEl = this.el;
32+
var toneMappingName = this.data.toneMapping.charAt(0).toUpperCase() + this.data.toneMapping.slice(1);
3033
// This is the rendering engine, such as THREE.js so copy over any persistent properties from the rendering system.
3134
var renderer = sceneEl.renderer;
3235
renderer.sortObjects = data.sortObjects;
3336
renderer.physicallyCorrectLights = data.physicallyCorrectLights;
37+
renderer.toneMapping = THREE[toneMappingName + 'ToneMapping'];
3438

3539
if (data.colorManagement || data.gammaOutput) {
3640
renderer.outputEncoding = THREE.sRGBEncoding;
@@ -48,6 +52,15 @@ module.exports.System = registerSystem('renderer', {
4852
}
4953
},
5054

55+
update: function () {
56+
var data = this.data;
57+
var sceneEl = this.el;
58+
var renderer = sceneEl.renderer;
59+
var toneMappingName = this.data.toneMapping.charAt(0).toUpperCase() + this.data.toneMapping.slice(1);
60+
renderer.toneMapping = THREE[toneMappingName + 'ToneMapping'];
61+
renderer.toneMappingExposure = data.exposure;
62+
},
63+
5164
applyColorCorrection: function (colorOrTexture) {
5265
if (!this.data.colorManagement || !colorOrTexture) {
5366
return;

0 commit comments

Comments
 (0)