Instanced Rendering

实例渲染

Introduction

介绍

Qt Quick 3D supports instancing of Model objects. Instancing refers to a technique where one object is rendered multiple times with a single draw call. (For example the OpenGL function glDrawElementsInstanced.)

​Qt Quick 3D支持模型对象的实例化。实例化是指使用一个绘制调用多次渲染一个对象的技术。(例如,OpenGL函数glDrawElementsInstanced。)

Instancing allows duplicating a model with variations. In contrast to using a Repeater3D, the model and its graphics resources are only allocated once. The rendering of the duplicated instances is done at a low level by the GPU. Depending on the complexity of the model, this can give a performance improvement of several orders of magnitude.

​实例化允许复制具有变量的模型。与使用Repeater3D不同,模型及其图形资源只分配一次。重复实例的渲染由GPU在低级别完成。根据模型的复杂性,这可以使性能提高几个数量级。

In practice, instancing is done by defining a table that specifies how each instance is modified relative to the base model.

实际上,实例化是通过定义一个表来完成的,该表指定每个实例相对于基础模型的修改方式。

Instancing API

实例API

The main principle of the instancing API is that it is explicit: It doesn't try to autodetect opportunities for instancing within the existing API. Instead, each model is marked individually by setting its instancing property to reference an Instancing object. The same Instancing object can be used on multiple models at the same time.

实例化API的主要原则是它是明确的:它不会尝试自动检测现有API中的实例化机会。相反,通过将其实例化属性设置为引用实例化对象,可以单独标记每个模型。同一实例对象可以同时用于多个模型。

The Instancing object specifies a table that defines how each copy is rendered. The available modifications are:

实例化对象指定一个表,该表定义如何渲染每个副本。可用的修改包括:

  • transformation: position, rotation, and scale
  • 变换:位置、旋转和缩放
  • color: a color that is blended with the model’s material
  • 颜色:与模型材质混合的颜色
  • custom data: data that can be used by custom materials
  • 自定义数据:可由自定义材质使用的数据

Qt provides three QML types that inherit from Instancing:

Qt提供了三种继承自实例的QML类型:

  • InstanceList enumerates all instances and allows binding to the properties of each instance.
  • InstanceList枚举所有实例,并允许绑定到每个实例的属性。
  • RandomInstancing provides a way to quickly test and prototype by generating random instances within defined bounds.
  • RandomInstancing通过在定义的范围内生成随机实例,提供了一种快速测试和原型化的方法。
  • FileInstancing reads an instance table from an external file.
  • FileInstance从外部文件读取实例表。

The instancing example shows how to create a scene using the QML API.

​实例化示例显示了如何使用QML API创建场景。

Other kinds of instance tables can be defined in C++ by subclassing QQuick3DInstancing. For example, the particle system uses its own instancing table internally. It is available as ModelParticle3D.instanceTable.

​通过子类化QQuick3DInstance,可以在C++中定义其他类型的实例表。例如,粒子系统在内部使用自己的实例化表。它作为ModelParticle3D.instanceTable提供。

By writing custom shader code, it is possible to use instancing to control additional properties, such as variables for physically based rendering, skeletal animation weights, distortion, or anything else that can be expressed with custom materials. The custom data in the instancing table consists of four floating point numbers.

通过编写自定义着色器代码,可以使用实例化来控制其他属性,例如用于基于物理的渲染的变量、骨骼动画权重、扭曲或可以用自定义材质表示的任何其他属性。实例化表中的自定义数据由四个浮点数组成。

The custom instancing example shows how to combine custom materials and an instance table implemented in C++.

​自定义实例化示例显示了如何将自定义材质与C++实现的实例表相结合。

Alpha-blending and instancing

Alpha混合和实例化

Correct alpha blending requires that semi-transparent objects are rendered back-to-front. For this reason, QtQuick3D sorts opaque and semi-transparent objects separately, and renders them in the correct order. With instancing, however, the GPU will render the instances in the order specified by the instancing table, if depth-sorting is not turned on. For performance reasons, QtQuick3D does not sort the table by default as it can take long time with large number of instances. This means that if semi-transparent instances overlap with each other, or with other semi-transparent objects, the results may look wrong. In general, the error is less visible when the opacity is low.

​正确的alpha混合需要将半透明对象渲染回前面。因此,QtQuick3D分别对不透明和半透明对象进行排序,并以正确的顺序渲染它们。但是,如果没有启用深度排序,使用实例化,GPU将按照实例化表指定的顺序呈现实例。出于性能原因,QtQuick3D默认情况下不会对表进行排序,因为大量实例可能需要很长时间。这意味着,如果半透明实例彼此重叠,或与其他半透明对象重叠,则结果可能看起来不正确。通常,当不透明度较低时,错误不太明显。

Fully opaque objects together with non-overlapping semi-transparent objects will always be rendered correctly, since Qt uses depth buffer testing to avoid drawing behind opaque objects. However, the lack of sorting has potential performance implications for opaque objects: They may not be rendered in the optimal order, meaning that the same pixel can be written multiple times, making more work for the fragment shader.

完全不透明对象和非重叠半透明对象将始终正确渲染,因为Qt使用深度缓冲区测试来避免在不透明对象后面绘制。但是,缺少排序对不透明对象有潜在的性能影响:它们可能不会以最佳顺序渲染,这意味着同一像素可以多次写入,从而为片段着色器带来更多工作。

The renderer does not inspect the contents of the instancing table, so it must be specified explicitly when an instance table contains semi-transparent alpha values: Set the hasTransparency property to to true to make sure that the renderer enables alpha blending. This applies to all the instances: Even fully opaque instances will be rendered without depth testing, potentially causing visible errors.

​渲染器不检查实例化表的内容,因此当实例表包含半透明alpha值时,必须明确指定它:将hasTransparency属性设置为true,以确保渲染器启用alpha混合。这适用于所有实例:即使完全不透明的实例也会在没有深度测试的情况下渲染,这可能会导致可见错误。

The rendering order relative to the rest of the scene can be adjusted by setting the depth bias of the model.

​可以通过设置模型的深度偏移来调整相对于场景其余部分的渲染顺序。

Transforms and instancing

转换和实例化

Each instance has its own transform in the instance table. This is combined with the transforms on the instanced model. This is slightly complex, since there are several use cases:

每个实例在实例表中都有自己的转换。这与实例化模型上的变换相结合。这有点复杂,因为有几个用例:

  • Doing a transform on the model that is applied to each individual instance. This allows cheap animations, for example by rotating all instances at once without having to change the instance table.
  • 对应用于每个实例的模型进行转换。这允许廉价的动画,例如,通过一次旋转所有实例而无需更改实例表。
  • Transforming the entire group of instances at once.
  • 一次转换整个实例组。
  • Instancing a model hierarchy.
  • 实例化模型层次结构。

To support all these cases, The model’s transform is split into two parts: the local instance transform, and the global instance transform. Conceptually, instancing is performed like this:

为了支持所有这些情况,模型的转换分为两部分:本地实例转换和全局实例转换。从概念上讲,实例化的执行方式如下:

  • First the model is transformed according to the local instance transform.
  • 首先根据局部实例变换对模型进行变换。
  • Then each instance is calculated by applying the instance table transform
  • 然后通过应用实例表转换计算每个实例
  • Finally, the whole group of instanced objects is transformed according to the global instance transform.
  • 最后,根据全局实例变换变换整个实例化对象组。

By default, the local instance transform of a model consists of the model’s scale and rotation, while the rest goes into the global instance transform.

默认情况下,模型的局部实例变换由模型的缩放和旋转组成,而其余的则进入全局实例变换。

This can be controlled by setting the model’s instanceRoot property. This defines the origin of the instance’s coordinate system. The most common use is when instancing a hierarchy of models. For example, a sphere orbiting around a cube:

​这可以通过设置模型的instanceRoot属性来控制。这将定义实例坐标系的原点。最常见的用法是实例化模型层次结构。例如,围绕立方体旋转的球体:

Model {id: cubeinstancing: someInstanceTablesource: "#Cube"materials: DefaultMaterial { diffuseColor: "lightgray" }Node {Model {source: "#Sphere"instanceRoot: cubeinstancing: cube.instancingx: 150materials: DefaultMaterial { diffuseColor: "gray" }}NumberAnimation on eulerRotation.y {from: 0to: 360duration: 4000loops: Animation.Infinite}}
}

The instanceRoot is necessary to specify that the sphere instance should be positioned as if it were an element of the cube. Each model in a hierarchy still needs to specify the instancing property: in normal cases they should all be set to the same Instancing object.

必须使用instanceRoot来指定球体实例的位置,就像它是立方体的元素一样。层次中的每个模型仍然需要指定实例化属性:在正常情况下,它们都应该设置为同一个实例化对象。

instanceRoot can also be used when instancing a single model. For example, a cylinder rotating around an off-center point:

在实例化单个模型时,也可以使用instanceRoot。例如,围绕偏心点旋转的圆柱体:

 Node {id: parentNodeModel {source: "#Cylinder"instanceRoot: parentNodeinstancing: anotherInstanceTablex: 25materials: DefaultMaterial { diffuseColor: "white" }}NumberAnimation on eulerRotation.y {from: 0to: 360duration: 1000loops: Animation.Infinite}
}

Picking and instancing

拾取和实例化

Picking is a mechanism that enables selecting a model from a user interface interaction. With instanced rendering, there are several representations of the same model, so the pick result will include an instance index. Instanced picking is enabled by setting the pickable property on the base model.

拾取是一种允许从用户界面交互中选择模型的机制。对于实例化渲染,同一模型有多个表示形式,因此拾取结果将包括一个实例索引。通过在基本模型上设置pickable属性,可以启用实例化拾取。

© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. 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.

实例渲染(Instanced Rendering)相关推荐

  1. 实例渲染Instanced Rendering

    实例渲染Instanced Rendering 0.前言 在此之前红宝书已经介绍了不少关于缓存和绘制的命令,并给出了用同样的顶点绘制几个三角形的例程,但是此前的例程实现起来非常麻烦,每个三角形要指定一 ...

  2. OpenGL 分层渲染Layered Rendering的实例

    OpenGL 分层渲染Layered Rendering 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <string> #incl ...

  3. OpenGL 文本渲染Text Rendering

    OpenGL文本渲染Text Rendering 文本渲染Text Rendering简介 经典文本渲染:位图字体 现代文本渲染:FreeType 着色器 渲染一行文本 更进一步 文本渲染Text R ...

  4. CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率

    CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率 当场景中有比较复杂的模型时,条件渲染能够加速对复杂模型的渲染. 条件渲染(Conditio ...

  5. 延迟渲染(Deferred Rendering)

    什么是延迟渲染?( Deferred Rendering) 在计算机图形学中,延迟渲染( Deferred Rendering) ,即延迟着色(Deferred Shading),是将着色计算延迟到深 ...

  6. Three.js BIM模型轻量化 FPS渲染速率优化 多 实例渲染[Instance]+顶点合并[Merge]

    BIM模型不经过处理,直接加载到Three.js 创建的场景中,很大可能会很使fps帧率下降,原因在于模型的个数太多,有的模型是多材质的话还需要在Three.js中绘制两次,这样会导致drawcall ...

  7. Unity3d 基于物理渲染Physically-Based Rendering之最终篇

    前情提要: 讲求基本算法 Unity3d 基于物理渲染Physically-Based Rendering之specular BRDF plus篇 Unity3d 基于物理渲染Physically-B ...

  8. 立体渲染 Volumetric Rendering

    基础概念 在3D游戏引擎中,球体.立方体以及所有其它复杂的集合体都是由三角面片组成的.引擎只会渲染物体的表面,比如球体,半透明物体等.整个世界由各种空壳构成. 立体渲染(Volumetric Rend ...

  9. 渲染上下文Rendering Context

    渲染描述表,包含一次渲染所需的全部数据.用于提交给游戏渲染引擎的渲染器进行渲染 ------------------------------------------------------------ ...

最新文章

  1. Carrier frequency 和 EARFCN的关系
  2. python日期格式化
  3. Ubuntu安装VLC播放器
  4. 程序员必备:Java 日期处理的十个坑
  5. 一些关于 SAP Spartacus 组件和模块延迟加载的问题和解答
  6. 使用WebApiClient请求和管理Restful Api
  7. linux下redis的安装和配置
  8. 清除默认的内边距与外边距
  9. shp设置utf8格式_shapefile与字符集编码设置
  10. 获取指定路径下所有PDF文件的总页数
  11. 5.分布式服务架构:原理、设计与实战 --- 基于调用链的服务治理系统的设计与实现
  12. 随手记_选方向读论文发论文相关
  13. linux常用命令技巧
  14. springmvc和layui富文本编辑器实时上传图片功能实现
  15. python实现——视频转桌面壁纸
  16. 工业互联网,姓工,名互
  17. 1.5 人工智能迅速发展的技术领域
  18. JAVA生成安卓签名证书
  19. raid卡缓存对硬盘性能_1000倍可靠性,专为高端NAS而生 西部数据SA500 RED SSD固态硬盘首发评测...
  20. 安卓使用connectbot连接centos云服务器

热门文章

  1. 利用MS的CASTEP模块计算铁磁性铁声子谱
  2. 极大似然估计思想的最简单解释
  3. 梯度下降法求解多元线性回归 — NumPy
  4. 分析问题的黄金法则——MECE分析法
  5. python学习记录(基础知识+案例实现)
  6. 多色彩产品合格证模板 - cdr2019 Design
  7. 我的职业生涯(2)----接触SAP
  8. LPS和RAS坐标系
  9. 携职教育:2022年第2期广东省企业人力资源管理师职业技能等级认定工作的通知
  10. EXCEL 2016常用知识--Excel函数