             continue;
         }
 
-		// Note: reflect takes incident vector.
-		vec3 V = N;
-		vec3 L = normalize(reflect(-V, H));
-		float NdotL = dot(N, L);
-
-		if (NdotL > 0.0)
-		{
+        // Note: reflect takes incident vector.
+        vec3 V = N;
+        vec3 L = normalize(reflect(-V, H));
+        float NdotL = dot(N, L);
+
+        if (NdotL > 0.0)
+        {
             if(u_roughness == 0.0)
             {
                 // without this the roughness=0 lod is too high (taken from original implementation)


vec3 uvToXYZ(int face, vec2 uv)
{
	if(face == 0)
		return vec3(     1.f,   uv.y,    -uv.x);

	else if(face == 1)
		return vec3(    -1.f,   uv.y,     uv.x);

	else if(face == 2)
		return vec3(   +uv.x,   -1.f,    +uv.y);

	else if(face == 3)
		return vec3(   +uv.x,    1.f,    -uv.y);

	else if(face == 4)
		return vec3(   +uv.x,   uv.y,      1.f);

	else {//if(face == 5)
		return vec3(    -uv.x,  +uv.y,     -1.f);}
}

vec2 dirToUV(vec3 dir)
{
	return vec2(
		0.5f + 0.5f * atan(dir.z, dir.x) / MATH_PI,
		1.f - acos(dir.y) / MATH_PI);
}

float saturate(float v)
{
	return clamp(v, 0.0f, 1.0f);
}

// Hammersley Points on the Hemisphere

    float v = hammersleyPoint.y;

    // declare importance sample parameters
    float phi = 0.0; // theoretically there could be a distribution that defines phi differently
    float cosTheta = 0.f;
    float sinTheta = 0.f;
    float pdf = 0.0;

    // generate the points on the hemisphere with a fitting mapping for
    // the distribution (e.g. lambertian uses a cosine importance)
    if(u_distribution == cLambertian)
    {
        // Cosine weighted hemisphere sampling
        // http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations.html#Cosine-WeightedHemisphereSampling
        cosTheta = sqrt(1.0 - u);
        sinTheta = sqrt(u); // equivalent to `sqrt(1.0 - cosTheta*cosTheta)`;
        phi = 2.0 * MATH_PI * v;

        pdf = cosTheta / MATH_PI; // evaluation for solid angle, therefore drop the sinTheta
    }
    else if(u_distribution == cGGX)
    {
        // specular mapping
        float alpha = roughness * roughness;
        cosTheta = sqrt((1.0 - u) / (1.0 + (alpha*alpha - 1.0) * u));
        sinTheta = sqrt(1.0 - cosTheta*cosTheta);
        phi = 2.0 * MATH_PI * v;
    }
    else if(u_distribution == cCharlie)
    {
        // sheen mapping
        float alpha = roughness * roughness;
        sinTheta = pow(u, alpha / (2.0*alpha + 1.0));
        cosTheta = sqrt(1.0 - sinTheta * sinTheta);
        phi = 2.0 * MATH_PI * v;
    }

    // transform the hemisphere sample to the normal coordinate frame
    // i.e. rotate the hemisphere to the normal direction
