Changes the appearance of the atmosphere in a scene.

Use case
Atmospheric effect can be used to make the scene view look more realistic.
How to use the sample
Select one of the three available atmosphere effects. The sky will change to display the selected atmosphere effect.
How it works
- Create an ArcGISScene and add it to a SceneView composable.
- Expose the selected
AtmosphereEffectfrom a ViewModel and observe it in the Compose screen usingcollectAsStateWithLifecycle. - Pass the
AtmosphereEffectvalue into the SceneView composable, so changing the selected value updates the composable SceneView.
Relevant API
- ArcGISScene
- ArcGISTiledElevationSource
- AtmosphereEffect
- SceneView
- Viewpoint
Additional information
There are three atmosphere effect options:
- Realistic - A realistic atmosphere effect is applied over the entire surface.
- HorizonOnly - Atmosphere effect applied to the sky (horizon) only.
- None - No atmosphere effect. The sky is rendered black with a starfield consisting of randomly placed white dots.
Tags
atmosphere, horizon, scene, sky
Sample Code
/* 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.setatmosphereeffectinscene
import android.os.Bundleimport androidx.activity.ComponentActivityimport androidx.activity.compose.setContentimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.Surfaceimport androidx.compose.runtime.Composableimport com.arcgismaps.ApiKeyimport com.arcgismaps.ArcGISEnvironmentimport com.esri.arcgismaps.sample.sampleslib.theme.SampleAppThemeimport com.esri.arcgismaps.sample.setatmosphereeffectinscene.screens.SetAtmosphereEffectInSceneScreen
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)
setContent { SampleAppTheme { SetAtmosphereEffectInSceneApp() } } }
@Composable private fun SetAtmosphereEffectInSceneApp() { Surface(color = MaterialTheme.colorScheme.background) { SetAtmosphereEffectInSceneScreen( sampleName = getString(R.string.set_atmosphere_effect_in_scene_app_name) ) } }}/* 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.setatmosphereeffectinscene.components
import android.app.Applicationimport androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.viewModelScopeimport com.arcgismaps.mapping.ArcGISSceneimport com.arcgismaps.mapping.ArcGISTiledElevationSourceimport com.arcgismaps.mapping.BasemapStyleimport com.arcgismaps.mapping.Viewpointimport com.arcgismaps.mapping.view.AtmosphereEffectimport com.arcgismaps.mapping.view.Cameraimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModelimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.launch
/** * ViewModel for the sample demonstrating setting the atmosphere effect on a Scene. */class SetAtmosphereEffectInSceneViewModel(app: Application) : AndroidViewModel(app) {
// Create a scene with an imagery basemap & set an initial viewpoint. var arcGISScene = ArcGISScene(BasemapStyle.ArcGISImagery).apply { val camera = Camera( latitude = 64.416919, longitude = -14.483728, altitude = 0.0, heading = 318.0, pitch = 105.0, roll = 0.0 ) // Add an initial viewpoint using a camera. initialViewpoint = Viewpoint( boundingGeometry = camera.location, camera = camera ) // Creates an elevation source and set it on the scene's base surface. baseSurface.elevationSources.add( ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer") ) }
// Keep track of the SceneView's atmosphere effect state. private val _atmosphereEffect = MutableStateFlow<AtmosphereEffect>(AtmosphereEffect.HorizonOnly) val atmosphereEffect = _atmosphereEffect.asStateFlow()
// Message dialog view model for error handling. val messageDialogVM = MessageDialogViewModel()
init { // Load the scene and report load failures if they occur. viewModelScope.launch { arcGISScene.load().onFailure { messageDialogVM.showMessageDialog(it) } } }
/** * Update the [AtmosphereEffect] applied to the SceneView. */ fun updateAtmosphereEffect(newEffect: AtmosphereEffect) { _atmosphereEffect.value = newEffect }}/* 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.setatmosphereeffectinscene.screens
import androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.paddingimport androidx.compose.material3.Scaffoldimport androidx.compose.material3.Textimport androidx.compose.material3.SegmentedButtonimport androidx.compose.material3.SingleChoiceSegmentedButtonRowimport androidx.compose.material3.SegmentedButtonDefaultsimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.ui.Modifierimport androidx.lifecycle.compose.collectAsStateWithLifecycleimport androidx.lifecycle.viewmodel.compose.viewModelimport com.arcgismaps.mapping.view.AtmosphereEffectimport com.arcgismaps.toolkit.geoviewcompose.SceneViewimport com.esri.arcgismaps.sample.setatmosphereeffectinscene.components.SetAtmosphereEffectInSceneViewModelimport com.esri.arcgismaps.sample.sampleslib.components.MessageDialogimport com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
/** * Main screen layout for the sample app. */@Composablefun SetAtmosphereEffectInSceneScreen(sampleName: String) { val viewModel: SetAtmosphereEffectInSceneViewModel = viewModel()
// Observe the currently selected atmosphere effect. val currentAtmosphereEffect by viewModel.atmosphereEffect.collectAsStateWithLifecycle()
Scaffold( topBar = { SampleTopAppBar(title = sampleName) }, content = { paddingValues -> Column(modifier = Modifier .fillMaxSize() .padding(paddingValues), verticalArrangement = Arrangement.Center) { // SceneView composable that displays the 3D Scene. // The atmosphere effect parameter controls how the sky/atmosphere is rendered. SceneView( modifier = Modifier .weight(1f) .fillMaxSize(), arcGISScene = viewModel.arcGISScene, atmosphereEffect = currentAtmosphereEffect )
// A SingleChoiceSegmentedButtonRow with 3 choices to switch atmosphere effects. AtmosphereEffectSelector( currentEffect = currentAtmosphereEffect, onEffectSelected = viewModel::updateAtmosphereEffect ) }
// Display a dialog if the sample encounters an error. viewModel.messageDialogVM.apply { if (dialogStatus) { MessageDialog( title = messageTitle, description = messageDescription, onDismissRequest = ::dismissDialog ) } } } )}
@Composableprivate fun AtmosphereEffectSelector( currentEffect: AtmosphereEffect, onEffectSelected: (AtmosphereEffect) -> Unit) { // The list of atmosphere options displayed in the segmented control. val effectOptions = listOf( AtmosphereEffect.Realistic, AtmosphereEffect.HorizonOnly, AtmosphereEffect.None )
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) { effectOptions.forEachIndexed { index, label -> SegmentedButton( shape = SegmentedButtonDefaults.itemShape(index = index, count = effectOptions.size), onClick = { onEffectSelected(effectOptions[index]) }, selected = currentEffect == effectOptions[index] ) { Text(text = label.javaClass.simpleName) } } }}