Initial project import
This commit is contained in:
245
node_modules/three-stdlib/csm/CSM.cjs
generated
vendored
Normal file
245
node_modules/three-stdlib/csm/CSM.cjs
generated
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const THREE = require("three");
|
||||
const CSMFrustum = require("./CSMFrustum.cjs");
|
||||
const CSMShader = require("./CSMShader.cjs");
|
||||
const _cameraToLightMatrix = /* @__PURE__ */ new THREE.Matrix4();
|
||||
const _lightSpaceFrustum = /* @__PURE__ */ new CSMFrustum.CSMFrustum();
|
||||
const _center = /* @__PURE__ */ new THREE.Vector3();
|
||||
const _bbox = /* @__PURE__ */ new THREE.Box3();
|
||||
const _uniformArray = [];
|
||||
const _logArray = [];
|
||||
class CSM {
|
||||
constructor(data) {
|
||||
data = data || {};
|
||||
this.camera = data.camera;
|
||||
this.parent = data.parent;
|
||||
this.cascades = data.cascades || 3;
|
||||
this.maxFar = data.maxFar || 1e5;
|
||||
this.mode = data.mode || "practical";
|
||||
this.shadowMapSize = data.shadowMapSize || 2048;
|
||||
this.shadowBias = data.shadowBias || 1e-6;
|
||||
this.lightDirection = data.lightDirection || new THREE.Vector3(1, -1, 1).normalize();
|
||||
this.lightIntensity = data.lightIntensity || 1;
|
||||
this.lightNear = data.lightNear || 1;
|
||||
this.lightFar = data.lightFar || 2e3;
|
||||
this.lightMargin = data.lightMargin || 200;
|
||||
this.customSplitsCallback = data.customSplitsCallback;
|
||||
this.fade = false;
|
||||
this.mainFrustum = new CSMFrustum.CSMFrustum();
|
||||
this.frustums = [];
|
||||
this.breaks = [];
|
||||
this.lights = [];
|
||||
this.shaders = /* @__PURE__ */ new Map();
|
||||
this.createLights();
|
||||
this.updateFrustums();
|
||||
this.injectInclude();
|
||||
}
|
||||
createLights() {
|
||||
for (let i = 0; i < this.cascades; i++) {
|
||||
const light = new THREE.DirectionalLight(16777215, this.lightIntensity);
|
||||
light.castShadow = true;
|
||||
light.shadow.mapSize.width = this.shadowMapSize;
|
||||
light.shadow.mapSize.height = this.shadowMapSize;
|
||||
light.shadow.camera.near = this.lightNear;
|
||||
light.shadow.camera.far = this.lightFar;
|
||||
light.shadow.bias = this.shadowBias;
|
||||
this.parent.add(light);
|
||||
this.parent.add(light.target);
|
||||
this.lights.push(light);
|
||||
}
|
||||
}
|
||||
initCascades() {
|
||||
const camera = this.camera;
|
||||
camera.updateProjectionMatrix();
|
||||
this.mainFrustum.setFromProjectionMatrix(camera.projectionMatrix, this.maxFar);
|
||||
this.mainFrustum.split(this.breaks, this.frustums);
|
||||
}
|
||||
updateShadowBounds() {
|
||||
const frustums = this.frustums;
|
||||
for (let i = 0; i < frustums.length; i++) {
|
||||
const light = this.lights[i];
|
||||
const shadowCam = light.shadow.camera;
|
||||
const frustum = this.frustums[i];
|
||||
const nearVerts = frustum.vertices.near;
|
||||
const farVerts = frustum.vertices.far;
|
||||
const point1 = farVerts[0];
|
||||
let point2;
|
||||
if (point1.distanceTo(farVerts[2]) > point1.distanceTo(nearVerts[2])) {
|
||||
point2 = farVerts[2];
|
||||
} else {
|
||||
point2 = nearVerts[2];
|
||||
}
|
||||
let squaredBBWidth = point1.distanceTo(point2);
|
||||
if (this.fade) {
|
||||
const camera = this.camera;
|
||||
const far = Math.max(camera.far, this.maxFar);
|
||||
const linearDepth = frustum.vertices.far[0].z / (far - camera.near);
|
||||
const margin = 0.25 * Math.pow(linearDepth, 2) * (far - camera.near);
|
||||
squaredBBWidth += margin;
|
||||
}
|
||||
shadowCam.left = -squaredBBWidth / 2;
|
||||
shadowCam.right = squaredBBWidth / 2;
|
||||
shadowCam.top = squaredBBWidth / 2;
|
||||
shadowCam.bottom = -squaredBBWidth / 2;
|
||||
shadowCam.updateProjectionMatrix();
|
||||
}
|
||||
}
|
||||
getBreaks() {
|
||||
const camera = this.camera;
|
||||
const far = Math.min(camera.far, this.maxFar);
|
||||
this.breaks.length = 0;
|
||||
switch (this.mode) {
|
||||
case "uniform":
|
||||
uniformSplit(this.cascades, camera.near, far, this.breaks);
|
||||
break;
|
||||
case "logarithmic":
|
||||
logarithmicSplit(this.cascades, camera.near, far, this.breaks);
|
||||
break;
|
||||
case "practical":
|
||||
practicalSplit(this.cascades, camera.near, far, 0.5, this.breaks);
|
||||
break;
|
||||
case "custom":
|
||||
if (this.customSplitsCallback === void 0)
|
||||
console.error("CSM: Custom split scheme callback not defined.");
|
||||
this.customSplitsCallback(this.cascades, camera.near, far, this.breaks);
|
||||
break;
|
||||
}
|
||||
function uniformSplit(amount, near, far2, target) {
|
||||
for (let i = 1; i < amount; i++) {
|
||||
target.push((near + (far2 - near) * i / amount) / far2);
|
||||
}
|
||||
target.push(1);
|
||||
}
|
||||
function logarithmicSplit(amount, near, far2, target) {
|
||||
for (let i = 1; i < amount; i++) {
|
||||
target.push(near * (far2 / near) ** (i / amount) / far2);
|
||||
}
|
||||
target.push(1);
|
||||
}
|
||||
function practicalSplit(amount, near, far2, lambda, target) {
|
||||
_uniformArray.length = 0;
|
||||
_logArray.length = 0;
|
||||
logarithmicSplit(amount, near, far2, _logArray);
|
||||
uniformSplit(amount, near, far2, _uniformArray);
|
||||
for (let i = 1; i < amount; i++) {
|
||||
target.push(THREE.MathUtils.lerp(_uniformArray[i - 1], _logArray[i - 1], lambda));
|
||||
}
|
||||
target.push(1);
|
||||
}
|
||||
}
|
||||
update() {
|
||||
const camera = this.camera;
|
||||
const frustums = this.frustums;
|
||||
for (let i = 0; i < frustums.length; i++) {
|
||||
const light = this.lights[i];
|
||||
const shadowCam = light.shadow.camera;
|
||||
const texelWidth = (shadowCam.right - shadowCam.left) / this.shadowMapSize;
|
||||
const texelHeight = (shadowCam.top - shadowCam.bottom) / this.shadowMapSize;
|
||||
light.shadow.camera.updateMatrixWorld(true);
|
||||
_cameraToLightMatrix.multiplyMatrices(light.shadow.camera.matrixWorldInverse, camera.matrixWorld);
|
||||
frustums[i].toSpace(_cameraToLightMatrix, _lightSpaceFrustum);
|
||||
const nearVerts = _lightSpaceFrustum.vertices.near;
|
||||
const farVerts = _lightSpaceFrustum.vertices.far;
|
||||
_bbox.makeEmpty();
|
||||
for (let j = 0; j < 4; j++) {
|
||||
_bbox.expandByPoint(nearVerts[j]);
|
||||
_bbox.expandByPoint(farVerts[j]);
|
||||
}
|
||||
_bbox.getCenter(_center);
|
||||
_center.z = _bbox.max.z + this.lightMargin;
|
||||
_center.x = Math.floor(_center.x / texelWidth) * texelWidth;
|
||||
_center.y = Math.floor(_center.y / texelHeight) * texelHeight;
|
||||
_center.applyMatrix4(light.shadow.camera.matrixWorld);
|
||||
light.position.copy(_center);
|
||||
light.target.position.copy(_center);
|
||||
light.target.position.x += this.lightDirection.x;
|
||||
light.target.position.y += this.lightDirection.y;
|
||||
light.target.position.z += this.lightDirection.z;
|
||||
}
|
||||
}
|
||||
injectInclude() {
|
||||
THREE.ShaderChunk.lights_fragment_begin = CSMShader.CSMShader.lights_fragment_begin;
|
||||
THREE.ShaderChunk.lights_pars_begin = CSMShader.CSMShader.lights_pars_begin;
|
||||
}
|
||||
setupMaterial(material) {
|
||||
material.defines = material.defines || {};
|
||||
material.defines.USE_CSM = 1;
|
||||
material.defines.CSM_CASCADES = this.cascades;
|
||||
if (this.fade) {
|
||||
material.defines.CSM_FADE = "";
|
||||
}
|
||||
const breaksVec2 = [];
|
||||
const scope = this;
|
||||
const shaders = this.shaders;
|
||||
material.onBeforeCompile = function(shader) {
|
||||
const far = Math.min(scope.camera.far, scope.maxFar);
|
||||
scope.getExtendedBreaks(breaksVec2);
|
||||
shader.uniforms.CSM_cascades = { value: breaksVec2 };
|
||||
shader.uniforms.cameraNear = { value: scope.camera.near };
|
||||
shader.uniforms.shadowFar = { value: far };
|
||||
shaders.set(material, shader);
|
||||
};
|
||||
shaders.set(material, null);
|
||||
}
|
||||
updateUniforms() {
|
||||
const far = Math.min(this.camera.far, this.maxFar);
|
||||
const shaders = this.shaders;
|
||||
shaders.forEach(function(shader, material) {
|
||||
if (shader !== null) {
|
||||
const uniforms = shader.uniforms;
|
||||
this.getExtendedBreaks(uniforms.CSM_cascades.value);
|
||||
uniforms.cameraNear.value = this.camera.near;
|
||||
uniforms.shadowFar.value = far;
|
||||
}
|
||||
if (!this.fade && "CSM_FADE" in material.defines) {
|
||||
delete material.defines.CSM_FADE;
|
||||
material.needsUpdate = true;
|
||||
} else if (this.fade && !("CSM_FADE" in material.defines)) {
|
||||
material.defines.CSM_FADE = "";
|
||||
material.needsUpdate = true;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
getExtendedBreaks(target) {
|
||||
while (target.length < this.breaks.length) {
|
||||
target.push(new THREE.Vector2());
|
||||
}
|
||||
target.length = this.breaks.length;
|
||||
for (let i = 0; i < this.cascades; i++) {
|
||||
const amount = this.breaks[i];
|
||||
const prev = this.breaks[i - 1] || 0;
|
||||
target[i].x = prev;
|
||||
target[i].y = amount;
|
||||
}
|
||||
}
|
||||
updateFrustums() {
|
||||
this.getBreaks();
|
||||
this.initCascades();
|
||||
this.updateShadowBounds();
|
||||
this.updateUniforms();
|
||||
}
|
||||
remove() {
|
||||
for (let i = 0; i < this.lights.length; i++) {
|
||||
this.parent.remove(this.lights[i]);
|
||||
}
|
||||
}
|
||||
dispose() {
|
||||
const shaders = this.shaders;
|
||||
shaders.forEach(function(shader, material) {
|
||||
delete material.onBeforeCompile;
|
||||
delete material.defines.USE_CSM;
|
||||
delete material.defines.CSM_CASCADES;
|
||||
delete material.defines.CSM_FADE;
|
||||
if (shader !== null) {
|
||||
delete shader.uniforms.CSM_cascades;
|
||||
delete shader.uniforms.cameraNear;
|
||||
delete shader.uniforms.shadowFar;
|
||||
}
|
||||
material.needsUpdate = true;
|
||||
});
|
||||
shaders.clear();
|
||||
}
|
||||
}
|
||||
exports.CSM = CSM;
|
||||
//# sourceMappingURL=CSM.cjs.map
|
||||
1
node_modules/three-stdlib/csm/CSM.cjs.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSM.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
61
node_modules/three-stdlib/csm/CSM.d.ts
generated
vendored
Normal file
61
node_modules/three-stdlib/csm/CSM.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Camera, Vector3, DirectionalLight, Material, Vector2, Object3D } from 'three'
|
||||
|
||||
export enum CMSMode {
|
||||
practical = 'practical',
|
||||
uniform = 'uniform',
|
||||
logarithmic = 'logarithmic',
|
||||
custom = 'custom',
|
||||
}
|
||||
|
||||
export interface CMSParameters {
|
||||
camera?: Camera
|
||||
parent?: Object3D
|
||||
cascades?: number
|
||||
maxFar?: number
|
||||
mode?: CMSMode
|
||||
shadowMapSize?: number
|
||||
shadowBias?: number
|
||||
lightDirection?: Vector3
|
||||
lightIntensity?: number
|
||||
lightNear?: number
|
||||
lightFar?: number
|
||||
lightMargin?: number
|
||||
customSplitsCallback?: (cascades: number, cameraNear: number, cameraFar: number, breaks: number[]) => void
|
||||
}
|
||||
|
||||
export class CSM {
|
||||
constructor(data?: CMSParameters)
|
||||
camera: Camera
|
||||
parent: Object3D
|
||||
cascades: number
|
||||
maxFar: number
|
||||
mode: CMSMode
|
||||
shadowMapSize: number
|
||||
shadowBias: number
|
||||
lightDirection: Vector3
|
||||
lightIntensity: number
|
||||
lightNear: number
|
||||
lightFar: number
|
||||
lightMargin: number
|
||||
customSplitsCallback: (cascades: number, cameraNear: number, cameraFar: number, breaks: number[]) => void
|
||||
fade: boolean
|
||||
mainFrustum: CSMFrustrum
|
||||
frustums: CSMFrustrum[]
|
||||
breaks: number[]
|
||||
lights: DirectionalLight[]
|
||||
shaders: Map<unknown, string>
|
||||
createLights(): void
|
||||
initCascades(): void
|
||||
updateShadowBounds(): void
|
||||
getBreaks(): void
|
||||
update(): void
|
||||
injectInclude(): void
|
||||
setupMaterial(material: Material): void
|
||||
updateUniforms(): void
|
||||
getExtendedBreaks(target: Vector2[]): void
|
||||
updateFrustums(): void
|
||||
remove(): void
|
||||
dispose(): void
|
||||
}
|
||||
|
||||
import CSMFrustrum from './CSMFrustum.js'
|
||||
245
node_modules/three-stdlib/csm/CSM.js
generated
vendored
Normal file
245
node_modules/three-stdlib/csm/CSM.js
generated
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
import { Vector3, DirectionalLight, MathUtils, ShaderChunk, Vector2, Matrix4, Box3 } from "three";
|
||||
import { CSMFrustum } from "./CSMFrustum.js";
|
||||
import { CSMShader } from "./CSMShader.js";
|
||||
const _cameraToLightMatrix = /* @__PURE__ */ new Matrix4();
|
||||
const _lightSpaceFrustum = /* @__PURE__ */ new CSMFrustum();
|
||||
const _center = /* @__PURE__ */ new Vector3();
|
||||
const _bbox = /* @__PURE__ */ new Box3();
|
||||
const _uniformArray = [];
|
||||
const _logArray = [];
|
||||
class CSM {
|
||||
constructor(data) {
|
||||
data = data || {};
|
||||
this.camera = data.camera;
|
||||
this.parent = data.parent;
|
||||
this.cascades = data.cascades || 3;
|
||||
this.maxFar = data.maxFar || 1e5;
|
||||
this.mode = data.mode || "practical";
|
||||
this.shadowMapSize = data.shadowMapSize || 2048;
|
||||
this.shadowBias = data.shadowBias || 1e-6;
|
||||
this.lightDirection = data.lightDirection || new Vector3(1, -1, 1).normalize();
|
||||
this.lightIntensity = data.lightIntensity || 1;
|
||||
this.lightNear = data.lightNear || 1;
|
||||
this.lightFar = data.lightFar || 2e3;
|
||||
this.lightMargin = data.lightMargin || 200;
|
||||
this.customSplitsCallback = data.customSplitsCallback;
|
||||
this.fade = false;
|
||||
this.mainFrustum = new CSMFrustum();
|
||||
this.frustums = [];
|
||||
this.breaks = [];
|
||||
this.lights = [];
|
||||
this.shaders = /* @__PURE__ */ new Map();
|
||||
this.createLights();
|
||||
this.updateFrustums();
|
||||
this.injectInclude();
|
||||
}
|
||||
createLights() {
|
||||
for (let i = 0; i < this.cascades; i++) {
|
||||
const light = new DirectionalLight(16777215, this.lightIntensity);
|
||||
light.castShadow = true;
|
||||
light.shadow.mapSize.width = this.shadowMapSize;
|
||||
light.shadow.mapSize.height = this.shadowMapSize;
|
||||
light.shadow.camera.near = this.lightNear;
|
||||
light.shadow.camera.far = this.lightFar;
|
||||
light.shadow.bias = this.shadowBias;
|
||||
this.parent.add(light);
|
||||
this.parent.add(light.target);
|
||||
this.lights.push(light);
|
||||
}
|
||||
}
|
||||
initCascades() {
|
||||
const camera = this.camera;
|
||||
camera.updateProjectionMatrix();
|
||||
this.mainFrustum.setFromProjectionMatrix(camera.projectionMatrix, this.maxFar);
|
||||
this.mainFrustum.split(this.breaks, this.frustums);
|
||||
}
|
||||
updateShadowBounds() {
|
||||
const frustums = this.frustums;
|
||||
for (let i = 0; i < frustums.length; i++) {
|
||||
const light = this.lights[i];
|
||||
const shadowCam = light.shadow.camera;
|
||||
const frustum = this.frustums[i];
|
||||
const nearVerts = frustum.vertices.near;
|
||||
const farVerts = frustum.vertices.far;
|
||||
const point1 = farVerts[0];
|
||||
let point2;
|
||||
if (point1.distanceTo(farVerts[2]) > point1.distanceTo(nearVerts[2])) {
|
||||
point2 = farVerts[2];
|
||||
} else {
|
||||
point2 = nearVerts[2];
|
||||
}
|
||||
let squaredBBWidth = point1.distanceTo(point2);
|
||||
if (this.fade) {
|
||||
const camera = this.camera;
|
||||
const far = Math.max(camera.far, this.maxFar);
|
||||
const linearDepth = frustum.vertices.far[0].z / (far - camera.near);
|
||||
const margin = 0.25 * Math.pow(linearDepth, 2) * (far - camera.near);
|
||||
squaredBBWidth += margin;
|
||||
}
|
||||
shadowCam.left = -squaredBBWidth / 2;
|
||||
shadowCam.right = squaredBBWidth / 2;
|
||||
shadowCam.top = squaredBBWidth / 2;
|
||||
shadowCam.bottom = -squaredBBWidth / 2;
|
||||
shadowCam.updateProjectionMatrix();
|
||||
}
|
||||
}
|
||||
getBreaks() {
|
||||
const camera = this.camera;
|
||||
const far = Math.min(camera.far, this.maxFar);
|
||||
this.breaks.length = 0;
|
||||
switch (this.mode) {
|
||||
case "uniform":
|
||||
uniformSplit(this.cascades, camera.near, far, this.breaks);
|
||||
break;
|
||||
case "logarithmic":
|
||||
logarithmicSplit(this.cascades, camera.near, far, this.breaks);
|
||||
break;
|
||||
case "practical":
|
||||
practicalSplit(this.cascades, camera.near, far, 0.5, this.breaks);
|
||||
break;
|
||||
case "custom":
|
||||
if (this.customSplitsCallback === void 0)
|
||||
console.error("CSM: Custom split scheme callback not defined.");
|
||||
this.customSplitsCallback(this.cascades, camera.near, far, this.breaks);
|
||||
break;
|
||||
}
|
||||
function uniformSplit(amount, near, far2, target) {
|
||||
for (let i = 1; i < amount; i++) {
|
||||
target.push((near + (far2 - near) * i / amount) / far2);
|
||||
}
|
||||
target.push(1);
|
||||
}
|
||||
function logarithmicSplit(amount, near, far2, target) {
|
||||
for (let i = 1; i < amount; i++) {
|
||||
target.push(near * (far2 / near) ** (i / amount) / far2);
|
||||
}
|
||||
target.push(1);
|
||||
}
|
||||
function practicalSplit(amount, near, far2, lambda, target) {
|
||||
_uniformArray.length = 0;
|
||||
_logArray.length = 0;
|
||||
logarithmicSplit(amount, near, far2, _logArray);
|
||||
uniformSplit(amount, near, far2, _uniformArray);
|
||||
for (let i = 1; i < amount; i++) {
|
||||
target.push(MathUtils.lerp(_uniformArray[i - 1], _logArray[i - 1], lambda));
|
||||
}
|
||||
target.push(1);
|
||||
}
|
||||
}
|
||||
update() {
|
||||
const camera = this.camera;
|
||||
const frustums = this.frustums;
|
||||
for (let i = 0; i < frustums.length; i++) {
|
||||
const light = this.lights[i];
|
||||
const shadowCam = light.shadow.camera;
|
||||
const texelWidth = (shadowCam.right - shadowCam.left) / this.shadowMapSize;
|
||||
const texelHeight = (shadowCam.top - shadowCam.bottom) / this.shadowMapSize;
|
||||
light.shadow.camera.updateMatrixWorld(true);
|
||||
_cameraToLightMatrix.multiplyMatrices(light.shadow.camera.matrixWorldInverse, camera.matrixWorld);
|
||||
frustums[i].toSpace(_cameraToLightMatrix, _lightSpaceFrustum);
|
||||
const nearVerts = _lightSpaceFrustum.vertices.near;
|
||||
const farVerts = _lightSpaceFrustum.vertices.far;
|
||||
_bbox.makeEmpty();
|
||||
for (let j = 0; j < 4; j++) {
|
||||
_bbox.expandByPoint(nearVerts[j]);
|
||||
_bbox.expandByPoint(farVerts[j]);
|
||||
}
|
||||
_bbox.getCenter(_center);
|
||||
_center.z = _bbox.max.z + this.lightMargin;
|
||||
_center.x = Math.floor(_center.x / texelWidth) * texelWidth;
|
||||
_center.y = Math.floor(_center.y / texelHeight) * texelHeight;
|
||||
_center.applyMatrix4(light.shadow.camera.matrixWorld);
|
||||
light.position.copy(_center);
|
||||
light.target.position.copy(_center);
|
||||
light.target.position.x += this.lightDirection.x;
|
||||
light.target.position.y += this.lightDirection.y;
|
||||
light.target.position.z += this.lightDirection.z;
|
||||
}
|
||||
}
|
||||
injectInclude() {
|
||||
ShaderChunk.lights_fragment_begin = CSMShader.lights_fragment_begin;
|
||||
ShaderChunk.lights_pars_begin = CSMShader.lights_pars_begin;
|
||||
}
|
||||
setupMaterial(material) {
|
||||
material.defines = material.defines || {};
|
||||
material.defines.USE_CSM = 1;
|
||||
material.defines.CSM_CASCADES = this.cascades;
|
||||
if (this.fade) {
|
||||
material.defines.CSM_FADE = "";
|
||||
}
|
||||
const breaksVec2 = [];
|
||||
const scope = this;
|
||||
const shaders = this.shaders;
|
||||
material.onBeforeCompile = function(shader) {
|
||||
const far = Math.min(scope.camera.far, scope.maxFar);
|
||||
scope.getExtendedBreaks(breaksVec2);
|
||||
shader.uniforms.CSM_cascades = { value: breaksVec2 };
|
||||
shader.uniforms.cameraNear = { value: scope.camera.near };
|
||||
shader.uniforms.shadowFar = { value: far };
|
||||
shaders.set(material, shader);
|
||||
};
|
||||
shaders.set(material, null);
|
||||
}
|
||||
updateUniforms() {
|
||||
const far = Math.min(this.camera.far, this.maxFar);
|
||||
const shaders = this.shaders;
|
||||
shaders.forEach(function(shader, material) {
|
||||
if (shader !== null) {
|
||||
const uniforms = shader.uniforms;
|
||||
this.getExtendedBreaks(uniforms.CSM_cascades.value);
|
||||
uniforms.cameraNear.value = this.camera.near;
|
||||
uniforms.shadowFar.value = far;
|
||||
}
|
||||
if (!this.fade && "CSM_FADE" in material.defines) {
|
||||
delete material.defines.CSM_FADE;
|
||||
material.needsUpdate = true;
|
||||
} else if (this.fade && !("CSM_FADE" in material.defines)) {
|
||||
material.defines.CSM_FADE = "";
|
||||
material.needsUpdate = true;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
getExtendedBreaks(target) {
|
||||
while (target.length < this.breaks.length) {
|
||||
target.push(new Vector2());
|
||||
}
|
||||
target.length = this.breaks.length;
|
||||
for (let i = 0; i < this.cascades; i++) {
|
||||
const amount = this.breaks[i];
|
||||
const prev = this.breaks[i - 1] || 0;
|
||||
target[i].x = prev;
|
||||
target[i].y = amount;
|
||||
}
|
||||
}
|
||||
updateFrustums() {
|
||||
this.getBreaks();
|
||||
this.initCascades();
|
||||
this.updateShadowBounds();
|
||||
this.updateUniforms();
|
||||
}
|
||||
remove() {
|
||||
for (let i = 0; i < this.lights.length; i++) {
|
||||
this.parent.remove(this.lights[i]);
|
||||
}
|
||||
}
|
||||
dispose() {
|
||||
const shaders = this.shaders;
|
||||
shaders.forEach(function(shader, material) {
|
||||
delete material.onBeforeCompile;
|
||||
delete material.defines.USE_CSM;
|
||||
delete material.defines.CSM_CASCADES;
|
||||
delete material.defines.CSM_FADE;
|
||||
if (shader !== null) {
|
||||
delete shader.uniforms.CSM_cascades;
|
||||
delete shader.uniforms.cameraNear;
|
||||
delete shader.uniforms.shadowFar;
|
||||
}
|
||||
material.needsUpdate = true;
|
||||
});
|
||||
shaders.clear();
|
||||
}
|
||||
}
|
||||
export {
|
||||
CSM
|
||||
};
|
||||
//# sourceMappingURL=CSM.js.map
|
||||
1
node_modules/three-stdlib/csm/CSM.js.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSM.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
76
node_modules/three-stdlib/csm/CSMFrustum.cjs
generated
vendored
Normal file
76
node_modules/three-stdlib/csm/CSMFrustum.cjs
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const THREE = require("three");
|
||||
const inverseProjectionMatrix = /* @__PURE__ */ new THREE.Matrix4();
|
||||
class CSMFrustum {
|
||||
constructor(data) {
|
||||
data = data || {};
|
||||
this.vertices = {
|
||||
near: [new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3()],
|
||||
far: [new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3()]
|
||||
};
|
||||
if (data.projectionMatrix !== void 0) {
|
||||
this.setFromProjectionMatrix(data.projectionMatrix, data.maxFar || 1e4);
|
||||
}
|
||||
}
|
||||
setFromProjectionMatrix(projectionMatrix, maxFar) {
|
||||
const isOrthographic = projectionMatrix.elements[2 * 4 + 3] === 0;
|
||||
inverseProjectionMatrix.copy(projectionMatrix).invert();
|
||||
this.vertices.near[0].set(1, 1, -1);
|
||||
this.vertices.near[1].set(1, -1, -1);
|
||||
this.vertices.near[2].set(-1, -1, -1);
|
||||
this.vertices.near[3].set(-1, 1, -1);
|
||||
this.vertices.near.forEach(function(v) {
|
||||
v.applyMatrix4(inverseProjectionMatrix);
|
||||
});
|
||||
this.vertices.far[0].set(1, 1, 1);
|
||||
this.vertices.far[1].set(1, -1, 1);
|
||||
this.vertices.far[2].set(-1, -1, 1);
|
||||
this.vertices.far[3].set(-1, 1, 1);
|
||||
this.vertices.far.forEach(function(v) {
|
||||
v.applyMatrix4(inverseProjectionMatrix);
|
||||
const absZ = Math.abs(v.z);
|
||||
if (isOrthographic) {
|
||||
v.z *= Math.min(maxFar / absZ, 1);
|
||||
} else {
|
||||
v.multiplyScalar(Math.min(maxFar / absZ, 1));
|
||||
}
|
||||
});
|
||||
return this.vertices;
|
||||
}
|
||||
split(breaks, target) {
|
||||
while (breaks.length > target.length) {
|
||||
target.push(new CSMFrustum());
|
||||
}
|
||||
target.length = breaks.length;
|
||||
for (let i = 0; i < breaks.length; i++) {
|
||||
const cascade = target[i];
|
||||
if (i === 0) {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.near[j].copy(this.vertices.near[j]);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.near[j].lerpVectors(this.vertices.near[j], this.vertices.far[j], breaks[i - 1]);
|
||||
}
|
||||
}
|
||||
if (i === breaks.length - 1) {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.far[j].copy(this.vertices.far[j]);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.far[j].lerpVectors(this.vertices.near[j], this.vertices.far[j], breaks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
toSpace(cameraMatrix, target) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
target.vertices.near[i].copy(this.vertices.near[i]).applyMatrix4(cameraMatrix);
|
||||
target.vertices.far[i].copy(this.vertices.far[i]).applyMatrix4(cameraMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.CSMFrustum = CSMFrustum;
|
||||
//# sourceMappingURL=CSMFrustum.cjs.map
|
||||
1
node_modules/three-stdlib/csm/CSMFrustum.cjs.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSMFrustum.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
19
node_modules/three-stdlib/csm/CSMFrustum.d.ts
generated
vendored
Normal file
19
node_modules/three-stdlib/csm/CSMFrustum.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Matrix4, Vector3 } from 'three'
|
||||
|
||||
export interface CSMFrustumVerticies {
|
||||
near: Vector3[]
|
||||
far: Vector3[]
|
||||
}
|
||||
|
||||
export interface CSMFrustumParameters {
|
||||
projectionMatrix?: Matrix4
|
||||
maxFar?: number
|
||||
}
|
||||
|
||||
export default class CSMFrustum {
|
||||
constructor(data?: CSMFrustumParameters)
|
||||
vertices: CSMFrustumVerticies
|
||||
setFromProjectionMatrix(projectionMatrix: Matrix4, maxFar: number): CSMFrustumVerticies
|
||||
split(breaks: number[], target: CSMFrustum[]): void
|
||||
toSpace(cameraMatrix: Matrix4, target: CSMFrustum): void
|
||||
}
|
||||
76
node_modules/three-stdlib/csm/CSMFrustum.js
generated
vendored
Normal file
76
node_modules/three-stdlib/csm/CSMFrustum.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { Vector3, Matrix4 } from "three";
|
||||
const inverseProjectionMatrix = /* @__PURE__ */ new Matrix4();
|
||||
class CSMFrustum {
|
||||
constructor(data) {
|
||||
data = data || {};
|
||||
this.vertices = {
|
||||
near: [new Vector3(), new Vector3(), new Vector3(), new Vector3()],
|
||||
far: [new Vector3(), new Vector3(), new Vector3(), new Vector3()]
|
||||
};
|
||||
if (data.projectionMatrix !== void 0) {
|
||||
this.setFromProjectionMatrix(data.projectionMatrix, data.maxFar || 1e4);
|
||||
}
|
||||
}
|
||||
setFromProjectionMatrix(projectionMatrix, maxFar) {
|
||||
const isOrthographic = projectionMatrix.elements[2 * 4 + 3] === 0;
|
||||
inverseProjectionMatrix.copy(projectionMatrix).invert();
|
||||
this.vertices.near[0].set(1, 1, -1);
|
||||
this.vertices.near[1].set(1, -1, -1);
|
||||
this.vertices.near[2].set(-1, -1, -1);
|
||||
this.vertices.near[3].set(-1, 1, -1);
|
||||
this.vertices.near.forEach(function(v) {
|
||||
v.applyMatrix4(inverseProjectionMatrix);
|
||||
});
|
||||
this.vertices.far[0].set(1, 1, 1);
|
||||
this.vertices.far[1].set(1, -1, 1);
|
||||
this.vertices.far[2].set(-1, -1, 1);
|
||||
this.vertices.far[3].set(-1, 1, 1);
|
||||
this.vertices.far.forEach(function(v) {
|
||||
v.applyMatrix4(inverseProjectionMatrix);
|
||||
const absZ = Math.abs(v.z);
|
||||
if (isOrthographic) {
|
||||
v.z *= Math.min(maxFar / absZ, 1);
|
||||
} else {
|
||||
v.multiplyScalar(Math.min(maxFar / absZ, 1));
|
||||
}
|
||||
});
|
||||
return this.vertices;
|
||||
}
|
||||
split(breaks, target) {
|
||||
while (breaks.length > target.length) {
|
||||
target.push(new CSMFrustum());
|
||||
}
|
||||
target.length = breaks.length;
|
||||
for (let i = 0; i < breaks.length; i++) {
|
||||
const cascade = target[i];
|
||||
if (i === 0) {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.near[j].copy(this.vertices.near[j]);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.near[j].lerpVectors(this.vertices.near[j], this.vertices.far[j], breaks[i - 1]);
|
||||
}
|
||||
}
|
||||
if (i === breaks.length - 1) {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.far[j].copy(this.vertices.far[j]);
|
||||
}
|
||||
} else {
|
||||
for (let j = 0; j < 4; j++) {
|
||||
cascade.vertices.far[j].lerpVectors(this.vertices.near[j], this.vertices.far[j], breaks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
toSpace(cameraMatrix, target) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
target.vertices.near[i].copy(this.vertices.near[i]).applyMatrix4(cameraMatrix);
|
||||
target.vertices.far[i].copy(this.vertices.far[i]).applyMatrix4(cameraMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
CSMFrustum
|
||||
};
|
||||
//# sourceMappingURL=CSMFrustum.js.map
|
||||
1
node_modules/three-stdlib/csm/CSMFrustum.js.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSMFrustum.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
115
node_modules/three-stdlib/csm/CSMHelper.cjs
generated
vendored
Normal file
115
node_modules/three-stdlib/csm/CSMHelper.cjs
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const THREE = require("three");
|
||||
class CSMHelper extends THREE.Group {
|
||||
constructor(csm) {
|
||||
super();
|
||||
this.csm = csm;
|
||||
this.displayFrustum = true;
|
||||
this.displayPlanes = true;
|
||||
this.displayShadowBounds = true;
|
||||
const indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
|
||||
const positions = new Float32Array(24);
|
||||
const frustumGeometry = new THREE.BufferGeometry();
|
||||
frustumGeometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
frustumGeometry.setAttribute("position", new THREE.BufferAttribute(positions, 3, false));
|
||||
const frustumLines = new THREE.LineSegments(frustumGeometry, new THREE.LineBasicMaterial());
|
||||
this.add(frustumLines);
|
||||
this.frustumLines = frustumLines;
|
||||
this.cascadeLines = [];
|
||||
this.cascadePlanes = [];
|
||||
this.shadowLines = [];
|
||||
}
|
||||
updateVisibility() {
|
||||
const displayFrustum = this.displayFrustum;
|
||||
const displayPlanes = this.displayPlanes;
|
||||
const displayShadowBounds = this.displayShadowBounds;
|
||||
const frustumLines = this.frustumLines;
|
||||
const cascadeLines = this.cascadeLines;
|
||||
const cascadePlanes = this.cascadePlanes;
|
||||
const shadowLines = this.shadowLines;
|
||||
for (let i = 0, l = cascadeLines.length; i < l; i++) {
|
||||
const cascadeLine = cascadeLines[i];
|
||||
const cascadePlane = cascadePlanes[i];
|
||||
const shadowLineGroup = shadowLines[i];
|
||||
cascadeLine.visible = displayFrustum;
|
||||
cascadePlane.visible = displayFrustum && displayPlanes;
|
||||
shadowLineGroup.visible = displayShadowBounds;
|
||||
}
|
||||
frustumLines.visible = displayFrustum;
|
||||
}
|
||||
update() {
|
||||
const csm = this.csm;
|
||||
const camera = csm.camera;
|
||||
const cascades = csm.cascades;
|
||||
const mainFrustum = csm.mainFrustum;
|
||||
const frustums = csm.frustums;
|
||||
const lights = csm.lights;
|
||||
const frustumLines = this.frustumLines;
|
||||
const frustumLinePositions = frustumLines.geometry.getAttribute("position");
|
||||
const cascadeLines = this.cascadeLines;
|
||||
const cascadePlanes = this.cascadePlanes;
|
||||
const shadowLines = this.shadowLines;
|
||||
this.position.copy(camera.position);
|
||||
this.quaternion.copy(camera.quaternion);
|
||||
this.scale.copy(camera.scale);
|
||||
this.updateMatrixWorld(true);
|
||||
while (cascadeLines.length > cascades) {
|
||||
this.remove(cascadeLines.pop());
|
||||
this.remove(cascadePlanes.pop());
|
||||
this.remove(shadowLines.pop());
|
||||
}
|
||||
while (cascadeLines.length < cascades) {
|
||||
const cascadeLine = new THREE.Box3Helper(new THREE.Box3(), 16777215);
|
||||
const planeMat = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0.1, depthWrite: false, side: THREE.DoubleSide });
|
||||
const cascadePlane = new THREE.Mesh(new THREE.PlaneGeometry(), planeMat);
|
||||
const shadowLineGroup = new THREE.Group();
|
||||
const shadowLine = new THREE.Box3Helper(new THREE.Box3(), 16776960);
|
||||
shadowLineGroup.add(shadowLine);
|
||||
this.add(cascadeLine);
|
||||
this.add(cascadePlane);
|
||||
this.add(shadowLineGroup);
|
||||
cascadeLines.push(cascadeLine);
|
||||
cascadePlanes.push(cascadePlane);
|
||||
shadowLines.push(shadowLineGroup);
|
||||
}
|
||||
for (let i = 0; i < cascades; i++) {
|
||||
const frustum = frustums[i];
|
||||
const light = lights[i];
|
||||
const shadowCam = light.shadow.camera;
|
||||
const farVerts2 = frustum.vertices.far;
|
||||
const cascadeLine = cascadeLines[i];
|
||||
const cascadePlane = cascadePlanes[i];
|
||||
const shadowLineGroup = shadowLines[i];
|
||||
const shadowLine = shadowLineGroup.children[0];
|
||||
cascadeLine.box.min.copy(farVerts2[2]);
|
||||
cascadeLine.box.max.copy(farVerts2[0]);
|
||||
cascadeLine.box.max.z += 1e-4;
|
||||
cascadePlane.position.addVectors(farVerts2[0], farVerts2[2]);
|
||||
cascadePlane.position.multiplyScalar(0.5);
|
||||
cascadePlane.scale.subVectors(farVerts2[0], farVerts2[2]);
|
||||
cascadePlane.scale.z = 1e-4;
|
||||
this.remove(shadowLineGroup);
|
||||
shadowLineGroup.position.copy(shadowCam.position);
|
||||
shadowLineGroup.quaternion.copy(shadowCam.quaternion);
|
||||
shadowLineGroup.scale.copy(shadowCam.scale);
|
||||
shadowLineGroup.updateMatrixWorld(true);
|
||||
this.attach(shadowLineGroup);
|
||||
shadowLine.box.min.set(shadowCam.bottom, shadowCam.left, -shadowCam.far);
|
||||
shadowLine.box.max.set(shadowCam.top, shadowCam.right, -shadowCam.near);
|
||||
}
|
||||
const nearVerts = mainFrustum.vertices.near;
|
||||
const farVerts = mainFrustum.vertices.far;
|
||||
frustumLinePositions.setXYZ(0, farVerts[0].x, farVerts[0].y, farVerts[0].z);
|
||||
frustumLinePositions.setXYZ(1, farVerts[3].x, farVerts[3].y, farVerts[3].z);
|
||||
frustumLinePositions.setXYZ(2, farVerts[2].x, farVerts[2].y, farVerts[2].z);
|
||||
frustumLinePositions.setXYZ(3, farVerts[1].x, farVerts[1].y, farVerts[1].z);
|
||||
frustumLinePositions.setXYZ(4, nearVerts[0].x, nearVerts[0].y, nearVerts[0].z);
|
||||
frustumLinePositions.setXYZ(5, nearVerts[3].x, nearVerts[3].y, nearVerts[3].z);
|
||||
frustumLinePositions.setXYZ(6, nearVerts[2].x, nearVerts[2].y, nearVerts[2].z);
|
||||
frustumLinePositions.setXYZ(7, nearVerts[1].x, nearVerts[1].y, nearVerts[1].z);
|
||||
frustumLinePositions.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
exports.CSMHelper = CSMHelper;
|
||||
//# sourceMappingURL=CSMHelper.cjs.map
|
||||
1
node_modules/three-stdlib/csm/CSMHelper.cjs.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSMHelper.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
26
node_modules/three-stdlib/csm/CSMHelper.d.ts
generated
vendored
Normal file
26
node_modules/three-stdlib/csm/CSMHelper.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
Box3Helper,
|
||||
BufferGeometry,
|
||||
Group,
|
||||
LineBasicMaterial,
|
||||
LineSegments,
|
||||
Mesh,
|
||||
MeshBasicMaterial,
|
||||
PlaneGeometry,
|
||||
} from 'three'
|
||||
|
||||
import { CSM } from './CSM'
|
||||
|
||||
export class CSMHelper<TCSM extends CSM = CSM> extends Group {
|
||||
constructor(csm: TCSM)
|
||||
csm: TCSM
|
||||
displayFrustum: boolean
|
||||
displayPlanes: boolean
|
||||
displayShadowBounds: boolean
|
||||
frustumLines: LineSegments<BufferGeometry, LineBasicMaterial>
|
||||
cascadeLines: Box3Helper[]
|
||||
cascadePlanes: Array<Mesh<PlaneGeometry, MeshBasicMaterial>>
|
||||
shadowLines: Box3Helper[]
|
||||
updateVisibility(): void
|
||||
update(): void
|
||||
}
|
||||
115
node_modules/three-stdlib/csm/CSMHelper.js
generated
vendored
Normal file
115
node_modules/three-stdlib/csm/CSMHelper.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
import { Group, BufferGeometry, BufferAttribute, LineSegments, LineBasicMaterial, Box3Helper, Box3, MeshBasicMaterial, DoubleSide, Mesh, PlaneGeometry } from "three";
|
||||
class CSMHelper extends Group {
|
||||
constructor(csm) {
|
||||
super();
|
||||
this.csm = csm;
|
||||
this.displayFrustum = true;
|
||||
this.displayPlanes = true;
|
||||
this.displayShadowBounds = true;
|
||||
const indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
|
||||
const positions = new Float32Array(24);
|
||||
const frustumGeometry = new BufferGeometry();
|
||||
frustumGeometry.setIndex(new BufferAttribute(indices, 1));
|
||||
frustumGeometry.setAttribute("position", new BufferAttribute(positions, 3, false));
|
||||
const frustumLines = new LineSegments(frustumGeometry, new LineBasicMaterial());
|
||||
this.add(frustumLines);
|
||||
this.frustumLines = frustumLines;
|
||||
this.cascadeLines = [];
|
||||
this.cascadePlanes = [];
|
||||
this.shadowLines = [];
|
||||
}
|
||||
updateVisibility() {
|
||||
const displayFrustum = this.displayFrustum;
|
||||
const displayPlanes = this.displayPlanes;
|
||||
const displayShadowBounds = this.displayShadowBounds;
|
||||
const frustumLines = this.frustumLines;
|
||||
const cascadeLines = this.cascadeLines;
|
||||
const cascadePlanes = this.cascadePlanes;
|
||||
const shadowLines = this.shadowLines;
|
||||
for (let i = 0, l = cascadeLines.length; i < l; i++) {
|
||||
const cascadeLine = cascadeLines[i];
|
||||
const cascadePlane = cascadePlanes[i];
|
||||
const shadowLineGroup = shadowLines[i];
|
||||
cascadeLine.visible = displayFrustum;
|
||||
cascadePlane.visible = displayFrustum && displayPlanes;
|
||||
shadowLineGroup.visible = displayShadowBounds;
|
||||
}
|
||||
frustumLines.visible = displayFrustum;
|
||||
}
|
||||
update() {
|
||||
const csm = this.csm;
|
||||
const camera = csm.camera;
|
||||
const cascades = csm.cascades;
|
||||
const mainFrustum = csm.mainFrustum;
|
||||
const frustums = csm.frustums;
|
||||
const lights = csm.lights;
|
||||
const frustumLines = this.frustumLines;
|
||||
const frustumLinePositions = frustumLines.geometry.getAttribute("position");
|
||||
const cascadeLines = this.cascadeLines;
|
||||
const cascadePlanes = this.cascadePlanes;
|
||||
const shadowLines = this.shadowLines;
|
||||
this.position.copy(camera.position);
|
||||
this.quaternion.copy(camera.quaternion);
|
||||
this.scale.copy(camera.scale);
|
||||
this.updateMatrixWorld(true);
|
||||
while (cascadeLines.length > cascades) {
|
||||
this.remove(cascadeLines.pop());
|
||||
this.remove(cascadePlanes.pop());
|
||||
this.remove(shadowLines.pop());
|
||||
}
|
||||
while (cascadeLines.length < cascades) {
|
||||
const cascadeLine = new Box3Helper(new Box3(), 16777215);
|
||||
const planeMat = new MeshBasicMaterial({ transparent: true, opacity: 0.1, depthWrite: false, side: DoubleSide });
|
||||
const cascadePlane = new Mesh(new PlaneGeometry(), planeMat);
|
||||
const shadowLineGroup = new Group();
|
||||
const shadowLine = new Box3Helper(new Box3(), 16776960);
|
||||
shadowLineGroup.add(shadowLine);
|
||||
this.add(cascadeLine);
|
||||
this.add(cascadePlane);
|
||||
this.add(shadowLineGroup);
|
||||
cascadeLines.push(cascadeLine);
|
||||
cascadePlanes.push(cascadePlane);
|
||||
shadowLines.push(shadowLineGroup);
|
||||
}
|
||||
for (let i = 0; i < cascades; i++) {
|
||||
const frustum = frustums[i];
|
||||
const light = lights[i];
|
||||
const shadowCam = light.shadow.camera;
|
||||
const farVerts2 = frustum.vertices.far;
|
||||
const cascadeLine = cascadeLines[i];
|
||||
const cascadePlane = cascadePlanes[i];
|
||||
const shadowLineGroup = shadowLines[i];
|
||||
const shadowLine = shadowLineGroup.children[0];
|
||||
cascadeLine.box.min.copy(farVerts2[2]);
|
||||
cascadeLine.box.max.copy(farVerts2[0]);
|
||||
cascadeLine.box.max.z += 1e-4;
|
||||
cascadePlane.position.addVectors(farVerts2[0], farVerts2[2]);
|
||||
cascadePlane.position.multiplyScalar(0.5);
|
||||
cascadePlane.scale.subVectors(farVerts2[0], farVerts2[2]);
|
||||
cascadePlane.scale.z = 1e-4;
|
||||
this.remove(shadowLineGroup);
|
||||
shadowLineGroup.position.copy(shadowCam.position);
|
||||
shadowLineGroup.quaternion.copy(shadowCam.quaternion);
|
||||
shadowLineGroup.scale.copy(shadowCam.scale);
|
||||
shadowLineGroup.updateMatrixWorld(true);
|
||||
this.attach(shadowLineGroup);
|
||||
shadowLine.box.min.set(shadowCam.bottom, shadowCam.left, -shadowCam.far);
|
||||
shadowLine.box.max.set(shadowCam.top, shadowCam.right, -shadowCam.near);
|
||||
}
|
||||
const nearVerts = mainFrustum.vertices.near;
|
||||
const farVerts = mainFrustum.vertices.far;
|
||||
frustumLinePositions.setXYZ(0, farVerts[0].x, farVerts[0].y, farVerts[0].z);
|
||||
frustumLinePositions.setXYZ(1, farVerts[3].x, farVerts[3].y, farVerts[3].z);
|
||||
frustumLinePositions.setXYZ(2, farVerts[2].x, farVerts[2].y, farVerts[2].z);
|
||||
frustumLinePositions.setXYZ(3, farVerts[1].x, farVerts[1].y, farVerts[1].z);
|
||||
frustumLinePositions.setXYZ(4, nearVerts[0].x, nearVerts[0].y, nearVerts[0].z);
|
||||
frustumLinePositions.setXYZ(5, nearVerts[3].x, nearVerts[3].y, nearVerts[3].z);
|
||||
frustumLinePositions.setXYZ(6, nearVerts[2].x, nearVerts[2].y, nearVerts[2].z);
|
||||
frustumLinePositions.setXYZ(7, nearVerts[1].x, nearVerts[1].y, nearVerts[1].z);
|
||||
frustumLinePositions.needsUpdate = true;
|
||||
}
|
||||
}
|
||||
export {
|
||||
CSMHelper
|
||||
};
|
||||
//# sourceMappingURL=CSMHelper.js.map
|
||||
1
node_modules/three-stdlib/csm/CSMHelper.js.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSMHelper.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
262
node_modules/three-stdlib/csm/CSMShader.cjs
generated
vendored
Normal file
262
node_modules/three-stdlib/csm/CSMShader.cjs
generated
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const THREE = require("three");
|
||||
const CSMShader = {
|
||||
lights_fragment_begin: (
|
||||
/* glsl */
|
||||
`
|
||||
GeometricContext geometry;
|
||||
|
||||
geometry.position = - vViewPosition;
|
||||
geometry.normal = normal;
|
||||
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
|
||||
|
||||
#ifdef CLEARCOAT
|
||||
|
||||
geometry.clearcoatNormal = clearcoatNormal;
|
||||
|
||||
#endif
|
||||
|
||||
IncidentLight directLight;
|
||||
|
||||
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
|
||||
|
||||
PointLight pointLight;
|
||||
#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
|
||||
PointLightShadow pointLightShadow;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
||||
|
||||
pointLight = pointLights[ i ];
|
||||
|
||||
getPointLightInfo( pointLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
|
||||
pointLightShadow = pointLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
||||
#endif
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
|
||||
|
||||
SpotLight spotLight;
|
||||
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
|
||||
SpotLightShadow spotLightShadow;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
||||
|
||||
spotLight = spotLights[ i ];
|
||||
|
||||
getSpotLightInfo( spotLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
||||
spotLightShadow = spotLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
|
||||
#endif
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_DIR_LIGHTS > 0) && defined( RE_Direct ) && defined( USE_CSM ) && defined( CSM_CASCADES )
|
||||
|
||||
DirectionalLight directionalLight;
|
||||
float linearDepth = (vViewPosition.z) / (shadowFar - cameraNear);
|
||||
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
|
||||
DirectionalLightShadow directionalLightShadow;
|
||||
#endif
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && defined( CSM_FADE )
|
||||
vec2 cascade;
|
||||
float cascadeCenter;
|
||||
float closestEdge;
|
||||
float margin;
|
||||
float csmx;
|
||||
float csmy;
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
||||
// NOTE: Depth gets larger away from the camera.
|
||||
// cascade.x is closer, cascade.y is further
|
||||
cascade = CSM_cascades[ i ];
|
||||
cascadeCenter = ( cascade.x + cascade.y ) / 2.0;
|
||||
closestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;
|
||||
margin = 0.25 * pow( closestEdge, 2.0 );
|
||||
csmx = cascade.x - margin / 2.0;
|
||||
csmy = cascade.y + margin / 2.0;
|
||||
if( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {
|
||||
|
||||
float dist = min( linearDepth - csmx, csmy - linearDepth );
|
||||
float ratio = clamp( dist / margin, 0.0, 1.0 );
|
||||
|
||||
vec3 prevColor = directLight.color;
|
||||
directionalLightShadow = directionalLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
||||
|
||||
bool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;
|
||||
directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
|
||||
|
||||
ReflectedLight prevLight = reflectedLight;
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
|
||||
float blendRatio = shouldBlend ? ratio : 1.0;
|
||||
|
||||
reflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );
|
||||
reflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );
|
||||
reflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );
|
||||
reflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
#else
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
||||
|
||||
directionalLightShadow = directionalLightShadows[ i ];
|
||||
if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
||||
|
||||
if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS)
|
||||
// compute the lights not casting shadows (if any)
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = NUM_DIR_LIGHT_SHADOWS; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) && !defined( USE_CSM ) && !defined( CSM_CASCADES )
|
||||
|
||||
DirectionalLight directionalLight;
|
||||
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
|
||||
DirectionalLightShadow directionalLightShadow;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
||||
directionalLightShadow = directionalLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
||||
#endif
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
|
||||
|
||||
RectAreaLight rectAreaLight;
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
||||
|
||||
rectAreaLight = rectAreaLights[ i ];
|
||||
RE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( RE_IndirectDiffuse )
|
||||
|
||||
vec3 iblIrradiance = vec3( 0.0 );
|
||||
|
||||
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
||||
|
||||
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
||||
|
||||
#if ( NUM_HEMI_LIGHTS > 0 )
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
||||
|
||||
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( RE_IndirectSpecular )
|
||||
|
||||
vec3 radiance = vec3( 0.0 );
|
||||
vec3 clearcoatRadiance = vec3( 0.0 );
|
||||
|
||||
#endif
|
||||
`
|
||||
),
|
||||
getlights_pars_begin() {
|
||||
return (
|
||||
/* glsl */
|
||||
`
|
||||
#if defined( USE_CSM ) && defined( CSM_CASCADES )
|
||||
uniform vec2 CSM_cascades[CSM_CASCADES];
|
||||
uniform float cameraNear;
|
||||
uniform float shadowFar;
|
||||
#endif
|
||||
|
||||
${THREE.ShaderChunk.lights_pars_begin}
|
||||
`
|
||||
);
|
||||
}
|
||||
};
|
||||
exports.CSMShader = CSMShader;
|
||||
//# sourceMappingURL=CSMShader.cjs.map
|
||||
1
node_modules/three-stdlib/csm/CSMShader.cjs.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSMShader.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
4
node_modules/three-stdlib/csm/CSMShader.d.ts
generated
vendored
Normal file
4
node_modules/three-stdlib/csm/CSMShader.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface CSMShader {
|
||||
lights_fragment_begin: string
|
||||
lights_pars_begin: string
|
||||
}
|
||||
262
node_modules/three-stdlib/csm/CSMShader.js
generated
vendored
Normal file
262
node_modules/three-stdlib/csm/CSMShader.js
generated
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
import { ShaderChunk } from "three";
|
||||
const CSMShader = {
|
||||
lights_fragment_begin: (
|
||||
/* glsl */
|
||||
`
|
||||
GeometricContext geometry;
|
||||
|
||||
geometry.position = - vViewPosition;
|
||||
geometry.normal = normal;
|
||||
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
|
||||
|
||||
#ifdef CLEARCOAT
|
||||
|
||||
geometry.clearcoatNormal = clearcoatNormal;
|
||||
|
||||
#endif
|
||||
|
||||
IncidentLight directLight;
|
||||
|
||||
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
|
||||
|
||||
PointLight pointLight;
|
||||
#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
|
||||
PointLightShadow pointLightShadow;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
||||
|
||||
pointLight = pointLights[ i ];
|
||||
|
||||
getPointLightInfo( pointLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
|
||||
pointLightShadow = pointLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
||||
#endif
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
|
||||
|
||||
SpotLight spotLight;
|
||||
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
|
||||
SpotLightShadow spotLightShadow;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
||||
|
||||
spotLight = spotLights[ i ];
|
||||
|
||||
getSpotLightInfo( spotLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
||||
spotLightShadow = spotLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
|
||||
#endif
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_DIR_LIGHTS > 0) && defined( RE_Direct ) && defined( USE_CSM ) && defined( CSM_CASCADES )
|
||||
|
||||
DirectionalLight directionalLight;
|
||||
float linearDepth = (vViewPosition.z) / (shadowFar - cameraNear);
|
||||
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
|
||||
DirectionalLightShadow directionalLightShadow;
|
||||
#endif
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && defined( CSM_FADE )
|
||||
vec2 cascade;
|
||||
float cascadeCenter;
|
||||
float closestEdge;
|
||||
float margin;
|
||||
float csmx;
|
||||
float csmy;
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
||||
// NOTE: Depth gets larger away from the camera.
|
||||
// cascade.x is closer, cascade.y is further
|
||||
cascade = CSM_cascades[ i ];
|
||||
cascadeCenter = ( cascade.x + cascade.y ) / 2.0;
|
||||
closestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;
|
||||
margin = 0.25 * pow( closestEdge, 2.0 );
|
||||
csmx = cascade.x - margin / 2.0;
|
||||
csmy = cascade.y + margin / 2.0;
|
||||
if( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {
|
||||
|
||||
float dist = min( linearDepth - csmx, csmy - linearDepth );
|
||||
float ratio = clamp( dist / margin, 0.0, 1.0 );
|
||||
|
||||
vec3 prevColor = directLight.color;
|
||||
directionalLightShadow = directionalLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
||||
|
||||
bool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;
|
||||
directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
|
||||
|
||||
ReflectedLight prevLight = reflectedLight;
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
|
||||
float blendRatio = shouldBlend ? ratio : 1.0;
|
||||
|
||||
reflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );
|
||||
reflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );
|
||||
reflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );
|
||||
reflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
#else
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
||||
|
||||
directionalLightShadow = directionalLightShadows[ i ];
|
||||
if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
||||
|
||||
if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS)
|
||||
// compute the lights not casting shadows (if any)
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = NUM_DIR_LIGHT_SHADOWS; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) && !defined( USE_CSM ) && !defined( CSM_CASCADES )
|
||||
|
||||
DirectionalLight directionalLight;
|
||||
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
|
||||
DirectionalLightShadow directionalLightShadow;
|
||||
#endif
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
||||
|
||||
directionalLight = directionalLights[ i ];
|
||||
|
||||
getDirectionalLightInfo( directionalLight, geometry, directLight );
|
||||
|
||||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
||||
directionalLightShadow = directionalLightShadows[ i ];
|
||||
directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
||||
#endif
|
||||
|
||||
RE_Direct( directLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
|
||||
|
||||
RectAreaLight rectAreaLight;
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
||||
|
||||
rectAreaLight = rectAreaLights[ i ];
|
||||
RE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( RE_IndirectDiffuse )
|
||||
|
||||
vec3 iblIrradiance = vec3( 0.0 );
|
||||
|
||||
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
||||
|
||||
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
||||
|
||||
#if ( NUM_HEMI_LIGHTS > 0 )
|
||||
|
||||
#pragma unroll_loop_start
|
||||
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
||||
|
||||
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
|
||||
|
||||
}
|
||||
#pragma unroll_loop_end
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( RE_IndirectSpecular )
|
||||
|
||||
vec3 radiance = vec3( 0.0 );
|
||||
vec3 clearcoatRadiance = vec3( 0.0 );
|
||||
|
||||
#endif
|
||||
`
|
||||
),
|
||||
getlights_pars_begin() {
|
||||
return (
|
||||
/* glsl */
|
||||
`
|
||||
#if defined( USE_CSM ) && defined( CSM_CASCADES )
|
||||
uniform vec2 CSM_cascades[CSM_CASCADES];
|
||||
uniform float cameraNear;
|
||||
uniform float shadowFar;
|
||||
#endif
|
||||
|
||||
${ShaderChunk.lights_pars_begin}
|
||||
`
|
||||
);
|
||||
}
|
||||
};
|
||||
export {
|
||||
CSMShader
|
||||
};
|
||||
//# sourceMappingURL=CSMShader.js.map
|
||||
1
node_modules/three-stdlib/csm/CSMShader.js.map
generated
vendored
Normal file
1
node_modules/three-stdlib/csm/CSMShader.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user