Lod caculation for this shader

Hi, all

i am trying debug a render error issue for this case.

this original fragment shader:

precision mediump float;
uniform float mixAmount;
uniform sampler2D inTexture;
uniform sampler2D colorCube0;
uniform sampler2D colorCube1;
varying vec2 v_texCoord;

vec4 sampleAs3DTexture(sampler2D tex, vec3 texCoord, float size) {
   float sliceSize = 1.0 / size;                         // space of 1 slice
   float slicePixelSize = sliceSize / size;              // space of 1 pixel
   float sliceInnerSize = slicePixelSize * (size - 1.0); // space of size pixels
   float zSlice0 = min(floor(texCoord.z * size), size - 1.0);
   float zSlice1 = min(zSlice0 + 1.0, size - 1.0);
   float xOffset = slicePixelSize * 0.5 + texCoord.x * sliceInnerSize;
   float s0 = xOffset + (zSlice0 * sliceSize);
   float s1 = xOffset + (zSlice1 * sliceSize);
   vec4 slice0Color = texture2D(tex, vec2(s0, texCoord.y));
   vec4 slice1Color = texture2D(tex, vec2(s1, texCoord.y));
   float zOffset = mod(texCoord.z * size, 1.0);
   #if defined(USE_NEAREST)
     return mix(slice0Color, slice1Color, step(0.5, zOffset));
   #else
     return mix(slice0Color, slice1Color, zOffset);
   #endif
}

void main() {
  vec4 originalColor = texture2D(inTexture, v_texCoord);
  vec4 color0 = sampleAs3DTexture(colorCube0, originalColor.rgb, 8.0);
  vec4 color1 = sampleAs3DTexture(colorCube1, originalColor.rgb, 8.0);
  gl_FragColor = vec4(mix(color0, color1, mixAmount).rgb, originalColor.a);
}

for the sampler colorCube0, colorCube1 the texture size is 64 x 8, and in the function sampleAs3DTexture(),
there will be some quad(2x2 pixel) which zSlice0 = a and the pixel next zSlice0 = a + 1.

so when caculate the lod for the colorCube0 and colorCube1 like below:

  float2 dx = dfdx( uv * 64);
  float2 dy = dfdy( uv * 8 );
  float d = max( dot( dx, dx ), dot( dy, dy ) );
  float lod= 0.5 * log2(d);

there will be lod which almost equal to 3 in the shader.

but on some gpu like Qualcomm adreno, the lod always zero. is there any something i missing?

[QUOTE=cristiano790;1291390]


  float2 dx = dfdx( uv * 64);
  float2 dy = dfdy( uv * 8 );

there will be lod which almost equal to 3 in the shader.

but on some gpu like Qualcomm adreno, the lod always zero. is there any something i missing?[/QUOTE]

I’m assuming dfdx() is a typo; the built-in function is dFdx() with an upper-case F. And if you’re using OpenGL ES, bear in mind that ES 2 doesn’t have derivatives as standard (they’re available via the OES_standard_derivatives extension).