summit/frontend/node_modules/three-stdlib/cameras/CinematicCamera.cjs.map

1 line
9.9 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"CinematicCamera.cjs","sources":["../../src/cameras/CinematicCamera.js"],"sourcesContent":["import {\n Mesh,\n OrthographicCamera,\n PerspectiveCamera,\n PlaneGeometry,\n Scene,\n ShaderMaterial,\n UniformsUtils,\n WebGLRenderTarget,\n} from 'three'\nimport { BokehShader2, BokehDepthShader } from '../shaders/BokehShader2'\n\nclass CinematicCamera extends PerspectiveCamera {\n constructor(fov, aspect, near, far) {\n super(fov, aspect, near, far)\n\n this.type = 'CinematicCamera'\n\n this.postprocessing = { enabled: true }\n this.shaderSettings = {\n rings: 3,\n samples: 4,\n }\n\n const depthShader = BokehDepthShader\n\n this.materialDepth = new ShaderMaterial({\n uniforms: depthShader.uniforms,\n vertexShader: depthShader.vertexShader,\n fragmentShader: depthShader.fragmentShader,\n })\n\n this.materialDepth.uniforms['mNear'].value = near\n this.materialDepth.uniforms['mFar'].value = far\n\n // In case of cinematicCamera, having a default lens set is important\n this.setLens()\n\n this.initPostProcessing()\n }\n\n // providing fnumber and coc(Circle of Confusion) as extra arguments\n setLens(focalLength, filmGauge, fNumber, coc) {\n // In case of cinematicCamera, having a default lens set is important\n if (focalLength === undefined) focalLength = 35\n if (filmGauge !== undefined) this.filmGauge = filmGauge\n\n this.setFocalLength(focalLength)\n\n // if fnumber and coc are not provided, cinematicCamera tries to act as a basic PerspectiveCamera\n if (fNumber === undefined) fNumber = 8\n if (coc === undefined) coc = 0.019\n\n this.fNumber = fNumber\n this.coc = coc\n\n // fNumber is focalLength by aperture\n this.aperture = focalLength / this.fNumber\n\n // hyperFocal is required to calculate depthOfField when a lens tries to focus at a distance with given fNumber and focalLength\n this.hyperFocal = (focalLength * focalLength) / (this.aperture * this.coc)\n }\n\n linearize(depth) {\n const zfar = this.far\n const znear = this.near\n return (-zfar * znear) / (depth * (zfar - znear) - zfar)\n }\n\n smoothstep(near, far, depth) {\n const x = this.saturate((depth - near) / (far - near))\n return x * x * (3 - 2 * x)\n }\n\n saturate(x) {\n return Math.max(0, Math.min(1, x))\n }\n\n // function for focusing at a distance from the camera\n focusAt(focusDistance) {\n if (focusDistance === undefined) focusDistance = 20\n\n const focalLength = this.getFocalLength()\n\n // distance from the camera (normal to frustrum) to focus on\n this.focus = focusDistance\n\n // the nearest point from the camera which is in focus (unused)\n this.nearPoint = (this.hyperFocal * this.focus) / (this.hyperFocal + (this.focus - focalLength))\n\n // the farthest point from the camera which is in focus (unused)\n this.farPoint = (this.hyperFocal * this.focus) / (this.hyperFocal - (this.focus - focalLength))\n\n // the gap or width of the space in which is everything is in focus (unused)\n this.depthOfField = this.farPoint - this.nearPoint\n\n // Considering minimum distance of focus for a standard lens (unused)\n if (this.depthOfField < 0) this.depthOfField = 0\n\n this.sdistance = this.smoothstep(this.near, this.far, this.focus)\n\n this.ldistance = this.linearize(1 - this.sdistance)\n\n this.postprocessing.bokeh_uniforms['focalDepth'].value = this.ldistance\n }\n\n initPostProcessing() {\n if (this.postprocessing.enabled) {\n this.postprocessing.scene = new Scene()\n\n this.postprocessing.camera = new OrthographicCamera(\n window.innerWidth / -2,\n window.innerWidth / 2,\n window.innerHeight / 2,\n window.innerHeight / -2,\n -10000,\n 10000,\n )\n\n this.postprocessing.scene.add(this.postprocessing.camera)\n\n this.postprocessing.rtTextureDepth = new WebGLRenderTarget(window.innerWidth, window.innerHeight)\n this.postprocessing.rtTextureColor = new WebGLRenderTarget(window.