Skip to content

Commit

Permalink
added smaa effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinoooo committed Sep 5, 2024
1 parent 377a650 commit 37f1ab6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
10 changes: 7 additions & 3 deletions playground/src/components/BasicScene.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import { TresCanvas } from '@tresjs/core'
import { EffectComposerThree, PixelationThree } from '@tresjs/post-processing'

Check failure on line 3 in playground/src/components/BasicScene.vue

View workflow job for this annotation

GitHub Actions / Lint (20)

'PixelationThree' is defined but never used
import { OrbitControls } from '@tresjs/cientos'
defineProps<{
wireframe?: boolean
}>()
</script>

<template>
Expand All @@ -15,17 +19,17 @@ import { OrbitControls } from '@tresjs/cientos'
:position="[-3.5, 1, 0]"
>
<TresConeGeometry :args="[1.25, 2, 4, 1, false, Math.PI * 0.25]" />
<TresMeshNormalMaterial />
<TresMeshNormalMaterial :wireframe="wireframe" />
</TresMesh>

<TresMesh :position="[0, 1, 0]">
<TresBoxGeometry :args="[2, 2, 2]" />
<TresMeshNormalMaterial />
<TresMeshNormalMaterial :wireframe="wireframe" />
</TresMesh>

<TresMesh :position="[3.5, 1, 0]">
<TresSphereGeometry />
<TresMeshNormalMaterial />
<TresMeshNormalMaterial :wireframe="wireframe" />
</TresMesh>

<TresGridHelper />
Expand Down
18 changes: 18 additions & 0 deletions playground/src/pages/three/smaa.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts" setup>
import { SMAAThree } from '@tresjs/post-processing'
import { ref } from 'vue'
import BasicScene from '../../components/BasicScene.vue'
const enabled = ref(true)
</script>

<template>
<div class="absolute top-0 left-0 z-10">
<input v-model="enabled" type="checkbox" /> enabled
</div>
<BasicScene wireframe>
<template #effects>
<SMAAThree v-if="enabled" />
</template>
</BasicScene>
</template>
1 change: 1 addition & 0 deletions playground/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const home: RouteRecordRaw = {
export const threeRoutes = [
makeRoute('Pixelation', '👾'),
makeRoute('Glitch', '📺'),
makeRoute('SMAA', '📐'),
]

export const postProcessingRoutes = [
Expand Down
26 changes: 26 additions & 0 deletions src/core/three/SMAA.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts" setup>
import { SMAAPass } from 'three/examples/jsm/postprocessing/SMAAPass.js'
import { useTresContext } from '@tresjs/core'
import { computed, watchEffect } from 'vue'
import { useDevicePixelRatio } from '@vueuse/core'
import { useEffectThree } from '../composables/useEffectThree'
const props = defineProps<{
width?: number
height?: number
}>()
const { sizes } = useTresContext()
const { pixelRatio } = useDevicePixelRatio() // the renderers pixel ratio is not used because it is not reactive
const width = computed(() => props.width ?? sizes.width.value * pixelRatio.value)
const height = computed(() => props.height ?? sizes.height.value * pixelRatio.value)
const { pass } = useEffectThree(() => new SMAAPass(width.value, height.value))
defineExpose({ pass })
watchEffect(() => {
pass.value.setSize(width.value, height.value)
})
</script>
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import EffectComposer from './core/EffectComposer.vue'
import EffectComposerThree from './core/three/EffectComposer.vue'
import PixelationThree from './core/three/Pixelation.vue' // TODO seperate exports differently
import GlitchThree from './core/three/Glitch.vue' // TODO seperate exports differently
import SMAAThree from './core/three/SMAA.vue' // TODO seperate exports differently
import Glitch from './core/postprocessing/Glitch.vue'
import Outline from './core/postprocessing/Outline.vue'
import Pixelation from './core/postprocessing/Pixelation.vue'
Expand All @@ -25,4 +26,5 @@ export {
EffectComposerThree,
PixelationThree,
GlitchThree,
SMAAThree,
}

0 comments on commit 37f1ab6

Please sign in to comment.