Realistic lighting and shadows

View inQMLC++
View on GitHub
Sample viewer app

Show realistic lighting and shadows for the specific date and time of day.

screenshot

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 available lighting options to display that lighting effect. Adjust the slider to show the lighting effect for a particular time of day. The 3D buildings will display shadows when "Sun light with shadows" is selected.

How it works

  1. Create an ArcGISSceneLayer and display it in a SceneView.
  2. Create a QDateTime to define the date and time of day.
  3. Set the sun time of the scene view to the specified date and time with m_sceneView->setSunTime(QDateTime).
  4. Set the lightingMode of the scene view to NoLight, Light, or LightAndShadows with m_sceneView->setSunLighting(LightingMode).

Relevant API

  • ArcGISSceneLayer
  • LightingMode
  • Scene
  • SceneView

Tags

3D, lighting, realism, realistic, rendering, shadows, sun, time

Sample Code

RealisticLightingAndShadows.qmlRealisticLightingAndShadows.cppRealisticLightingAndShadows.h
                                                                                  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// [WriteFile Name=RealisticLightingAndShadows, Category=Scenes]
// [Legal]
// Copyright 2020 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.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.Samples 1.0

Item {

    SceneView {
        id: view
        anchors.fill: parent
    }

    // Declare the C++ instance which creates the scene etc. and supply the view
    RealisticLightingAndShadowsSample {
        id: model
        sceneView: view
        onSunTimeChanged: timeValue.text = "August 10, 2018, " + sunTimeText

    }
    Rectangle {
        anchors {
            top: parent.top
            right: parent.right
            margins: 5
        }
        width: childrenRect.width
        height: childrenRect.height
        color: "#ffffff"
        opacity: 0.7
        Column {
            id: settingsColumn
            spacing: 5
            padding: 15
            Text {
                id: timeValue
                anchors.horizontalCenter: parent.horizontalCenter
                font.pixelSize: 16
                // text is set from C++ instance
            }

            ComboBox {
                id: sunLightingSelection
                anchors.horizontalCenter: parent.horizontalCenter
                width: 200
                model: [
                    "No Light",
                    "Light",
                    "Light and Shadows"
                ]
                currentIndex: 2
                onCurrentIndexChanged: {
                    model.setLightingMode(currentIndex);
                }
            }
            Slider {
                id: sunTimeSlider
                anchors.horizontalCenter: parent.horizontalCenter
                opacity: 0.7
                from: 0; to: 23.99
                value: 8.5
                onValueChanged: {
                    model.setSunTimeFromValue(sunTimeSlider.value);
                }
            }
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.