Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add <Fbo /> abstraction #228

Merged
merged 28 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f8e3cf3
[broken] add `useFBO`
kekkorider Sep 21, 2023
e97cb3d
Use `useTresContext` in `useFBO`
kekkorider Sep 21, 2023
97ba472
Lint
kekkorider Sep 21, 2023
9a97aaa
Refactor to renderless component
kekkorider Sep 21, 2023
5e8e04e
Lint
kekkorider Sep 21, 2023
9bb8483
Setup docs page
kekkorider Sep 21, 2023
4546a0a
Lint
kekkorider Sep 22, 2023
b37bd13
Refactor to renderless component
kekkorider Sep 26, 2023
3c74131
Test with Alvaro
kekkorider Sep 27, 2023
bbd087e
fix: check for `.value` in depth check
kekkorider Sep 27, 2023
404b182
fix: `depth` was setting `depthBuffer`
kekkorider Sep 27, 2023
ca56d65
feat: added sizes as default if width and height are not explicity set
alvarosabu Sep 28, 2023
4e0408b
feat: add composable + component approach
alvarosabu Sep 28, 2023
8767bfa
chore: forcing rename of folder for casing issues
alvarosabu Sep 28, 2023
7ee0a18
chore: rename back
alvarosabu Sep 28, 2023
4971fb8
Update docs
kekkorider Oct 5, 2023
e7b334b
Finalize docs of `<Fbo />`
kekkorider Oct 5, 2023
eccead2
Finalize docs
kekkorider Oct 5, 2023
789629c
Fix default values for `width` and `height`
kekkorider Oct 5, 2023
07a4a11
Fix typo
kekkorider Oct 6, 2023
81acaed
Update global components
kekkorider Oct 6, 2023
49c717c
Remove `docs/components.d.ts`
kekkorider Oct 6, 2023
0add19d
Use separate pages for `<Fbo />` and `useFBO`
kekkorider Oct 6, 2023
33002ae
Import demos
kekkorider Oct 6, 2023
2a5da98
Lint `UseFBODemo.vue`
kekkorider Oct 6, 2023
38e76aa
Refactor `UseFBODemo`
kekkorider Oct 6, 2023
ac994e0
Add warning about usage in child component
kekkorider Oct 6, 2023
54b3730
chore: fix route for examples on playground and color of cube
alvarosabu Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default defineConfig({
{ text: 'MouseParallax', link: '/guide/abstractions/mouse-parallax' },
{ text: 'Lensflare', link: '/guide/abstractions/lensflare' },
{ text: 'GlobalAudio', link: '/guide/abstractions/global-audio' },
{ text: 'Fbo', link: '/guide/abstractions/fbo' },
{ text: 'useFBO', link: '/guide/abstractions/use-fbo' },
],
},
{
Expand Down
23 changes: 23 additions & 0 deletions docs/.vitepress/theme/components/FboCube.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { useFBO } from '@tresjs/cientos'

const fboTarget = useFBO({
depth: true,
width: 512,
height: 512,
settings: {
samples: 1,
},
})
</script>

<template>
<TresMesh>
<TresBoxGeometry :args="[1, 1, 1]" />

<TresMeshBasicMaterial
:color="0xffffff"
:map="fboTarget?.texture ?? null"
/>
</TresMesh>
</template>
78 changes: 78 additions & 0 deletions docs/.vitepress/theme/components/FboDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<script setup lang="ts">
import { TresCanvas, useRenderLoop } from '@tresjs/core'
import { OrbitControls, Fbo } from '@tresjs/cientos'
import { SRGBColorSpace, ACESFilmicToneMapping } from 'three'
import { ref, shallowRef, shallowReactive, onMounted, nextTick } from 'vue'

const gl = {
clearColor: '#82DBC5',
shadows: true,
alpha: false,
outputColorSpace: SRGBColorSpace,
toneMapping: ACESFilmicToneMapping,
}

const fboRef = ref(null)
const torusRef = shallowRef(null)
const capsuleRef = shallowRef(null)

const { onLoop } = useRenderLoop()

const state = shallowReactive({
depth: false,
settings: {
samples: 1,
},
})

onMounted(async () => {
await nextTick()

onLoop(({ elapsed }) => {
torusRef.value.rotation.x = elapsed * 0.745
torusRef.value.rotation.y = elapsed * 0.361

capsuleRef.value.rotation.x = elapsed * 0.471
capsuleRef.value.rotation.z = elapsed * 0.632
})
})
</script>

<template>
<TresCanvas v-bind="gl">
<TresPerspectiveCamera :position="[0, 0.5, 5]" />
<OrbitControls />

<TresGridHelper :args="[10, 10]" />

<Fbo
ref="fboRef"
v-bind="state"
/>

<TresMesh>
<TresBoxGeometry :args="[1, 1, 1]" />

<TresMeshBasicMaterial
:color="0xffffff"
:map="fboRef?.value.texture ?? null"
/>
</TresMesh>

<TresMesh
ref="torusRef"
:position="[3, 0, 0]"
>
<TresTorusGeometry :args="[1, 0.5, 16, 100]" />
<TresMeshNormalMaterial />
</TresMesh>

<TresMesh
ref="capsuleRef"
:position="[-2, 0, 0]"
>
<TresCapsuleGeometry :args="[0.4, 1, 4, 8]" />
<TresMeshNormalMaterial />
</TresMesh>
</TresCanvas>
</template>
58 changes: 58 additions & 0 deletions docs/.vitepress/theme/components/UseFBODemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script setup lang="ts">
import { TresCanvas, useRenderLoop } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { SRGBColorSpace, ACESFilmicToneMapping } from 'three'
import { shallowRef, onMounted, nextTick } from 'vue'

const gl = {
clearColor: '#82DBC5',
shadows: true,
alpha: false,
outputColorSpace: SRGBColorSpace,
toneMapping: ACESFilmicToneMapping,
}

const torusRef = shallowRef(null)
const capsuleRef = shallowRef(null)

const { onLoop } = useRenderLoop()

onMounted(async () => {
await nextTick()

onLoop(({ elapsed }) => {
torusRef.value.rotation.x = elapsed * 0.745
torusRef.value.rotation.y = elapsed * 0.361

capsuleRef.value.rotation.x = elapsed * 0.471
capsuleRef.value.rotation.z = elapsed * 0.632
})
})
</script>

<template>
<TresCanvas v-bind="gl">
<TresPerspectiveCamera :position="[0, 0.5, 5]" />
<OrbitControls />

<TresGridHelper :args="[10, 10]" />

<FboCube />

<TresMesh
ref="torusRef"
:position="[3, 0, 0]"
>
<TresTorusGeometry :args="[1, 0.5, 16, 100]" />
<TresMeshNormalMaterial />
</TresMesh>

<TresMesh
ref="capsuleRef"
:position="[-2, 0, 0]"
>
<TresCapsuleGeometry :args="[0.4, 1, 4, 8]" />
<TresMeshNormalMaterial />
</TresMesh>
</TresCanvas>
</template>
49 changes: 0 additions & 49 deletions docs/components.d.ts

This file was deleted.

22 changes: 22 additions & 0 deletions docs/guide/abstractions/fbo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Fbo <Badge type="warning" text="^3.5.0" />

An FBO (or Frame Buffer Object) is generally used to render to a texture. This is useful for post-processing effects like blurring, or for rendering to a texture that will be used as a texture in a later draw call.

Cientos provides an `<Fbo />` component make it easy to use FBOs in your application.

<DocsDemo>
<FboDemo />
</DocsDemo>

## Usage

<<< @/.vitepress/theme/components/FboDemo.vue{3,15,48,49,50,51,58}

## Props

| Prop | Description | Default |
| :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| **`width`** | `number` - The width of the FBO. | Width of the canvas |
| **`height`** | `number` - the height of the FBO | Height of the canvas |
| **`depth`** | `boolean` - Whether or not the FBO should render the depth to a [`depthTexture`](https://threejs.org/docs/?q=webglre#api/en/renderers/WebGLRenderTarget.depthTexture). | `false` |
| **`settings`** | `WebGLRenderTargetOptions` - Every other configuration property for the [`WebGLRenderTarget` class](https://threejs.org/docs/#api/en/renderers/WebGLRenderTarget) | `{}` |
32 changes: 32 additions & 0 deletions docs/guide/abstractions/use-fbo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# useFBO <Badge type="warning" text="^3.5.0" />

An FBO (or Frame Buffer Object) is generally used to render to a texture. This is useful for post-processing effects like blurring, or for rendering to a texture that will be used as a texture in a later draw call.

Cientos provides a `useFBO` composable to make it easy to use FBOs in your application.

::: warning
The `useFBO` composable must be used inside of a child component since it needs the context of TresCanvas.
:::

<DocsDemo>
<UseFBODemo />
</DocsDemo>

## Usage

`FboCube.vue`

<<< @/.vitepress/theme/components/FboCube.vue{2,4,5,6,7,8,9,10,11,20}

`Experience.vue`

<<< @/.vitepress/theme/components/UseFBODemo.vue{40}

## Props

| Prop | Description | Default |
| :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| **`width`** | `number` - The width of the FBO. | Width of the canvas |
| **`height`** | `number` - the height of the FBO | Height of the canvas |
| **`depth`** | `boolean` - Whether or not the FBO should render the depth to a [`depthTexture`](https://threejs.org/docs/?q=webglre#api/en/renderers/WebGLRenderTarget.depthTexture). | `false` |
| **`settings`** | `WebGLRenderTargetOptions` - Every other configuration property for the [`WebGLRenderTarget` class](https://threejs.org/docs/#api/en/renderers/WebGLRenderTarget) | `{}` |
1 change: 1 addition & 0 deletions playground/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module 'vue' {
export interface GlobalComponents {
AkuAku: typeof import('./src/components/AkuAku.vue')['default']
DirectivesDemo: typeof import('./src/components/DirectivesDemo.vue')['default']
FboCube: typeof import('./src/components/FboCube.vue')['default']
Gltf: typeof import('./src/components/gltf/index.vue')['default']
ModelsDemo: typeof import('./src/components/ModelsDemo.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
Expand Down
23 changes: 23 additions & 0 deletions playground/src/components/FboCube.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { useFBO } from '@tresjs/cientos'

const fboTarget = useFBO({
depth: true,
width: 512,
height: 512,
settings: {
samples: 1,
},
})
</script>

<template>
<TresMesh>
<TresBoxGeometry :args="[1, 1, 1]" />

<TresMeshBasicMaterial
:color="0xff8833"
:map="fboTarget?.texture ?? null"
/>
</TresMesh>
</template>
Loading