texture2d in glsl issue

  • Follow


I am trying to manually choose the mipmap for a texture in my fragment
shader

My fragment shader code is this:

uniform sampler2D tex0;
uniform float mipmap_level;

void main(){
	gl_FragColor = texture2D(tex0,vec2(gl_TexCoord[0].st), mipmap_level);
}

I specify the value for "mipmap_level" thru glUniform but opengl always
uses the 0th mipmap. I have checked the value in mipmap_level by using
glGetUniform. It is the same as the one i had passed still the level 0
mipmap is used
Iam using GL_NEAREST for both my mag and min filter

0
Reply shirsoft (12) 7/26/2005 7:34:45 PM

shirsoft@gmail.com wrote:
> I am trying to manually choose the mipmap for a texture in my fragment
> shader
>
> My fragment shader code is this:
>
> uniform sampler2D tex0;
> uniform float mipmap_level;
>
> void main(){
> 	gl_FragColor = texture2D(tex0,vec2(gl_TexCoord[0].st), mipmap_level);
> }
>
> I specify the value for "mipmap_level" thru glUniform but opengl always
> uses the 0th mipmap. I have checked the value in mipmap_level by using
> glGetUniform. It is the same as the one i had passed still the level 0
> mipmap is used
> Iam using GL_NEAREST for both my mag and min filter

It seems that the problem is that you aren't using mip-mapping in the
first place. Assuming this is the problem, the solution is very simple.

GL_NEAREST means that when a pixel covers more or fewer than one texel,
OpenGL selects the texel that it is closest* to to use. So there's no
mip-mapping here.

So I suspect, that if you use GL_NEAREST_MIPMAP_NEAREST (or some
variation
on that, provided that it uses mip-mapping), and of course also provide
mipmaps to OpenGL -- a function gluBuild2DMipmaps -- can do this, then
things should start working in the shader.

I hope that I'm not barking up the wrong tree and that this helps.

Nicholas

p.s.*Although it isn't really relevant, above closest is defined in
terms of the so-called Manhattan distance. Which, between two (2d)
points, is the sum in of the absolute values of the differences in the
two points coordinates)

0
Reply Nicholas 7/28/2005 11:15:03 AM


1 Replies
233 Views

(page loaded in 0.022 seconds)

Similiar Articles:







7/22/2012 6:57:46 AM


Reply: