简体   繁体   English

在 OpenGL 纹理中使用超过四个组件

[英]Use more than four components in OpenGL texture

I know it is simply not possible to have more than the four built-in texture components.我知道不可能拥有超过四个内置纹理组件。 At least directly.至少直接。 Generally, the proposed solution is simple - use multiple textures.通常,建议的解决方案很简单——使用多个纹理。 However, I think that it is not optimal.但是,我认为这不是最优的。 Let's look at an example.让我们看一个例子。

Let's say there is a basic material format that has the following properties:假设有一个具有以下属性的基本材质格式:

  1. albedo - 3 components反照率 - 3 个组件
  2. normal - 3 components正常 - 3 个组件
  3. roughness - 1 component粗糙度 - 1 个分量
  4. metallness - 1 component金属度 - 1 个组件

The simplest way to store this data would be to use 4 diffrent textures with respectively 3, 3, 1, and 1 components.存储此数据的最简单方法是使用 4 个不同的纹理,分别具有 3、3、1 和 1 个分量。 This is inefficient for at least two reasons:这是低效的,至少有两个原因:

  1. Most probably the GPU does not actually store the first two textures with only 3 components, but with four, as most GPUs align 3 component vectors, matrices, textures to four components.很可能 GPU 实际上并没有存储只有 3 个分量的前两个纹理,而是存储了 4 个分量,因为大多数 GPU 将 3 个分量向量、矩阵、纹理与四个分量对齐。
  2. Getting all the data in the shader requires 4 texture samples获取着色器中的所有数据需要 4 个纹理样本

The common way to deal with this would be to pack the data in the least amount if textures possible that also nicely align.处理这个问题的常用方法是尽可能少地打包数据,如果纹理也可以很好地对齐。 In this case it could be put in two textures with 4 components each.在这种情况下,它可以放入两个纹理中,每个纹理有 4 个组件。 This solves the first issue of wasted memory, but the second one still exists as it is still required to do 2 texture samples to read the data.这解决了第一个浪费 memory 的问题,但第二个问题仍然存在,因为仍然需要执行 2 个纹理样本来读取数据。 2 samples is not really a lot, but what if it could be reduced to just one? 2 个样本并不是很多,但如果可以减少到只有一个呢?

My idea is to pack all 6 components in one texture.我的想法是将所有 6 个组件打包在一个纹理中。 How?如何? GL_RGB16_SNORM . GL_RGB16_SNORM It is a texture internal format that albeit having only 3 components, could actually fit 6 because each pixel is 6 bytes.这是一种纹理内部格式,虽然只有 3 个组件,但实际上可以容纳 6 个,因为每个像素是 6 个字节。

So my question is:所以我的问题是:

  1. Would it be possible to upload the data as 6 components to such a texture and somehow read it in the shader.是否可以将数据作为 6 个组件上传到这样的纹理并以某种方式在着色器中读取它。
  2. Would it be faster to use this packing or just stick to using two separate textures.使用这种包装会更快还是坚持使用两个单独的纹理。
  3. Is there a different, better approach to this?有没有不同的,更好的方法呢?

Use an array texture & sample at the same (u,v) location in the other layers to retrieve your extra texture channel data.在其他层的相同 (u,v) 位置使用阵列纹理和样本来检索额外的纹理通道数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM