Materials and Light

材料和灯光

Up until now, we've only worked with basic materials. To create a convincing 3D scene, proper materials and more advanced lighting is needed. Qt Quick 3D supports a number of techniques to achieve this, and in this section we will look at a few of them.

到目前为止,我们只研究了基本材料。为了创建令人信服的3D场景,需要适当的材料和更先进的照明。Qt Quick 3D支持多种技术来实现这一点,在本节中,我们将介绍其中的一些技术。

The Built-in Materials

内置材质

First up, we will look at the built in materials. Qt Quick 3D comes with three material types: DefaultMaterialPrincipledMaterial, and CustomMaterial. In this chapter we will touch on the two first, while the latter allows you to create truly custom material by providing your own vertex and fragment shaders.

首先,我们来看一下内置材料。Qt Quick 3D提供了三种材质类型:DefaultMaterial、PrincipledMaterial和CustomMaterial。在本章中,我们将首先讨论这两种材质,而后者允许您通过提供自己的顶点和片段着色器来创建真正的自定义材质。

The DefaultMaterial lets you control the appearance of the material through the specularroughness, and diffuseColor properties. The PrincipledMaterial lets you control the appearache through the metalnessroughness, and baseColor properties.

DefaultMaterial允许您通过镜面反射、粗糙度和漫反射颜色属性控制材质的外观。PrincipledMaterial允许您通过金属度、粗糙度和基色属性来控制外观。

Examples of the two material types can be seen below, with the PrincipledMaterial to the left, and the DefaultMaterial to the right.

下面可以看到两种材质类型的示例,PrincipledMaterial位于左侧,DefaultMaterial位于右侧。

Comparing the two Suzannes, we can see how the two materials are set up.

比较这两种,我们可以看到这两种材料是如何建立的。

For the DefaultMaterial, we use the diffuseColorspecularTint, and specularAmount properties. We will look at how variations of these properties affect the appearance of the objects later in this section.

对于DefaultMaterial,我们使用diffuseColor、specularTint和specularAmount属性。在本节后面,我们将研究这些属性的变化如何影响对象的外观。

Model {source: "meshes/suzanne.mesh"position: Qt.vector3d(5, 4, 0)scale: Qt.vector3d(2, 2, 2)rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))materials: [ DefaultMaterial {diffuseColor: "yellow";specularTint: "red";specularAmount: 0.7} ]
}

For the PrincipledMaterial, we tune the baseColormetalness, and roughnessproperties. Again, we will look at how variations of these properties affect the appearance later in this section.

对于PrincipledMaterial,我们调整基色、金属度和粗糙度属性。在本节后面,我们将再次研究这些特性的变化如何影响外观。

Model {source: "meshes/suzanne.mesh"position: Qt.vector3d(-5, 4, 0)scale: Qt.vector3d(2, 2, 2)rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))materials: [ PrincipledMaterial {baseColor: "yellow";metalness: 0.8roughness: 0.3} ]
}

Default Material Properties

默认材质属性

The figure below shows the default material with various values for the specularAmount and the specularRoughness properties.

下图显示了默认材质,其镜面反射量specularAmount和镜面反射粗糙度specularRoughness属性具有各种值。

The specularAmount varies from 0.8 (left-most), through 0.5 (center), to 0.2 (right-most).

镜面值specularAmount从0.8(最左侧)、0.5(中心)到0.2(最右侧)不等。

The specularRoughness varies from 0.0 (top), through 0.4 (middle), to 0.8 (bottom).

镜面粗糙度specularRoughness从0.0(顶部)、0.4(中间)到0.8(底部)不等。

The code for the middle Model is shown below.

中间模型的代码如下所示。

Model {source: "meshes/suzanne.mesh"position: Qt.vector3d(0, 0, 0)scale: Qt.vector3d(2, 2, 2)rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))materials: [ DefaultMaterial {diffuseColor: "yellow";specularTint: "red";specularAmount: 0.5specularRoughness: 0.4} ]
}

Principled Material Properties

Principled材质属性

The figure below shows the principled material with various values for the metalness and roughness properties.

下图显示了具有不同金属度和粗糙度属性值的原理材料。

The metalness varies from 0.8 (left-most), through 0.5 (center), to 0.2 (right-most).

金属度metalness从0.8(最左侧)、0.5(中心)到0.2(最右侧)不等。

The roughness varies from 0.9 (top), through 0.6 (middle), to 0.3 (bottom).

粗糙度roughness从0.9(顶部)、0.6(中间)到0.3(底部)不等。

Model {source: "meshes/suzanne.mesh"position: Qt.vector3d(0, 0, 0)scale: Qt.vector3d(2, 2, 2)rotation: Quaternion.fromEulerAngles(Qt.vector3d(-80, 30, 0))materials: [ PrincipledMaterial {baseColor: "yellow";metalness: 0.5roughness: 0.6} ]
}

Image-based Lighting

基于图像的光照

One final detail in the main example in this section is the skybox. For this example, we are using an image as skybox, instead of a single colour background.

本节主要示例中的最后一个细节是skybox。在本例中,我们使用图像作为skybox,而不是单色背景。

To provide a skybox, assign a Texture to the lightProbe property of the SceneEnvironment as shown in the code below. This means that the scene receives image-based light, i.e. that the skybox is used to light the scene. We also adjust the probeExposure which is used to control how much light is exposed through the probe, i.e. how brightly the scene will be lit. In this scene, we combine the light probe with a DirectionalLight for the final lighting.

要提供skybox,请将纹理Texture指定给SceneEnvironment的lightProbe属性,如下面的代码所示。这意味着场景接收基于图像的光,即skybox用于照亮场景。我们还调整probeExposure,它用于控制通过探头暴露的光线量,即场景的照明亮度。在这个场景中,我们将光探测器与方向光相结合,以获得最终照明。

environment: SceneEnvironment {clearColor: "#222222"backgroundMode: SceneEnvironment.SkyBoxlightProbe: Texture {source: "maps/skybox.jpg"}probeExposure: 0.75
}

In addition to what we show, the orientation of the light probe can be adjusted using the probeOrientation vector, and the probeHorizon property can be used to darken the bottom half of the environment, simulating that the light comes from above, i.e. from the sky, rather than from all around.

除了我们所展示的之外,可以使用probeOrientation向量调整光探测器的方向,probeHorizon属性可以用于使环境的下半部分变暗,模拟光来自上方,即来自天空,而不是来自周围。

Qt6 QML Book/Qt Quick 3D/材料和灯光相关推荐

  1. Qt Quick 3D介绍:Qt Quick的高级3D API

    目录 我们的目标是什么?为什么提出另一个3D解决方案? 统一图形技术 直观易用的API Qt Quick的统一工具 一流的素材优化管道 跨平台性能和兼容性 Qt Quick 3D到底是什么? 您能用Q ...

  2. Qt Quick 3D学习:使用鼠标键盘控制节点位置和方向

    (注意,开源版的 Qt Quick 3D 是狗都不用的 GPL 协议) Qt Quick 3D 模块提供了  WasdController 类型来控制节点的位置和方向,受控节点一般是 Camera.( ...

  3. Qt Widgets、QML、Qt Quick的概念与区别

    1 QML 和 Qt Quick 是什么关系? 从概念上区分 QML 是一种用户界面规范和标记语言,它允许开发/设计人员创建高性能.流畅的动画和具有视觉吸引力的应用程序. 这里,主要涉及两点: 用户界 ...

  4. Qt文档阅读笔记-Qt Quick 3D - Simple Example解析

    程序运行截图如下: 还是动的. 官方出这篇博文的目的是如何教我们使用Qt Quick 3D去渲染简单的场景. 首先是设置其场景. 在main.qml文件中设置整个场景,导入QtQuick3D组建,用于 ...

  5. Qt Quick 3D学习:模型加载

    (注意,开源版的 Qt Quick 3D 是狗都不用的 GPL 协议) Qt Quick 3D 模块提供了 Model 类型用于 3D 模型加载,通过设置 source 的资源路径来加载对应的 3D ...

  6. Qt Quick 3D模块初探

    0.前言 Qt Quick 3D提供了用于基于Qt Quick创建3D内容或UI的高级API.提供了对现有Qt Quick场景图(scenegraph )的扩展,以及对该扩展场景图的渲染器.使用空间场 ...

  7. Qt Quick 3D系列(五):三维模型展示示例

    为了展示一个好看的3D模型,需要对模型设置背景,设置三维材质,设置周围光线,设置模型阴影等等.下面示例展示了一个比较好看的三维模型效果,大家可以先在C4D等调整好模型效果,然后将三维工程转换为.mes ...

  8. Qt Widgets、QML、Qt Quick 的区别

    作者: 一去.二三里 个人微信号: iwaleon 微信公众号: 高效程序员 在接触 Qt 之后,很多人难免会有一些疑惑: Q1:QML 和 Qt Quick 之间有什么区别? Q2:QtQuick ...

  9. Qt Quick 3D系列(一):加载3d模型

    如果我们想在QML中使用3D且你之前没有三维程序开发的基础,使用Qt Quick 3D是个不错的选择,下面我介绍如何使用Qt Quick 3D加载3d模型.注意:Qt Quick 3D从Qt 5.15 ...

最新文章

  1. 天体摇摆仪的工作原理-测量电路中的部分电路波形
  2. Visual Studio 2005常用插件搜罗
  3. ORACLE 回收站管理
  4. The GenerateResource task failed unexpectedly. a generic error occured in GDI+
  5. Kubernetes详解(二十)——ReplicaSet控制器
  6. TabLayout实现自定义标题栏目功能
  7. 基于社会资源的普通摄像机1400结构化AI算法改造方案
  8. 使用WinDbg分析Windows dump文件方法
  9. Excel的写入与读取(openpyxl)
  10. 计算机组成原理运算器设计实验之8位可控加减法电路设计
  11. 基于51单片机的电子钟万年历LCD1602显示
  12. 《BPF( 伯克利数据包过滤器 ) Performance Tools》 第六章 CPU
  13. 关于声卡驱动安装问题 ghost版本的危害
  14. 画动漫人物眼睛怎么上色
  15. Dreamweaver CC 2017中文版
  16. 单位根检验、航空模型、季节模型
  17. 985复旦大学,软件工程学硕停止招生!
  18. python 文件读取错误之FileNotFoundError: [Errno 2] No such file or directory:,顺便学习斜杠/和反斜杠\的用法
  19. 二年级计算机是学什么内容的,小学二年级上册信息技术教案【三篇】
  20. python安装文件乱码_Python程序在Windows终端乱码解决方法

热门文章

  1. 【ASP.NET Identity系列教程(三)】Identity高级技术
  2. 网康防火墙--上线指南_在线付款接受指南-第1部分
  3. Python抢票程序优化,可以选择车次和座次
  4. 程序员们为什么频繁地跳槽
  5. css 滚动条不占宽度
  6. 雷军:穿越人生低谷的感悟(节选)
  7. 利用Excel 2010的“图表模板”功能,快速创建新图表
  8. 数据分析的方法与技术
  9. 雷神Springboot2笔记
  10. 软件项目量化管理(QPM)及根因分析实践总结(CMMI高成熟度访谈)