|
56 | 56 |
|
57 | 57 | if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); |
58 | 58 |
|
59 | | - THREE.CustomShaderLib = { |
| 59 | + THREE.ShaderLib.customDepthRGBA = { // this is a cut-and-paste of the depth shader -- modified to accommodate instancing for this app |
60 | 60 |
|
61 | | - customDepthRGBA: { // this is a cut-and-paste of the depth shader -- modified to accommodate instancing for this app |
| 61 | + uniforms: THREE.ShaderLib.depth.uniforms, |
62 | 62 |
|
63 | | - uniforms: THREE.ShaderLib.depth.uniforms, |
| 63 | + vertexShader: |
| 64 | + ` |
| 65 | + // instanced |
| 66 | + #ifdef INSTANCED |
64 | 67 |
|
65 | | - vertexShader: |
66 | | - ` |
67 | | - // instanced |
68 | | - #ifdef INSTANCED |
| 68 | + attribute vec3 instanceOffset; |
| 69 | + attribute float instanceScale; |
69 | 70 |
|
70 | | - attribute vec3 instanceOffset; |
71 | | - attribute float instanceScale; |
| 71 | + #endif |
72 | 72 |
|
73 | | - #endif |
| 73 | + #include <common> |
| 74 | + #include <uv_pars_vertex> |
| 75 | + #include <displacementmap_pars_vertex> |
| 76 | + #include <morphtarget_pars_vertex> |
| 77 | + #include <skinning_pars_vertex> |
| 78 | + #include <logdepthbuf_pars_vertex> |
| 79 | + #include <clipping_planes_pars_vertex> |
74 | 80 |
|
75 | | - #include <common> |
76 | | - #include <uv_pars_vertex> |
77 | | - #include <displacementmap_pars_vertex> |
78 | | - #include <morphtarget_pars_vertex> |
79 | | - #include <skinning_pars_vertex> |
80 | | - #include <logdepthbuf_pars_vertex> |
81 | | - #include <clipping_planes_pars_vertex> |
| 81 | + void main() { |
82 | 82 |
|
83 | | - void main() { |
| 83 | + #include <uv_vertex> |
84 | 84 |
|
85 | | - #include <uv_vertex> |
| 85 | + #include <skinbase_vertex> |
86 | 86 |
|
87 | | - #include <skinbase_vertex> |
| 87 | + #ifdef USE_DISPLACEMENTMAP |
88 | 88 |
|
89 | | - #ifdef USE_DISPLACEMENTMAP |
| 89 | + #include <beginnormal_vertex> |
| 90 | + #include <morphnormal_vertex> |
| 91 | + #include <skinnormal_vertex> |
90 | 92 |
|
91 | | - #include <beginnormal_vertex> |
92 | | - #include <morphnormal_vertex> |
93 | | - #include <skinnormal_vertex> |
| 93 | + #endif |
94 | 94 |
|
95 | | - #endif |
| 95 | + #include <begin_vertex> |
96 | 96 |
|
97 | | - #include <begin_vertex> |
| 97 | + // instanced |
| 98 | + #ifdef INSTANCED |
98 | 99 |
|
99 | | - // instanced |
100 | | - #ifdef INSTANCED |
| 100 | + transformed *= instanceScale; |
| 101 | + transformed = transformed + instanceOffset; |
101 | 102 |
|
102 | | - transformed *= instanceScale; |
103 | | - transformed = transformed + instanceOffset; |
| 103 | + #endif |
104 | 104 |
|
105 | | - #endif |
| 105 | + #include <morphtarget_vertex> |
| 106 | + #include <skinning_vertex> |
| 107 | + #include <displacementmap_vertex> |
| 108 | + #include <project_vertex> |
| 109 | + #include <logdepthbuf_vertex> |
| 110 | + #include <clipping_planes_vertex> |
106 | 111 |
|
107 | | - #include <morphtarget_vertex> |
108 | | - #include <skinning_vertex> |
109 | | - #include <displacementmap_vertex> |
110 | | - #include <project_vertex> |
111 | | - #include <logdepthbuf_vertex> |
112 | | - #include <clipping_planes_vertex> |
| 112 | + } |
| 113 | + `, |
113 | 114 |
|
114 | | - } |
115 | | - `, |
| 115 | + fragmentShader: THREE.ShaderChunk.depth_frag |
116 | 116 |
|
117 | | - fragmentShader: THREE.ShaderChunk.depth_frag |
| 117 | + }; |
118 | 118 |
|
119 | | - }, |
| 119 | + THREE.ShaderLib.lambert = { // this is a cut-and-paste of the lambert shader -- modified to accommodate instancing for this app |
120 | 120 |
|
121 | | - lambert: { // this is a cut-and-paste of the lambert shader -- modified to accommodate instancing for this app |
| 121 | + uniforms: THREE.ShaderLib.lambert.uniforms, |
122 | 122 |
|
123 | | - uniforms: THREE.ShaderLib.lambert.uniforms, |
| 123 | + vertexShader: |
| 124 | + ` |
| 125 | + #define LAMBERT |
124 | 126 |
|
125 | | - vertexShader: |
126 | | - ` |
127 | | - #define LAMBERT |
| 127 | + #ifdef INSTANCED |
| 128 | + attribute vec3 instanceOffset; |
| 129 | + attribute vec3 instanceColor; |
| 130 | + attribute float instanceScale; |
| 131 | + #endif |
128 | 132 |
|
129 | | - #ifdef INSTANCED |
130 | | - attribute vec3 instanceOffset; |
131 | | - attribute vec3 instanceColor; |
132 | | - attribute float instanceScale; |
133 | | - #endif |
| 133 | + varying vec3 vLightFront; |
134 | 134 |
|
135 | | - varying vec3 vLightFront; |
| 135 | + #ifdef DOUBLE_SIDED |
136 | 136 |
|
137 | | - #ifdef DOUBLE_SIDED |
| 137 | + varying vec3 vLightBack; |
138 | 138 |
|
139 | | - varying vec3 vLightBack; |
| 139 | + #endif |
140 | 140 |
|
141 | | - #endif |
| 141 | + #include <common> |
| 142 | + #include <uv_pars_vertex> |
| 143 | + #include <uv2_pars_vertex> |
| 144 | + #include <envmap_pars_vertex> |
| 145 | + #include <bsdfs> |
| 146 | + #include <lights_pars_begin> |
| 147 | + #include <lights_pars_maps> |
| 148 | + #include <color_pars_vertex> |
| 149 | + #include <fog_pars_vertex> |
| 150 | + #include <morphtarget_pars_vertex> |
| 151 | + #include <skinning_pars_vertex> |
| 152 | + #include <shadowmap_pars_vertex> |
| 153 | + #include <logdepthbuf_pars_vertex> |
| 154 | + #include <clipping_planes_pars_vertex> |
142 | 155 |
|
143 | | - #include <common> |
144 | | - #include <uv_pars_vertex> |
145 | | - #include <uv2_pars_vertex> |
146 | | - #include <envmap_pars_vertex> |
147 | | - #include <bsdfs> |
148 | | - #include <lights_pars_begin> |
149 | | - #include <lights_pars_maps> |
150 | | - #include <color_pars_vertex> |
151 | | - #include <fog_pars_vertex> |
152 | | - #include <morphtarget_pars_vertex> |
153 | | - #include <skinning_pars_vertex> |
154 | | - #include <shadowmap_pars_vertex> |
155 | | - #include <logdepthbuf_pars_vertex> |
156 | | - #include <clipping_planes_pars_vertex> |
157 | | -
|
158 | | - void main() { |
159 | | -
|
160 | | - #include <uv_vertex> |
161 | | - #include <uv2_vertex> |
162 | | - #include <color_vertex> |
163 | | -
|
164 | | - // vertex colors instanced |
165 | | - #ifdef INSTANCED |
166 | | - #ifdef USE_COLOR |
167 | | - vColor.xyz = instanceColor.xyz; |
168 | | - #endif |
169 | | - #endif |
| 156 | + void main() { |
170 | 157 |
|
171 | | - #include <beginnormal_vertex> |
172 | | - #include <morphnormal_vertex> |
173 | | - #include <skinbase_vertex> |
174 | | - #include <skinnormal_vertex> |
175 | | - #include <defaultnormal_vertex> |
| 158 | + #include <uv_vertex> |
| 159 | + #include <uv2_vertex> |
| 160 | + #include <color_vertex> |
176 | 161 |
|
177 | | - #include <begin_vertex> |
178 | | -
|
179 | | - // position instanced |
180 | | - #ifdef INSTANCED |
181 | | - transformed *= instanceScale; |
182 | | - transformed = transformed + instanceOffset; |
| 162 | + // vertex colors instanced |
| 163 | + #ifdef INSTANCED |
| 164 | + #ifdef USE_COLOR |
| 165 | + vColor.xyz = instanceColor.xyz; |
183 | 166 | #endif |
| 167 | + #endif |
| 168 | +
|
| 169 | + #include <beginnormal_vertex> |
| 170 | + #include <morphnormal_vertex> |
| 171 | + #include <skinbase_vertex> |
| 172 | + #include <skinnormal_vertex> |
| 173 | + #include <defaultnormal_vertex> |
| 174 | +
|
| 175 | + #include <begin_vertex> |
184 | 176 |
|
185 | | - #include <morphtarget_vertex> |
186 | | - #include <skinning_vertex> |
187 | | - #include <project_vertex> |
188 | | - #include <logdepthbuf_vertex> |
189 | | - #include <clipping_planes_vertex> |
| 177 | + // position instanced |
| 178 | + #ifdef INSTANCED |
| 179 | + transformed *= instanceScale; |
| 180 | + transformed = transformed + instanceOffset; |
| 181 | + #endif |
190 | 182 |
|
191 | | - #include <worldpos_vertex> |
192 | | - #include <envmap_vertex> |
193 | | - #include <lights_lambert_vertex> |
194 | | - #include <shadowmap_vertex> |
195 | | - #include <fog_vertex> |
| 183 | + #include <morphtarget_vertex> |
| 184 | + #include <skinning_vertex> |
| 185 | + #include <project_vertex> |
| 186 | + #include <logdepthbuf_vertex> |
| 187 | + #include <clipping_planes_vertex> |
196 | 188 |
|
197 | | - } |
198 | | - `, |
| 189 | + #include <worldpos_vertex> |
| 190 | + #include <envmap_vertex> |
| 191 | + #include <lights_lambert_vertex> |
| 192 | + #include <shadowmap_vertex> |
| 193 | + #include <fog_vertex> |
199 | 194 |
|
200 | | - fragmentShader: THREE.ShaderLib.lambert.fragmentShader |
| 195 | + } |
| 196 | + `, |
201 | 197 |
|
202 | | - } |
| 198 | + fragmentShader: THREE.ShaderLib.lambert.fragmentShader |
203 | 199 |
|
204 | 200 | }; |
205 | 201 |
|
| 202 | + |
206 | 203 | // |
207 | 204 |
|
208 | 205 | var mesh, renderer, scene, camera, controls; |
|
303 | 300 | var envMap = new THREE.TextureLoader().load( `textures/metal.jpg`, function ( texture ) { |
304 | 301 |
|
305 | 302 | texture.mapping = THREE.SphericalReflectionMapping; |
| 303 | + texture.encoding = THREE.sRGBEncoding; |
| 304 | + if ( mesh ) mesh.material.needsUpdate = true; |
306 | 305 |
|
307 | 306 | } ); |
308 | 307 |
|
309 | | - var shader = THREE.CustomShaderLib[ 'lambert' ]; |
| 308 | + var material = new THREE.MeshLambertMaterial( { |
310 | 309 |
|
311 | | - var uniforms = THREE.UniformsUtils.clone( shader.uniforms ); |
312 | | - |
313 | | - uniforms[ "diffuse" ].value.set( 0xffb54a ); |
314 | | - uniforms[ "envMap" ].value = envMap; |
315 | | - uniforms[ "reflectivity" ].value = 1; |
316 | | - |
317 | | - // defines - Since we are reusing the ShaderChunks, we must specify the required defines. |
318 | | - // The renderer does not set these defines for ShaderMaterial |
319 | | - |
320 | | - var defines = { |
321 | | - 'INSTANCED': "", |
322 | | - 'USE_ENVMAP': "", |
323 | | - 'ENVMAP_TYPE_SPHERE': "", |
324 | | - 'ENVMAP_MODE_REFLECTION': "", |
325 | | - 'ENVMAP_BLENDING_MULTIPLY': "", |
326 | | - }; |
327 | | - |
328 | | - var material = new THREE.ShaderMaterial( { |
329 | | - |
330 | | - // Material and ShaderMaterial properties can be set here -- except opacity |
331 | | - // the Lambert-properties must be set in the uniforms or defines |
332 | | - |
333 | | - defines: defines, |
334 | | - uniforms: uniforms, |
335 | | - vertexShader: shader.vertexShader, |
336 | | - fragmentShader: shader.fragmentShader, |
| 310 | + color: 0xffb54a, |
| 311 | + envMap: envMap, |
| 312 | + combine: THREE.MultiplyOperation, |
| 313 | + reflectivity: 0.8, |
337 | 314 |
|
338 | 315 | vertexColors: THREE.VertexColors, |
339 | | - lights: true, |
340 | 316 | fog: true |
341 | 317 |
|
342 | 318 | } ); |
343 | 319 |
|
| 320 | + material.defines = material.defines || {}; |
| 321 | + material.defines[ 'INSTANCED'] = ""; |
| 322 | + |
344 | 323 |
|
345 | 324 | // custom depth material - required for instanced shadows |
346 | 325 |
|
347 | | - var shader = THREE.CustomShaderLib[ 'customDepthRGBA' ]; |
| 326 | + var shader = THREE.ShaderLib[ 'customDepthRGBA' ]; |
348 | 327 |
|
349 | 328 | var uniforms = THREE.UniformsUtils.clone( shader.uniforms ); |
350 | 329 |
|
|
0 commit comments