* Updates this effect. * * @param {WebGLRenderer} renderer - The renderer. * @param {WebGLRenderTarget} inputBuffer - A frame buffer that contains the result of the previous pass. * @param {Number} [delta] - The time between the last frame and the current one in seconds.
(renderer, inputBuffer, delta)
| 256 | */ |
| 257 | |
| 258 | update(renderer, inputBuffer, delta) { |
| 259 | |
| 260 | const position = this.position; |
| 261 | const camera = this.camera; |
| 262 | const uniforms = this.uniforms; |
| 263 | const uActive = uniforms.get("active"); |
| 264 | |
| 265 | if(this.active) { |
| 266 | |
| 267 | const waveSize = uniforms.get("waveSize").value; |
| 268 | |
| 269 | // Calculate direction vectors. |
| 270 | camera.getWorldDirection(v); |
| 271 | ab.copy(camera.position).sub(position); |
| 272 | |
| 273 | // Don't render the effect if the object is behind the camera. |
| 274 | uActive.value = (v.angleTo(ab) > HALF_PI); |
| 275 | |
| 276 | if(uActive.value) { |
| 277 | |
| 278 | // Scale the effect based on distance to the object. |
| 279 | uniforms.get("cameraDistance").value = camera.position.distanceTo(position); |
| 280 | |
| 281 | // Calculate the screen position of the shock wave. |
| 282 | v.copy(position).project(camera); |
| 283 | this.screenPosition.set((v.x + 1.0) * 0.5, (v.y + 1.0) * 0.5); |
| 284 | |
| 285 | } |
| 286 | |
| 287 | // Update the shock wave radius based on time. |
| 288 | this.time += delta * this.speed; |
| 289 | const radius = this.time - waveSize; |
| 290 | uniforms.get("radius").value = radius; |
| 291 | |
| 292 | if(radius >= (uniforms.get("maxRadius").value + waveSize) * 2.0) { |
| 293 | |
| 294 | this.active = false; |
| 295 | uActive.value = false; |
| 296 | |
| 297 | } |
| 298 | |
| 299 | } |
| 300 | |
| 301 | } |
| 302 | |
| 303 | } |