Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Re-add castShadow property to light components and default to false #7559

Merged
merged 7 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/client-core/i18n/en/editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@
"lbl-shadowmapResolution": "Shadow Map Resolution",
"lbl-shadowBias": "Shadow Bias",
"lbl-shadowRadius": "Shadow Radius",
"lbl-showCameraHelper": "Show Camera Helper"
"lbl-showCameraHelper": "Show Camera Helper",
"lbl-castShadows": "Cast Shadows"
},
"groundPlane": {
"name": "Ground Plane",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export const LightShadowProperties = (props: LightShadowPropertiesProps) => {
const lightComponent = useComponent(props.node.entity, props.comp).value as any

return (
<Fragment>
<>
<InputGroup name="Cast Shadows" label={t('editor:properties.directionalLight.lbl-castShadows')}>
<BooleanInput value={lightComponent.castShadow} onChange={updateProperty(props.comp, 'castShadow')} />
</InputGroup>
<InputGroup name="Shadow Map Resolution" label={t('editor:properties.directionalLight.lbl-shadowmapResolution')}>
<SelectInput
key={props.node.entity}
Expand Down Expand Up @@ -93,7 +96,7 @@ export const LightShadowProperties = (props: LightShadowPropertiesProps) => {
value={lightComponent.shadowRadius}
onChange={updateProperty(props.comp, 'shadowRadius')}
/>
</Fragment>
</>
)
}

Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/functions/addMediaNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createEntity } from '@xrengine/engine/src/ecs/functions/EntityFunctions
import { EntityTreeNode } from '@xrengine/engine/src/ecs/functions/EntityTree'
import { createEntityNode } from '@xrengine/engine/src/ecs/functions/EntityTree'
import { ImageComponent } from '@xrengine/engine/src/scene/components/ImageComponent'
import { LinkComponent } from '@xrengine/engine/src/scene/components/LinkComponent'
import { MediaComponent } from '@xrengine/engine/src/scene/components/MediaComponent'
import { ModelComponent } from '@xrengine/engine/src/scene/components/ModelComponent'
import { PrefabComponent } from '@xrengine/engine/src/scene/components/PrefabComponent'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const DirectionalLightComponent = defineComponent({
light,
color: new Color(),
intensity: 1,
castShadow: false,
shadowMapResolution: 512,
shadowBias: -0.00001,
shadowRadius: 1,
Expand All @@ -44,6 +45,7 @@ export const DirectionalLightComponent = defineComponent({
if (matches.string.test(json.color)) component.color.value.set(json.color)
if (matches.number.test(json.intensity)) component.intensity.set(json.intensity)
if (matches.number.test(json.cameraFar)) component.cameraFar.set(json.cameraFar)
if (matches.boolean.test(json.castShadow)) component.castShadow.set(json.castShadow)
/** backwards compat */
if (matches.array.test(json.shadowMapResolution))
component.shadowMapResolution.set((json.shadowMapResolution as any)[0])
Expand All @@ -58,6 +60,7 @@ export const DirectionalLightComponent = defineComponent({
color: component.color.value.getHex(),
intensity: component.intensity.value,
cameraFar: component.cameraFar.value,
castShadow: component.castShadow.value,
shadowMapResolution: component.shadowMapResolution.value,
shadowBias: component.shadowBias.value,
shadowRadius: component.shadowRadius.value,
Expand All @@ -84,6 +87,10 @@ export const DirectionalLightComponent = defineComponent({
light.light.value.intensity = light.intensity.value
}, [light.intensity])

useEffect(() => {
light.light.value.castShadow = light.castShadow.value
}, [light.castShadow])

useEffect(() => {
light.light.value.shadow.camera.far = light.cameraFar.value
}, [light.cameraFar])
Expand Down
3 changes: 0 additions & 3 deletions packages/engine/src/scene/components/LightComponent.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/engine/src/scene/components/LinkComponent.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/engine/src/scene/components/PointLightComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const PointLightComponent = defineComponent({
intensity: 1,
range: 0,
decay: 2,
castShadow: false,
shadowMapResolution: 256,
shadowBias: 0.5,
shadowRadius: 1,
Expand All @@ -37,6 +38,7 @@ export const PointLightComponent = defineComponent({
if (matches.number.test(json.intensity)) component.intensity.set(json.intensity)
if (matches.number.test(json.range)) component.range.set(json.range)
if (matches.number.test(json.decay)) component.decay.set(json.decay)
if (matches.boolean.test(json.castShadow)) component.castShadow.set(json.castShadow)
/** backwards compat */
if (matches.array.test(json.shadowMapResolution))
component.shadowMapResolution.set((json.shadowMapResolution as any)[0])
Expand All @@ -51,6 +53,7 @@ export const PointLightComponent = defineComponent({
intensity: component.intensity.value,
range: component.range.value,
decay: component.decay.value,
castShadow: component.castShadow.value,
shadowMapResolution: component.shadowMapResolution.value,
shadowBias: component.shadowBias.value,
shadowRadius: component.shadowRadius.value
Expand Down Expand Up @@ -84,6 +87,10 @@ export const PointLightComponent = defineComponent({
light.light.value.decay = light.decay.value
}, [light.decay])

useEffect(() => {
light.light.value.castShadow = light.castShadow.value
}, [light.castShadow])

useEffect(() => {
light.light.value.shadow.bias = light.shadowBias.value
}, [light.shadowBias])
Expand Down
7 changes: 7 additions & 0 deletions packages/engine/src/scene/components/SpotLightComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const SpotLightComponent = defineComponent({
decay: 2,
angle: Math.PI / 3,
penumbra: 1,
castShadow: false,
shadowMapResolution: 256,
shadowBias: 0.5,
shadowRadius: 1,
Expand All @@ -46,6 +47,7 @@ export const SpotLightComponent = defineComponent({
if (matches.number.test(json.decay)) component.decay.set(json.decay)
if (matches.number.test(json.angle)) component.angle.set(json.angle)
if (matches.number.test(json.penumbra)) component.angle.set(json.penumbra)
if (matches.boolean.test(json.castShadow)) component.castShadow.set(json.castShadow)
/** backwards compat */
if (matches.array.test(json.shadowMapResolution))
component.shadowMapResolution.set((json.shadowMapResolution as any)[0])
Expand All @@ -62,6 +64,7 @@ export const SpotLightComponent = defineComponent({
decay: component.decay.value,
angle: component.angle.value,
penumbra: component.penumbra.value,
castShadow: component.castShadow.value,
shadowMapResolution: component.shadowMapResolution.value,
shadowBias: component.shadowBias.value,
shadowRadius: component.shadowRadius.value
Expand Down Expand Up @@ -113,6 +116,10 @@ export const SpotLightComponent = defineComponent({
light.light.value.shadow.radius = light.shadowRadius.value
}, [light.shadowRadius])

useEffect(() => {
light.light.value.castShadow = light.castShadow.value
}, [light.castShadow])

useEffect(() => {
if (light.light.value.shadow.mapSize.x !== light.shadowMapResolution.value) {
light.light.value.shadow.mapSize.set(light.shadowMapResolution.value, light.shadowMapResolution.value)
Expand Down