Contents

GroundingShadowComponent

A component that controls an entity’s grounding shadow.

Declaration

struct GroundingShadowComponent

Overview

A grounding shadow is an effect that makes an entity look like it has a light source directly above it. You can add a grounding shadow to any entity that has a ModelComponent in its component set by adding a grounding shadow component to the entity’s components property.

if let model = try? await ModelEntity(named: "tv_retro") {
    let shadowComponent = GroundingShadowComponent(castsShadow: true)
    model.components.set(shadowComponent)
}

Without shadow

With shadow

[Image]

[Image]

You need to add the grounding shadow component to each entity you want to apply the effect to, because the grounding shadow component doesn’t apply to hierarchies.

Receiving Shadows

By default, all entity models with a grounding shadow component can cast a shadow onto any other model entities in the scene. However, you can configure an entity to opt out of receiving shadows from other entities by setting a grounding shadow component’s receivesShadow property to false and adding that component to the entity that’s opting out.

let tvShadow = GroundingShadowComponent(castsShadow: true)
tvShadow.receivesShadow = false
tv.components.set(tvShadow)

Alternatively, you can create a new grounding shadow component instance that opts out of receiving shadows by passing false to the receivesShadow parameter of the init(castsShadow:receivesShadow:) initializer.

let robotShadow = GroundingShadowComponent(castsShadow: true,
                                           receivesShadow: false)
robot.components.set(robotShadow)

Receiving shadows

Not receiving shadows

[Image]

[Image]

RealityKit generates grounding shadows from the perspective of another entity that receives the first entity’s shadow. One-sided geometry only casts a shadow if its facets face the entity that receives the shadow, which typically means they face downward. Make each 2D object cast a grounding shadow by applying a material that disables face culling, or by replacing it with a watertight mesh.

Topics

Initializers

Instance Properties

Enumerations

See Also

General shadows