PointLight


A light that radiates equally in every direction from a single point in front of the surface, like a bare bulb.

elevation is measured from the plane the surface rests on. A surface with a thickness (see SurfaceGeometrySpec) rises towards the light, so the light's height above it is elevation - thickness. Keep elevation larger than the thickness so the light stays in front of the surface.

Brightness falls away with distance and reaches zero at falloffRadius. The distance is measured in three dimensions, so it includes the light's height above the surface: a light raised falloffRadius or more above the surface cannot reach it at all, and lights nothing. Keep falloffRadius comfortably larger than elevation - thickness.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.lighting.LightPosition
import androidx.compose.ui.lighting.PointLight
import androidx.compose.ui.lighting.SurfaceGeometrySpec
import androidx.compose.ui.lighting.SurfaceMaterial
import androidx.compose.ui.lighting.illuminate
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp

// Since our light color is white, we set a darker background so that its visible.
val backgroundColor = remember { Color.Black }
val surfaceShape = remember { RoundedCornerShape(24.dp) }
Box(
    Modifier.size(160.dp)
        .background(backgroundColor)
        .illuminate(
            lights =
                listOf(
                    PointLight(
                        color = Color.White,
                        // Above the top-left corner of the lit composable.
                        position = LightPosition.Local(DpOffset(x = 0.dp, y = 0.dp)),
                        elevation = 48.dp,
                        falloffRadius = 320.dp,
                        intensity = 1f,
                    )
                ),
            surfaceMaterial =
                SurfaceMaterial.diffuse(Color.White).specular(Color.White, shininess = 32f),
            surfaceGeometrySpec =
                SurfaceGeometrySpec.convex(
                    shape = surfaceShape,
                    thickness = 1.dp,
                    bevelWidth = 12.dp,
                ),
        )
)

Summary

Public constructors

PointLight(
    color: Color,
    position: LightPosition,
    elevation: Dp,
    falloffRadius: Dp,
    intensity: @FloatRange(from = 0.0) Float
)
Cmn

Public functions

open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
open String
Cmn

Public properties

open Color

color emitted by this light.

Cmn
Dp

distance of the light in front of the plane the surface rests on, towards the viewer.

Cmn
Dp

distance at which the light has fully faded out.

Cmn
open @FloatRange(from = 0.0) Float

multiplier applied to color.

Cmn
open LightPosition

where the light sits in the plane of the surface.

Cmn

Public constructors

PointLight

PointLight(
    color: Color,
    position: LightPosition,
    elevation: Dp,
    falloffRadius: Dp,
    intensity: @FloatRange(from = 0.0) Float
)
Parameters
color: Color

color emitted by this light.

position: LightPosition

where the light sits in the plane of the surface.

elevation: Dp

distance of the light in front of the plane the surface rests on, towards the viewer. The light's height above the surface itself is elevation - thickness.

falloffRadius: Dp

distance at which the light has fully faded out. A radius of zero or less disables falloff entirely, so the light reaches the whole surface at full strength.

intensity: @FloatRange(from = 0.0) Float

multiplier applied to color. A light with an intensity of 0 contributes nothing.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

color

open val color: Color

color emitted by this light.

elevation

val elevation: Dp

distance of the light in front of the plane the surface rests on, towards the viewer. The light's height above the surface itself is elevation - thickness.

falloffRadius

val falloffRadius: Dp

distance at which the light has fully faded out. A radius of zero or less disables falloff entirely, so the light reaches the whole surface at full strength.

intensity

open val intensity: @FloatRange(from = 0.0) Float

multiplier applied to color. A light with an intensity of 0 contributes nothing.

position

open val position: LightPosition

where the light sits in the plane of the surface.