Skip to content

Commit 8e3e583

Browse files
authored
feat(post-processing): pixelation effect (#68)
* feat: added pixelation effect component * chore: added playground code for pixelation effect * docs: pixelation effect docs * chore: removed debug code
1 parent a2afd3f commit 8e3e583

File tree

9 files changed

+173
-2
lines changed

9 files changed

+173
-2
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default defineConfig({
3232
{ text: 'Depth of Field', link: '/guide/effects/depth-of-field' },
3333
{ text: 'Glitch', link: '/guide/effects/glitch' },
3434
{ text: 'Outline', link: '/guide/effects/outline' },
35+
{ text: 'Pixelation', link: '/guide/effects/pixelation' },
3536
],
3637
},
3738
],
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script lang="ts" setup>
2+
import { Color } from 'three'
3+
import { TresCanvas } from '@tresjs/core'
4+
import { OrbitControls } from '@tresjs/cientos'
5+
import { EffectComposer, Pixelation } from '@tresjs/post-processing'
6+
7+
const boxWidth = 2
8+
</script>
9+
10+
<template>
11+
<TresCanvas
12+
clear-color="#121212"
13+
:alpha="false"
14+
:shadows="true"
15+
:disable-render="true"
16+
>
17+
<TresPerspectiveCamera
18+
:position="[3, 2, 4]"
19+
:look-at="[0, 0, 0]"
20+
/>
21+
<OrbitControls />
22+
<TresMesh
23+
:position="[1, 0.5, 1]"
24+
>
25+
<TresBoxGeometry />
26+
<TresMeshStandardMaterial
27+
color="hotpink"
28+
/>
29+
</TresMesh>
30+
<TresMesh
31+
:position="[-1.5, 0.75, 0]"
32+
>
33+
<TresConeGeometry :args="[1, 1.5, 4, 1, false, Math.PI * 0.25]" />
34+
<TresMeshNormalMaterial />
35+
<TresMeshStandardMaterial
36+
color="aqua"
37+
/>
38+
</TresMesh>
39+
40+
<TresGridHelper />
41+
<TresAmbientLight :intensity="0.9" />
42+
<TresDirectionalLight
43+
:position="[-10, 5, 8]"
44+
:intensity="1"
45+
/>
46+
47+
<Suspense>
48+
<EffectComposer>
49+
<Pixelation :granularity="8" />
50+
</EffectComposer>
51+
</Suspense>
52+
</TresCanvas>
53+
</template>
54+

docs/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare module '@vue/runtime-core' {
1515
GlitchDemo: typeof import('./.vitepress/theme/components/GlitchDemo.vue')['default']
1616
LoveVueThreeJS: typeof import('./.vitepress/theme/components/LoveVueThreeJS.vue')['default']
1717
OutlineDemo: typeof import('./.vitepress/theme/components/OutlineDemo.vue')['default']
18+
PixelationDemo: typeof import('./.vitepress/theme/components/PixelationDemo.vue')['default']
1819
RouterLink: typeof import('vue-router')['RouterLink']
1920
RouterView: typeof import('vue-router')['RouterView']
2021
}

docs/guide/effects/pixelation.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Pixelation
2+
3+
<DocsDemo>
4+
<PixelationDemo />
5+
</DocsDemo>
6+
7+
Pixelation is an effect that pixelates the scene.
8+
9+
## Usage
10+
11+
```vue
12+
<script setup lang="ts">
13+
import { EffectComposer, Pixelation } from '@tresjs/post-processing'
14+
</script>
15+
16+
<template>
17+
<EffectComposer>
18+
<Pixelation />
19+
</EffectComposer>
20+
</template>
21+
```
22+
23+
## Props
24+
25+
| Prop | Description | Default |
26+
| ----------- | ------------------------------ | ------- |
27+
| granularity | The granularity of the pixels. | 30 |
28+
29+
## Further Reading
30+
see [postprocessing docs](https://pmndrs.github.io/postprocessing/public/docs/class/src/effects/PixelationEffect.js~PixelationEffect.html)

playground/src/pages/pixelation.vue

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<script lang="ts" setup>
2+
import { computed } from 'vue'
3+
import { TresCanvas } from '@tresjs/core'
4+
import { OrbitControls } from '@tresjs/cientos'
5+
import { EffectComposer, Pixelation } from '@tresjs/post-processing'
6+
import { TresLeches, useControls } from '@tresjs/leches'
7+
import '@tresjs/leches/styles'
8+
9+
useControls('fpsgraph')
10+
const { granularity } = useControls({
11+
granularity: {
12+
value: 10,
13+
min: 1,
14+
max: 30,
15+
step: 1,
16+
},
17+
})
18+
</script>
19+
20+
<template>
21+
<TresLeches />
22+
<TresCanvas>
23+
<TresPerspectiveCamera
24+
:position="[5, 5, 5]"
25+
:look-at="[0, 0, 0]"
26+
/>
27+
<OrbitControls />
28+
<TresMesh
29+
:position="[-3.5, 1, 0]"
30+
>
31+
<TresConeGeometry :args="[1.25, 2, 4, 1, false, Math.PI * 0.25]" />
32+
<TresMeshNormalMaterial />
33+
</TresMesh>
34+
35+
<TresMesh :position="[0, 1, 0]">
36+
<TresBoxGeometry :args="[2, 2, 2]" />
37+
<TresMeshNormalMaterial />
38+
</TresMesh>
39+
40+
<TresMesh :position="[3.5, 1, 0]">
41+
<TresSphereGeometry />
42+
<TresMeshNormalMaterial />
43+
</TresMesh>
44+
45+
<TresGridHelper />
46+
47+
<EffectComposer>
48+
<Pixelation :granularity="granularity" />
49+
</EffectComposer>
50+
</TresCanvas>
51+
</template>

playground/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const routes = [
2020
makeRoute('Outline'),
2121
makeRoute('Glitch'),
2222
makeRoute('Depth of Field'),
23+
makeRoute('Pixelation'),
2324
]
2425

2526
export const router = createRouter({

src/core/effects/Pixelation.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script lang="ts" setup>
2+
import { PixelationEffect } from 'postprocessing'
3+
import { useEffect } from '../composables/effect'
4+
import { makePropWatchersUsingAllProps } from '../../util/prop'
5+
6+
export interface PixelationProps {
7+
/**
8+
* The pixel granularity.
9+
*/
10+
granularity?: number
11+
}
12+
13+
const props = defineProps<PixelationProps>()
14+
15+
const { pass, effect } = useEffect(() => new PixelationEffect(props.granularity))
16+
defineExpose({ pass, effect }) // to allow users to modify pass and effect via template ref
17+
18+
makePropWatchersUsingAllProps(
19+
props,
20+
effect,
21+
() => new PixelationEffect(),
22+
)
23+
</script>
24+
25+
<template></template>

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import Bloom from './core/effects/Bloom.vue'
22
import Glitch from './core/effects/Glitch.vue'
33
import Outline from './core/effects/Outline.vue'
4+
import Pixelation from './core/effects/Pixelation.vue'
45
import DepthOfField from './core/effects/DepthOfField.vue'
56

67
import EffectComposer from './core/EffectComposer.vue'
78

8-
export { EffectComposer, Bloom, Outline, Glitch, DepthOfField }
9+
export {
10+
Bloom,
11+
Glitch,
12+
Outline,
13+
Pixelation,
14+
DepthOfField,
15+
EffectComposer,
16+
}

stats.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)