Qt 3D Overview

Source: Internet
Author: User

The goal of the Qt3d is to enable developers to quickly create 3D scenes with a wide variety of rendering techniques to achieve 3D interaction scenarios. Qt3d In addition to Qt -like cross-platform, but also can choose the specific implementation of OpenGL , custom GLSL, so that the different performance of the machine, to adjust the rendering effect.

The Qt3d provides a fully configurable renderer that enables developers to quickly implement any rendering pipeline through the renderer. In addition to rendering,Qt3d also provides a common framework for near real-time simulations.

The Qt3d consists of a core module and additional modules. These add-ons provide specific aspects of functionality, including physical model modules, audio modules, collision modules, AI modules, and path search modules.

basic3d Features

Qt3d is a frame that can draw and move a 3D model, or you can move the camera. The framework supports the following basic features:

    • 2D and 3D rendering for C + + and QtQuick applications

    • Mesh

    • Material

    • Coloring device

    • Shadow Map

    • Environmental impact

    • High Dynamic Range (HDR)

    • Deferred rendering

    • Multiple textures

    • Instance rendering

    • Unified Buffer Object (UBO)

Materials

The material system provided by Qt3d is stable and flexible, and the user can be customized in multiple levels. It enables material rendering on different platforms or on different OpenGL versions, renders multiple times by passing different sets of states, provides different levels of parameter overrides, and allows switching between shaders. These features are implemented through C + + or by using QML property bindings.

In the GLSL shader Program, a material type property can be mapped by a uniform variable, and a shader program can be specified in a program.

For examples of materials, refer to qt3d:materials C + + Example andqt3d:materials QML Example.

Shaders

The Qt3d supports all OpenGL programmable render pipeline stages: vertex, arrange control, arrange calculation, geometry, and fragment shader. The compute shader (CS) will be supported in a future release.

Examples of shaders can be found in:thesimple Shaders QML Example, qt3d:tessellation Modes QMLExample,qt3d:shadow Map QML Exa Mple,qt3d:wireframe QML Example, andqt3d:wave QML Example.

shadowmapping

OpenGL does not directly support shadow effects, but it has a variety of implementation techniques. Shadow maps can produce a nice shading effect with very low performance losses.

Shadow maps are implemented with two rendering. The shadow information is generated at the first render, and the scene is generated by a special rendering technique during the second rendering, and the shadow is drawn using the information generated during the first rendering.

The principle of shadow mapping technology is to illuminate only the clips closest to the light source. Other fragments of light are obscured, showing the shadow effect.

Therefore, in the first rendering phase, the scene is drawn with the light source as the viewpoint. In this light space, the information stored is just the closest segment instance to the light source. In OpenGL terminology, this instance corresponds to a buffer object (FBO) that contains the depth texture information. In fact, the distance from the eye to the instance is the definition of depth, andOpenGL 's default depth test actually stores only the depth closest to the source fragment.

Color texture attachments are not even required, for shadow fragments this is unnecessary, just to calculate the depth.

The film shows the scene of the plane with the shadow map and the three-leaf knot:


Shows an exaggerated shadow map texture scene:

The picture shows the depth of scene rendering with the light source as its viewpoint. The dark color represents the depth of the shadow (that is, near the camera). This light source is placed above the target object, to the right of the main camera (compared to the first screenshot). The toy plane is closer to the camera than any other target.

When the shadow map is generated, the second stage of rendering is complete. In the second stage, the rendering is done through a normal scene camera. This stage can handle other effects, such as complementary color coloring. The shadow map algorithm can be used in the fragment shader, that is, the clip near the light is drawn brightly, and the other fragments draw a shadow effect.

The first stage generates the necessary information for the shadow map, which contains information about the distance from the clip to the light source. The fragment is then remapped in the light space, calculating the depth of the light source as the viewpoint, and the coordinates in the shadow map texture. The shadow map texture is sampled in a given coordinate system, and the fragment depth can be compared with the sampled results. If the fragment depth is farther, the fragment is displayed in the shadow, or the fragment is illuminated by the light source.

For more examples, refer to qt3d:shadow Map QML Example.

instancedrendering

Instancing draws multiple copies of a base instance through the GPU , which vary based on the same instance. For example, the location of the instance, angle, color, material properties, scale, and so on parameter changes. Qt3d provides API access to the qtquickrepeater element. Then, the proxy is the base object, and the model provides data for each instance. Thus an entity drawing process with a mesh is converted to a call to gldrawelements , and an entity drawing process with an instantiated component is converted to a call to gldrawelementsinstanced .

In a future release, there will be more instantiation rendering support.

Uniformbuffer Objects

UBO can submit high-volume drawing data by binding to the OpenGL shader program. Typical use of UBO such as material and illumination parameter sets.

Configurablerenderer

To enable fully configurable renderers to support both C + + and Qmlapi, the concept ofFramegraph was born. Scene Graphics (scenegraph) and Frame graphics (framegraph) are data-driven, the difference being that the data in the former describes what is plotted, and the latter's data describes how to draw it.

With frame graphics (framegraph), developers can choose forward renderers ( rendered in z -Depth order )or deferred renderers, such as controlling when to render transparent objects and so on. Choose which renderer is configurable and can be configured at run time, without modifying any C + + code. Developers can create their own frame graphics (framegraph)by implementing a custom rendering algorithm as an extension of the Qt3d .

3DExtensions

In addition to rendering 3D content on the screen,Qt3d also contains the following features about 3D objects:

    • Physical simulation

    • Collision detection

    • 3D Azimuth Audio

    • Rigid body, skeleton, target animation transformation

    • Path finding and other artificial intelligence

    • Pickup

    • Particle

    • Object splitting

Performance

The more CPU cores, the higher the performance of theQt3d , and now the CPU is improving performance by increasing the number of cores rather than increasing the clock frequency. Using multicore CPUs can improve performance to some extent, and many tasks are independent of each other and can be executed in parallel. For example, the path lookup module performs actions and renderer rendering actions are independent of each other, can be executed concurrently, get rendering debugging information and statistics can be single-line execution.

Qt3d Architecture


The Qt3d is primarily used for near real-time object emulation while rendering objects of different states on the screen. The example Space Invaders (Thespace Invaders) contains the following objects:

    • Player-controlled ground cannon

    • Ground

    • Defense Block

    • Enemy's space invasion ship

    • The enemy's command UFO

    • Bullets fired by enemies and players

In traditional C + + Design patterns, these objects are described in the object tree class of the inheritance relationship. Additional features and features can be added to each inheritance branch of the object tree, such as:

    • Receive user input

    • Voice

    • Survival / death status

    • Collisions with other objects

    • Do you want to draw on the screen

Examples of space Invaders contain these characteristics. However, it is not easy to design an elegant inheritance tree for a simple example.

This inherited design approach and other similar design methods have the following problems:

    • The level of depth and breadth inheritance is difficult to understand, maintain, and extend.

    • Inheritance classifications are fixed at compile time.

    • Each level on a class inheritance tree can only be categorized based on a single criterion or mainline.

    • The functionality common to multiple classes will rise to the upper class.

    • Can't predict what developers want to do.

Extended depth and breadth inheritance trees often need to understand and recognize the way the original authors are categorized. Qt3d is the ability to assign functionality to an object instance in a way that is aggregated rather than inherited. To achieve this,Qt3d implements a physical build system (ECS).

Usingan ECS

In an ECS , an entity represents a simulated object, but the object itself does not have any specific behavior or characteristics. You can add ECS behavior by binding the entity component.

In the Space Invaders example, the ground acts as an entity and contains an additional component that describes how the entity needs to be rendered and in which way it is rendered. The enemy's spaceship is another entity whose add-ons describe the spaceship's rendering, sound, collision, dynamic flight, and control of the flight trajectory through simple AI.

In addition to the artillery without AI components, the player's cannon entities are similar to the components of the enemy spaceship entities. The cannon has input components to help the player move the cannon and fire bullets.

Ecsbackend


Here is an important concept-aspect-oriented. So in which you see a lot of Aspect words. This is because we are dividing an entity(entity) into many components (Component), many of which are grouped together to form one aspect, and the rest are made up of another. For example, Qt3d has core aspects, rendering aspects, sound aspects, input aspects,Quick rendering aspects. They are formed into a library, linked according to the needs of the user.

For example, the rendering facet looks for the mesh, material, and transformation ( if needed ) components of the entity. If such entities are found in the rendering aspect, the renderer knows how to fetch the data and draw them better. If the entity does not have these components, the rendering aspect ignores this entity.

Qt 3D creates a new custom entity by aggregating components that provide additional capabilities. The Qt3d engine processes and updates entities through the specified components of the facet.

For example, the physical side looks for many collision detection components, simulating components related to specific properties such as block physics, friction coefficients, and so on. A sound-emitting entity has a sound-related component, and the component also specifies when to emit which sound.

Because ECS uses aggregations rather than inheritance, it can change the behavior of objects at run time by simply adding and removing components.

For example, in order to allow a player to suddenly cross a wall in a power-on state, the collision detection component of the entity can be temporarily removed before the power-up state ends. However, we do not need to implement special switch subclasses such asPlayerWhoRunsThroughWalls

Qt3d ECS Implementation

Qt 3D implements ECSthrough simple class inheritance. The Qt3d base class is Qt3dcore::qnode, which is a subclass of Qobject . When a property changes,Qt3dcore::qnode automatically notifies you of a property change, while processing properties in a child thread,Qt3dcore::qnode also simplifies data transfer for user interface threads and property-related child threads.

In general,Qt3dcore::qnode subclasses provide additional support for data, which is used in components. For example, when rendering an entity set, theQshaderprogram class specifies the use of GLSL code.

The components in Qt3d inherit from qt3dcore::qcomponent, and the required properties are added for related aspects. For example, the rendering facet uses a mesh component to retrieve each vertex data that should be sent to the OpenGL pipeline.

Finally,qt3dcore::qentity is an object capable of aggregating 0 or more qt3dcore::qcomponent entities.

EXTENDINGQT 3D

Whether you add Qt3d functionality as part of Qt or as part of your application, a multi-threaded backend typically consists of the following tasks:

Identify and implement any required components and supported data.

Use the QML engine to register the component ( only when using qmlapi ).

Sub-class Qabstractaspect and implement subsystem functions.

Qt3d task-based Engine

In Qt3d , each frame in a task set asks which aspect to use for execution. To improve performance, the scheduler distributes tasks based on the number of CPU cores that are configured.

Qt3d ' s aspects

Qt3d provides qt3drender and qt3dinput aspects by default. These aspects provide components and other supported classes, which are described in the documentation. In future versions of Qt3d , additional aspects will provide more capabilities.


Summary

Qt 3D is a new module introduced in Qt5.5.0 and is currently in the technical preview state. The Qt3d module should have broad application prospects in 3D visualization, gaming, and simulation, enabling developers to quickly and easily implement the required features faster than using OpenGL interfaces directly. Currently Qt3d related documents and support is not very comprehensive, in the future version will continue to improve.

Qt 3D Overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.