|
33 | 33 | </head> |
34 | 34 |
|
35 | 35 | <body> |
36 | | - <script src="../build/three.min.js"></script> |
| 36 | + <script src="../build/three.js"></script> |
37 | 37 |
|
| 38 | + <script src="js/shaders/CopyShader.js"></script> |
38 | 39 | <script src="js/shaders/BokehShader.js"></script> |
39 | 40 |
|
| 41 | + <script src="js/postprocessing/EffectComposer.js"></script> |
| 42 | + <script src="js/postprocessing/RenderPass.js"></script> |
| 43 | + <script src="js/postprocessing/ShaderPass.js"></script> |
| 44 | + <script src="js/postprocessing/MaskPass.js"></script> |
| 45 | + <script src="js/postprocessing/BokehPass.js"></script> |
| 46 | + |
40 | 47 | <script src="js/Detector.js"></script> |
41 | 48 | <script src="js/libs/stats.min.js"></script> |
42 | 49 |
|
|
64 | 71 | var windowHalfX = window.innerWidth / 2; |
65 | 72 | var windowHalfY = window.innerHeight / 2; |
66 | 73 |
|
| 74 | + var width = window.innerWidth; |
67 | 75 | var height = window.innerHeight - 300; |
68 | 76 |
|
69 | 77 | var postprocessing = { enabled : true }; |
|
76 | 84 | container = document.createElement( 'div' ); |
77 | 85 | document.body.appendChild( container ); |
78 | 86 |
|
79 | | - camera = new THREE.PerspectiveCamera( 70, window.innerWidth / height, 1, 3000 ); |
| 87 | + camera = new THREE.PerspectiveCamera( 70, width / height, 1, 3000 ); |
80 | 88 | camera.position.z = 200; |
81 | 89 |
|
82 | 90 | scene = new THREE.Scene(); |
83 | 91 |
|
84 | 92 | renderer = new THREE.WebGLRenderer( { antialias: false } ); |
85 | | - renderer.setSize( window.innerWidth, height ); |
| 93 | + renderer.setSize( width, height ); |
86 | 94 | container.appendChild( renderer.domElement ); |
87 | 95 |
|
88 | 96 | renderer.sortObjects = false; |
|
177 | 185 | document.addEventListener( 'touchstart', onDocumentTouchStart, false ); |
178 | 186 | document.addEventListener( 'touchmove', onDocumentTouchMove, false ); |
179 | 187 |
|
| 188 | + window.addEventListener( 'resize', onWindowResize, false ); |
| 189 | + |
180 | 190 | var effectController = { |
181 | 191 |
|
182 | 192 | focus: 1.0, |
|
187 | 197 |
|
188 | 198 | var matChanger = function( ) { |
189 | 199 |
|
190 | | - postprocessing.bokeh_uniforms[ "focus" ].value = effectController.focus; |
191 | | - postprocessing.bokeh_uniforms[ "aperture" ].value = effectController.aperture; |
192 | | - postprocessing.bokeh_uniforms[ "maxblur" ].value = effectController.maxblur; |
| 200 | + postprocessing.bokeh.uniforms[ "focus" ].value = effectController.focus; |
| 201 | + postprocessing.bokeh.uniforms[ "aperture" ].value = effectController.aperture; |
| 202 | + postprocessing.bokeh.uniforms[ "maxblur" ].value = effectController.maxblur; |
193 | 203 |
|
194 | 204 | }; |
195 | 205 |
|
|
233 | 243 |
|
234 | 244 | } |
235 | 245 |
|
236 | | - function initPostprocessing() { |
| 246 | + function onWindowResize() { |
237 | 247 |
|
238 | | - postprocessing.scene = new THREE.Scene(); |
| 248 | + windowHalfX = window.innerWidth / 2; |
| 249 | + windowHalfY = window.innerHeight / 2; |
239 | 250 |
|
240 | | - postprocessing.camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -10000, 10000 ); |
241 | | - postprocessing.camera.position.z = 100; |
| 251 | + width = window.innerWidth; |
| 252 | + height = window.innerHeight - 300; |
242 | 253 |
|
243 | | - postprocessing.scene.add( postprocessing.camera ); |
| 254 | + camera.aspect = width / height; |
| 255 | + camera.updateProjectionMatrix(); |
244 | 256 |
|
245 | | - var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat }; |
246 | | - postprocessing.rtTextureDepth = new THREE.WebGLRenderTarget( window.innerWidth, height, pars ); |
247 | | - postprocessing.rtTextureColor = new THREE.WebGLRenderTarget( window.innerWidth, height, pars ); |
| 257 | + renderer.setSize( width, height ); |
| 258 | + postprocessing.composer.setSize( width, height ); |
| 259 | + |
| 260 | + } |
248 | 261 |
|
249 | | - var bokeh_shader = THREE.BokehShader; |
| 262 | + function initPostprocessing() { |
| 263 | + var renderPass = new THREE.RenderPass( scene, camera ); |
250 | 264 |
|
251 | | - postprocessing.bokeh_uniforms = THREE.UniformsUtils.clone( bokeh_shader.uniforms ); |
| 265 | + var bokehPass = new THREE.BokehPass( scene, camera, { |
| 266 | + focus: 1.0, |
| 267 | + aperture: 0.025, |
| 268 | + maxblur: 1.0, |
252 | 269 |
|
253 | | - postprocessing.bokeh_uniforms[ "tColor" ].value = postprocessing.rtTextureColor; |
254 | | - postprocessing.bokeh_uniforms[ "tDepth" ].value = postprocessing.rtTextureDepth; |
255 | | - postprocessing.bokeh_uniforms[ "focus" ].value = 1.1; |
256 | | - postprocessing.bokeh_uniforms[ "aspect" ].value = window.innerWidth / height; |
| 270 | + width: width, |
| 271 | + height: height |
| 272 | + } ); |
257 | 273 |
|
258 | | - postprocessing.materialBokeh = new THREE.ShaderMaterial( { |
| 274 | + bokehPass.renderToScreen = true; |
259 | 275 |
|
260 | | - uniforms: postprocessing.bokeh_uniforms, |
261 | | - vertexShader: bokeh_shader.vertexShader, |
262 | | - fragmentShader: bokeh_shader.fragmentShader |
| 276 | + var composer = new THREE.EffectComposer( renderer ); |
263 | 277 |
|
264 | | - } ); |
| 278 | + composer.addPass( renderPass ); |
| 279 | + composer.addPass( bokehPass ); |
265 | 280 |
|
266 | | - postprocessing.quad = new THREE.Mesh( new THREE.PlaneGeometry( window.innerWidth, window.innerHeight ), postprocessing.materialBokeh ); |
267 | | - postprocessing.quad.position.z = - 500; |
268 | | - postprocessing.scene.add( postprocessing.quad ); |
| 281 | + postprocessing.composer = composer; |
| 282 | + postprocessing.bokeh = bokehPass; |
269 | 283 |
|
270 | 284 | } |
271 | 285 |
|
|
300 | 314 |
|
301 | 315 | if ( postprocessing.enabled ) { |
302 | 316 |
|
303 | | - renderer.clear(); |
304 | | - |
305 | | - // Render scene into texture |
306 | | - |
307 | | - scene.overrideMaterial = null; |
308 | | - renderer.render( scene, camera, postprocessing.rtTextureColor, true ); |
309 | | - |
310 | | - // Render depth into texture |
311 | | - |
312 | | - scene.overrideMaterial = material_depth; |
313 | | - renderer.render( scene, camera, postprocessing.rtTextureDepth, true ); |
314 | | - |
315 | | - // Render bokeh composite |
316 | | - |
317 | | - renderer.render( postprocessing.scene, postprocessing.camera ); |
318 | | - |
| 317 | + postprocessing.composer.render( 0.1 ); |
319 | 318 |
|
320 | 319 | } else { |
321 | 320 |
|
|
326 | 325 |
|
327 | 326 | } |
328 | 327 |
|
329 | | - |
330 | 328 | </script> |
331 | 329 | </body> |
332 | 330 | </html> |
0 commit comments