Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/components/material.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ such as images or videos. Set `shader` to `flat`:
| height | Height of video (in pixels), if defining a video texture. | 360 |
| repeat | How many times a texture (defined by `src`) repeats in the X and Y direction. | 1 1 |
| src | Image or video texture map. Can either be a selector to an `<img>` or `<video>`, or an inline URL. | None |
| toneMapped | Whether to ignore toneMapping, set to false you are using renderer.toneMapping and an element should appear to emit light. | true |
| width | Width of video (in pixels), if defining a video texture. | 640 |
| wireframe | Whether to render just the geometry edges. | false |
| wireframeLinewidth | Width in px of the rendered line. | 2 |
Expand Down
6 changes: 4 additions & 2 deletions docs/components/renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ It also configures presentation attributes when entering WebVR/WebXR.
| maxCanvasWidth | Maximum canvas width. Uses the size multiplied by device pixel ratio. Does not limit canvas width if set to -1. | 1920 |
| maxCanvasHeight | Maximum canvas height. Behaves the same as maxCanvasWidth. | 1920 |
| logarithmicDepthBuffer | Whether to use a logarithmic depth buffer. | auto |
| precision | Fragment shader [precision][precision] : low, medium or high. | high |
| precision | Fragment shader [precision][precision] : low, medium or high. | high |
| alpha | Whether the canvas should contain an alpha buffer. | true |
| toneMapping | Type of toneMapping to use, one of: 'no', 'ACESFilmic', 'linear', 'reinhard', 'cineon' | 'no' |
| exposure | When any toneMapping other than "no" is used this can be used to make the overall scene brighter or darker | 1 |

> **NOTE:** Once the scene is initialized, these properties may no longer be changed.
> **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.

### antialias

Expand Down
4 changes: 3 additions & 1 deletion src/shaders/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports.Shader = registerShader('flat', {
src: {type: 'map'},
width: {default: 512},
wireframe: {default: false},
wireframeLinewidth: {default: 2}
wireframeLinewidth: {default: 2},
toneMapped: {default: true}
},

/**
Expand Down Expand Up @@ -63,6 +64,7 @@ function getMaterialData (data, materialData) {
materialData.color.set(data.color);
materialData.fog = data.fog;
materialData.wireframe = data.wireframe;
materialData.toneMapped = data.toneMapped;
materialData.wireframeLinewidth = data.wireframeLinewidth;
return materialData;
}
13 changes: 13 additions & 0 deletions src/systems/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports.System = registerSystem('renderer', {
maxCanvasWidth: {default: 1920},
maxCanvasHeight: {default: 1920},
physicallyCorrectLights: {default: false},
exposure: {default: 1, if: {toneMapping: ['ACESFilmic', 'linear', 'reinhard', 'cineon']}},
toneMapping: {default: 'no', oneOf: ['no', 'ACESFilmic', 'linear', 'reinhard', 'cineon']},
precision: {default: 'high', oneOf: ['high', 'medium', 'low']},
sortObjects: {default: false},
colorManagement: {default: false},
Expand All @@ -27,10 +29,12 @@ module.exports.System = registerSystem('renderer', {
init: function () {
var data = this.data;
var sceneEl = this.el;
var toneMappingName = this.data.toneMapping.charAt(0).toUpperCase() + this.data.toneMapping.slice(1);
// This is the rendering engine, such as THREE.js so copy over any persistent properties from the rendering system.
var renderer = sceneEl.renderer;
renderer.sortObjects = data.sortObjects;
renderer.physicallyCorrectLights = data.physicallyCorrectLights;
renderer.toneMapping = THREE[toneMappingName + 'ToneMapping'];

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

update: function () {
var data = this.data;
var sceneEl = this.el;
var renderer = sceneEl.renderer;
var toneMappingName = this.data.toneMapping.charAt(0).toUpperCase() + this.data.toneMapping.slice(1);
renderer.toneMapping = THREE[toneMappingName + 'ToneMapping'];
renderer.toneMappingExposure = data.exposure;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no experience with exposure or tone mapping so this might be dumb. Are there use cases for different values of tone mapping and exposure? Should we always match them automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tone toneMapping option is a list of functions that act on the colour of each pixel according to the exposure value specified.

The different functions each have a slightly different aesthetic.

You control the exposure for when the user moves into a bright environment you lower it to make the dark areas darker and make the outside less blinding bright.

Usually it's just used to control the lighting on a global level to get the right feeling for the environment the developer is building.

},

applyColorCorrection: function (colorOrTexture) {
if (!this.data.colorManagement || !colorOrTexture) {
return;
Expand Down