One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

GroundingShadowComponent

struct · iOS 18.0+ · SDK 27.1

struct GroundingShadowComponent

A component that controls an entity's grounding shadow. 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 ``Entity/components`` property. ```swift if let model = try? await ModelEntity(named: "tv_retro") { let shadowComponent = GroundingShadowComponent(castsShadow: true) model.components.set(shadowComponent) } ``` | Without shadow | With shadow | |:-:|:-:| | ![A screenshot of a vintage-style TV near the floor of a kitchen scene, which doesn't cast a shadow onto the floor.](groundingshadowcomponent-tv-off) | ![A screenshot of a vintage-style TV near the floor of a kitchen scene, which casts a shadow onto the floor.](groundingshadowcomponent-tv-on) | 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. - Note: Neither virtual nor physical light sources affect grounding shadows. ### 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 ``GroundingShadowComponent/receivesShadow`` property to `false` and adding that component to the entity that's opting out. ```swift 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 ``GroundingShadowComponent/init(castsShadow:receivesShadow:)`` initializer. ```swift let robotShadow = GroundingShadowComponent(castsShadow: true, receivesShadow: false) robot.components.set(robotShadow) ``` | Receiving shadows | Not receiving shadows | |:-:|:-:| | ![A screenshot of a vintage toy robot on a vintage TV set in a RealityKit scene where the robot casts a shadow onto both the TV that it's standing on, and onto own body.](groundingshadowcomponent-tv-robot-receive-on) | ![A screenshot of a vintage toy robot on a vintage TV set in a RealityKit scene where the robot doesn't cast a shadow on any entity in the scene, including itself.](groundingshadowcomponent-tv-robot-receive-off) 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.

Members (9)

init · iOS 18.0+

init

TypeScript
static initCastsShadowReceivesShadowFadeBehaviorNearPhysicalObjects(castsShadow: boolean, receivesShadow: boolean, fadeBehaviorNearPhysicalObjects: GroundingShadowComponent_FadeBehaviorNearPhysicalObjects): GroundingShadowComponent
Swift declaration
init(castsShadow: Bool, receivesShadow: Bool, fadeBehaviorNearPhysicalObjects: GroundingShadowComponent.FadeBehaviorNearPhysicalObjects)

Creates a grounding shadow component by configuring whether its entity receives shadows and its fade behavior near physical objects. - Parameters: - castsShadow: A Boolean value that indicates whether the component's entity casts a shadow on the environment and other model entities. - receivesShadow: A Boolean value that indicates whether the component's entity receives shadows from other model entities. - fadeBehaviorNearPhysicalObjects: A fade behavior for the entity's shadow when the entity is near physical objects.

init · iOS 18.0+

init

TypeScript
static initCastsShadowReceivesShadow(castsShadow: boolean, receivesShadow: boolean): GroundingShadowComponent
Swift declaration
init(castsShadow: Bool, receivesShadow: Bool)

Creates a grounding shadow component by configuring whether its entity receives shadows from other model entities with the component. - Parameters: - castsShadow: A Boolean value that indicates whether the component's entity casts a shadow on the environment and other model entities. - receivesShadow: A Boolean value that indicates whether the component's entity receives shadows from other model entities. This initializer is an alternative to ``init(castsShadow:)``, which creates a component that, by default, configures an entity to receive grounding shadows from other model entities in the scene.

init · iOS 18.0+

init

TypeScript
static initCastsShadow(castsShadow: boolean): GroundingShadowComponent
Swift declaration
init(castsShadow: Bool)

Creates a grounding shadow component. - Parameter castsShadow: A Boolean that indicates whether an entity with the component casts a shadow onto other model entities in the scene. By default, the component makes an entity receive grounding shadows from other model entities in the scene.

get · iOS 18.0+

castsShadow

TypeScript
get castsShadow(): boolean
Swift declaration
var castsShadow: Bool

A Boolean value that indicates whether an entity casts a shadow onto other model entities in the scene.

set · iOS 18.0+

castsShadow

TypeScript
set castsShadow(value: boolean)
Swift declaration
var castsShadow: Bool

A Boolean value that indicates whether an entity casts a shadow onto other model entities in the scene.

get · iOS 18.0+

receivesShadow

TypeScript
get receivesShadow(): boolean
Swift declaration
var receivesShadow: Bool { get set }

A Boolean value that indicates whether an entity with the grounding shadow component receives grounding shadows from other model entities.

set · iOS 18.0+

receivesShadow

TypeScript
set receivesShadow(value: boolean)
Swift declaration
var receivesShadow: Bool { get set }

A Boolean value that indicates whether an entity with the grounding shadow component receives grounding shadows from other model entities.

get · iOS 18.0+

fadeBehaviorNearPhysicalObjects

TypeScript
get fadeBehaviorNearPhysicalObjects(): GroundingShadowComponent_FadeBehaviorNearPhysicalObjects
Swift declaration
var fadeBehaviorNearPhysicalObjects: GroundingShadowComponent.FadeBehaviorNearPhysicalObjects { get set }

Configures the grounding shadow's fade behavior when the entity is near physical objects.

set · iOS 18.0+

fadeBehaviorNearPhysicalObjects

TypeScript
set fadeBehaviorNearPhysicalObjects(value: GroundingShadowComponent_FadeBehaviorNearPhysicalObjects)
Swift declaration
var fadeBehaviorNearPhysicalObjects: GroundingShadowComponent.FadeBehaviorNearPhysicalObjects { get set }

Configures the grounding shadow's fade behavior when the entity is near physical objects.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →