在GLSL片段着色器中,如何访问特定mipmap级别的texel?

发布于 2024-09-17 08:51:55 字数 488 浏览 11 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紅太極 2024-09-24 08:51:55
gvec4 textureLod (gsampler1D sampler, float P, float lod)
gvec4 textureLod (gsampler2D sampler, vec2 P, float lod)
gvec4 textureLod (gsampler3D sampler, vec3 P, float lod)
gvec4 textureLod (gsamplerCube sampler, vec3 P, float lod)
float textureLod (sampler1DShadow sampler, vec3 P, float lod)
float textureLod (sampler2DShadow sampler, vec3 P, float lod)
gvec4 textureLod (gsampler1DArray sampler, vec2 P, float lod)
gvec4 textureLod (gsampler2DArray sampler, vec3 P, float lod)
float textureLod (sampler1DArrayShadow sampler, vec3 P, float lod)

您尝试过其中之一吗?另外,lod 必须是浮点类型。 GLSL 编译器报告什么错误/警告?

gvec4 textureLod (gsampler1D sampler, float P, float lod)
gvec4 textureLod (gsampler2D sampler, vec2 P, float lod)
gvec4 textureLod (gsampler3D sampler, vec3 P, float lod)
gvec4 textureLod (gsamplerCube sampler, vec3 P, float lod)
float textureLod (sampler1DShadow sampler, vec3 P, float lod)
float textureLod (sampler2DShadow sampler, vec3 P, float lod)
gvec4 textureLod (gsampler1DArray sampler, vec2 P, float lod)
gvec4 textureLod (gsampler2DArray sampler, vec3 P, float lod)
float textureLod (sampler1DArrayShadow sampler, vec3 P, float lod)

Did you try one of those built-in? Also lod has to be a float type. What errors/warning is reporting GLSL compiler?

眼藏柔 2024-09-24 08:51:55

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.

所谓喜欢 2024-09-24 08:51:55

尝试:

glGenerateMipmapEXT(GL_TEXTURE_2D);

在绑定纹理之后。 (当然,在进行渲染之前)

我认为 glTexParameteri-GL_GENERATE_MIPMAP 已被弃用......
制造商数码

try:

glGenerateMipmapEXT(GL_TEXTURE_2D);

after you bind the texture. (And before doing the rendering of course)

The glTexParameteri-GL_GENERATE_MIPMAP is deprecated I think...
MfG Digi

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文