简体   繁体   English

究竟什么是浮点纹理?

[英]What exactly is a floating point texture?

I tried reading the OpenGL ARB_texture_float spec, but I still cannot get it in my head..我尝试阅读 OpenGL ARB_texture_float 规范,但我仍然无法理解它。

And how is floating point data related to just normal 8-bit per channel RGBA or RGB data from an image that I am loading into a texture?浮点数据如何与我加载到纹理中的图像中的普通 8 位每通道 RGBA 或 RGB 数据相关?

Here is a read a little bit here about it.这里是一个读一点点在这里了。

Basically floating point texture is a texture in which data is of floating point type :) That is it is not clamped.基本上浮点纹理是一种纹理,其中数据是浮点类型:) 也就是说它没有被限制。 So if you have 3.14f in your texture you will read the same value in the shader.因此,如果您的纹理中有 3.14f,您将在着色器中读取相同的值。

You may create them with different numbers of channels.您可以使用不同数量的频道创建它们。 Also you may crate 16 or 32 bit textures depending on the format.您也可以根据格式创建 16 位或 32 位纹理。 eg例如

// create 32bit 4 component texture, each component has type float    
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 16, 0, GL_RGBA, GL_FLOAT, data);

where data could be like this:数据可能是这样的:

float data[16][16];
for(int i=0;i<16*16;++i) data[i] = sin(i*M_PI/180.0f); // whatever

then in shader you can get exactly same (if you use FLOAT32 texture) value.然后在着色器中您可以获得完全相同的(如果您使用 FLOAT32 纹理)值。

eg例如

uniform sampler2D myFloatTex;
float value = texture2D(myFloatTex, texcoord.xy);

If you were using 16bit format, say GL_RGBA16F, then whenever you read in shader you will have a convertion.如果您使用的是 16 位格式,比如 GL_RGBA16F,那么无论何时您在着色器中读取,您都会进行转换。 So, to avoid this you may use half4 type: half4 value = texture2D(my16BitTex, texcoord.xy);因此,为了避免这种情况,您可以使用 half4 类型:half4 value = texture2D(my16BitTex, texcoord.xy);

So, basically, difference between the normalized 8bit and floating point texture is that in the first case your values will be brought to [0..1] range and clamped, whereas in latter you will receive your values as is ( except for 16<->32 conversion, see my example above).因此,基本上,归一化 8 位纹理和浮点纹理之间的区别在于,在第一种情况下,您的值将被带到 [0..1] 范围内并被限制,而在后者中,您将按原样接收您的值(除了 16< ->32 转换,见我上面的例子)。

Not that you'd probably want to use them with FBO as a render target, in this case you need to know that not all of the formats may be attached as a render target.并不是说您可能希望将它们与 FBO 一起用作渲染目标,在这种情况下,您需要知道并非所有格式都可以附加为渲染目标。 Eg you cannot attach Luminance and intensity formats.例如,您不能附加亮度和强度格式。

Also not all hardware supports filtering of floating point textures, so you need to check it first for your case if you need it.此外,并非所有硬件都支持过滤浮点纹理,因此如果需要,您需要先针对您的情况进行检查。

Hope this helps.希望这可以帮助。

FP textures have a special designated range of internal formats (RGBA_16F,RGBA_32F,etc). FP 纹理具有特殊指定的内部格式范围(RGBA_16F、RGBA_32F 等)。 Regular textures store fixed-point data, so reading from them gives you [0,1] range values.常规纹理存储定点数据,因此从它们中读取会为您提供 [0,1] 范围值。 Contrary, FP textures give you [-inf,+inf] range as a result (not necessarily with a higher precision).相反,FP 纹理会为您提供 [-inf,+inf] 范围(不一定具有更高的精度)。

In many cases (like HDR rendering) you can easily proceed without FP textures, just by transforming the values to fit in [0,1] range.在许多情况下(如 HDR 渲染),您可以在没有 FP 纹理的情况下轻松进行,只需将值转换为适合 [0,1] 范围。 But there are cases like deferred rendering when you may want to store, for example, world-space coordinate without caring about their range.但是在某些情况下,例如您可能想要存储世界空间坐标而不关心它们的范围时,会出现延迟渲染之类的情况。

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

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