From 6fa0e3ca6cf7d1719ca49345b5e57b3ce532b35a Mon Sep 17 00:00:00 2001 From: Damien Montastier Date: Sun, 12 Jan 2025 14:04:07 +0100 Subject: [PATCH] feat: add shock wave (#164) * init shockwave effect * wip shock wave effect * add demo playground * wip demo doc * add depthpickingpass * wip component depth picking pass fix issue / types * wip doc demo * wip doc * wip doc * fix doc * fix documentation * fix reviews PR --------- Co-authored-by: Tino Koch <17991193+Tinoooo@users.noreply.github.com> --- docs/.vitepress/config.ts | 1 + .../theme/components/pmdrs/ShockWaveDemo.vue | 218 ++++++++++++++++++ docs/components.d.ts | 1 + docs/guide/pmndrs/shock-wave.md | 188 +++++++++++++++ .../src/pages/postprocessing/shock-wave.vue | 121 ++++++++++ playground/src/router.ts | 1 + src/core/pmndrs/DepthPickingPassPmndrs.vue | 31 +++ src/core/pmndrs/ShockWavePmndrs.vue | 72 ++++++ src/core/pmndrs/index.ts | 6 + 9 files changed, 639 insertions(+) create mode 100644 docs/.vitepress/theme/components/pmdrs/ShockWaveDemo.vue create mode 100644 docs/guide/pmndrs/shock-wave.md create mode 100644 playground/src/pages/postprocessing/shock-wave.vue create mode 100644 src/core/pmndrs/DepthPickingPassPmndrs.vue create mode 100644 src/core/pmndrs/ShockWavePmndrs.vue diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 3cfba603..09bd028f 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -57,6 +57,7 @@ export default defineConfig({ { text: 'Chromatic Aberration', link: '/guide/pmndrs/chromatic-aberration' }, { text: 'Sepia', link: '/guide/pmndrs/sepia' }, { text: 'Scanline', link: '/guide/pmndrs/scanline' }, + { text: 'Shock Wave', link: '/guide/pmndrs/shock-wave' }, { text: 'Pixelation', link: '/guide/pmndrs/pixelation' }, { text: 'Vignette', link: '/guide/pmndrs/vignette' }, { text: 'Barrel blur', link: '/guide/pmndrs/barrel-blur' }, diff --git a/docs/.vitepress/theme/components/pmdrs/ShockWaveDemo.vue b/docs/.vitepress/theme/components/pmdrs/ShockWaveDemo.vue new file mode 100644 index 00000000..f6e06858 --- /dev/null +++ b/docs/.vitepress/theme/components/pmdrs/ShockWaveDemo.vue @@ -0,0 +1,218 @@ + + + + + diff --git a/docs/components.d.ts b/docs/components.d.ts index 14007f1b..2bb9120c 100644 --- a/docs/components.d.ts +++ b/docs/components.d.ts @@ -26,6 +26,7 @@ declare module 'vue' { PixelationDemo: typeof import('./.vitepress/theme/components/pmdrs/PixelationDemo.vue')['default'] PixelationThreeDemo: typeof import('./.vitepress/theme/components/three/PixelationThreeDemo.vue')['default'] ScanlineDemo: typeof import('./.vitepress/theme/components/pmdrs/ScanlineDemo.vue')['default'] + ShockWaveDemo: typeof import('./.vitepress/theme/components/pmdrs/ShockWaveDemo.vue')['default'] SepiaDemo: typeof import('./.vitepress/theme/components/pmdrs/SepiaDemo.vue')['default'] SMAAThreeDemo: typeof import('./.vitepress/theme/components/three/SMAAThreeDemo.vue')['default'] TiltShiftDemo: typeof import('./.vitepress/theme/components/pmdrs/TiltShiftDemo.vue')['default'] diff --git a/docs/guide/pmndrs/shock-wave.md b/docs/guide/pmndrs/shock-wave.md new file mode 100644 index 00000000..e2778043 --- /dev/null +++ b/docs/guide/pmndrs/shock-wave.md @@ -0,0 +1,188 @@ +# Shock Wave + + + + + +
+ Demo code + + <<< @/.vitepress/theme/components/pmdrs/ShockWaveDemo.vue{0} +
+ +The `ShockWave` effect is part of the [`postprocessing`](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/ShockWaveEffect.js~ShockWaveEffect.html) package. It simulates a shockwave effect originating from a center point, creating a ripple-like distortion in the scene. This effect can add dramatic impact to your scene by simulating explosions or other shockwave phenomena. + +## Usage + +The `` component is easy to use and provides customizable options to suit different visual styles. There are several possible techniques to achieve this. See [Events](#events) and [DepthPickingPass](#depthpickingpass) for more details. + +The main difference between `Events` and `DepthPickingPass` lies in the scope you want. `Events` is more suited for being used on a specific element, while `DepthPickingPass` is intended to be used for an entire scene (depth is calculated globally). + +### Events + +To determine the position of the shockwave effect, you can use Tres.js events. Tres.js allows you to handle user interactions directly and find the intersection point with objects in the scene. This technique is useful when you need to interact with specific objects based on user input. + +You can use various Tres.js events such as `click`, `pointer-enter`, etc., to trigger the shockwave effect. For more details about available events, see the [documentation](https://docs.tresjs.org/api/events.html). + +Here is an example of how to use events to trigger the shockwave effect: + +```vue{2,3,13-15,17-18,20-21,23-24,26-28,30-36,45,50-58} + + + +``` + +### DepthPickingPass + +The `DepthPickingPassPmndrs` component reads depth information from the scene. This is particularly useful for interacting with 3D objects based on their depth, such as triggering effects at specific points in 3D space. + +In the example above, `DepthPickingPassPmndrs` determines the depth of the point where the shockwave effect should originate, allowing accurate interaction with 3D objects. + +```vue{2,3,13-15,17-20,22-23,25-26,28-37,39-45,51,58,63-72} + + + +``` + +For more details about DepthPickingPass, see the [documentation](https://pmndrs.github.io/postprocessing/public/docs/class/src/passes/DepthPickingPass.js~DepthPickingPass.html). + +## Props + +| Prop | Description | Default | +| ----------------- | ------------------------------------------------------------------------------------------------------------- | ------------------------- | +| position | The position of the shockwave. | `Vector3(0, 0, 0)` | +| amplitude | The amplitude of the shockwave. | `0.05` | +| waveSize | The wave size of the shockwave. | `0.2` | +| speed | The speed of the shockwave. | `2.0` | +| maxRadius | The max radius of the shockwave. | `1.0` | + +## Further Reading +see [postprocessing docs](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/ShockWaveEffect.js~ShockWaveEffect.html) diff --git a/playground/src/pages/postprocessing/shock-wave.vue b/playground/src/pages/postprocessing/shock-wave.vue new file mode 100644 index 00000000..02e0b498 --- /dev/null +++ b/playground/src/pages/postprocessing/shock-wave.vue @@ -0,0 +1,121 @@ + + + + + diff --git a/playground/src/router.ts b/playground/src/router.ts index 621e8b7b..a8190415 100644 --- a/playground/src/router.ts +++ b/playground/src/router.ts @@ -45,6 +45,7 @@ export const postProcessingRoutes = [ makeRoute('Chromatic Aberration', '🌈', false), makeRoute('Sepia', '🌅', false), makeRoute('Scanline', '📺', false), + makeRoute('Shock Wave', '🌊', false), makeRoute('Vignette', '🕶️', false), makeRoute('Barrel blur', '🌀', false), makeRoute('On-demand', '🔄', false), diff --git a/src/core/pmndrs/DepthPickingPassPmndrs.vue b/src/core/pmndrs/DepthPickingPassPmndrs.vue new file mode 100644 index 00000000..1c82be0a --- /dev/null +++ b/src/core/pmndrs/DepthPickingPassPmndrs.vue @@ -0,0 +1,31 @@ + diff --git a/src/core/pmndrs/ShockWavePmndrs.vue b/src/core/pmndrs/ShockWavePmndrs.vue new file mode 100644 index 00000000..ab509ab0 --- /dev/null +++ b/src/core/pmndrs/ShockWavePmndrs.vue @@ -0,0 +1,72 @@ + diff --git a/src/core/pmndrs/index.ts b/src/core/pmndrs/index.ts index 9f4fd8a5..1fa0bb61 100644 --- a/src/core/pmndrs/index.ts +++ b/src/core/pmndrs/index.ts @@ -14,6 +14,8 @@ import ToneMappingPmndrs, { type ToneMappingPmndrsProps } from './ToneMappingPmn import ChromaticAberrationPmndrs, { type ChromaticAberrationPmndrsProps } from './ChromaticAberrationPmndrs.vue' import HueSaturationPmndrs, { type HueSaturationPmndrsProps } from './HueSaturationPmndrs.vue' import ScanlinePmndrs, { type ScanlinePmndrsProps } from './ScanlinePmndrs.vue' +import ShockWavePmndrs, { type ShockWavePmndrsProps } from './ShockWavePmndrs.vue' +import DepthPickingPassPmndrs, { type DepthPickingPassPmndrsProps } from './DepthPickingPassPmndrs.vue' import TiltShiftPmndrs, { type TiltShiftPmndrsProps } from './TiltShiftPmndrs.vue' import DotScreenPmndrs, { type DotScreenPmndrsProps } from './DotScreenPmndrs.vue' import SepiaPmndrs, { type SepiaPmndrsProps } from './SepiaPmndrs.vue' @@ -35,6 +37,8 @@ export { ChromaticAberrationPmndrs, HueSaturationPmndrs, ScanlinePmndrs, + ShockWavePmndrs, + DepthPickingPassPmndrs, TiltShiftPmndrs, DotScreenPmndrs, SepiaPmndrs, @@ -52,6 +56,8 @@ export { ChromaticAberrationPmndrsProps, HueSaturationPmndrsProps, ScanlinePmndrsProps, + ShockWavePmndrsProps, + DepthPickingPassPmndrsProps, TiltShiftPmndrsProps, DotScreenPmndrsProps, SepiaPmndrsProps,