Skip to content

ToneMapping

The ToneMapping effect from the postprocessing 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.

INFO

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.

Usage

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.

vue
<script setup lang="ts">
import { EffectComposerPmndrs, ToneMappingPmndrs } from '@tresjs/post-processing/pmndrs'
import { onUnmounted, shallowRef } from 'vue'
import { ToneMappingMode } from 'postprocessing'

const gl = {
  toneMappingExposure: 1,
  toneMapping: NoToneMapping,
  multisampling: 8,
}

const modelRef = shallowRef(null)

const { scene: model } = await useGLTF('https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/realistic-pokeball/scene.gltf', { draco: true })

onUnmounted(() => {
  dispose(modelRef.value)
})
</script>

<template>
  <TresCanvas
    v-bind="gl"
  >
    <TresPerspectiveCamera
      :position="[5, 5, 5]"
      :look-at="[0, 0, 0]"
    />

    <primitive ref="modelRef" :object="model" />

    <Suspense>
      <EffectComposerPmndrs>
        <ToneMappingPmndrs :mode="ToneMappingMode.AGX" />
      </EffectComposerPmndrs>
    </Suspense>
  </TresCanvas>
</template>

Props

PropDescriptionDefault
modeTone mapping mode used, defined by ToneMappingMode.ToneMappingMode.AGX
blendFunctionDefines the BlendFunction used for the effect.BlendFunction.SRC
resolutionResolution of the luminance texture (must be a power of two, e.g., 256, 512, etc.).256
averageLuminanceAverage luminance value used in adaptive calculations. Only applicable to ToneMappingMode.REINHARD21.0
middleGreyFactor to adjust the balance of grey in luminance calculations. Only applicable to ToneMappingMode.REINHARD20.6
minLuminanceLower luminance limit, used to avoid overexposure effects in dark scenes. Only applicable to ToneMappingMode.REINHARD20.01
whitePointWhite point for tone mapping, used to balance luminance values. Only applicable to ToneMappingMode.REINHARD24.0

Further Reading

For more details, see the Tone Mapping documentation