使用VTK引入基于物理的渲染

原文地址:https://blog.kitware.com/vtk-pbr/

Introducing Physically Based Rendering with VTK
在这里插入图片描述

Introduction 介绍

Until VTK 8.2, surface shading through the vtkPolyDataMapper is computed using the Phong reflectance model. While it achieves plausible results, it requires the user to specify the parameters to define materials and that he should be familiar with: the ambient color (RGB), the diffuse color (RGB), the specular color (RGB), and the specular power (positive floating value).

在VTK 8.2之前,通过vtkPolyDataMapper的表面阴影是使用Phong反射率模型计算的。虽然它取得了似是而非的结果,但它要求用户指定定义材质的参数,并且用户应该熟悉这些参数:环境色(RGB)、漫反射色(RGB)、高光色(RGB)和高光功率(正值浮动值)。

There are several drawbacks to this model though. The parameters are not physically based, difficult to define, and they are only heuristics that can lead to non-plausible materials if not carefully set. Moreover, this model does not ensure light energy conservation (the object can emit more light than it has received). Finally, changing the environment does not affect the model shading and requires that the parameters be tuned accordingly.

不过,这种模式有几个缺点。这些参数没有物理基础,很难定义,如果不仔细设置,它们只是启发,可能导致不合理的材料。此外,这个模型并不能确保光的能量守恒(对象可以发出比它所接收到的更多的光)。最后,改变环境不会影响模型的着色,并且需要相应地调整参数。

Starting from VTK 9.0 (and already available on the master branch), an alternative reflectance model, based on the microfacet theory – commonly called Physically Based Rendering (PBR) – is added to the vtkPolyDataMapper. This new model is physically based (thus enforcing light energy conservation), the parameters are simpler, more intuitive, and are environment agnostic. The diffuse and specular parts are not explicitly set by the user but internally computed based on those parameters. This ensures that those parts, which are mutually exclusive, correspond to the input light energy. All of these details make surface rendering a lot more realistic! This article will describe in-depth how to use and parameterize this new model.

从VTK 9.0开始(在主分支上已经可用),基于微面理论的另一种反射模型—通常称为基于物理的呈现(PBR)—被添加到vtkPolyDataMapper中。这个新模型是基于物理的(从而实现了光的能量守恒),参数更简单,更直观,并且是环境不可知的。漫反射和高光部分不是由用户显式设置的,而是根据这些参数进行内部计算。这就保证了那些互相排斥的部分,对应于输入的光能。所有这些细节使表面渲染更加真实!本文将深入描述如何使用和参数化这个新模型。

Parameters 参数

In order to enable this new shading model on a specific actor in the scene, you just have to change its interpolation/shading model by callingvtkProperty::SetInterpolationToPBR(). Then, all the required parameters of this model are listed below:

为了在场景中的一个特定的角色上启用这个新的材质模型,你只需要通过调用vtkproperty:: setationtopbr()来改变它的插值/材质模型。然后,该模型所需的所有参数如下:

  • Base Color (RGB): also called albedo, this is the perceived color of the object, the diffuse color for non-metallic objects or the specular color for metallic objects. This is set using the usual vtkProperty::SetColor().
  • 基色(RGB):也叫反照率,是物体感知到的颜色,非金属物体的漫反射色或金属物体的高光色。这是使用通常的vtkProperty::SetColor()设置的。
  • Metallic (float): in the real world, common objects are either metallic or non-metallic (called dielectric) and the shading computation is different depending on this parameter. For most materials, the value is either 0.0 or 1.0 but any value in between is valid. This is set using vtkProperty::SetMetallic(value).
  • metal (float):在现实世界中,常见的对象要么是金属的,要么是非金属的(称为电介质),根据这个参数,阴影计算是不同的。对于大多数资料,该值是0.0或1.0,但介于两者之间的任何值都是有效的。这是使用vtkProperty:: setmetal(值)设置的。
  • Roughness (float): parameter used to specify how an object is glossy. This is set using vtkProperty::SetRoughness(value)
  • 粗糙度(float):用于指定对象光泽的参数。这是使用vtkProperty::SetRoughness(值)设置的
    在这里插入图片描述
    As you can see in Figure 2, configuring a material is by far easier and more intuitive with this new model. Note how the Fresnel effect is visible at grazing angles, this effect is not visible with the classic shading model. More importantly, glossy materials (low roughness value) are reflecting the environment with a technique called Image-Based Lighting that is supported by the PBR shading model.

正如您在图2中所看到的,使用这个新模型配置素材要简单得多,也更直观得多。请注意菲涅耳效应是如何可见的掠角,这种效果是不可见的经典遮阳模型。更重要的是,光滑材料(低粗糙度值)通过一种称为基于图像的照明技术来反映环境,这种技术得到了PBR材质模型的支持。

It is also interesting to understand what is the difference between metals and non-metals. Metals have no diffuse part and a chromatic specular contribution, while non-metals have a diffuse color and an achromatic specular part. The two spheres in Figure 3 have the same base color and the same roughness.

理解金属和非金属之间的区别也很有趣。金属没有漫反射部分和彩色高光部分,而非金属有漫反射颜色和无色高光部分。图3中的两个球体具有相同的底色和相同的粗糙度。
在这里插入图片描述

Image-Based Lighting 基于图像的照明

In order to bring realism a step further, we have implemented Image-Based Lighting that allows the user to specify the environment with a cubemap texture. A cubemap texture is a texture consisting of 6 seamless images for the 6 different directions of the 3D space. Please, refer to vtkTexture::CubeMapOn() documentation to know how to create a cubemap. Note that it is important that this cubemap is in linear color space. Figure 4 illustrates the expected order of the vtkTexture input connections.

为了让真实感更进一步,我们实现了基于图像的照明,允许用户使用cubemap纹理来指定环境。cubemap纹理是指在三维空间的6个不同方向上由6张无缝图像组成的纹理。请参考vtkTexture::CubeMapOn()文档以了解如何创建cubemap。注意,cubemap在线性颜色空间中是很重要的。图4演示了vtkTexture输入连接的预期顺序。
在这里插入图片描述
The feature is easily enabled calling the method vtkRenderer::UseImageBasedLightingOn() and setting the previously created cubemap with vtkRenderer::SetEnvironmentCubeMap().

调用方法vtkRenderer::UseImageBasedLightingOn()并使用vtkRenderer::SetEnvironmentCubeMap()设置先前创建的cubemap是很容易的。

When using this feature, a quick precomputation is done by the rendering engine that allows the object to take into account the environment when computing the diffuse and the specular parts. Glossy objects will then display nice reflections of this environment.

当使用这个特性时,渲染引擎会做一个快速的预计算,允许对象在计算漫反射和高光部分时考虑环境。光滑的物体将会显示出这种环境的良好反射。

A new tool has also be introduced to facilitate the creation of the cubemap if you have a standard projected equirectangular environment texture. Please refer to vtkEquirectangularToCubeMapTexture.

如果您有一个标准的投影等矩形环境纹理,那么还引入了一个新工具来方便创建cubemap。请参考vtkEquirectangularToCubeMapTexture。

Parameters mapping 参数映射

Applying a color texture was already possible with the classic shading model. Of course, the texture coordinates are mandatory in the vtkPolyData point attributes. The PBR model adds the ability to map a material property texture called ORM texture where the 3 RGB channels of the image are respectively the Occlusion factor, the Roughness factor, and the Metalness factor. This texture format is widely adopted in digital creation contents and is supported by the recently added VTK glTF reader.

在经典的阴影模型中应用颜色纹理已经成为可能。当然,纹理坐标在vtkPolyData点属性中是必需的。PBR模型增加了映射一种称为ORM纹理的材质属性纹理的能力,其中图像的3个RGB通道分别是遮挡因子、粗糙度因子和金属度因子。这种纹理格式在数字创作内容中被广泛采用,并得到最近添加的VTK glTF阅读器的支持。

While we have already mentioned the roughness and metalness parameters, a new property (the occlusion) is supported when using an ORM texture. This factor darkens some parts of the model, simulating a cheap ambient occlusion, greatly improving 3D perception as depicted in Figure 5.

虽然我们已经提到了粗糙度和金属度参数,但在使用ORM纹理时支持一个新的属性(遮挡)。这个因素使模型的某些部分变暗,模拟了一个廉价的环境遮挡,极大地改善了如图5所示的3D感知。
在这里插入图片描述
Another optional texture, the emissive texture, is also supported by this new shading model in order to simulate an emissive object (car lights for example). This texture is an RGB texture in order to specify the emissive color, and a factor can be set to set the power of the light emission.

另一个可选的纹理,即发射纹理,也被这个新的材质模型所支持,以模拟一个发射对象(例如汽车灯光)。这个纹理是RGB纹理,为了指定发射颜色,可以设置一个因子来设置光发射的功率。

Normal mapping 法线贴图

On top of this, we have added the normal mapping technique, valid for both shading models. If a normal texture is added to the property of the actor and the model contains normals, texture coordinates, and tangents, the feature is enabled and small details appear on the model even if it has a low polys count as you can see in Figure 6**.**

在此基础上,我们添加了法线映射技术,这对两个阴影模型都有效。如果一个法线纹理被添加到角色的属性中,并且模型包含法线、纹理坐标和切线,那么这个特性就会被启用,即使模型的多边形数很低,小细节也会出现在模型中,如图6所示。
在这里插入图片描述
The tangents can be computed if you have only texture coordinates and normals using a new filter called vtkPolyDataTangents.

如果你只有纹理坐标和法线,可以使用一个叫做vtkPolyDataTangents的新过滤器来计算切线。

Example 例子

It is now easy to import modern digital content into VTK. With all the features enabled (do not underrate the benefits of the Image-Based Lighting!), the rendering is now a lot more realistic at almost no additional computational cost. Whether the digital content is the center of interest or only the context around your scientific visualization, give it a try! Here is a simple C++ example showcasing all new methods and how simple it is.

现在很容易将现代数字内容导入VTK。启用了所有特性(不要低估基于图像的照明的好处!),现在的渲染更加真实,几乎不需要额外的计算成本。不管数字内容是你感兴趣的中心,还是仅仅是你科学可视化的背景,试一试吧!下面是一个简单的c++示例,展示了所有的新方法及其简单程度。

vtkActor* actor; // the actor
vtkTexture* cubemap; // texture containing the cubemap
vtkRenderer* renderer; // the renderer
 
// ... usual object creation and initialization is hidden here
 
renderer->UseImageBasedLightingOn();
renderer->SetEnvironmentCubeMap(cubemap);
actor->GetProperty()->SetInterpolationToPBR();
 
// configure the basic properties
actor->GetProperty()->SetColor(r, g, b);
actor->GetProperty()->SetMetallic(metallicCoefficient);
actor->GetProperty()->SetRoughness(roughnessCoefficient);
 
// configure textures (needs tcoords on the mesh)
actor->GetProperty()->SetBaseColorTexture(colorTexture);
 
actor->GetProperty()->SetORMTexture(ormTexture);
actor->GetProperty()->SetOcclusionStrength(occlusionStrength);
 
actor->GetProperty()->SetEmissiveTexture(emissiveTexture);
actor->GetProperty()->SetEmissiveFactor(emissiveFactor);
 
// needs tcoords, normals and tangents on the mesh
actor->GetProperty()->SetNormalTexture(normalTexture);
actor->GetProperty()->SetNormalScale(normalScale);
Future work 未来的工作

While this is a major step toward realistic rendering, there is still room for improvement. Here are a few advanced techniques that are not implemented yet and that we have in mind:

虽然这是向真实渲染迈出的重要一步,但仍有改进的空间。以下是一些尚未实现的高级技术,我们已经考虑到:

  • PBR Clear Coat support;–PBR透明涂层支架;
  • PBR Anisotropy;–PBR各向异性;
  • Screen Space Reflection (SSR);–屏幕空间反射(SSR);
  • Subsurface scattering (SSS);–地下散射(SSS);
  • Parallax mapping;–视差贴图;
  • Emissive bloom;–发射开花;
  • HDR Environment maps–HDR环境地图

All the PBR features presented in this article are already available in VTK master and will be available in the upcoming VTK 9.0 release. Moreover, the integration of this technology has already been done in ParaView and another blog article will be dedicated to it.

本文中提供的所有PBR特性都已经可以在VTK master中使用,并将在即将发布的VTK 9.0版本中提供。此外,此技术的集成已经在ParaView中完成,另一篇博客文章将致力于此。

Acknowledgments 致谢

This work is part of the innovative effort of the SciViz team from Kitware SAS (France) and was partly funded by the VESTEC project.

这项工作是来自Kitware SAS(法国)的SciViz团队创新工作的一部分,部分资金来自VESTEC项目。
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
VTK(Visualization Toolkit)是一个开源的跨平台的图形处理工具包。它提供了丰富的数据结构和算法,可以用于可视化和图形处理。在VTK使用CUDA加速处理渲染,可以提高渲染的速度。 以下是使用CUDA加速处理渲染的步骤: 1. 安装CUDA工具包。在使用CUDA加速处理渲染之前,必须先安装CUDA工具包。CUDA工具包可以从NVIDIA官方网站下载。下载完成后,按照安装向导进行安装。 2. 配置VTK。在使用CUDA加速处理渲染之前,必须先配置VTK。在CMake中,设置VTK_USE_CUDA选项为ON,然后重新生成项目。 3. 使用VTK的CUDA加速渲染。在使用CUDA加速处理渲染时,可以使用VTKvtkCudaVolumeRayCastMapper或vtkCudaVolumeMapper类。这些类可以将体数据转换为CUDA格式,并使用CUDA内核进行渲染。 下面是一个简单的VTK CUDA加速渲染的例子: ``` #include <vtkSmartPointer.h> #include <vtkVolume.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkCudaVolumeRayCastMapper.h> #include <vtkImplicitModeller.h> int main(int argc, char *argv[]) { vtkSmartPointer<vtkImplicitModeller> modeller = vtkSmartPointer<vtkImplicitModeller>::New(); modeller->SetSampleDimensions(128, 128, 128); modeller->SetOrigin(-1, -1, -1); modeller->SetSpacing(0.02, 0.02, 0.02); modeller->SetMaximumDistance(0.1); modeller->SetModelBounds(-1, 1, -1, 1, -1, 1); modeller->ComputeNormalsOff(); modeller->SetOutputScalarTypeToFloat(); vtkSmartPointer<vtkCudaVolumeRayCastMapper> mapper = vtkSmartPointer<vtkCudaVolumeRayCastMapper>::New(); mapper->SetInputConnection(modeller->GetOutputPort()); mapper->SetBlendModeToComposite(); mapper->SetMaximumImageSampleDistance(0.01); mapper->SetAutoAdjustSampleDistances(0); mapper->SetUseJittering(1); mapper->SetImageSampleDistance(0.005); mapper->SetMinimumImageSampleDistance(0.001); mapper->SetMaximumImageSampleDistance(0.01); mapper->SetSampleDistanceAdjustmentFactor(1.0); mapper->SetMaximumNumberOfRaySamples(1000); mapper->SetImageSampleDistance(0.005); vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New(); volume->SetMapper(mapper); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); renderer->AddVolume(volume); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); interactor->SetRenderWindow(renderWindow); renderWindow->Render(); interactor->Start(); return 0; } ``` 在这个例子中,我们使用vtkImplicitModeller来创建一个体数据,然后使用vtkCudaVolumeRayCastMapper类将它渲染出来。在vtkCudaVolumeRayCastMapper类中,我们设置了一些渲染参数,例如采样距离、最大采样数等等。最后,我们将渲染结果添加到vtkRenderer中,并将vtkRenderWindow显示出来。 需要注意的是,使用CUDA加速处理渲染需要显卡支持CUDA技术,否则无法加速处理。同时,CUDA加速渲染并不一定能够提高渲染速度,它的效果取决于数据的复杂度和显卡性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力减肥的小胖子5

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值