简体   繁体   English

在iOS上的OpenGL ES 2.0中浮点纹理而不将它们钳制到[0,1]

[英]Floating point textures in OpenGL ES 2.0 on iOS without clamping them to [0, 1]

I need gl_FragColor to "paint" floating point values, which also can be negative (x < 0) and > 1.0. 我需要gl_FragColor来“绘制”浮点值,它也可以是负值(x <0)和> 1.0。 I then want to use the color attachement of the FBO this values where rendered to and use it as a texture in another FBO. 然后,我想使用FBO的颜色附件,这个值在渲染时使用,并将其用作另一个FBO中的纹理。 Now I have read on http://www.khronos.org/opengles/sdk/docs/man/ (under glTexImage2D) that all values are clamped to a range of [0, 1] and also I didn't find a glClampColor instruction. 现在我已经阅读http://www.khronos.org/opengles/sdk/docs/man/(GlTexImage2D下),所有值都被限制在[0,1]的范围内,而且我没有找到glClampColor指令。 Is there a possibility to find a workaround here or does somebody have an idea which could help me with my problem? 有没有可能在这里找到一个解决方法,或者有人有一个想法可以帮助我解决我的问题? :) :)

SOLVED 解决了

It is possible and the values are not clamped to [0, 1] at all, when using floating point textures, but it does only work using GL_HALF_FLOAT_OES as the texture's internal format. 当使用浮点纹理时,可能并且值根本不会被钳制到[0,1],但它只能使用GL_HALF_FLOAT_OES作为纹理的内部格式。 Using GL_FLOAT instead results into an incomplete framebuffer object, which is really sad, cause I was building a summed area table (SAT) and got a big precision problem here. 使用GL_FLOAT会导致一个不完整的帧缓冲对象,这真的很难过,因为我正在构建一个求和区域表(SAT)并且在这里遇到了很大的精度问题。 So in general it seems like only half precision (2 bytes, 1 sign bit + 5 exponent bits + 10 fraction) floating point numbers are supported on the iPad2. 所以一般来说,iPad2上只支持半精度(2个字节,1个符号位+ 5个指数位+ 10个分数)浮点数。

Working creation of the FBO's color attachement texture 工作创建FBO的颜色附件纹理

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_HALF_FLOAT_OES, NULL);

One more thing to mention: Instruments will report an "Invalid enum for argument 'type'" message, but it does work anyway. 还有一件事要提到:仪器将报告“无效枚举参数'类型'”消息,但无论如何它确实有效。 Also, the simulator will use full precision textures instead the specified half precision (I think cause there is no such data type in C). 此外,模拟器将使用全精度纹理而不是指定的半精度(我认为因为C中没有这样的数据类型)。 This is why u propably will get less precision problems on the simulator. 这就是为什么你可以在模拟器上获得较少的精度问题。

But the most confusing thing is that "GL_OES_texture_float" is supported when printing glGetString(GL_EXTENSIONS). 但最令人困惑的是打印glGetString(GL_EXTENSIONS)时支持“GL_OES_texture_float”。 However as mentioned before it does not work. 但是如前所述,它不起作用。

I do not believe this is true for float textures. 我不相信这对浮动纹理来说是真的。 Check the extension docs: 检查扩展文档:

http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt

It mentions: 它提到:

"The selected groups are processed as described in section 3.6.2, stopping after final expansion to RGBA. If the internal format of the texture is fixed-point, components are clamped to [0,1]. Otherwise, values are not modified." “所选组按3.6.2节所述进行处理,最终扩展到RGBA后停止。如果纹理的内部格式是固定点,则组件被限制为[0,1]。否则,不会修改值。 “

The whole thing about float textures is to support aprox [+inf,-inf] in shaders. 浮点纹理的全部内容是在着色器中支持aprox [+ inf,-inf]。 You may find more useful information here: render to floating point texture under iOS 您可以在此处找到更多有用的信息: 在iOS下渲染到浮点纹理

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

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