diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-06-24 14:05:53 +0200 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@theqtcompany.com> | 2015-06-25 04:21:23 +0000 |
commit | 05e378b2fcbe72725b4736946d65c1290c291d25 (patch) | |
tree | 97795821a4bc370074c319414fc693028ded7742 /src/core | |
parent | 1b98284ad0e775c84963385732c93ef0e2d5a0f1 (diff) |
Doc: Add some docs for the shadow map example
Change-Id: Iea29c9f654fc57518bf3d428b30fa5955aa1230d
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/doc/qt3dcore.qdocconf | 3 | ||||
-rw-r--r-- | src/core/doc/src/qt3d-overview.qdoc | 86 |
2 files changed, 85 insertions, 4 deletions
diff --git a/src/core/doc/qt3dcore.qdocconf b/src/core/doc/qt3dcore.qdocconf index 28f985029..923cc1345 100644 --- a/src/core/doc/qt3dcore.qdocconf +++ b/src/core/doc/qt3dcore.qdocconf @@ -48,7 +48,8 @@ exampledirs += src/snippets #excludedirs += -imagedirs += images +imagedirs += images \ + ../../../examples/qt3d/shadow-map-qml/doc/images Cpp.ignoretokens += QT3DCORE_PRIVATE_EXPORT \ QT3DINPUTSHARED_EXPORT \ diff --git a/src/core/doc/src/qt3d-overview.qdoc b/src/core/doc/src/qt3d-overview.qdoc index 74a4c2949..133f6fd14 100644 --- a/src/core/doc/src/qt3d-overview.qdoc +++ b/src/core/doc/src/qt3d-overview.qdoc @@ -61,14 +61,14 @@ \li 2D and 3D rendering for C++ and Qt Quick applications \li Meshes \li \l {Materials} - \li Shadows \li \l {Shaders} + \li \l {Shadow Mapping}{Shadow mapping} \li Ambient occlusion \li High dynamic range \li Deferred rendering \li Multitexturing - \li Instancing - \li Uniform Buffer Objects + \li \l {Instanced Rendering}{Instanced rendering} + \li \l {Uniform Buffer Objects} \endlist \section2 Materials @@ -98,6 +98,86 @@ \l {Qt3D: Shadow Map QML Example}, \l{Qt3D: Wireframe QML Example}, and \l {Qt3D: Wave QML Example}. + \section2 Shadow Mapping + + Shadows are not directly supported by OpenGL, but there are countless + techniques that can be employed to generate them. Shadow mapping is simple + to use for generating good-looking shadows, while having a very small + performance cost. + + Shadow mapping is typically implemented using a two pass rendering. In the + first pass, the shadow information is generated. In the second pass, the + scene is generated using a particular rendering technique, while at the + same time using the information gathered in the first pass to draw the + shadows. + + The idea behind shadow mapping is that only the closest fragments to the + light are lit. Fragments \e behind other fragments are occluded, and + therefore in shadow. + + Therefore, in the first pass, the scene is drawn from the point of view of + the light. The information that is stored is simply the distance of the + closest fragment in this \e {light space}. In OpenGL terms, this corresponds + to having a Framebuffer Object, or FBO, with a depth texture attached to it. + In fact, the \e {distance from the eye} is the definition of the depth, + and the default depth testing done by OpenGL will actually store only the + depth for the closest fragment. + + A color texture attachment is not even needed, because there is no need to + shade fragments, only to calculate their depth. + + The following image displays a scene with a self-shadowed plane and trefoil + knot: + + \image shadowmapping-qt3d.png + + The following image shows an exaggerated shadow map texture of the scene: + + \image shadowmapping-depth.png + + The image indicates the depth stored when rendering the scene from the light + point of view. Darker colors represent a shallow depth (that is, closer to + the camera). In this scene, the light is placed somewhere above the objects + in the scene, on the right side with respect to the main camera (compare + this with the first screenshot). This matches with the fact that the toy + plane is closer to the camera than the other objects. + + Once the shadow map has been generated, the second rendering pass is done. + In this second pass, rendering is done using the normal scene's camera. Any + effect can be used here, such as Phong shading. It is important that the + shadow map algorithm is applied in the fragment shader. That is, the + fragment that is closest to the light is drawn lit, whereas the other + fragments are drawn in shadow. + + The shadow map generated in the first pass provides the necessary + information about the distance of fragments to light. It then suffices to + remap the fragment in light space, thereby calculating its depth from the + light point of view, as well as where its coordinates are on the shadow map + texture. The shadow map texture can then be sampled at the given coordinates + and the fragment's depth can be compared with the result of the sampling. If + the fragment is further away, then it is in shadow; otherwise it is lit. + + For example code, see the \l {Qt3D: Shadow Map QML Example}. + + \section2 Instanced Rendering + + \e Instancing is a way of getting the GPU to draw many copies (instances) of + a base object that varies in some way for each copy. Often, in position, + orientation, color, material properties, scale, and so on. Qt3D provides an + API similar to the Qt Quick \l Repeater element. In this case, the delegate + is the base object and the model provides the per-instance data. So whereas + an entity with a \l Mesh component attached eventually gets transformed into + a call to glDrawElements, an entity with a instanced component will be + translated into a call to glDrawElementsInstanced. + + Instanced rendering is planned for a future release. + + \section2 Uniform Buffer Objects + + A Uniform Buffer Object (UBO) can be bound to OpenGL shader programs to make + large amounts of data readily available. Typical use cases for UBOs are for + sets of material or lighting parameters. + \section1 Configurable Renderer To combine support for both C++ and QML APIs with having a fully |