Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a GLSL fragment shader, how to access to texel at a specific mipmap level?

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.

like image 365
Jim Avatar asked Sep 03 '10 11:09

Jim


People also ask

What can you do with a fragment shader?

A Fragment Shader is the Shader stage that will process a Fragment generated by the Rasterization into a set of colors and a single depth value.

How does a vertex shader pass data to a fragment shader?

A vertex shader receives its input data from a vertex attribute. But how does a fragment shader gets its data? Data is passed from shader to shader by using the in and out keywords. You create an output shader variable by using the out keyword.

How many times does fragment shader run?

Unless you have early depth testing enabled, a fragment is only discarded after you run the fragment shader. In this case, the frag shader would run once for every fragment in both quads, so 20000 times.

Is fragment shader same as pixel shader?

A fragment shader is the same as pixel shader. One main difference is that a vertex shader can manipulate the attributes of vertices. which are the corner points of your polygons. The fragment shader on the other hand takes care of how the pixels between the vertices look.


1 Answers

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?

like image 153
Stringer Avatar answered Oct 04 '22 19:10

Stringer