auto-git:
[change] src/rendering/advanced-rendering.ts
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
PointLight,
|
PointLight,
|
||||||
SpotLight,
|
SpotLight,
|
||||||
type Object3D,
|
type Object3D,
|
||||||
|
type Material,
|
||||||
type PerspectiveCamera,
|
type PerspectiveCamera,
|
||||||
type Scene,
|
type Scene,
|
||||||
type WebGLRenderer,
|
type WebGLRenderer,
|
||||||
@@ -207,25 +208,50 @@ export function createAdvancedRenderingComposer(
|
|||||||
|
|
||||||
export function applyAdvancedRenderingRenderableShadowFlags(root: Object3D, enabled: boolean) {
|
export function applyAdvancedRenderingRenderableShadowFlags(root: Object3D, enabled: boolean) {
|
||||||
root.traverse((object) => {
|
root.traverse((object) => {
|
||||||
if ((object as Mesh).isMesh === true && object.userData.shadowIgnored !== true) {
|
if ((object as Mesh).isMesh === true) {
|
||||||
const mesh = object as Mesh;
|
const mesh = object as Mesh;
|
||||||
mesh.castShadow = enabled;
|
const shadowEligible =
|
||||||
mesh.receiveShadow = enabled;
|
enabled &&
|
||||||
|
object.userData.shadowIgnored !== true &&
|
||||||
|
isRenderableMaterialEligibleForShadows(mesh.material);
|
||||||
|
mesh.castShadow = shadowEligible;
|
||||||
|
mesh.receiveShadow = shadowEligible;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function applyAdvancedRenderingLightShadowFlags(
|
function isRenderableMaterialEligibleForShadows(
|
||||||
root: Object3D,
|
material: Material | Material[]
|
||||||
settings: Pick<AdvancedRenderingSettings, "enabled" | "shadows">
|
|
||||||
) {
|
) {
|
||||||
const shadowEnabled = settings.enabled && settings.shadows.enabled;
|
const materials = Array.isArray(material) ? material : [material];
|
||||||
|
|
||||||
root.traverse((object) => {
|
return materials.every((candidate) => {
|
||||||
if (object instanceof DirectionalLight || object instanceof PointLight || object instanceof SpotLight) {
|
const shadowMaterial = candidate as Material & {
|
||||||
object.castShadow = shadowEnabled;
|
opacity?: number;
|
||||||
object.shadow.bias = settings.shadows.bias;
|
transparent?: boolean;
|
||||||
object.shadow.mapSize.set(settings.shadows.mapSize, settings.shadows.mapSize);
|
visible?: boolean;
|
||||||
}
|
};
|
||||||
|
const opacity = shadowMaterial.opacity ?? 1;
|
||||||
|
|
||||||
|
return shadowMaterial.visible !== false &&
|
||||||
|
shadowMaterial.transparent !== true &&
|
||||||
|
opacity >= 0.999;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function configureAdvancedRenderingShadowLight(
|
||||||
|
light: DirectionalLight | PointLight | SpotLight,
|
||||||
|
settings: Pick<AdvancedRenderingSettings, "enabled" | "shadows">
|
||||||
|
,
|
||||||
|
castShadow: boolean,
|
||||||
|
normalBias = 0
|
||||||
|
) {
|
||||||
|
const shadowEnabled =
|
||||||
|
settings.enabled && settings.shadows.enabled && castShadow;
|
||||||
|
|
||||||
|
light.castShadow = shadowEnabled;
|
||||||
|
light.shadow.autoUpdate = shadowEnabled;
|
||||||
|
light.shadow.bias = settings.shadows.bias;
|
||||||
|
light.shadow.normalBias = shadowEnabled ? Math.max(0, normalBias) : 0;
|
||||||
|
light.shadow.mapSize.set(settings.shadows.mapSize, settings.shadows.mapSize);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user