4

I'm writing a physically based shader using glsl es in three.js. For the addition of specular global illumination I use a cubemap dds texture with mipmap chain inside (precalculate with CubeMapGen as it's explained here). I need to access this texture in fragment shader and I would like to select manually the index of mipmap. The correct function for doing this is

vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod)

but it's available only in vertex shader. In my fragment shader I'm using the similar function

vec4 textureCube(samplerCube sampler, vec3 coord, float bias)

but it doesn't work well, because the bias parameter is just added to the automatically calculated level of detail. So, when I zoom in or zoom out on the scene the LOD of mipmap change, but for my shader it must be the same (it must depends only on the rough parameter, as explained in the link above).

I would like to select manually the level of mipmap in fragment shader only depends on the roughness of the material (for example using the formula mipMapIndex = roughness*numMipMap), so it must be costant with the distance and no automatically changed when zooming. How can I solve this?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Ale_32
  • 648
  • 1
  • 6
  • 16

1 Answers1

1

It wont work with webGL atm, because there is no support for this feature. You can experiment with textureLOD extensions though with recent builds of chrome canary, but it still needs some tweaking. Go about flags and look for this:

Enable WebGL Draft Extensions

WebGL textureCube bias causing seams

Community
  • 1
  • 1
pailhead
  • 5,162
  • 2
  • 25
  • 46
  • Are you talking about WebGL EXT_shader_texture_lod extension? I tried to implement it according to the instructions shows [here](http://www.khronos.org/registry/webgl/extensions/EXT_shader_texture_lod/), but the browser tell me that is not supported – Ale_32 Aug 10 '14 at 15:30
  • yes, but if you download the latest version of chrome canary and enable this extension it should work. – pailhead Aug 10 '14 at 20:11
  • I just come back from holidays and I download the latest version of chrome canary and enable the _WebGL Draft Extensions_, but unfortunately it doesn't work. The console return me that the extension is not supported. It's that possible? I also add `#extension GL_EXT_shader_texture_lod : enable` in my fragment shader. – Ale_32 Aug 28 '14 at 13:16
  • Also need to add `renderer.context.getExtension('EXT_shader_texture_lod')` – Ale_32 Sep 01 '14 at 14:21
  • ahh i forgot about that :) – pailhead Sep 03 '14 at 19:32
  • However, the WebGL EXT_shader_texture_lod extension is available in the last stable version of Chrome (37.0.2062.103). – Ale_32 Sep 04 '14 at 13:10