OpenGL ES 2.0 中元胞自动机的纹理格式
我需要一些快速建议。
我想模拟一个元胞自动机(来自 一个简单的,高效方法 用于 GPU 上的逼真云动画)。但是,我仅限于 OpenGL ES 2.0 着色器(在 WebGL 中),它不支持任何按位运算。
由于该元胞自动机中的每个单元都代表一个布尔值,因此每个单元存储 1 位是理想的选择。那么以 OpenGL 纹理格式表示这些数据的最有效方法是什么?有什么技巧或者我应该坚持使用直接的 RGBA 纹理吗?
编辑:到目前为止,这是我的想法...
目前我正在考虑使用普通的 GL_RGBA8、GL_RGBA4 或 GL_RGB5_A1:
也许我可以选择 GL_RGBA8,并尝试提取原始数据使用浮点运算的位。例如,
x*255.0
给出一个近似整数值。然而,提取各个位有点麻烦(即除以 2 并舍入几次)。另外,我对精度问题很警惕。如果我选择 GL_RGBA4,我可以为每个组件存储 1.0 或 0.0,但是我也可以尝试使用 GL_RGBA8 之前的相同技巧。在本例中,它仅为
x*15.0
。不确定它是否会更快或看不到,因为提取位的操作应该更少,但每个纹理读取的信息更少。使用 GL_RGB5_A1 我可以尝试看看是否可以将我的单元格与一些附加信息打包在一起,例如每个体素的颜色,其中 alpha 通道存储 1 位单元状态。
I need some quick advice.
I would like to simulate a cellular automata (from A Simple, Efficient Method
for Realistic Animation of Clouds) on the GPU. However, I am limited to OpenGL ES 2.0 shaders (in WebGL) which does not support any bitwise operations.
Since every cell in this cellular automata represents a boolean value, storing 1 bit per cell would have been the ideal. So what is the most efficient way of representing this data in OpenGL's texture formats? Are there any tricks or should I just stick with a straight-forward RGBA texture?
EDIT: Here's my thoughts so far...
At the moment I'm thinking of going with either plain GL_RGBA8, GL_RGBA4 or GL_RGB5_A1:
Possibly I could pick GL_RGBA8, and try to extract the original bits using floating point ops. E.g.
x*255.0
gives an approximate integer value. However, extracting the individual bits is a bit of a pain (i.e. dividing by 2 and rounding a couple times). Also I'm wary of precision problems.If I pick GL_RGBA4, I could store 1.0 or 0.0 per component, but then I could probably also try the same trick as before with GL_RGBA8. In this case, it's only
x*15.0
. Not sure if it would be faster or not seeing as there should be fewer ops to extract the bits but less information per texture read.Using GL_RGB5_A1 I could try and see if I can pack my cells together with some additional information like a color per voxel where the alpha channel stores the 1 bit cell state.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建第二个纹理并将其用作查找表。在纹理的每个 256x256 块中,您可以表示一个布尔运算,其中输入由行/列表示,输出是纹理值。实际上,在每个 RGBA 纹理中,每个 256x256 区域都可以表示四个布尔运算。不过,请注意纹理压缩和 MIP 贴图!
Create a second texture and use it as a lookup table. In each 256x256 block of the texture you can represent one boolean operation where the inputs are represented by the row/column and the output is the texture value. Actually in each RGBA texture you can represent four boolean operations per 256x256 region. Beware texture compression and MIP maps, though!