View on GitHub Sample viewer app

Show realistic lighting and shadows for a given time of day.

Image of show realistic light and shadows

Use case

You can use realistic lighting to evaluate the shadow impact of buildings and utility infrastructure on the surrounding community. This could be useful for civil engineers and urban planners, or for events management assessing the impact of building shadows during an outdoor event.

How to use the sample

Select one of the three lighting options to show that lighting effect on the SceneView. Select a time of day from the slider (based on a 24hr clock), and a date from the date picker, to show the lighting for that time of day in the SceneView.

How it works

  1. Create a Scene and display it in a composable SceneView.
  2. Create a ZonedDateTime to define the day and time of day.
  3. Set the sun time to the scene view using zoned date time and a time offset in milliseconds.
  4. Set the sun lighting of the scene view to a LightingMode of NoLight, Light, or LightAndShadows.

Relevant API

  • Scene
  • SceneView
  • SceneView.SunLighting

Additional information

This sample uses the GeoView-Compose Toolkit module to be able to implement a composable SceneView.

Tags

3D, lighting, realism, realistic, rendering, sceneview-compose, shadows, sun, time, toolkit

Sample Code

MainActivity.kt MainActivity.kt ShowRealisticLightAndShadowsViewModel.kt ShowRealisticLightAndShadowsScreen.kt
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.showrealisticlightandshadows
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.showrealisticlightandshadows.screens.ShowRealisticLightAndShadowsScreen
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
enableEdgeToEdge()
setContent {
SampleAppTheme {
ShowRealisticLightAndShadowsApp()
}
}
}
@Composable
private fun ShowRealisticLightAndShadowsApp() {
Surface(color = MaterialTheme.colorScheme.background) {
ShowRealisticLightAndShadowsScreen(
sampleName = getString(R.string.show_realistic_light_and_shadows_app_name)
)
}
}
}