accessing a specific mip level in OpenGL ES 2.0

edited June 2014 in How To...

Hi!

I want to do environment mapping with selecting a specific mip level of a cube map in the sahder according to the roughness parameter of the material (per pixel). Since I target GL ES 2.0 (specifically webgl), I cannot use textureCubeLod (which is available on desktop GL and is working as expected), the only thing I can try is the bias parameter. In the cube map I store the mip level in the alpha channel in watchlive.us To the End. So first I do a lookup to find out for which mip level the hardware selecting, then do the bias in a second read. However I cannot select the specific mip level this way. To do some debugging, I put a specific color into each cube face mip level, like the entire 0. level for all faces is red, the 1. level is blue etc. With the following sample code, I wanted to access the 3rd mip level, but unfortunately it doesn't work:

Code :

float targetLevel = 3.0;
vec4 color = textureCube(envmap, tc);
float level = color.a * 255.0;
float bias = targetLevel - level;
gl_FragColor = textureCube(envmap, tc, bias);

The result is a gradient transition across multiple mip levels, and also it's changing for minification/magnification. If I put the read level into gl_FragColor, it's ok. So I guess the bias is not working this way.

Any help is appreciated. Thanks!

Tagged:
Sign In or Register to comment.