|
| 1 | +<script setup lang="ts"> |
| 2 | +import { Color, BasicShadowMap, NoToneMapping } from 'three' |
| 3 | +import { TresCanvas } from '@tresjs/core' |
| 4 | +import { OrbitControls, useTweakPane } from '@tresjs/cientos' |
| 5 | +import { BlendFunction, KernelSize } from 'postprocessing' |
| 6 | +import { EffectComposer, Bloom } from '@tresjs/post-processing' |
| 7 | +import { onMounted, reactive, ref, watch } from 'vue' |
| 8 | +import { TresLeches, useControls } from '@tresjs/leches' |
| 9 | +import '@tresjs/leches/styles' |
| 10 | +
|
| 11 | +const gl = { |
| 12 | + clearColor: '#121212', |
| 13 | + shadows: true, |
| 14 | + alpha: false, |
| 15 | + shadowMapType: BasicShadowMap, |
| 16 | + toneMapping: NoToneMapping, |
| 17 | +} |
| 18 | +
|
| 19 | +useControls('fpsgraph') |
| 20 | +
|
| 21 | +const materialRef = ref() |
| 22 | +const { |
| 23 | + intensity, |
| 24 | + blendFunction, |
| 25 | + resolution, |
| 26 | + kernelSize, |
| 27 | + mipmapBlur, |
| 28 | +} = useControls({ |
| 29 | + intensity: { |
| 30 | + value: 4.0, |
| 31 | + min: 0, |
| 32 | + max: 10, |
| 33 | + step: 0.1, |
| 34 | + }, |
| 35 | + blendFunction: { |
| 36 | + options: Object.keys(BlendFunction).map(key => ({ |
| 37 | + text: key, |
| 38 | + value: BlendFunction[key], |
| 39 | + })), |
| 40 | + value: BlendFunction.ADD, |
| 41 | + }, |
| 42 | + resolution: { |
| 43 | + value: 256, |
| 44 | + min: 64, |
| 45 | + max: 512, |
| 46 | + step: 64, |
| 47 | + }, |
| 48 | + kernelSize: { |
| 49 | + options: Object.keys(KernelSize).map(key => ({ |
| 50 | + text: key, |
| 51 | + value: KernelSize[key], |
| 52 | + })), |
| 53 | + value: KernelSize.VERY_SMALL, |
| 54 | + }, |
| 55 | + mipmapBlur: true, |
| 56 | +}) |
| 57 | +
|
| 58 | +const { threshold, smoothing } = useControls('luminance', { |
| 59 | + threshold: { |
| 60 | + value: 0.2, |
| 61 | + min: 0, |
| 62 | + max: 1, |
| 63 | + step: 0.01, |
| 64 | + }, |
| 65 | + smoothing: { |
| 66 | + value: 0.3, |
| 67 | + min: 0, |
| 68 | + max: 1, |
| 69 | + step: 0.01, |
| 70 | + }, |
| 71 | +}) |
| 72 | +
|
| 73 | +onMounted(() => { |
| 74 | + if (materialRef.value) { |
| 75 | + const { value: emissiveIntensity } = useControls({ |
| 76 | + emissiveIntensity: { |
| 77 | + value: 1, |
| 78 | + min: 0, |
| 79 | + max: 10, |
| 80 | + step: 0.1, |
| 81 | + }, |
| 82 | + }) |
| 83 | + |
| 84 | + watch(emissiveIntensity, (newValue) => { |
| 85 | + materialRef.value.emissiveIntensity = newValue |
| 86 | + }) |
| 87 | + } |
| 88 | +}) |
| 89 | +</script> |
| 90 | + |
| 91 | +<template> |
| 92 | + <TresLeches /> |
| 93 | + <TresCanvas |
| 94 | + v-bind="gl" |
| 95 | + :disable-render="true" |
| 96 | + > |
| 97 | + <TresPerspectiveCamera |
| 98 | + :position="[5, 5, 5]" |
| 99 | + :look-at="[0, 0, 0]" |
| 100 | + /> |
| 101 | + <OrbitControls /> |
| 102 | + <TresMesh> |
| 103 | + <TresSphereGeometry :args="[2, 32, 32]" /> |
| 104 | + <TresMeshStandardMaterial |
| 105 | + color="hotpink" |
| 106 | + :emissive="new Color('hotpink')" |
| 107 | + :emissive-intensity="9" |
| 108 | + /> |
| 109 | + </TresMesh> |
| 110 | + <TresMesh :position="[2, 2, -2]"> |
| 111 | + <TresSphereGeometry :args="[2, 32, 32]" /> |
| 112 | + <TresMeshStandardMaterial color="hotpink" /> |
| 113 | + </TresMesh> |
| 114 | + <TresMesh> |
| 115 | + <TresSphereGeometry :args="[2, 32, 32]" /> |
| 116 | + <TresMeshStandardMaterial |
| 117 | + ref="materialRef" |
| 118 | + color="hotpink" |
| 119 | + :emissive="new Color('hotpink')" |
| 120 | + :emissive-intensity="1" |
| 121 | + /> |
| 122 | + </TresMesh> |
| 123 | + <TresGridHelper /> |
| 124 | + <TresAmbientLight :intensity="0.5" /> |
| 125 | + <TresDirectionalLight |
| 126 | + :position="[3, 3, 3]" |
| 127 | + :intensity="2" |
| 128 | + /> |
| 129 | + <Suspense> |
| 130 | + <EffectComposer :depth-buffer="true"> |
| 131 | + <Bloom |
| 132 | + :luminance-threshold="threshold.value" |
| 133 | + :luminance-smoothing="smoothing.value" |
| 134 | + :intensity="intensity.value" |
| 135 | + :blend-function="blendFunction.value" |
| 136 | + :kernel-size="kernelSize.value" |
| 137 | + :resolution="resolution.value" |
| 138 | + :mipmap-blur="mipmapBlur.value" |
| 139 | + /> |
| 140 | + </EffectComposer> |
| 141 | + </Suspense> |
| 142 | + </TresCanvas> |
| 143 | +</template> |
0 commit comments