|
| 1 | +# ToneMapping |
| 2 | + |
| 3 | +<DocsDemo> |
| 4 | + <ToneMappingDemo /> |
| 5 | +</DocsDemo> |
| 6 | + |
| 7 | +The `ToneMapping` effect from the [`postprocessing`](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/ToneMappingEffect.js~ToneMappingEffect.html) package provides an abstraction for various tone mapping algorithms to improve the visual rendering of HDR (high dynamic range) content. Tone mapping is used to map high-range brightness values to a range that is displayable on standard screens. This effect contributes significantly to the visual quality of your scene by controlling luminance and color balance. |
| 8 | + |
| 9 | +::: info |
| 10 | +If the colors in your scene look incorrect after adding the EffectComposer, it might be because tone mapping is deactivated by default, which is normal behavior. Add `<ToneMappingPmndrs>` manually as an effect at the end of the `<EffectComposerPmndrs>` to fix this. |
| 11 | +::: |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +The `<ToneMappingPmndrs>` component is easy to set up and comes with multiple tone mapping modes to suit different visual requirements. Below is an example of how to use it in a Vue application. |
| 16 | + |
| 17 | +```vue{2,4,7-8,32-36} |
| 18 | +<script setup lang="ts"> |
| 19 | +import { EffectComposerPmndrs, ToneMappingPmndrs } from '@tresjs/post-processing/pmndrs' |
| 20 | +import { onUnmounted, shallowRef } from 'vue' |
| 21 | +import { ToneMappingMode } from 'postprocessing' |
| 22 | +
|
| 23 | +const gl = { |
| 24 | + toneMappingExposure: 1, |
| 25 | + toneMapping: NoToneMapping, |
| 26 | + multisampling: 8, |
| 27 | +} |
| 28 | +
|
| 29 | +const modelRef = shallowRef(null) |
| 30 | +
|
| 31 | +const { scene: model } = await useGLTF('https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/realistic-pokeball/scene.gltf', { draco: true }) |
| 32 | +
|
| 33 | +onUnmounted(() => { |
| 34 | + dispose(modelRef.value) |
| 35 | +}) |
| 36 | +</script> |
| 37 | +
|
| 38 | +<template> |
| 39 | + <TresCanvas |
| 40 | + v-bind="gl" |
| 41 | + > |
| 42 | + <TresPerspectiveCamera |
| 43 | + :position="[5, 5, 5]" |
| 44 | + :look-at="[0, 0, 0]" |
| 45 | + /> |
| 46 | +
|
| 47 | + <primitive ref="modelRef" :object="model" /> |
| 48 | +
|
| 49 | + <Suspense> |
| 50 | + <EffectComposerPmndrs> |
| 51 | + <ToneMappingPmndrs :mode="ToneMappingMode.AGX" /> |
| 52 | + </EffectComposerPmndrs> |
| 53 | + </Suspense> |
| 54 | + </TresCanvas> |
| 55 | +</template> |
| 56 | +``` |
| 57 | + |
| 58 | +## Props |
| 59 | + |
| 60 | +| Prop | Description | Default | |
| 61 | +| ----------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | |
| 62 | +| mode | Tone mapping mode used, defined by [`ToneMappingMode`](https://pmndrs.github.io/postprocessing/public/docs/variable/index.html#static-variable-ToneMappingMode). | `ToneMappingMode.AGX` | |
| 63 | +| blendFunction | Defines the [`BlendFunction`](https://pmndrs.github.io/postprocessing/public/docs/variable/index.html#static-variable-BlendFunction) used for the effect. | `BlendFunction.SRC` | |
| 64 | +| resolution | Resolution of the luminance texture (must be a power of two, e.g., 256, 512, etc.). | `256` | |
| 65 | +| averageLuminance | Average luminance value used in adaptive calculations. Only applicable to `ToneMappingMode.REINHARD2` | `1.0` | |
| 66 | +| middleGrey | Factor to adjust the balance of grey in luminance calculations. Only applicable to `ToneMappingMode.REINHARD2` | `0.6` | |
| 67 | +| minLuminance | Lower luminance limit, used to avoid overexposure effects in dark scenes. Only applicable to `ToneMappingMode.REINHARD2` | `0.01` | |
| 68 | +| whitePoint | White point for tone mapping, used to balance luminance values. Only applicable to `ToneMappingMode.REINHARD2` | `4.0` | |
| 69 | + |
| 70 | +## Further Reading |
| 71 | +For more details, see the [Tone Mapping documentation](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/ToneMappingEffect.js~ToneMappingEffect.html) |
0 commit comments