This file is indexed.

/usr/share/qt5/doc/qt3drenderer/qt3drenderer-shadow-map-qml-example.html is in qt3d5-doc-html 5.5.1-4ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- shadow-map-qml.qdoc -->
  <title>Qt3D: Shadow Map QML Example | Qt3D Module 5.5</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.5</li>
<li>Qt3D Module</li>
<li>Qt3D: Shadow Map QML Example</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#setting-up-the-scene">Setting Up the Scene</a></li>
<li class="level1"><a href="#specifying-the-light">Specifying the Light</a></li>
<li class="level1"><a href="#configuring-the-framegraph">Configuring the Framegraph</a></li>
<li class="level1"><a href="#generating-the-shadow-map">Generating the Shadow Map</a></li>
<li class="level1"><a href="#using-effects">Using Effects</a></li>
<li class="level1"><a href="#rendering-using-phong-shading">Rendering Using Phong Shading</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt3D: Shadow Map QML Example</h1>
<span class="subtitle"></span>
<!-- $$$shadow-map-qml-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/shadowmapping-qt3d.png" alt="" /></p><p><i>Qt3D Shadow Map</i> illustrates how to configure the renderer in order to accommodate custom rendering techniques. The example application displays a self-shadowed plane and trefoil knot.</p>
<p>We implement shadow mapping using a two pass rendering. In the first pass, we generate the shadow information. In the second pass, we generate the scene using the forward rendering technique with Phong shading, while at the same time using the information gathered in the first pass to draw the shadows.</p>
<p>The entire rendering is configured using QML, but it is possible to use C++ to achieve the very same result.</p>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="setting-up-the-scene"></a>
<h2 id="setting-up-the-scene">Setting Up the Scene</h2>
<p>We set up the entire scene in the <i>main.qml</i> file.</p>
<p>To be able to use the types in the Q3D and Q3D Renderer modules, we must import the modules:</p>
<pre class="qml">import Qt3D 2.0
import Qt3D.Renderer 2.0</pre>
<p>The first entities we create are a Camera, which represents the camera used for the final rendering, and a Configuration, which allows us to control this camera using the keyboard or the mouse:</p>
<pre class="qml"><span class="type">Entity</span> {
    <span class="name">id</span>: <span class="name">sceneRoot</span>

    <span class="type">Camera</span> {
        <span class="name">id</span>: <span class="name">camera</span>
        <span class="name">projectionType</span>: <span class="name">CameraLens</span>.<span class="name">PerspectiveProjection</span>
        <span class="name">fieldOfView</span>: <span class="number">45</span>
        <span class="name">aspectRatio</span>: <span class="name">_window</span>.<span class="name">width</span> <span class="operator">/</span> <span class="name">_window</span>.<span class="name">height</span>
        <span class="name">nearPlane</span>: <span class="number">0.1</span>
        <span class="name">farPlane</span>: <span class="number">1000.0</span>
        <span class="name">position</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">0.0</span>, <span class="number">10.0</span>, <span class="number">20.0</span>)
        <span class="name">viewCenter</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>)
        <span class="name">upVector</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>)
    }

    <span class="type">Configuration</span>  {
        <span class="name">controlledCamera</span>: <span class="name">camera</span>
    }</pre>
<p>We then create a Light custom entity, which represents our light. It is a directional spotlight, placed somewhere above the plane and looking down at the scene’s origin:</p>
<pre class="qml">    <span class="type">Light</span> {
        <span class="name">id</span>: <span class="name">light</span>
    }</pre>
<p>This light entity is used by our custom framegraph, ShadowMapFrameGraph, and our rendering effect, AdsEffect, whose instances are created just after the light:</p>
<pre class="qml">    <span class="name">components</span>: [
        <span class="type">ShadowMapFrameGraph</span> {
            <span class="name">id</span>: <span class="name">framegraph</span>
            <span class="name">viewCamera</span>: <span class="name">camera</span>
            <span class="name">lightCamera</span>: <span class="name">light</span>.<span class="name">lightCamera</span>
        }
    ]

    <span class="type">AdsEffect</span> {
        <span class="name">id</span>: <span class="name">shadowMapEffect</span>

        <span class="name">shadowTexture</span>: <span class="name">framegraph</span>.<span class="name">shadowTexture</span>
        <span class="name">light</span>: <span class="name">light</span>
    }</pre>
<p>Last, we create three entities for the meshes in the scene: a trefoil knot, a toy plane, and a ground plane. They aggregate a mesh, a transformation, and a material that uses the AdsEffect. The toy plane and the trefoil knot transformations are animated:</p>
<pre class="qml">    <span class="comment">// Trefoil knot entity</span>
    <span class="type">Trefoil</span> {
        <span class="name">material</span>: <span class="name">AdsMaterial</span> {
            <span class="name">effect</span>: <span class="name">shadowMapEffect</span>
            <span class="name">specularColor</span>: <span class="name">Qt</span>.<span class="name">rgba</span>(<span class="number">0.5</span>, <span class="number">0.5</span>, <span class="number">0.5</span>, <span class="number">1.0</span>)
        }
    }

    <span class="comment">// Toyplane entity</span>
    <span class="type">Toyplane</span> {
        <span class="name">material</span>: <span class="name">AdsMaterial</span> {
            <span class="name">effect</span>: <span class="name">shadowMapEffect</span>
            <span class="name">diffuseColor</span>: <span class="name">Qt</span>.<span class="name">rgba</span>(<span class="number">0.9</span>, <span class="number">0.5</span>, <span class="number">0.3</span>, <span class="number">1.0</span>)
            <span class="name">shininess</span>: <span class="number">75</span>
        }
    }

    <span class="comment">// Plane entity</span>
    <span class="type">GroundPlane</span> {
        <span class="name">material</span>: <span class="name">AdsMaterial</span> {
            <span class="name">effect</span>: <span class="name">shadowMapEffect</span>
            <span class="name">diffuseColor</span>: <span class="name">Qt</span>.<span class="name">rgba</span>(<span class="number">0.2</span>, <span class="number">0.5</span>, <span class="number">0.3</span>, <span class="number">1.0</span>)
            <span class="name">specularColor</span>: <span class="name">Qt</span>.<span class="name">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1.0</span>)
        }
    }
}</pre>
<a name="specifying-the-light"></a>
<h2 id="specifying-the-light">Specifying the Light</h2>
<p>We specify the Light custom entity in <i>Light.qml</i>.</p>
<p>Again, we import the necessary modules:</p>
<pre class="qml">import Qt3D 2.0
import Qt3D.Renderer 2.0</pre>
<p>We then use an Entity type as the root element of the custom QML type. The light is a directional spotlight that exposes as properties a position, intensity, and a 4×4 transformation matrix:</p>
<pre class="qml"><span class="type">Entity</span> {
    <span class="name">id</span>: <span class="name">root</span>

    property <span class="type">vector3d</span> <span class="name">lightPosition</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">30.0</span>, <span class="number">30.0</span>, <span class="number">0.0</span>)
    property <span class="type">vector3d</span> <span class="name">lightIntensity</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">1.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>)

    readonly property <span class="type">Camera</span> <span class="name">lightCamera</span>: <span class="name">lightCamera</span>
    readonly property <span class="type">matrix4x4</span> <span class="name">lightViewProjection</span>: <span class="name">lightCamera</span>.<span class="name">projectionMatrix</span>.<span class="name">times</span>(<span class="name">lightCamera</span>.<span class="name">matrix</span>)</pre>
<p>In the first rendering pass, we use the light as a camera, and therefore we use a Camera entity within the light and expose it as a property:</p>
<pre class="qml">    <span class="type">Camera</span> {
        <span class="name">id</span>: <span class="name">lightCamera</span>
        <span class="name">objectName</span>: <span class="string">&quot;lightCameraLens&quot;</span>
        <span class="name">projectionType</span>: <span class="name">CameraLens</span>.<span class="name">PerspectiveProjection</span>
        <span class="name">fieldOfView</span>: <span class="number">45</span>
        <span class="name">aspectRatio</span>: <span class="number">1</span>
        <span class="name">nearPlane</span> : <span class="number">0.1</span>
        <span class="name">farPlane</span> : <span class="number">200.0</span>
        <span class="name">position</span>: <span class="name">root</span>.<span class="name">lightPosition</span>
        <span class="name">viewCenter</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>)
        <span class="name">upVector</span>: <span class="name">Qt</span>.<span class="name">vector3d</span>(<span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>)
    }
}</pre>
<a name="configuring-the-framegraph"></a>
<h2 id="configuring-the-framegraph">Configuring the Framegraph</h2>
<p>In Qt3D, the framegraph is the data-driven configuration for the rendering. We implement the framegraph in the <i>ShadowMapFrameGraph.qml</i> file.</p>
<p>In addition to the Qt3D and Qt3D Renderer modules, we also import the Qt Quick module:</p>
<pre class="qml">import Qt3D 2.0
import Qt3D.Renderer 2.0
import QtQuick 2.2 as QQ2</pre>
<p>The code defines a <a href="qml-qt3d-renderer-framegraph.html">FrameGraph</a> entity that has a tree of entities as the active framegraph:</p>
<pre class="qml"><span class="type"><a href="qml-qt3d-renderer-framegraph.html">FrameGraph</a></span> {
    <span class="name">id</span>: <span class="name">root</span>

    property <span class="type">alias</span> <span class="name">viewCamera</span>: <span class="name">viewCameraSelector</span>.<span class="name">camera</span>
    property <span class="type">alias</span> <span class="name">lightCamera</span>: <span class="name">lightCameraSelector</span>.<span class="name">camera</span>
    readonly property <span class="type">Texture2D</span> <span class="name">shadowTexture</span>: <span class="name">depthTexture</span>

    <span class="name">activeFrameGraph</span>: <span class="name">Viewport</span> {
        <span class="name">rect</span>: <span class="name">Qt</span>.<span class="name">rect</span>(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1.0</span>)
        <span class="name">clearColor</span>: <span class="name">Qt</span>.<span class="name">rgba</span>(<span class="number">0.0</span>, <span class="number">0.4</span>, <span class="number">0.7</span>, <span class="number">1.0</span>)</pre>
<p>Any path from the leaves of this tree to the root is a viable framegraph configuration. Filter entities can enable or disable such paths, and selector entities can alter the configuration.</p>
<p>In our case, the tree looks like this:</p>
<pre class="cpp">Viewport
    RenderPassFilter
        RenderTargetSelector
            ClearBuffer
                CameraSelector
    RenderPassFilter
        ClearBuffer
            CameraSelector</pre>
<p>So we have two paths from the topmost Viewport entity. Each path corresponds to a pass of the shadow map technique. The paths are enabled and disabled using a RenderPassFilter, an entity that can filter depending on arbitrary values defined in a given render pass. In this example, it is a string:</p>
<pre class="qml">        <span class="type">RenderPassFilter</span> {
            <span class="name">includes</span>: [ <span class="type"><a href="qml-qt3d-renderer-annotation.html">Annotation</a></span> { <span class="name">name</span>: <span class="string">&quot;pass&quot;</span>; <span class="name">value</span>: <span class="string">&quot;shadowmap&quot;</span> } ]</pre>
<p>The actual passes are not defined here. The framegraph simply modifies its configuration when a given pass is rendered.</p>
<a name="generating-the-shadow-map"></a>
<h2 id="generating-the-shadow-map">Generating the Shadow Map</h2>
<p>In the shadow map generation pass, we must render to an offscreen surface (Framebuffer Object) which has a depth texture attachment. In Qt3D, it is represented by the RenderTarget entity, which has a number of attachments.</p>
<p>In this example, we need only a depth attachment. We define it as a RenderAttachment entity using the RenderAttachment.DepthAttachment <code>type</code> that stores the depth and a Texture2D entity that actually configures the exture storage used to store the depth information:</p>
<pre class="qml">            <span class="type">RenderTargetSelector</span> {
                <span class="name">target</span>: <span class="name">RenderTarget</span> {
                    <span class="name">attachments</span>: [
                        <span class="type">RenderAttachment</span> {
                            <span class="name">name</span>: <span class="string">&quot;depth&quot;</span>
                            <span class="name">type</span>: <span class="name">RenderAttachment</span>.<span class="name">DepthAttachment</span>
                            <span class="name">texture</span>: <span class="name">Texture2D</span> {
                                <span class="name">id</span>: <span class="name">depthTexture</span>
                                <span class="name">width</span>: <span class="number">1024</span>
                                <span class="name">height</span>: <span class="number">1024</span>
                                <span class="name">format</span>: <span class="name">Texture</span>.<span class="name">DepthFormat</span>
                                <span class="name">generateMipMaps</span>: <span class="number">false</span>
                                <span class="name">magnificationFilter</span>: <span class="name">Texture</span>.<span class="name">Linear</span>
                                <span class="name">minificationFilter</span>: <span class="name">Texture</span>.<span class="name">Linear</span>
                                <span class="type">wrapMode</span> {
                                    <span class="name">x</span>: <span class="name">WrapMode</span>.<span class="name">ClampToEdge</span>
                                    <span class="name">y</span>: <span class="name">WrapMode</span>.<span class="name">ClampToEdge</span>
                                }
                                <span class="name">comparisonFunction</span>: <span class="name">Texture</span>.<span class="name">CompareLessEqual</span>
                                <span class="name">comparisonMode</span>: <span class="name">Texture</span>.<span class="name">CompareRefToTexture</span>
                            }
                        }
                    ]
                }</pre>
<p>Moreover, in this first pass, we must render using the light’s camera. Therefore, we have a CameraSelector entity that sets the camera to the one exported by the Light:</p>
<pre class="qml">                    <span class="type">CameraSelector</span> {
                        <span class="name">id</span>: <span class="name">lightCameraSelector</span>
                    }</pre>
<p>The second pass is more straightforward, because we simply render to the screen using the main camera.</p>
<a name="using-effects"></a>
<h2 id="using-effects">Using Effects</h2>
<p>The bulk of the magic happens in the <i>AdsEffect.qml</i> file, where our main Effect entity is defined. It implements the Ambient, Diffuse and Specular (ADS) Lightning Model Phong shading with the addition of shadow mapped generated shadows.</p>
<p>An effect contains the implementation of a particular rendering strategy. In this example, shadow mapping using two passes:</p>
<pre class="qml"><span class="type">Effect</span> {
    <span class="name">id</span>: <span class="name">root</span>

    property <span class="type">Texture2D</span> <span class="name">shadowTexture</span>
    property <span class="type">Light</span> <span class="name">light</span></pre>
<p>The <code>parameters</code> list defines some default values for the effect. The values will get mapped to OpenGL shader program uniforms, so that in the shaders we can access them. In this example, we expose some information from the Light entity (position, intensity, view or projection matrix defined by the internal camera) and the shadow map texture exposed by the framegraph:</p>
<pre class="qml">    <span class="name">parameters</span>: [
        <span class="type">Parameter</span> { <span class="name">name</span>: <span class="string">&quot;lightViewProjection&quot;</span>; <span class="name">value</span>: <span class="name">root</span>.<span class="name">light</span>.<span class="name">lightViewProjection</span> },
        <span class="type">Parameter</span> { <span class="name">name</span>: <span class="string">&quot;lightPosition&quot;</span>;  <span class="name">value</span>: <span class="name">root</span>.<span class="name">light</span>.<span class="name">lightPosition</span> },
        <span class="type">Parameter</span> { <span class="name">name</span>: <span class="string">&quot;lightIntensity&quot;</span>; <span class="name">value</span>: <span class="name">root</span>.<span class="name">light</span>.<span class="name">lightIntensity</span> },

        <span class="type">Parameter</span> { <span class="name">name</span>: <span class="string">&quot;shadowMapTexture&quot;</span>; <span class="name">value</span>: <span class="name">root</span>.<span class="name">shadowTexture</span> }
    ]</pre>
<p>It is possible to put such parameters all the way down, from a Material, to its Effect, to one of the effect’s Techniques. This allows a Material instance to override defaults in an Effect or Technique. The bindings array provides the same thing, except that it also allows us to rename some parameters. In this example, it renames the <code>ambient</code>, <code>diffuse</code>, and <code>specular</code> values defined in the material to the actual uniform names used by the shader programs:</p>
<pre class="qml">                    <span class="name">bindings</span>: [
                        <span class="comment">// Uniforms (those provided by the user)</span>
                        <span class="type"><a href="qml-qt3d-renderer-parametermapping.html">ParameterMapping</a></span> { <span class="name">parameterName</span>: <span class="string">&quot;ambient&quot;</span>;  <span class="name">shaderVariableName</span>: <span class="string">&quot;ka&quot;</span>; <span class="name">bindingType</span>: <span class="name">ParameterMapping</span>.<span class="name">Uniform</span> },
                        <span class="type"><a href="qml-qt3d-renderer-parametermapping.html">ParameterMapping</a></span> { <span class="name">parameterName</span>: <span class="string">&quot;diffuse&quot;</span>;  <span class="name">shaderVariableName</span>: <span class="string">&quot;kd&quot;</span>; <span class="name">bindingType</span>: <span class="name">ParameterMapping</span>.<span class="name">Uniform</span> },
                        <span class="type"><a href="qml-qt3d-renderer-parametermapping.html">ParameterMapping</a></span> { <span class="name">parameterName</span>: <span class="string">&quot;specular&quot;</span>; <span class="name">shaderVariableName</span>: <span class="string">&quot;ks&quot;</span>; <span class="name">bindingType</span>: <span class="name">ParameterMapping</span>.<span class="name">Uniform</span> }
                    ]</pre>
<p>To adapt the implementation to different hardware or OpenGL versions, we could use one or more Technique elements. In this example, only one technique is provided, targeting OpenGL 3.2 Core, or later:</p>
<pre class="qml">    <span class="name">techniques</span>: [
        <span class="type">Technique</span> {
            <span class="type">openGLFilter</span> {
                <span class="name">api</span>: <span class="name">OpenGLFilter</span>.<span class="name">Desktop</span>
                <span class="name">profile</span>: <span class="name">OpenGLFilter</span>.<span class="name">Core</span>
                <span class="name">majorVersion</span>: <span class="number">3</span>
                <span class="name">minorVersion</span>: <span class="number">2</span>
            }</pre>
<p>Inside the technique, we finally have the definition of our two rendering passes. We <i>tag</i> each pass with an <a href="qml-qt3d-renderer-annotation.html">Annotation</a> entity, matching the ones we specified in the framegraph configuration, so that each pass will have different rendering settings:</p>
<pre class="qml">            <span class="name">renderPasses</span>: [
                <span class="type">RenderPass</span> {
                    <span class="name">annotations</span>: [ <span class="type"><a href="qml-qt3d-renderer-annotation.html">Annotation</a></span> { <span class="name">name</span>: <span class="string">&quot;pass&quot;</span>; <span class="name">value</span>: <span class="string">&quot;shadowmap&quot;</span> } ]</pre>
<p>The first pass is the shadow map generation. We load a suitable set of GLSL shaders, which are actually extremely simple. They do only MVP (Model, View, Projection) to bring meshes from their model space into clip space (and, remember, in this first pass, the light is the camera). The fragment shader is totally empty, because there is no color to be generated, and the depth will be automatically captured for us by OpenGL:</p>
<pre class="qml">                    <span class="name">shaderProgram</span>: <span class="name">ShaderProgram</span> {
                        <span class="name">vertexShaderCode</span>:   <span class="name">loadSource</span>(<span class="string">&quot;qrc:/shaders/shadowmap.vert&quot;</span>)
                        <span class="name">fragmentShaderCode</span>: <span class="name">loadSource</span>(<span class="string">&quot;qrc:/shaders/shadowmap.frag&quot;</span>)
                    }</pre>
<p>In this first pass, we also set some custom OpenGL state in the form of a polygon offset and depth testing mode:</p>
<pre class="qml">                    <span class="name">renderStates</span>: [
                        <span class="type">PolygonOffset</span> { <span class="name">factor</span>: <span class="number">4</span>; <span class="name">units</span>: <span class="number">4</span> },
                        <span class="type">DepthTest</span> { <span class="name">func</span>: <span class="name">DepthTest</span>.<span class="name">Less</span> }
                    ]</pre>
<a name="rendering-using-phong-shading"></a>
<h2 id="rendering-using-phong-shading">Rendering Using Phong Shading</h2>
<p>The second pass is a normal forward rendering using Phong shading. The code in the effect entity is extremely simple. We simply configure some parameters and load a pair of shaders which will be used when drawing.</p>
<p>The first part of the shadow mapping happens in the vertex shader defined in <i>ads.vert</i> file, where we output towards the fragment shader the coordinates of each vertex in light space:</p>
<pre class="qml">    positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);</pre>
<p>Actually, the coordinates get adjusted a little to allow us to easily sample the shadow map texture.</p>
<p>The second part happens in the fragment shader defined in the <i>ads.frag</i> file, where we sample the shadow map. If the currently processed fragment is behind the one closest to the light, then the current fragment is in shadow (and only gets ambient contribution). Otherwise, it gets full Phong shading:</p>
<pre class="qml">void main()
{
    float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);

    vec3 ambient = lightIntensity * ka;

    vec3 result = ambient;
    if (shadowMapSample &gt; 0)
        result += dsModel(position, normalize(normal));

    fragColor = vec4(result, 1.0);
}</pre>
<p>Files:</p>
<ul>
<li><a href="qt3drenderer-shadow-map-qml-adseffect-qml.html">shadow-map-qml/AdsEffect.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-adsmaterial-qml.html">shadow-map-qml/AdsMaterial.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-groundplane-qml.html">shadow-map-qml/GroundPlane.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-light-qml.html">shadow-map-qml/Light.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shadowmapframegraph-qml.html">shadow-map-qml/ShadowMapFrameGraph.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-toyplane-qml.html">shadow-map-qml/Toyplane.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-trefoil-qml.html">shadow-map-qml/Trefoil.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-main-qml.html">shadow-map-qml/main.qml</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shaders-ads-vert.html">shadow-map-qml/shaders/ads.vert</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shaders-shadowmap-vert.html">shadow-map-qml/shaders/shadowmap.vert</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shaders-es3-ads-vert.html">shadow-map-qml/shaders/es3/ads.vert</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shaders-es3-shadowmap-vert.html">shadow-map-qml/shaders/es3/shadowmap.vert</a></li>
<li><a href="qt3drenderer-shadow-map-qml-main-cpp.html">shadow-map-qml/main.cpp</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shadow-map-qml-pro.html">shadow-map-qml/shadow-map-qml.pro</a></li>
<li><a href="qt3drenderer-shadow-map-qml-shadow-map-qml-qrc.html">shadow-map-qml/shadow-map-qml.qrc</a></li>
</ul>
</div>
<!-- @@@shadow-map-qml -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>