summit/frontend/node_modules/three-stdlib/objects/Reflector.cjs.map

1 line
12 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"Reflector.cjs","sources":["../../src/objects/Reflector.js"],"sourcesContent":["import {\n Color,\n Matrix4,\n Mesh,\n PerspectiveCamera,\n Plane,\n ShaderMaterial,\n UniformsUtils,\n Vector3,\n Vector4,\n WebGLRenderTarget,\n HalfFloatType,\n NoToneMapping,\n} from 'three'\nimport { version } from '../_polyfill/constants'\n\nconst Reflector = /* @__PURE__ */ (() => {\n class Reflector extends Mesh {\n static ReflectorShader = {\n uniforms: {\n color: {\n value: null,\n },\n\n tDiffuse: {\n value: null,\n },\n\n textureMatrix: {\n value: null,\n },\n },\n\n vertexShader: /* glsl */ `\n\t\tuniform mat4 textureMatrix;\n\t\tvarying vec4 vUv;\n\n\t\t#include <common>\n\t\t#include <logdepthbuf_pars_vertex>\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t\t#include <logdepthbuf_vertex>\n\n\t\t}`,\n\n fragmentShader: /* glsl */ `\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\t\tvarying vec4 vUv;\n\n\t\t#include <logdepthbuf_pars_fragment>\n\n\t\tfloat blendOverlay( float base, float blend ) {\n\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\n\t\t}\n\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\n\t\t\t#include <tonemapping_fragment>\n\t\t\t#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n\n\t\t}`,\n }\n\n constructor(geometry, options = {}) {\n super(geometry)\n\n this.isReflector = true\n\n this.type = 'Reflector'\n this.camera = new PerspectiveCamera()\n\n const scope = this\n\n const color = options.color !== undefined ? new Color(options.color) : new Color(0x7f7f7f)\n const textureWidth = options.textureWidth || 512\n const textureHeight = options.textureHeight || 512\n const clipBias = options.clipBias || 0\n const shader = options.shader || Reflector.ReflectorShader\n const multisample = options.multisample !== undefined ? options.multisample : 4\n\n //\n\n const reflectorPlane = new Plane()\n const normal = new Vector3()\n const reflectorWorldPosition = new Vector3()\n const cameraWorldPosition = new Vector3()\n const rotationMatrix = new Matrix4()\n const lookAtPosition = new Vector3(0, 0, -1)\n const clipPlane = new Vector4()\n\n const view = new Vector3()\n const target = new Vector3()\n const q = new Vector4()\n\n const textureMatrix = new Matrix4()\n const virtualCamera = this.camera\n\n const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, {\n samples: multisample,\n type: HalfFloatType,\n })\n\n const material = new ShaderMaterial({\n uniforms: UniformsUtils.clone(shader.uniforms),\n fragmentShader: shader.fragmentShader,\n vertexShader: shader.vertexShader,\n })\n\n material.uniforms['tDiffuse'].value = renderTarget.texture\n material.uniforms['color'].value = color\n material.uniforms['textureMatrix'].value = textureMatrix\n\n this.material = material\n\n this.onBeforeRender = function (renderer, scene, camera) {\n reflectorWorldPosition.setFromMatrixPosition(scope.matrixWorld)\n cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld)\n\n rotationMatrix.extractRotation(scope.matrixWorld)\n\n normal.set(0, 0, 1)\n normal.applyMatrix4(rotationMatrix)\n\n view.subVectors(reflectorWorldPosition, cameraWorldPosition)\n\n // Avoid rendering when reflector is facing away\n\n if (view.