 // https://developer.nvidia.com/gpugems/gpugems3/part-iii-rendering/chapter-20-gpu-based-importance-sampling
 float computeLod(float pdf)
 {
-    // IBL Baker (Matt Davidson)
-    // https://github.com/derkreature/IBLBaker/blob/65d244546d2e79dd8df18a28efdabcf1f2eb7717/data/shadersD3D11/IblImportanceSamplingDiffuse.fx#L215
-    float solidAngleTexel = 4.0 * MATH_PI / (6.0 * float(u_width) * float(u_sampleCount));
-    float solidAngleSample = 1.0 / (float(u_sampleCount) * pdf);
-    float lod = 0.5 * log2(solidAngleSample / solidAngleTexel);
+    // // IBL Baker (Matt Davidson)
+    // // https://github.com/derkreature/IBLBaker/blob/65d244546d2e79dd8df18a28efdabcf1f2eb7717/data/shadersD3D11/IblImportanceSamplingDiffuse.fx#L215
+    // float solidAngleTexel = 4.0 * MATH_PI / (6.0 * float(u_width) * float(u_sampleCount));
+    // float solidAngleSample = 1.0 / (float(u_sampleCount) * pdf);
+    // float lod = 0.5 * log2(solidAngleSample / solidAngleTexel);
+
+    // Solid angle of current sample -- bigger for less likely samples
+    float omegaS = 1.0 / (float(u_sampleCount) * pdf);
+    // Solid angle of texel
+    float omegaP = 4.0 * MATH_PI / (6.0 * float(u_width) * float(u_width));
+    // Mip level is determined by the ratio of our sample's solid angle to a texel's solid angle
+    float lod = max(0.5 * log2(omegaS / omegaP), 0.0);
 
     return lod;
 }

{
    //return  textureLod(uCubeMap, N, 3.0).rgb;
    vec3 color = vec3(0.f);

    for(int i = 0; i < u_sampleCount; ++i)
    {

                    lod = u_lodBias;
                }
                vec3 sampleColor = textureLod(uCubeMap, L, lod).rgb;
                color += sampleColor * NdotL;
                weight += NdotL;
            }
        }
    }

    if(weight != 0.0f)
    {
        color /= weight;
    }
    else
    {
        color /= float(u_sampleCount);
    }

    return color.rgb ;
}

// From the filament docs. Geometric Shadowing function
