|
| 1 | +# Texture |
| 2 | + |
| 3 | +<DocsDemoGUI> |
| 4 | + <TextureDemo /> |
| 5 | +</DocsDemoGUI> |
| 6 | + |
| 7 | +<details> |
| 8 | + <summary>Demo code</summary> |
| 9 | + |
| 10 | + <<< @/.vitepress/theme/components/pmdrs/TextureDemo.vue{0} |
| 11 | +</details> |
| 12 | + |
| 13 | +The `TextureEffect` component is part of the [`postprocessing`](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/TextureEffect.js~TextureEffect.html) package. |
| 14 | +It allows rendering a texture with customizable options to create various visual effects. |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +The `<TexturePmndrs>` component is easy to use and provides customizable options to suit different visual styles. |
| 19 | + |
| 20 | +:::info |
| 21 | +This component is designed to work with a provided texture and **does not** include built-in functionality to modify the texture itself. <br><br> |
| 22 | +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 `<TexturePmndrs />` component. |
| 23 | +::: |
| 24 | + |
| 25 | +```vue{2,16-20,41-45} |
| 26 | +<script setup lang="ts"> |
| 27 | +import { EffectComposerPmndrs, TexturePmndrs } from '@tresjs/post-processing/pmndrs' |
| 28 | +import { TresCanvas, useTexture } from '@tresjs/core' |
| 29 | +import { NoToneMapping, RepeatWrapping, SRGBColorSpace } from 'three' |
| 30 | +import { BlendFunction, ColorChannel } from 'postprocessing' |
| 31 | +
|
| 32 | +const gl = { |
| 33 | + toneMapping: NoToneMapping, |
| 34 | +} |
| 35 | +
|
| 36 | +const effectProps = { |
| 37 | + blendFunction: BlendFunction.OVERLAY, |
| 38 | + opacity: 0.65 |
| 39 | +} |
| 40 | +
|
| 41 | +const texture = await useTexture(['your-path-to-texture']) |
| 42 | +texture.colorSpace = SRGBColorSpace |
| 43 | +texture.wrapS = texture.wrapT = RepeatWrapping |
| 44 | +texture.rotation = Math.PI / 2 |
| 45 | +texture.repeat.set( 2, 2 ); |
| 46 | +
|
| 47 | +function setTextureSwizzleRGBA(red, green, blue, alpha) { |
| 48 | + // This is an example of using a function belonging to the TextureEffect class. |
| 49 | + // https://pmndrs.github.io/postprocessing/public/docs/file/src/effects/TextureEffect.js.html#lineNumber192 |
| 50 | + textureEffectRef.value?.effect.setTextureSwizzleRGBA(red, green, blue, alpha) |
| 51 | +} |
| 52 | +
|
| 53 | +// Example how to mix texture's color channels. |
| 54 | +setTextureSwizzleRGBA(ColorChannel.GREEN, ColorChannel.BLUE, ColorChannel.RED, ColorChannel.ALPHA) |
| 55 | +
|
| 56 | +// Example how to reset the texture's color channels (default). |
| 57 | +setTextureSwizzleRGBA(ColorChannel.RED, ColorChannel.BLUE, ColorChannel.GREEN, ColorChannel.ALPHA) |
| 58 | +</script> |
| 59 | +
|
| 60 | +<template> |
| 61 | + <TresCanvas v-bind="gl"> |
| 62 | + <TresPerspectiveCamera :position="[5, 5, 5]" /> |
| 63 | +
|
| 64 | + <!-- Your Scene --> |
| 65 | +
|
| 66 | + <Suspense> |
| 67 | + <EffectComposerPmndrs> |
| 68 | + <TexturePmndrs v-bind="effectProps" :texture="texture" /> |
| 69 | + </EffectComposerPmndrs> |
| 70 | + </Suspense> |
| 71 | + </TresCanvas> |
| 72 | +</template> |
| 73 | +``` |
| 74 | + |
| 75 | +## Props |
| 76 | + |
| 77 | +| Prop | Description | Default | |
| 78 | +| ------------- | ----------------------------------------------------------------------------------------------- | --------------------------- | |
| 79 | +| 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` | |
| 80 | +| texture | The texture used for the effect. See the [`Texture`](https://threejs.org/docs/#api/en/textures/Texture) documentation | `null` | |
| 81 | +| opacity | The opacity of the texture. | `1.0` | |
| 82 | + |
| 83 | +## Further Reading |
| 84 | + |
| 85 | +For more details, see the [TextureEffect documentation](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/TextureEffect.js~TextureEffect.html). |
0 commit comments