简体   繁体   English

GLSL-对3D纹理进行采样

[英]GLSL - Sample an volume of 3d texture

I'm recently working with 3d textures in OpenGL. 我最近正在OpenGL中使用3d纹理。 I realized that when you are working with 3d textures, you have to use texture3d() A LOT. 我意识到,当您使用3d纹理时,必须大量使用texture3d()。 Which is pretty much a gpu killer. 这几乎是一个gpu杀手。 Is there any function in glsl that allows me to sample an VOLUME of 3d texture? glsl中是否有任何功能可以让我采样3D纹理的体积? So, instead of calling texture3D() 32768 times, I can do something like this: 因此,我可以执行以下操作,而不是调用texture3D()32768次:

texture3DVolume(3dtexture, vec3(0.5, 0.5, 0.5), vec3(0.2, 0.2, 0.2));

Which samples at 0.5 0.5 0.5, an volume of 0.2 0.2 0.2. 其中样品为0.5 0.5 0.5,体积为0.2 0.2 0.2。

No : this would involve, as you noticed it yourself, sampling all the volume. 否:正如您自己注意到的那样,这涉及对所有音量进行采样。

In 2D you can use Summed Area Tables. 在2D模式下,您可以使用汇总面积表。 It enables you to compute the sum of all the values of a matrix inside a "box" with only 4 samples; 它使您能够仅用4个样本来计算“框”内矩阵的所有值的总和。 I guess the concept extends to 3D easily. 我想这个概念很容易扩展到3D。

Note that you will have a pretty expensive preprocessing step; 请注意,您将有一个非常昂贵的预处理步骤。 and you can only have the mean and the sum, no other fancy stuff like geometric mean or median. 而且您只能拥有均值和总和,没有其他奇特的东西,例如几何均值或中位数。

Here are some explanations from AMD on a different use-case : http://developer.amd.com/media/gpu_assets/GDC2005_SATEnvironmentReflections.pdf 这是AMD针对不同用例的一些解释: http : //developer.amd.com/media/gpu_assets/GDC2005_SATEnvironmentReflections.pdf

I guess you could also use mipmaps : to sample a 2x2x2 volume, sample the 1rst mipmap... but this won't work out of the box for arbitrary sample locations. 我猜您也可以使用mipmaps:对2x2x2体积进行采样,对第一个rip mipmap进行采样...但是,对于任意的采样位置,这将无法立即使用。

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

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