@@ -6,4 +6,99 @@ description: A realistic glass/plastic effect, play with it!
6
6
tags : ['materials', 'useTweakPane']
7
7
---
8
8
9
- <GlassExample />
9
+ :: glass-example
10
+ ::
11
+
12
+ :: the-info
13
+
14
+ ![ Glass material] ( /glass-example.png )
15
+
16
+ # Glass material
17
+
18
+ Author: [ @** jaimebboyjt** ] ( https://twitter.com/jaimebboyjt ) .
19
+
20
+ > This effect is base on: https://tympanus.net/codrops/2021/10/27/creating-the-effect-of-transparent-glass-and-plastic-in-three-js/
21
+
22
+ ``` vue
23
+ // App.vue
24
+ <script setup>
25
+ import { EquirectangularReflectionMapping } from 'three'
26
+ import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader'
27
+
28
+ const { map, normalMap } = await useTexture({
29
+ map: 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/glass-effect/bg-texture.jpg',
30
+ normalMap: 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/glass-effect/normal-example.jpg',
31
+ })
32
+
33
+ const planeRef = shallowRef(null)
34
+
35
+ // the hdrEquirect image add a beautiful realistic glass effect
36
+ const hdrEquirect = await new RGBELoader().load(
37
+ 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/glass-effect/glass-effect.hdr',
38
+ () => {
39
+ hdrEquirect.mapping = EquirectangularReflectionMapping
40
+ },
41
+ )
42
+
43
+ const options = reactive({
44
+ transmission: 1,
45
+ thickness: 0.5,
46
+ roughness: 0,
47
+ envMap: hdrEquirect,
48
+ clearcoatNormalMap: normalMap,
49
+ envMapIntensity: 1.5,
50
+ })
51
+
52
+ const { pane } = useTweakPane()
53
+ pane.addInput(options, 'transmission', {
54
+ label: 'transmission',
55
+ min: 0,
56
+ max: 1,
57
+ step: 0.01,
58
+ })
59
+ pane.addInput(options, 'thickness', {
60
+ label: 'thickness',
61
+ min: 0,
62
+ max: 1,
63
+ step: 0.01,
64
+ })
65
+ pane.addInput(options, 'envMapIntensity', {
66
+ label: 'envMapIntensity',
67
+ min: 0,
68
+ max: 3,
69
+ step: 0.1,
70
+ })
71
+ pane.addInput(options, 'roughness', {
72
+ label: 'roughness',
73
+ min: 0,
74
+ max: 1,
75
+ step: 0.01,
76
+ })
77
+
78
+ const hdrEquiredButton = pane.addButton({
79
+ title: 'Enable/Disable hdrEquired',
80
+ })
81
+ hdrEquiredButton.on('click', () => {
82
+ options.envMap = options.envMap ? null : hdrEquirect
83
+ })
84
+ </script>
85
+ <template>
86
+ <TresCanvas window-size clear-color="#F7F7F7" class="over-hidden" grid>
87
+ <TresPerspectiveCamera :position="[0, 0, 3]" :fov="45" :aspect="1" :near="0.1" :far="1000" />
88
+ <OrbitControls />
89
+ <TresGridHelper :args="[30, 30]" :position="[0, -2.5, 0]" />
90
+ <TresMesh :position="[-0, 0, 0]">
91
+ <TresIcosahedronGeometry :args="[1, 10]" />
92
+ <TresMeshPhysicalMaterial v-bind="options" />
93
+ </TresMesh>
94
+ <TresMesh ref="planeRef" :position="[0, 0, -1]">
95
+ <TresPlaneGeometry :args="[5, 5]" />
96
+ <TresMeshBasicMaterial :map="map" />
97
+ </TresMesh>
98
+ <TresDirectionalLight :position="[0, 2, 4]" :intensity="2" cast-shadow />
99
+ <TresAmbientLight />
100
+ </TresCanvas>
101
+ </template>
102
+ ```
103
+
104
+ ::
0 commit comments