在GLSL片段着色器中,如何访问特定mipmap级别的texel?
我正在使用 OpenGL 通过一个顶点着色器和一个片段着色器的组合来执行一些 GPGPU 计算。我需要对不同比例的图像进行计算。我想使用 mipmap,因为它们的生成可以自动且硬件加速。但是我无法设法访问片段着色器中的 mipmap 纹理。
我启用了自动 mipmap 生成: glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
我尝试在着色器中使用texture2DLod,但没有成功,它只是继续提供正常的纹理。我还尝试在主程序中使用 glTextureParameteri(GL_BASE_LEVEL, X) 并且它没有改变任何东西。
你会怎么做?
我正在使用Linux。我的显卡是 Nvidia Quadro,相当旧了。 这里是我的 glxinfo 输出以及所有支持的扩展。
I am using OpenGL to do some GPGPU computations through the combination of one vertex shader and one fragment shader. I need to do computations on a image at different scale. I would like to use mipmaps since their generation can be automatic and hardware accelerated. However I can't manage to get access to the mipmap textures in the fragment shader.
I enabled automatic mipmap generation:
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
I tried using texture2DLod in the shader with no luck, it simply kept giving the normal texture. I also tried using glTextureParameteri(GL_BASE_LEVEL, X) in the main program and it did not change anything.
How would you do that?
I am using Linux. My graphic card is a Nvidia Quadro quite old. Here is my glxinfo output with all the supported extensions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试过其中之一吗?另外,lod 必须是浮点类型。 GLSL 编译器报告什么错误/警告?
Did you try one of those built-in? Also
lod
has to be a float type. What errors/warning is reporting GLSL compiler?GLSL 1.20 规范(第 8.7 节)规定片段着色器无法选择自己的 mipmap 级别(并且texture*Lod 函数仅在顶点着色器中可用)。如果有的话,您也许可以使用非 Lod 变体的偏差参数来更改 mipmap 级别,但它只能相对于卡已为您计算的值进行更改。
我不知道 GLSL 的最新版本是否会改变这一点。
The GLSL 1.20 specification (section 8.7) states that fragment shaders cannot choose their own mipmap level (and that the texture*Lod function are only available in vertex shaders). If anything, you may be able to use the bias parameter to the non-Lod variants to change the mipmap level, but it can only change it relative to what that the card has already calculated for you.
I don't know if latter versions of GLSL may have changed that.
尝试:
在绑定纹理之后。 (当然,在进行渲染之前)
我认为
glTexParameteri-GL_GENERATE_MIPMAP
已被弃用......制造商数码
try:
after you bind the texture. (And before doing the rendering of course)
The
glTexParameteri-GL_GENERATE_MIPMAP
is deprecated I think...MfG Digi