Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tonemapping effect #148

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

damienmontastier
Copy link

This component introduces the ToneMapping effect, which provides an abstraction for various tone mapping algorithms from the pmndrs/postprocessing package. The <ToneMapping> effect is specifically designed to improve the visual rendering of HDR content by mapping high-range brightness values to a displayable range, thus enhancing luminance and color balance in the scene.

  • Fixes potential issues with incorrect colors when EffectComposer is added by applying tone mapping manually as an effect.
  • Easy to set up — simply include it in your <EffectComposer> pipeline.
  • Multiple tone mapping modes and options for fine-tuning luminance are available.
  • Fully supports different blend functions for enhanced visual styles.

For more details, see ToneMapping on pmndrs/postprocessing.


Local Playground — pnpm run playground

Local Documentation — pnpm run docs:dev


@alvarosabu @Tinoooo

Copy link
Contributor

@Tinoooo Tinoooo left a comment

Choose a reason for hiding this comment

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

Thank you @damienmontastier for your PR. Very helpful!

@@ -53,6 +53,7 @@ export default defineConfig({
{ text: 'Glitch', link: '/guide/pmndrs/glitch' },
{ text: 'Noise', link: '/guide/pmndrs/noise' },
{ text: 'Outline', link: '/guide/pmndrs/outline' },
{ text: 'ToneMapping', link: '/guide/pmndrs/tonemapping' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{ text: 'ToneMapping', link: '/guide/pmndrs/tonemapping' },
{ text: 'Tone Mapping', link: '/guide/pmndrs/tonemapping' },

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I suggest calling this file tone-mapping.md to be uniform with the others (depth-of-field.md for example)

const props = withDefaults(
defineProps<ToneMappingProps>(),
{
mode: ToneMappingMode.AGX,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: We set defaults only in very rare cases to minimize maintenance effort when postprocessing changes the internals of their effects. I suggest omitting these.

[() => props.resolution, 'resolution'],
[() => props.averageLuminance, 'averageLuminance'],
[() => props.middleGrey, 'middleGrey'],
[() => props.minLuminance, 'minLuminance'],
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I think this has to be like so:

Suggested change
[() => props.minLuminance, 'minLuminance'],
[() => props.minLuminance, 'adaptiveLuminanceMaterial.minLuminance'],

minLuminance is not a property of effect.value. These paths are used to update the effect when the props change. So we need the exact location of the property.

Comment on lines +61 to +69
watchEffect(() => {
if (!effect.value) { return }

effect.value.blendMode.blendFunction = Number(props.blendFunction)
})

makePropWatchers(
[
[() => props.mode, 'mode'],
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: You can omit the seperate watcher like so:

Suggested change
watchEffect(() => {
if (!effect.value) { return }
effect.value.blendMode.blendFunction = Number(props.blendFunction)
})
makePropWatchers(
[
[() => props.mode, 'mode'],
makePropWatchers(
[
[() => props.blendFunction, 'blendMode.blendFunction'],
[() => props.mode, 'mode'],


The `<ToneMapping>` 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{2,4,7-8,32-36}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: While I like to have a full example on the page, I think it is better to stay uniform with the other effects and only show the usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants