Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for ShadowComponent in UVOL #9303

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/engine/src/scene/components/UVOL1Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
25 changes: 15 additions & 10 deletions packages/engine/src/scene/components/UVOL2Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 && shadow) {
CITIZENDOT marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Cast shadows properly with uniform solve
shadow.cast.set(false)
shadow.receive.set(false)
} else if (shadow) {
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]
Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/scene/components/VolumetricComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down