diff --git a/packages/engine/src/scene/components/UVOL1Component.ts b/packages/engine/src/scene/components/UVOL1Component.ts index f257e6472c2..beea50a147a 100644 --- a/packages/engine/src/scene/components/UVOL1Component.ts +++ b/packages/engine/src/scene/components/UVOL1Component.ts @@ -47,7 +47,8 @@ import { hasComponent, removeComponent, setComponent, - useComponent + useComponent, + useOptionalComponent } from '../../ecs/functions/ComponentFunctions' import { AnimationSystemGroup } from '../../ecs/functions/EngineFunctions' import { useEntityContext } from '../../ecs/functions/EntityFunctions' @@ -113,6 +114,7 @@ function UVOL1Reactor() { const entity = useEntityContext() const volumetric = useComponent(entity, VolumetricComponent) const component = useComponent(entity, UVOL1Component) + const shadow = useOptionalComponent(entity, ShadowComponent) const videoElement = getMutableComponent(entity, MediaElementComponent).value const audioContext = getState(AudioState).audioContext const video = videoElement.element as HTMLVideoElement @@ -160,9 +162,6 @@ function UVOL1Reactor() { if (volumetric.useLoadingEffect.value) { setComponent(entity, UVOLDissolveComponent) } - const shadow = getMutableComponent(entity, ShadowComponent) - shadow.cast.set(true) - shadow.receive.set(true) video.src = component.manifestPath.value.replace('.manifest', '.mp4') video.load() @@ -181,6 +180,13 @@ function UVOL1Reactor() { } }, []) + useEffect(() => { + if (shadow) { + shadow.cast.set(true) + shadow.receive.set(true) + } + }, [shadow]) + useEffect(() => { if (component.loadingEffectStarted.value && !component.loadingEffectEnded.value) { // Loading effect in progress. Let it finish diff --git a/packages/engine/src/scene/components/UVOL2Component.ts b/packages/engine/src/scene/components/UVOL2Component.ts index 123fba41682..f5011a0ed35 100644 --- a/packages/engine/src/scene/components/UVOL2Component.ts +++ b/packages/engine/src/scene/components/UVOL2Component.ts @@ -50,7 +50,8 @@ import { getMutableComponent, removeComponent, setComponent, - useComponent + useComponent, + useOptionalComponent } from '../../ecs/functions/ComponentFunctions' import { AnimationSystemGroup } from '../../ecs/functions/EngineFunctions' import { useEntityContext } from '../../ecs/functions/EntityFunctions' @@ -282,6 +283,7 @@ function UVOL2Reactor() { const entity = useEntityContext() const volumetric = useComponent(entity, VolumetricComponent) const component = useComponent(entity, UVOL2Component) + const shadow = useOptionalComponent(entity, ShadowComponent) // These are accessed very frequently, Better not to fetch from state everytime const manifest = useRef(component.data.value) @@ -401,15 +403,6 @@ transformed.z += mix(keyframeA.z, keyframeB.z, mixRatio); manifest.current = calculatePriority(component.data.get({ noproxy: true })) component.data.set(manifest.current) - const shadow = getMutableComponent(entity, ShadowComponent) - if (manifest.current.type === UVOL_TYPE.UNIFORM_SOLVE_WITH_COMPRESSED_TEXTURE) { - // TODO: Cast shadows properly with uniform solve - shadow.cast.set(false) - shadow.receive.set(false) - } else { - shadow.cast.set(true) - shadow.receive.set(true) - } geometryTargets.current = Object.keys(manifest.current.geometry.targets) geometryTargets.current.sort((a, b) => { @@ -459,6 +452,18 @@ transformed.z += mix(keyframeA.z, keyframeB.z, mixRatio); } }, []) + useEffect(() => { + if (!shadow) return + if (manifest.current.type === UVOL_TYPE.UNIFORM_SOLVE_WITH_COMPRESSED_TEXTURE) { + // TODO: Cast shadows properly with uniform solve + shadow.cast.set(false) + shadow.receive.set(false) + } else { + shadow.cast.set(true) + shadow.receive.set(true) + } + }, [shadow]) + const fetchNonUniformSolveGeometry = (startFrame: number, endFrame: number, target: string) => { // TODO: Needs thorough testing const targetData = manifest.current.geometry.targets[target] diff --git a/packages/engine/src/scene/components/VolumetricComponent.ts b/packages/engine/src/scene/components/VolumetricComponent.ts index 5c0cfd483c6..bf3b8e2936a 100755 --- a/packages/engine/src/scene/components/VolumetricComponent.ts +++ b/packages/engine/src/scene/components/VolumetricComponent.ts @@ -40,6 +40,7 @@ import { useEntityContext } from '../../ecs/functions/EntityFunctions' import { EngineRenderer } from '../../renderer/WebGLRendererSystem' import { PlayMode } from '../constants/PlayMode' import { AudioNodeGroups, MediaElementComponent, createAudioNodeGroup, getNextTrack } from './MediaComponent' +import { ShadowComponent } from './ShadowComponent' import { UVOL1Component } from './UVOL1Component' import { UVOL2Component } from './UVOL2Component' @@ -166,6 +167,7 @@ export function VolumetricReactor() { setComponent(entity, MediaElementComponent, { element: document.createElement('video') as HTMLMediaElement }) + setComponent(entity, ShadowComponent) const videoElement = getMutableComponent(entity, MediaElementComponent) const element = videoElement.element.value as HTMLVideoElement element.playsInline = true