Skip to content

Commit

Permalink
fix: expose effectComposer (#83)
Browse files Browse the repository at this point in the history
* fix: expose effectComposer

* fixed types and restructured composable a bit

* cleanup

* fixed linting errors

---------

Co-authored-by: Tino Koch <17991193+Tinoooo@users.noreply.github.com>
  • Loading branch information
alvarosabu and Tinoooo authored Nov 17, 2023
1 parent ccfa8fb commit 4878a95
Show file tree
Hide file tree
Showing 15 changed files with 703 additions and 471 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// .vitepress/config.ts
import { defineConfig } from "file:///Users/alvarosabu/Projects/tres/post-processing/node_modules/.pnpm/vitepress@1.0.0-rc.25_@algolia+client-search@4.20.0_postcss@8.4.31_search-insights@2.10.0_typescript@5.2.2/node_modules/vitepress/dist/node/index.js";
import { resolve } from "file:///Users/alvarosabu/Projects/tres/post-processing/node_modules/.pnpm/pathe@1.1.1/node_modules/pathe/dist/index.mjs";
import { templateCompilerOptions } from "file:///Users/alvarosabu/Projects/tres/post-processing/node_modules/.pnpm/@tresjs+core@3.5.0_three@0.158.0_vue@3.3.8/node_modules/@tresjs/core/dist/tres.js";
var __vite_injected_original_dirname = "/Users/alvarosabu/Projects/tres/post-processing/docs/.vitepress";
var config_default = defineConfig({
title: "Post-processing",
description: "Post-processing effects for ViteJS",
head: [["link", { rel: "icon", type: "image/svg", href: "/favicon.svg" }]],
themeConfig: {
logo: "/logo.svg",
search: {
provider: "local"
},
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "Guide", link: "/guide/" },
{ text: "Examples", link: "/examples" }
],
sidebar: [
{
text: "Guide",
items: [{ text: "Introduction", link: "/guide/" }]
},
{
text: "Effects",
items: [
{ text: "Bloom", link: "/guide/effects/bloom" },
{ text: "Depth of Field", link: "/guide/effects/depth-of-field" },
{ text: "Glitch", link: "/guide/effects/glitch" },
{ text: "Noise", link: "/guide/effects/noise" },
{ text: "Outline", link: "/guide/effects/outline" },
{ text: "Pixelation", link: "/guide/effects/pixelation" },
{ text: "Vignette", link: "/guide/effects/vignette" }
]
}
],
socialLinks: [
{ icon: "twitter", link: "https://twitter.com/tresjs_dev" },
{ icon: "discord", link: "https://discord.gg/UCr96AQmWn" }
]
},
vite: {
optimizeDeps: {
exclude: ["vitepress"],
include: ["three"]
},
server: {
hmr: {
overlay: false
}
},
resolve: {
alias: {
"@tresjs/post-processing": resolve(__vite_injected_original_dirname, "../../dist/tres-postprocessing.js")
},
dedupe: ["three"]
}
},
vue: {
...templateCompilerOptions
}
});
export {
config_default as default
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLnZpdGVwcmVzcy9jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMvYWx2YXJvc2FidS9Qcm9qZWN0cy90cmVzL3Bvc3QtcHJvY2Vzc2luZy9kb2NzLy52aXRlcHJlc3NcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfZmlsZW5hbWUgPSBcIi9Vc2Vycy9hbHZhcm9zYWJ1L1Byb2plY3RzL3RyZXMvcG9zdC1wcm9jZXNzaW5nL2RvY3MvLnZpdGVwcmVzcy9jb25maWcudHNcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfaW1wb3J0X21ldGFfdXJsID0gXCJmaWxlOi8vL1VzZXJzL2FsdmFyb3NhYnUvUHJvamVjdHMvdHJlcy9wb3N0LXByb2Nlc3NpbmcvZG9jcy8udml0ZXByZXNzL2NvbmZpZy50c1wiO2ltcG9ydCB7IGRlZmluZUNvbmZpZyB9IGZyb20gJ3ZpdGVwcmVzcydcbmltcG9ydCBVbm9jc3MgZnJvbSAndW5vY3NzL3ZpdGUnXG5pbXBvcnQgc3ZnTG9hZGVyIGZyb20gJ3ZpdGUtc3ZnLWxvYWRlcidcbmltcG9ydCB7IHJlc29sdmUgfSBmcm9t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QztBQUFBLFVBQ2hFLEVBQUUsTUFBTSxVQUFVLE1BQU0sd0JBQXdCO0FBQUEsVUFDaEQsRUFBRSxNQUFNLFNBQVMsTUFBTSx1QkFBdUI7QUFBQSxVQUM5QyxFQUFFLE1BQU0sV0FBVyxNQUFNLHlCQUF5QjtBQUFBLFVBQ2xELEVBQUUsTUFBTSxjQUFjLE1BQU0sNEJBQTRCO0FBQUEsVUFDeEQsRUFBRSxNQUFNLFlBQVksTUFBTSwwQkFBMEI7QUFBQSxRQUN0RDtBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsSUFFQSxhQUFhO0FBQUEsTUFDWCxFQUFFLE1BQU0sV0FBVyxNQUFNLGlDQUFpQztBQUFBLE1BQzFELEVBQUUsTUFBTSxXQUFXLE1BQU0sZ0NBQWdDO0FBQUEsSUFDM0Q7QUFBQSxFQUNGO0FBQUEsRUFDQSxNQUFNO0FBQUEsSUFDSixjQUFjO0FBQUEsTUFDWixTQUFTLENBQUMsV0FBVztBQUFBLE1BQ3JCLFNBQVMsQ0FBQyxPQUFPO0FBQUEsSUFDbkI7QUFBQSxJQUNBLFFBQVE7QUFBQSxNQUNOLEtBQUs7QUFBQSxRQUNILFNBQVM7QUFBQSxNQUNYO0FBQUEsSUFDRjtBQUFBLElBQ0EsU0FBUztBQUFBLE1BQ1AsT0FBTztBQUFBLFFBQ0wsMkJBQTJCLFFBQVEsa0NBQVcsbUNBQW1DO0FBQUEsTUFDbkY7QUFBQSxNQUNBLFFBQVEsQ0FBQyxPQUFPO0FBQUEsSUFDbEI7QUFBQSxFQUNGO0FBQUEsRUFDQSxLQUFLO0FBQUEsSUFDSCxHQUFHO0FBQUEsRUFDTDtBQUNGLENBQUM7IiwKICAibmFtZXMiOiBbXQp9Cg==
9 changes: 7 additions & 2 deletions docs/.vitepress/theme/components/BloomDemo.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { Color } from 'three'
import { reactive } from 'vue'
import { reactive, ref } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { BlendFunction } from 'postprocessing'
import { EffectComposer, Bloom } from '@tresjs/post-processing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
const gl = {
clearColor: '#121212',
shadows: true,
Expand All @@ -20,6 +22,9 @@ const bloomParams = reactive({
disableRender: true,
blendFunction: BlendFunction.ADD,
})
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand All @@ -44,7 +49,7 @@ const bloomParams = reactive({
:intensity="1"
/>
<Suspense>
<EffectComposer>
<EffectComposer ref="effectComposer">
<Bloom v-bind="bloomParams" />
</EffectComposer>
</Suspense>
Expand Down
7 changes: 6 additions & 1 deletion docs/.vitepress/theme/components/DepthOfFieldDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { gsap } from 'gsap'
import { TresCanvas } from '@tresjs/core'
import { EffectComposer, DepthOfField } from '@tresjs/post-processing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
const dofEffect = ref<InstanceType<typeof DepthOfField> | null>(null)
const toggleFocusDistance = () => {
Expand All @@ -13,6 +15,9 @@ const toggleFocusDistance = () => {
ease: 'power2',
})
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down Expand Up @@ -59,7 +64,7 @@ const toggleFocusDistance = () => {
<TresMeshNormalMaterial />
</TresMesh>
<TresGridHelper />
<EffectComposer>
<EffectComposer ref="effectComposer">
<DepthOfField
ref="dofEffect"
:focus-distance="0.0012"
Expand Down
7 changes: 6 additions & 1 deletion docs/.vitepress/theme/components/GlitchDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { Text3D } from '@tresjs/cientos'
import { EffectComposer, Glitch } from '@tresjs/post-processing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
const gl = {
clearColor: '#121212',
shadows: true,
alpha: false,
disableRender: true,
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down Expand Up @@ -40,7 +45,7 @@ const gl = {
:intensity="1"
/>
<Suspense>
<EffectComposer>
<EffectComposer ref="effectComposer">
<Glitch />
</EffectComposer>
</Suspense>
Expand Down
8 changes: 6 additions & 2 deletions docs/.vitepress/theme/components/NoiseDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { EffectComposer, Noise } from '@tresjs/post-processing'
import { OrbitControls } from '@tresjs/cientos'
import { BlendFunction } from 'postprocessing'
import '@tresjs/leches/styles'
import { useRouteDisposal } from '../composables/useRouteDisposal'
const gl = {
clearColor: '#82DBC5',
Expand All @@ -14,6 +15,9 @@ const gl = {
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand All @@ -23,7 +27,7 @@ const gl = {
<TresGridHelper />
<TresAmbientLight :intensity="1" />
<Suspense>
<EffectComposer :depth-buffer="true">
<EffectComposer ref="effectComposer">
<Noise
premultiply
:blend-function="BlendFunction.SCREEN"
Expand Down
108 changes: 68 additions & 40 deletions docs/.vitepress/theme/components/OutlineDemo.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<script lang="ts" setup>
import { ref, shallowRef } from 'vue'
import { watchOnce } from '@vueuse/core'
import { ref } from 'vue'
import type { Intersection, Object3D } from 'three'
import { NoToneMapping } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { Outline, EffectComposer } from '@tresjs/post-processing'
import { KernelSize } from 'postprocessing'
import { EffectComposer, Outline } from '@tresjs/post-processing'
import type { Intersection, Object3D } from 'three'
import { Color } from 'three'
const boxWidth = 2
import { TresLeches, useControls } from '@tresjs/leches'
import '@tresjs/leches/styles'
import { useRouteDisposal } from '../composables/useRouteDisposal'
const gl = {
clearColor: '#121212',
toneMapping: NoToneMapping,
disableRender: true,
}
const { effectComposer } = useRouteDisposal()
const outlinedObjects = ref<Object3D[]>([])
const toggleMeshSelectionState = ({ object }: Intersection) => {
Expand All @@ -16,55 +28,71 @@ const toggleMeshSelectionState = ({ object }: Intersection) => {
else outlinedObjects.value = [...outlinedObjects.value, object]
}
const meshes = shallowRef<Object3D[] | null>(null)
watchOnce(meshes, () => {
if (meshes.value?.[0]) outlinedObjects.value.push(meshes.value[0])
if (meshes.value?.[2]) outlinedObjects.value.push(meshes.value[2])
const { edgeStrength, pulseSpeed, visibleEdgeColor, blur, kernelSize } = useControls({
edgeStrength: {
value: 8000,
min: 0,
max: 8000,
step: 10,
},
pulseSpeed: {
value: 0,
min: 0,
max: 2,
step: 0.01,
},
visibleEdgeColor: '#ffffff',
blur: false,
kernelSize: {
value: 0,
min: KernelSize.VERY_SMALL,
max: KernelSize.VERY_LARGE,
step: 1,
},
})
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
useRouteDisposal(effectComposer)
</script>

<template>
<TresLeches />
<TresCanvas
clear-color="#121212"
:alpha="false"
:shadows="true"
v-bind="gl"
:disable-render="true"
>
<TresPerspectiveCamera
:position="[3, 3, 4]"
:look-at="[0, 0, 0]"
:position="[1, 3, 3]"
:look-at="[2, 2, 2]"
/>
<TresMesh
v-for="i in 3"
ref="meshes"
:key="i.toString()"
:position="[(i - 2) * boxWidth, 0.5, 1]"
@click="toggleMeshSelectionState"
<OrbitControls />
<template
v-for="i in 5"
:key="i"
>
<TresBoxGeometry />
<TresMeshStandardMaterial
color="hotpink"
:emissive="new Color('hotpink')"
:emissive-intensity="1"
/>
</TresMesh>
<TresMesh
:position="[i * 1.1 - 2.8, 1, 0]"
@click="toggleMeshSelectionState"
>
<TresBoxGeometry
:width="4"
:height="4"
:depth="4"
/>
<TresMeshStandardMaterial color="hotpink" />
</TresMesh>
</template>
<TresGridHelper />
<TresAmbientLight :intensity="2" />
<TresDirectionalLight
:position="[-4, 4, 3]"
:intensity="2"
/>

<Suspense>
<EffectComposer>
<EffectComposer ref="effectComposer">
<Outline
blur
:edge-glow="3"
:kernel-size="KernelSize.LARGE"
:edge-strength="20"
:outlined-objects="outlinedObjects"
visible-edge-color="#82DBC5"
:blur="blur.value"
:edge-strength="edgeStrength.value"
:pulse-speed="pulseSpeed.value"
:visible-edge-color="visibleEdgeColor.value"
:kernel-size="kernelSize.value"
/>
</EffectComposer>
</Suspense>
Expand Down
9 changes: 6 additions & 3 deletions docs/.vitepress/theme/components/PixelationDemo.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<script lang="ts" setup>
import { Color } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { EffectComposer, Pixelation } from '@tresjs/post-processing'
const boxWidth = 2
import { ref } from 'vue'
import { useRouteDisposal } from '../composables/useRouteDisposal'
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand Down Expand Up @@ -45,7 +48,7 @@ const boxWidth = 2
/>

<Suspense>
<EffectComposer>
<EffectComposer ref="effectComposer">
<Pixelation :granularity="8" />
</EffectComposer>
</Suspense>
Expand Down
8 changes: 7 additions & 1 deletion docs/.vitepress/theme/components/VignetteDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { TresCanvas } from '@tresjs/core'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { OrbitControls } from '@tresjs/cientos'
import { EffectComposer, Vignette, DepthOfField } from '@tresjs/post-processing'
import { useRouteDisposal } from '../composables/useRouteDisposal'
import BlenderCube from './BlenderCube.vue'
const gl = {
Expand All @@ -13,6 +16,9 @@ const gl = {
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
// Need to dispose of the effect composer when the route changes because Vitepress doesnt unmount the components
const { effectComposer } = useRouteDisposal()
</script>

<template>
Expand All @@ -23,7 +29,7 @@ const gl = {
<Suspense>
<BlenderCube />
</Suspense>
<EffectComposer>
<EffectComposer ref="effectComposer">
<DepthOfField
:focus-distance="0"
:focal-length="0.02"
Expand Down
17 changes: 17 additions & 0 deletions docs/.vitepress/theme/composables/useRouteDisposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ref, watch } from 'vue'
import { useRouter } from 'vitepress'
import type { EffectComposer } from '@tresjs/post-processing'

export function useRouteDisposal() {
const router = useRouter()

const effectComposer = ref<InstanceType<typeof EffectComposer> | null>(null)

watch(() => router.route.data.relativePath, () => {
effectComposer.value?.composer.dispose()
})

return {
effectComposer,
}
}
Loading

0 comments on commit 4878a95

Please sign in to comment.