 }
 
 // Hammersley Points on the Hemisphere
+// CC BY 3.0 (Holger Dammertz)
 // http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
+// with adapted interface
 float radicalInverse_VdC(uint bits)
 {
     bits = (bits << 16u) | (bits >> 16u);

    bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
	return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
vec2 hammersley2d(int i, int N) {
    return vec2(float(i)/float(N), radicalInverse_VdC(uint(i)));
 }


vec3 getImportanceSampleDirection(vec3 normal, float sinTheta, float cosTheta, float phi)
{
	vec3 H = normalize(vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta));

    vec3 bitangent = vec3(0.0, 1.0, 0.0);

	// Eliminates singularities.

    float cos2h = NdotH * NdotH;
    float sin2h = 1.0 - cos2h;
    return (2.0 + invR) * pow(sin2h, invR * 0.5) / (2.0 * MATH_PI);
}

float PDF(vec3 V, vec3 H, vec3 N, vec3 L, float roughness)
