<div dir="ltr">Hi,<br>As we reached the end of Google Summer of Code 2020. I present my final report.<br>I really enjoyed being part of this project and I'm looking forward to making more open source contributions in the future.<br><ul><li><b>Title:</b>  Improving QGIS 3D</li><li><b>Organization: </b>QGIS and OSGeo</li><li><b>Abstract: </b></li></ul>QGIS 3D was introduced in QGIS 3.0 in 2018 and has been improved over the last 2 years. This is a continuation of last year’s summer of code project which was done by Ismail Sunni. The project goal is to implement some features for QGIS 3D viewer.<br><ul><li><b>State of the project before GSoC:</b></li></ul>The 3D viewer of QGIS was introduced in QGIS 3.0 and implemented by my mentor Martin Dobias. It has improved over the time and got new functionalities, but when I used it for a brief time I noticed some missing features I wanted to implement.<br><ul><li><b>Work done before the GSoC coding period:</b></li><ul><li>Setup of the development environment.</li><li>Reading the QEP (QGIS Enhancement Proposal) of QGIS 3D.</li><li>Understanding more about how the 3D side of QGIS is implemented.</li><li>Made a small bug fix that got merged into the master branch (Github commit)</li></ul><li><b>Work done during GSoC:</b></li><ul><li><b>Texturing support</b>:<br>Previously, QGIS users could only use Phong shading as materials for building geometries generated from vector layers. My goal was to make it possible to add texture images to the geometry of buildings. I started by reading the internal QGIS code and experimenting with Qt3D internals. First I experimented with just adding a texture on all triangles and got it working.<br><a href="https://i.imgur.com/aqJD8yV.png" style="background-color:transparent;font-family:Arial;white-space:pre-wrap">screenshot of when I got textures working</a><br><a href="https://imgur.com/OdlrvDo" style="background-color:transparent;font-family:Arial;white-space:pre-wrap">Screenshot of the separation between walls and roofs</a><br>Then I moved on to the separation between walls and roofs, I solved this problem by calculating the angle between each triangle’s normal and the horizontal plane, if that angle is small enough we consider that the triangle belongs to a wall, otherwise it’s a roof.<br>For how the user interacts with the texturing and provides different texture for walls and roofs, I used the rule based rendering and added a combo box from which the user can specify which facade to render (meaning to render a wall or a roof). I also added some parameters to adjust the scale of the texture and its rotation. </li><li><b>Directional lights:</b><br>QGIS 3D already has support for point light. Since the two of them are quite similar, implementing directional light was quite straightforward</li><li><b>3D Scene export:</b><br>For the blender export I made a custom .obj files exporter. My implementation was quite tedious to implement because there were different types of layers and entities and I had to handle materials as well. I relied on extracting geometry information from the vertex buffer and the index buffer, making that work with DEM terrain, flat terrains and vector layers. For the materials I used the .mtl specification to export colors and textures. I added some UI to handle the resolution of texture and terrain.<br>Here are some screenshots of what I was able to export:</li><ul><li><a href="https://imgur.com/Jkl9kfu" style="white-space:pre-wrap;font-family:Arial">DEM terrain exported with .OBJ smoothing option on and off in Blender:</a></li><li><a href="https://imgur.com/LWBtHqf" style="white-space:pre-wrap;font-family:Arial">Vector layer export</a></li><li><a href="https://imgur.com/Rfm3PvB" style="font-family:Arial">Exporting terrain texture (Blender)</a></li><li><a href="https://imgur.com/2MOmeYJ">Exporting terrain texture (MeshLab)</a></li><li><a href="https://imgur.com/uUDCgcg">Rule based rendering and material export</a></li></ul><li><b>Skybox rendering:</b><br>First I experimented with Qt3D skybox but found some difficulties using it (there was a bug that was fixed in later releases) and it wasn’t also extensible (for different types of skyboxes), then I copied the implementation of the skybox entity from Qt3D and made it work.<br>I introduced 2 ways of providing skyboxes:</li><ul><li>6 distinct faces for the skybox cube map: The user gives each face of the skybox individually.</li><li>1 panoramic image: The user simply gives one panoramic image (like an .HDR image form <a href="https://hdrihaven.com/" style="background-color:transparent;white-space:pre-wrap;font-family:Arial;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline">https://hdrihaven.com/</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline"><font color="#000000" face="Arial"><span style="white-space:pre-wrap">) and the renderer takes care of making the skybox.</span></font></span></li><li>Some .gifs of the skybox in QGIS: <a href="https://imgur.com/5Z8fUvm" style="white-space:pre-wrap;font-family:Arial">gif image </a>, <a href="https://imgur.com/fLS6vs9" style="font-family:Arial">gif image 2</a></li></ul><li><b>Shadow rendering (unfinished work):</b><br>This was the hardest feature to implement and I couldn’t even finish it in time without some visual artifacts.<br>Previously, I learned about some shadow rendering techniques and shadow mapping was the technique I’m most familiar with, so after discussing with mentors I decided to try and implement it. <br><font color="#000000" face="Arial"><span style="white-space:pre-wrap"><span id="gmail-docs-internal-guid-1beb8d5a-7fff-3c2b-2100-09415a22cf0e"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline">To implement it, I first started with experimenting with Qt3D frame graphs and converted an example implementation of shadow mapping provided by Qt3D but made with QML. I made that implementation into a Github repository. </span><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline"> </span></span></span></font>Then I started to port that implementation to QGIS by making some post processing effects. After that I tried implementing the shadow rendering but using a static light camera which resulted in a bad shadow resolution. To try and fix that I calculated the view frustum in world coordinates and used that to compute a bounding box that is used to move the light camera to where the user is looking at. The results were not perfect but better than having the shadow being very low resolution. Also in the shader, I made the shadows look soft using a technique called percentage closer filtering.<br>Some screenshots of the shadow rendering: <a href="https://imgur.com/RWGM72e">zoom out</a>, <a href="https://imgur.com/hs6A8R2">zoom in</a></li></ul><li><b>Weekly reports: </b><a href="https://wiki.osgeo.org/wiki/Improving_qgis_3d">https://wiki.osgeo.org/wiki/Improving_qgis_3d</a><br></li><li><b>What is left to implement:</b><br></li><ul><li>Finishing the shadow rendering implementation.<br></li><li>Make point lights work with shadow rendering.<br></li><li>Enhance python integration that didn’t have the time to complete.<br></li></ul><li><span style="background-color:transparent;color:rgb(0,0,0);font-family:Arial;font-weight:700;white-space:pre-wrap">List of links to contribution I made related to the GSoC project:</span><br></li><ul><li><a href="https://github.com/qgis/QGIS/commit/999ae580d3f788bde7726324e2ddf2f45a7b07de" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Small bug fix commit</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://github.com/qgis/QGIS/pull/36981" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Vector layer texturing PR</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://github.com/qgis/QGIS/pull/37016" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Directional lights PR</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://github.com/qgis/QGIS/pull/37588" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">3D scene export PR</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://github.com/qgis/QGIS/pull/38087" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Skybox rendering</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://github.com/qgis/QGIS/pull/38448" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Shadow rendering</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://github.com/NEDJIMAbelgacem/Qt3D-shadow-maps-CPP" style="background-color:transparent;font-family:Arial;white-space:pre;text-decoration-line:none"><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Qt3D shadow mapping sample in pure C++ repository</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;color:rgb(0,0,0);font-family:Arial;vertical-align:baseline;white-space:pre-wrap">.</span><br></li><li><a href="https://docs.google.com/document/d/1HO1ASYm2Ik5UgMhnrADg9As5mbIsbA6unfumNAP_-Qk/edit?usp=sharing" style="text-decoration-line:none"><span style="font-family:Arial;background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">QGIS improvements proposal</span></a><span style="background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap">.</span><br></li></ul><li><b style="white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">What's next: </b><span style="white-space:pre-wrap;color:rgb(0,0,0);font-family:Arial">I will try to implement new features and contribute more features in QGIS whenever I have the time to. The community was great and I loved working on the project.</span></li></ul><span style="color:rgb(0,0,0);font-family:Arial;white-space:pre-wrap">Best regards, </span><br><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px"></blockquote></blockquote>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">Belgacem Nedjima<div>4th year computer science and engineering student.</div><div><a href="https://github.com/NEDJIMAbelgacem" target="_blank">https://github.com/NEDJIMAbelgacem</a><br></div><div><br></div></div></div></div></div></div>