From 8fc0321a1c9e60b92bc48734373e67dfbd143fe2 Mon Sep 17 00:00:00 2001 From: Damien Montastier Date: Sat, 4 Jan 2025 16:41:15 +0100 Subject: [PATCH] feat: add chromatic aberration effect (#149) * add chromatic aberration * add chromatic aberration * improve doc and demo * fix doc * revert outlineDemo deleted by mistake * update for package v2 --------- Co-authored-by: Alvaro Saburido --- docs/.vitepress/config.ts | 1 + .../pmdrs/ChromaticAberrationDemo.vue | 80 +++++++++++++++++++ docs/components.d.ts | 2 + docs/guide/pmndrs/chromatic-aberration.md | 78 ++++++++++++++++++ .../postprocessing/chromatic-aberration.vue | 66 +++++++++++++++ playground/src/router.ts | 1 + src/core/pmndrs/ChromaticAberration.vue | 53 ++++++++++++ src/core/pmndrs/index.ts | 3 + 8 files changed, 284 insertions(+) create mode 100644 docs/.vitepress/theme/components/pmdrs/ChromaticAberrationDemo.vue create mode 100644 docs/guide/pmndrs/chromatic-aberration.md create mode 100644 playground/src/pages/postprocessing/chromatic-aberration.vue create mode 100644 src/core/pmndrs/ChromaticAberration.vue diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index f13a8cec..0f703ec8 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -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: 'Chromatic Aberration', link: '/guide/pmndrs/chromatic-aberration' }, { text: 'Scanline', link: '/guide/pmndrs/scanline' }, { text: 'Pixelation', link: '/guide/pmndrs/pixelation' }, { text: 'Vignette', link: '/guide/pmndrs/vignette' }, diff --git a/docs/.vitepress/theme/components/pmdrs/ChromaticAberrationDemo.vue b/docs/.vitepress/theme/components/pmdrs/ChromaticAberrationDemo.vue new file mode 100644 index 00000000..8a28e9aa --- /dev/null +++ b/docs/.vitepress/theme/components/pmdrs/ChromaticAberrationDemo.vue @@ -0,0 +1,80 @@ + + + diff --git a/docs/components.d.ts b/docs/components.d.ts index f948911e..c540c0c6 100644 --- a/docs/components.d.ts +++ b/docs/components.d.ts @@ -9,6 +9,7 @@ declare module 'vue' { export interface GlobalComponents { BlenderCube: typeof import('./.vitepress/theme/components/BlenderCube.vue')['default'] BloomDemo: typeof import('./.vitepress/theme/components/pmdrs/BloomDemo.vue')['default'] + ChromaticAberrationDemo: typeof import('./.vitepress/theme/components/pmdrs/ChromaticAberrationDemo.vue')['default'] DepthOfFieldDemo: typeof import('./.vitepress/theme/components/pmdrs/DepthOfFieldDemo.vue')['default'] DocsDemo: typeof import('./.vitepress/theme/components/DocsDemo.vue')['default'] Ducky: typeof import('./.vitepress/theme/components/Ducky.vue')['default'] @@ -24,6 +25,7 @@ declare module 'vue' { PixelationThreeDemo: typeof import('./.vitepress/theme/components/three/PixelationThreeDemo.vue')['default'] ScanlineDemo: typeof import('./.vitepress/theme/components/pmdrs/ScanlineDemo.vue')['default'] SMAAThreeDemo: typeof import('./.vitepress/theme/components/three/SMAAThreeDemo.vue')['default'] + ToneMappingDemo: typeof import('./.vitepress/theme/components/pmdrs/ToneMappingDemo.vue')['default'] UnrealBloomThreeDemo: typeof import('./.vitepress/theme/components/three/UnrealBloomThreeDemo.vue')['default'] VignetteDemo: typeof import('./.vitepress/theme/components/pmdrs/VignetteDemo.vue')['default'] } diff --git a/docs/guide/pmndrs/chromatic-aberration.md b/docs/guide/pmndrs/chromatic-aberration.md new file mode 100644 index 00000000..011263aa --- /dev/null +++ b/docs/guide/pmndrs/chromatic-aberration.md @@ -0,0 +1,78 @@ +# Chromatic Aberration + + + + + +The `ChromaticAberration` effect is part of the [`postprocessing`](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/ChromaticAberrationEffect.js~ChromaticAberrationEffect.html) package. It simulates the dispersion of light as it passes through a lens, creating subtle or dramatic color fringing effects at the edges of objects. This effect can enhance the visual appeal of your scene by adding a realistic lens effect or a stylized touch. + +## Usage + +The `` component is easy to use and provides customizable options to suit different visual styles. + +```vue{2,38-46} + + + +``` + +## Props + +| Prop | Description | Default | +| ----------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------- | +| blendFunction | Defines the [`BlendFunction`](https://pmndrs.github.io/postprocessing/public/docs/variable/index.html#static-variable-BlendFunction) used for the effect. | `BlendFunction.SRC` | +| offset | The color offset vector determining the intensity and direction of chromatic aberration. | `Vector2(0.01, 0.01)` | +| radialModulation | Enables radial modulation to vary the effect intensity based on distance from the center. | `false` | +| modulationOffset | Specifies the modulation offset when `radialModulation` is **enabled**. | `0.15` | + +::: info +The `modulationOffset` property is functional only when `radialModulation` is enabled. +::: + +## Further Reading +see [postprocessing docs](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/ToneMappingEffect.js~ToneMappingEffect.html) diff --git a/playground/src/pages/postprocessing/chromatic-aberration.vue b/playground/src/pages/postprocessing/chromatic-aberration.vue new file mode 100644 index 00000000..ace73745 --- /dev/null +++ b/playground/src/pages/postprocessing/chromatic-aberration.vue @@ -0,0 +1,66 @@ + + + diff --git a/playground/src/router.ts b/playground/src/router.ts index 984b80a7..d4314e84 100644 --- a/playground/src/router.ts +++ b/playground/src/router.ts @@ -39,6 +39,7 @@ export const postProcessingRoutes = [ makeRoute('Pixelation', '👾', false), makeRoute('Bloom', '🌼', false), makeRoute('Noise', '📟', false), + makeRoute('Chromatic Aberration', '🌈', false), makeRoute('Scanline', '📺', false), makeRoute('Vignette', '🕶️', false), makeRoute('On-demand', '🔄', false), diff --git a/src/core/pmndrs/ChromaticAberration.vue b/src/core/pmndrs/ChromaticAberration.vue new file mode 100644 index 00000000..f424d911 --- /dev/null +++ b/src/core/pmndrs/ChromaticAberration.vue @@ -0,0 +1,53 @@ + diff --git a/src/core/pmndrs/index.ts b/src/core/pmndrs/index.ts index b9cc46f1..738cb4ec 100644 --- a/src/core/pmndrs/index.ts +++ b/src/core/pmndrs/index.ts @@ -9,6 +9,7 @@ import NoisePmndrs, { type NoisePmndrsProps } from './NoisePmndrs.vue' import OutlinePmndrs, { type OutlinePmndrsProps } from './OutlinePmndrs.vue' import PixelationPmndrs, { type PixelationPmndrsProps } from './PixelationPmndrs.vue' import VignettePmndrs, { type VignettePmndrsProps } from './VignettePmndrs.vue' +import ChromaticAberrationPmndrs, { type ChromaticAberrationPmndrsProps } from './ChromaticAberration.vue' import HueSaturationPmndrs, { type HueSaturationPmndrsProps } from './HueSaturationPmndrs.vue' import ScanlinePmndrs, { type ScanlinePmndrsProps } from './ScanlinePmndrs.vue' @@ -22,6 +23,7 @@ export { PixelationPmndrs, useEffectPmndrs, VignettePmndrs, + ChromaticAberrationPmndrs, HueSaturationPmndrs, ScanlinePmndrs, BloomPmndrsProps, @@ -32,6 +34,7 @@ export { OutlinePmndrsProps, PixelationPmndrsProps, VignettePmndrsProps, + ChromaticAberrationPmndrsProps, HueSaturationPmndrsProps, ScanlinePmndrsProps, }