CoolFace
Apppublic

CyberSys/fruit-fly-simulation

sourceHugging Faceapache-2.0updated 16d agoView on Hugging Face
0likes
macro-dof.js41 linesDownload Raw Back to src
1import * as THREE from 'three';2import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';3import { BokehShader } from 'three/addons/shaders/BokehShader.js';4 5/** Reuse the beauty pass's depth. Transparent wings must not become opaque6 * depth sheets, and focusing must not require a second geometry render. */7export class MacroDOFPass extends ShaderPass {8  constructor(camera) {9    super(BokehShader, 'tColor');10    this.camera = camera;11    // Preserve the filtered coverage for the final backdrop composite.12    this.material.fragmentShader = this.material.fragmentShader.replace(13      'gl_FragColor.a = 1.0;',14      '',15    );16    this.material.defines.DEPTH_PACKING = 0;17    this.uniforms.aperture.value = 0.0012;18    this.uniforms.maxblur.value = 0.004;19  }20  setSize(width, height) {21    this.uniforms.aspect.value = width / height;22  }23  render(renderer, writeBuffer, readBuffer) {24    this.uniforms.tDepth.value = readBuffer.depthTexture;25    this.uniforms.nearClip.value = this.camera.near;26    this.uniforms.farClip.value = this.camera.far;27    super.render(renderer, writeBuffer, readBuffer);28  }29}30 31export function attachDepthBuffers(composer, renderer) {32  for (const target of [composer.renderTarget1, composer.renderTarget2]) {33    target.depthTexture = new THREE.DepthTexture(34      target.width,35      target.height,36      THREE.UnsignedIntType,37    );38    target.samples = Math.min(2, renderer.capabilities.maxSamples);39  }40}41