-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b94a70
commit 26269df
Showing
4 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
docs/.vitepress/theme/components/CustomShaderMaterialDemo.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<script setup lang="ts"> | ||
import { TresCanvas, useRenderLoop } from '@tresjs/core' | ||
import { | ||
CustomShaderMaterial, | ||
useTweakPane, | ||
OrbitControls, | ||
} from '@tresjs/cientos' | ||
import { MeshBasicMaterial } from 'three' | ||
import { onMounted, nextTick } from 'vue' | ||
const { onLoop } = useRenderLoop() | ||
const gl = { | ||
clearColor: '#82DBC5', | ||
} | ||
const materialProps = { | ||
baseMaterial: MeshBasicMaterial, | ||
fragmentShader: ` | ||
varying float vWobble; | ||
uniform float u_Time; | ||
void main() { | ||
float wobble = vWobble * 0.5 + 0.5; | ||
csm_FragColor = mix(vec4(0.0, 0.4, 1.5, 1.0), vec4(1.2, 0.6, 0.8, 1.0), wobble); | ||
} | ||
`, | ||
vertexShader: ` | ||
uniform float u_Time; | ||
uniform float u_WobbleSpeed; | ||
uniform float u_WobbleAmplitude; | ||
uniform float u_WobbleFrequency; | ||
varying float vWobble; | ||
void main() { | ||
float wobble = sin(csm_Position.z * u_WobbleFrequency + u_Time * u_WobbleSpeed); | ||
csm_Position += normal * wobble * u_WobbleAmplitude; | ||
vWobble = wobble; | ||
} | ||
`, | ||
uniforms: { | ||
u_Time: { value: 0 }, | ||
u_WobbleSpeed: { value: 3 }, | ||
u_WobbleAmplitude: { value: 0.07 }, | ||
u_WobbleFrequency: { value: 3 }, | ||
}, | ||
} | ||
onMounted(async () => { | ||
await nextTick() | ||
createDebugPanel() | ||
onLoop(() => { | ||
materialProps.uniforms.u_Time.value | ||
+= 0.01 * materialProps.uniforms.u_WobbleSpeed.value | ||
}) | ||
}) | ||
function createDebugPanel() { | ||
const { pane } = useTweakPane('.debug-container') | ||
const folder = pane.addFolder({ | ||
title: 'Settings', | ||
}) | ||
folder.addInput(materialProps.uniforms.u_WobbleSpeed, 'value', { | ||
label: 'Wobble Speed', | ||
min: 0, | ||
max: 10, | ||
}) | ||
folder.addInput(materialProps.uniforms.u_WobbleAmplitude, 'value', { | ||
label: 'Wobble Amplitude', | ||
min: 0, | ||
max: 0.2, | ||
}) | ||
folder.addInput(materialProps.uniforms.u_WobbleFrequency, 'value', { | ||
label: 'Wobble Frequency', | ||
min: 1, | ||
max: 30, | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<TresCanvas v-bind="gl"> | ||
<TresPerspectiveCamera | ||
:position="[0, 2, 4]" | ||
:look-at="[0, 0, 0]" | ||
/> | ||
|
||
<OrbitControls /> | ||
|
||
<TresMesh> | ||
<TresTorusKnotGeometry :args="[1, 0.3, 512, 32]" /> | ||
<CustomShaderMaterial v-bind="materialProps" /> | ||
</TresMesh> | ||
</TresCanvas> | ||
|
||
<div class="debug-container" /> | ||
</template> | ||
|
||
<style scoped> | ||
.debug-container { | ||
position: absolute; | ||
top: 0px; | ||
right: 0px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# TresCustomShaderMaterial <Badge type="warning" text="^3.6.0" /> | ||
|
||
<DocsDemo> | ||
<CustomShaderMaterialDemo /> | ||
</DocsDemo> | ||
|
||
The `cientos` package provides a new `<TresCustomShaderMaterial />` component which is a wrapper around the [`three-custom-shader-material`](https://github.com/FarazzShaikh/THREE-CustomShaderMaterial) class. As states in the repo, it _"lets you extend Three.js' material library with your own Vertex and Fragment shaders"_. | ||
|
||
## Usage | ||
|
||
<<< @/.vitepress/theme/components/CustomshaderMaterialDemo.vue{4,9,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,59,60,99} | ||
|
||
## Props | ||
|
||
Being a wrapper around the `CustomShaderMaterial` class, the `<TresCustomShaderMaterial />` component accepts all the props that the class does. You can find the full list of props in the [official repo](https://github.com/FarazzShaikh/THREE-CustomShaderMaterial). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters