QtQuick3D实时反射

本文探讨了QtQuick3D中两种实现3D场景实时反射的技术:反射探针和屏幕空间反射。反射探针通过环境映射计算反射,适用于静态环境,而屏幕空间反射则是一种更接近真实效果但计算成本更高的后处理技术,适用于动态场景。两种方法各有优劣,可以根据场景需求选择合适的方法。
摘要由CSDN通过智能技术生成

QtQuick3D Realtime Reflections

QtQuick3D实时反射

Wednesday February 09, 2022 by Hatem ElKharashy | Comments

​2022年2月9日星期三 Hatem ElKharashy | 评论

Reflections enhance the realism of a rendered 3D scene and without it we can not have objects like mirrors or puddles of water that reflect the surrounding environment. Raster rendering pipelines like QtQuick3D can approximately calculate reflections using different methods to get good results, as opposed to Ray Tracing where reflections can be calculated accurately by following the light rays and checking where they bounce from. In this blog post, we are going to discuss two different techniques to do reflections in QtQuick3D.

反射增强了渲染3D场景的真实感,没有它,我们就无法拥有反射周围环境的镜子或水坑之类的对象。像QtQuick3D这样的光栅渲染管道可以使用不同的方法近似计算反射以获得良好的效果,而不是光线跟踪,在光线跟踪中,可以通过跟踪光线并检查它们从何处反弹来精确计算反射。在这篇博文中,我们将讨论在QtQuick3D中进行反射的两种不同技术。

Reflection Probes

反射探针

Reflection Probe is a new QtQuick3D component introduced as a tech preview in Qt 6.3. This component uses environment mapping technique to calculate reflections. The probe is positioned somewhere in the scene where it captures the surrounding environment and saves it in a cube map. The objects can use this cube map to show reflections.

​反射探头是Qt 6.3中作为技术预览引入的一个新的QtQuick3D组件。该组件使用环境映射技术来计算反射。探测器位于场景中的某个位置,在那里它捕获周围环境并将其保存在立方体地图中。对象可以使用此立方体贴图显示反射。

The image shows a use case for that. The probe will capture the environment and the mirrors use the captured cube map to show the reflection of the car and other objects in the scene.

图中显示了一个用于此的用例。探测器将捕捉环境,镜子使用捕捉到的立方体地图显示汽车和场景中其他物体的反射。

There are couple of things to focus on here. First, the probe captures the environment from its current position so the placement of the probe in the world affects what is going to appear in the cube map.

这里有几件事需要关注。首先,探测器从其当前位置捕获环境,因此探测器在世界中的位置会影响立方体地图中将要显示的内容。

Second, for an object to show reflections it must have receivesReflections property set to true, which is a new property introduced for the Model component in Qt 6.3, and it must lie inside the probe. The probe has a property boxSize which defines the size of probe box. Any object that lies inside the probe's box can show reflections using this probe cube map. Moreover, if an object lies inside two probes at the same time, it will use the nearest probe cube map.

​其次,对于要显示反射的对象,它必须将receivesReflections属性设置为true,这是Qt 6.3中为模型组件引入的新属性,并且它必须位于探测器内部。探测器有一个属性boxSize,它定义了探测器盒的大小。位于探测器盒内的任何对象都可以使用此探测器立方体贴图显示反射。此外,如果一个对象同时位于两个探测器内,它将使用最近的探测器立方体贴图。

The Reflection Probe has three properties to control how the cube map is rendered. These properties let the user favor quality over performance and vice versa.

反射探测器有三个属性来控制立方体贴图的渲染方式。这些属性让用户更喜欢质量而不是性能,反之亦然。

  • Quality: Let the user choose the texture quality of the cube map.

  • 质量:让用户选择立方体贴图的纹理质量。

  • Refresh Mode:  Has two options, either first frame or every frame. First frame will make the probe capture the environment only once and It is suited for static environments. Every frame will make the probe capture the environment every frame. It makes reflections more realistic but it might affect the frame rate depending on the hardware.

  • 刷新模式:有两个选项,第一帧或每帧。第一帧将使探测器只捕获环境一次,它适合静态环境。每一帧都会让探测器捕捉到每一帧的环境。它使反射更加逼真,但可能会影响帧速率,具体取决于硬件。

  • Time Slicing: Let the user select how each face of the cube map is going to be rendered. For example, Individual Faces option will make the probe render a single face each frame while None option will make the probe render all the faces in a single frame

  • 时间切片:让用户选择如何渲染立方体贴图的每个面。例如,“单个面”选项将使探测器在每个帧中渲染一个面,而“无”选项将使探测器在单个帧中渲染所有面

One more thing that is worth mentioning, when the probe captures the environment in a cube map it considers everything to be infinitely far away. This works well for something like the skybox but not for nearby objects specially in an indoor area. Here is an image of the same scene showing this issue.

还有一件值得一提的事,当探测器在立方体地图中捕捉到环境时,它认为一切都是无限远的。这适用于skybox之类的东西,但不适用于附近的物体,特别是在室内区域。下面是同一场景的图片,展示了这个问题。

The reflections seem off. The car's reflection on the mirror is large and not represented in the correct size. To solve this issue, Reflection Probe has a property parallaxCorrection which corrects this issue by taking some variables into account including the boxSize. The first image in the blog is what you get when parallaxCorrection is enabled.

倒影似乎消失了。汽车在后视镜上的反射很大,大小不正确。为了解决这个问题,Reflection Probe有一个属性parallaxCorrection,它通过考虑一些变量(包括boxSize)来纠正这个问题。博客中的第一张图片是启用视差校正后得到的。

Screen Space Reflections

屏幕空间反射

Another way to calculate reflections is called Screen Space Reflections or simply SSR. It is a post processing effect technique that works on the rendered frame in screen space. A ray is emitted from the camera to each fragment and the ray can be traced and find which objects are hit. It is something like ray tracing but done in screen space. This technique is more computationally expensive than environment mapping but it has more accurate results. However, since it works in screen space  it has some drawbacks. Objects that are outside the frame or behind the camera do not appear in the reflections which is undesired effect.

另一种计算反射的方法称为屏幕空间反射或简单的SSR。这是一种后处理效果技术,适用于屏幕空间中的渲染帧。一条光线从相机发射到每个碎片,光线可以被追踪并找到被击中的物体。这有点像光线追踪,但在屏幕空间中完成。这种技术在计算上比环境映射更昂贵,但其结果更准确。然而,由于它在屏幕空间中工作,它也有一些缺点。帧外或相机后面的对象不会出现在反射中,这是不希望出现的效果。

This technique is not part of the QtQuick3D rendering pipeline but it can be implemented for a particular model using a custom material and a fragment shader. It is discussed in more detail in this example

​该技术不是QtQuick3D渲染管道的一部分,但可以使用自定义材质和片段着色器为特定模型实现。本例将更详细地讨论这一点。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值