问题描述
我需要gl_FragColor来绘制浮点值,它也可以是负值(x 1.0。然后,我想使用FBO的颜色附件,这个值在渲染时使用,并将其用作另一个FBO中的纹理。现在我已阅读(在glTexImage2D下)所有值都被限制在[0,1]的范围内,而且我没有找到glClampColor指令。有没有可能在这里找到一个解决方法,或者有人有一个想法可以帮助我解决我的问题? :)
I need gl_FragColor to "paint" floating point values, which also can be negative (x < 0) and > 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. 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. Is there a possibility to find a workaround here or does somebody have an idea which could help me with my problem? :)
已解决
有可能并且值不会被限制为[0,1],当使用浮点纹理时,它只能使用GL_HALF_FLOAT_OES作为纹理的内部格式。使用GL_FLOAT会导致一个不完整的帧缓冲对象,这真的很难过,因为我正在构建一个求和区域表(SAT)并且在这里遇到了很大的精度问题。所以一般来说,iPad2上只支持半精度(2个字节,1个符号位+ 5个指数位+10个分数)浮点数。
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. 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. 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.
工作创建FBO的颜色附件纹理
Working creation of the FBO's color attachement texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_HALF_FLOAT_OES, NULL);
还有一件事需要提及:乐器将报告参数无效枚举'类型'消息,但无论如何它确实有效。此外,模拟器将使用全精度纹理而不是指定的半精度(我认为因为C中没有这样的数据类型)。这就是为什么你可以在模拟器上获得较少的精度问题。
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). This is why u propably will get less precision problems on the simulator.
但最令人困惑的是打印glGetString(GL_EXTENSIONS)时支持GL_OES_texture_float。但是如前所述,它不起作用。
But the most confusing thing is that "GL_OES_texture_float" is supported when printing glGetString(GL_EXTENSIONS). However as mentioned before it does not work.
推荐答案
我不相信这对浮动纹理来说是正确的。检查扩展文档:
I do not believe this is true for float textures. Check the extension docs:
提及:
按照第3.6.2节的描述处理选定的组,在最终扩展到RGBA后停止
。如果纹理的内部格式是
固定 - 点,组件被钳制到[0,1]。否则,值不是
修改。
"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."
这篇关于在iOS上的OpenGL ES 2.0中浮点纹理而不将它们钳制到[0,1]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!