OpenGL ES 2.0 中的高效随机纹理采样
有没有有效的方法以随机方式获取纹理数据?也就是说,我想使用纹理作为查找表,并且需要随机访问其元素。因此我会以随机的方式对其进行采样。这是完全失败的原因吗?
Is there any efficient way to fetch texture data in a random way? That is, I'd like to use a texture as a look-up table and I need random access to its elements. Therefore I'd be sampling it in a random fashion. Is it a completely lost cause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
随机访问是GLSL的一个基本特性。例如
,根据您的硬件,如果您直接在像素着色器中计算样本位置而不是在顶点着色器中计算样本位置并允许它们作为变化自动插值,则读取纹理可能会花费更多,但这只是一个不可变的与您正在做的事情的可预测性降低相关的硬件成本。
Random access is a basic feature of GLSL. E.g.
Depending on your hardware, it may cost more to read a texture if you've calculated the sample locations directly in the pixel shader rather than out in the vertex shader and allowed them to be interpolated automatically as a varying, but that's just an immutable hardware cost relating to the decreased predictability of what you're doing.
您始终可以将另一个纹理传递给包含随机值和样本的着色器。这将为每个纹理坐标提供相同的随机值,但如果您不希望这样,则可以随时将坐标乘以更新每帧的统一种子。
You could always pass another texture to the shader containing random values and sample from that. That will give you the same random value for each texture coordinate but if you dont want that you can always multiply the coordinate by a uniform seed that you updated each frame.