From de407c469d70efd8afd01e16bbc8040bad07c9b8 Mon Sep 17 00:00:00 2001 From: Damien Montastier Date: Tue, 1 Apr 2025 14:53:23 +0200 Subject: [PATCH 1/2] feat: add texture effect (demo, source code) --- docs/.vitepress/config.ts | 1 + .../theme/components/pmdrs/TextureDemo.vue | 131 ++++++++++++++++++ docs/components.d.ts | 1 + docs/guide/pmndrs/texture.md | 85 ++++++++++++ .../src/pages/postprocessing/texture.vue | 102 ++++++++++++++ playground/src/router.ts | 1 + src/core/pmndrs/TexturePmndrs.vue | 57 ++++++++ src/core/pmndrs/index.ts | 3 + 8 files changed, 381 insertions(+) create mode 100644 docs/.vitepress/theme/components/pmdrs/TextureDemo.vue create mode 100644 docs/guide/pmndrs/texture.md create mode 100644 playground/src/pages/postprocessing/texture.vue create mode 100644 src/core/pmndrs/TexturePmndrs.vue diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 3689f806..46be9af5 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -61,6 +61,7 @@ export default defineConfig({ { text: 'Hue & Saturation', link: '/guide/pmndrs/hue-saturation' }, { text: 'Lens Distortion', link: '/guide/pmndrs/lens-distortion' }, { text: 'Grid', link: '/guide/pmndrs/grid' }, + { text: 'Texture', link: '/guide/pmndrs/texture' }, { text: 'FXAA', link: '/guide/pmndrs/fxaa' }, { text: 'SMAA', link: '/guide/pmndrs/smaa' }, { text: 'Kuwahara', link: '/guide/pmndrs/kuwahara' }, diff --git a/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue b/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue new file mode 100644 index 00000000..7da89f36 --- /dev/null +++ b/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue @@ -0,0 +1,131 @@ + + + diff --git a/docs/components.d.ts b/docs/components.d.ts index 680367d8..66a07bf1 100644 --- a/docs/components.d.ts +++ b/docs/components.d.ts @@ -42,6 +42,7 @@ declare module 'vue' { ShockWaveDemo: typeof import('./.vitepress/theme/components/pmdrs/ShockWaveDemo.vue')['default'] SMAADemo: typeof import('./.vitepress/theme/components/pmdrs/SMAADemo.vue')['default'] SMAAThreeDemo: typeof import('./.vitepress/theme/components/three/SMAAThreeDemo.vue')['default'] + TextureDemo: typeof import('./.vitepress/theme/components/pmdrs/TextureDemo.vue')['default'] TiltShiftDemo: typeof import('./.vitepress/theme/components/pmdrs/TiltShiftDemo.vue')['default'] ToneMappingDemo: typeof import('./.vitepress/theme/components/pmdrs/ToneMappingDemo.vue')['default'] UnrealBloomThreeDemo: typeof import('./.vitepress/theme/components/three/UnrealBloomThreeDemo.vue')['default'] diff --git a/docs/guide/pmndrs/texture.md b/docs/guide/pmndrs/texture.md new file mode 100644 index 00000000..5172c98f --- /dev/null +++ b/docs/guide/pmndrs/texture.md @@ -0,0 +1,85 @@ +# Texture + + + + + +
+ Demo code + + <<< @/.vitepress/theme/components/pmdrs/TextureDemo.vue{0} +
+ +The `TextureEffect` component is part of the [`postprocessing`](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/TextureEffect.js~TextureEffect.html) package. +It allows rendering a texture with customizable options to create various visual effects. + +## Usage + +The `` component is easy to use and provides customizable options to suit different visual styles. + +:::info +This component is designed to work with a provided texture and **does not** include built-in functionality to modify the texture itself.

+If you need to adjust properties such as **rotation**, **repeat**, or **other attributes**, you should modify them directly the texture *(See usage example below)* that you pass to the `` component. +::: + +```vue{2,16-20,41-45} + + + +``` + +## Props + +| Prop | Description | Default | +| ------------- | ----------------------------------------------------------------------------------------------- | --------------------------- | +| blendFunction | Defines how the effect blends with the original scene. See the [`BlendFunction`](https://pmndrs.github.io/postprocessing/public/docs/variable/index.html#static-variable-BlendFunction) options. | `BlendFunction.NORMAL` | +| texture | The texture used for the effect. See the [`Texture`](https://threejs.org/docs/#api/en/textures/Texture) documentation | `null` | +| opacity | The opacity of the texture. | `1.0` | + +## Further Reading + +For more details, see the [TextureEffect documentation](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/TextureEffect.js~TextureEffect.html). diff --git a/playground/src/pages/postprocessing/texture.vue b/playground/src/pages/postprocessing/texture.vue new file mode 100644 index 00000000..11a0d218 --- /dev/null +++ b/playground/src/pages/postprocessing/texture.vue @@ -0,0 +1,102 @@ + + + diff --git a/playground/src/router.ts b/playground/src/router.ts index adf6eda2..1a0159ab 100644 --- a/playground/src/router.ts +++ b/playground/src/router.ts @@ -52,6 +52,7 @@ export const postProcessingRoutes = [ makeRoute('Scanline', '📽️', false), makeRoute('Color Depth', '🔳', false), makeRoute('Grid', '#️⃣', false), + makeRoute('Texture', '🧩', false), makeRoute('SMAA', '📐', false), makeRoute('FXAA', '📐', false), makeRoute('Shock Wave', '🌊', false), diff --git a/src/core/pmndrs/TexturePmndrs.vue b/src/core/pmndrs/TexturePmndrs.vue new file mode 100644 index 00000000..4a3aa614 --- /dev/null +++ b/src/core/pmndrs/TexturePmndrs.vue @@ -0,0 +1,57 @@ + diff --git a/src/core/pmndrs/index.ts b/src/core/pmndrs/index.ts index b6da7b84..11833aa4 100644 --- a/src/core/pmndrs/index.ts +++ b/src/core/pmndrs/index.ts @@ -30,6 +30,7 @@ import FishEyePmndrs, { type FishEyePmndrsProps } from './FishEyePmndrs.vue' import BrightnessContrastPmndrs, { type BrightnessContrastPmndrsProps } from './BrightnessContrastPmndrs.vue' import SMAAPmndrs, { type SMAAPmndrsProps } from './SMAAPmndrs.vue' import FXAAPmndrs, { type FXAAPmndrsProps } from './FXAAPmndrs.vue' +import TexturePmndrs, { type TexturePmndrsProps } from './TexturePmndrs.vue' export { BloomPmndrs, @@ -62,6 +63,7 @@ export { BrightnessContrastPmndrs, SMAAPmndrs, FXAAPmndrs, + TexturePmndrs, BloomPmndrsProps, DepthOfFieldPmndrsProps, EffectComposerPmndrsProps, @@ -91,4 +93,5 @@ export { BrightnessContrastPmndrsProps, SMAAPmndrsProps, FXAAPmndrsProps, + TexturePmndrsProps, } From 3ae45bb6cfd97cfcca92ff9aaa86b451b57790a0 Mon Sep 17 00:00:00 2001 From: Damien Montastier Date: Tue, 1 Apr 2025 17:31:44 +0200 Subject: [PATCH 2/2] clean demos --- docs/.vitepress/theme/components/pmdrs/TextureDemo.vue | 10 ---------- playground/src/pages/postprocessing/texture.vue | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue b/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue index 7da89f36..bdaf5a3a 100644 --- a/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue +++ b/docs/.vitepress/theme/components/pmdrs/TextureDemo.vue @@ -77,16 +77,6 @@ const { blendFunction, rotation, opacity } = useControls({ watch(rotation, () => { texture.rotation = rotation.value }) - -// watch( -// () => textureEffectRef.value?.effect, -// () => { -// if (!textureEffectRef.value?.effect) { return} - -// use setTextureSwizzleRGBA() from TextureEffect (https://pmndrs.github.io/postprocessing/public/docs/file/src/effects/TextureEffect.js.html#lineNumber192) -// textureEffectRef.value?.effect.setTextureSwizzleRGBA() -// }, -// )