|
@@ -230,55 +230,56 @@
|
|
c = toLinearSpace(c);
|
|
c = toLinearSpace(c);
|
|
#endif
|
|
#endif
|
|
return c;
|
|
return c;
|
|
- }
|
|
|
|
-
|
|
|
|
- vec3 result = vec3(0.);
|
|
|
|
- vec3 tangent = abs(n.z) < 0.999 ? vec3(0., 0., 1.) : vec3(1., 0., 0.);
|
|
|
|
- tangent = normalize(cross(tangent, n));
|
|
|
|
- vec3 bitangent = cross(n, tangent);
|
|
|
|
- mat3 tbn = mat3(tangent, bitangent, n);
|
|
|
|
-
|
|
|
|
- float maxLevel = filteringInfo.y;
|
|
|
|
- float dim0 = filteringInfo.x;
|
|
|
|
- float omegaP = (4. * PI) / (6. * dim0 * dim0);
|
|
|
|
-
|
|
|
|
- float weight = 0.;
|
|
|
|
- #if defined(WEBGL2) || defined(WEBGPU)
|
|
|
|
- for(uint i = 0u; i < NUM_SAMPLES; ++i)
|
|
|
|
- #else
|
|
|
|
- for(int i = 0; i < NUM_SAMPLES; ++i)
|
|
|
|
- #endif
|
|
|
|
- {
|
|
|
|
- vec2 Xi = hammersley(i, NUM_SAMPLES);
|
|
|
|
- vec3 H = hemisphereImportanceSampleDggx(Xi, alphaG);
|
|
|
|
-
|
|
|
|
- float NoV = 1.;
|
|
|
|
- float NoH = H.z;
|
|
|
|
- float NoH2 = H.z * H.z;
|
|
|
|
- float NoL = 2. * NoH2 - 1.;
|
|
|
|
- vec3 L = vec3(2. * NoH * H.x, 2. * NoH * H.y, NoL);
|
|
|
|
- L = normalize(L);
|
|
|
|
-
|
|
|
|
- if (NoL > 0.) {
|
|
|
|
- float pdf_inversed = 4. / normalDistributionFunction_TrowbridgeReitzGGX(NoH, alphaG);
|
|
|
|
-
|
|
|
|
- float omegaS = NUM_SAMPLES_FLOAT_INVERSED * pdf_inversed;
|
|
|
|
- float l = log4(omegaS) - log4(omegaP) + log4(K);
|
|
|
|
- float mipLevel = clamp(float(l), 0.0, maxLevel);
|
|
|
|
-
|
|
|
|
- weight += NoL;
|
|
|
|
-
|
|
|
|
- vec3 c = textureCubeLodEXT(inputTexture, tbn * L, mipLevel).rgb;
|
|
|
|
- #ifdef GAMMA_INPUT
|
|
|
|
- c = toLinearSpace(c);
|
|
|
|
- #endif
|
|
|
|
- result += c * NoL;
|
|
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ vec3 result = vec3(0.);
|
|
|
|
+ vec3 tangent = abs(n.z) < 0.999 ? vec3(0., 0., 1.) : vec3(1., 0., 0.);
|
|
|
|
+ tangent = normalize(cross(tangent, n));
|
|
|
|
+ vec3 bitangent = cross(n, tangent);
|
|
|
|
+ mat3 tbn = mat3(tangent, bitangent, n);
|
|
|
|
+
|
|
|
|
+ float maxLevel = filteringInfo.y;
|
|
|
|
+ float dim0 = filteringInfo.x;
|
|
|
|
+ float omegaP = (4. * PI) / (6. * dim0 * dim0);
|
|
|
|
+
|
|
|
|
+ float weight = 0.;
|
|
|
|
+ #if defined(WEBGL2) || defined(WEBGPU)
|
|
|
|
+ for(uint i = 0u; i < NUM_SAMPLES; ++i)
|
|
|
|
+ #else
|
|
|
|
+ for(int i = 0; i < NUM_SAMPLES; ++i)
|
|
|
|
+ #endif
|
|
|
|
+ {
|
|
|
|
+ vec2 Xi = hammersley(i, NUM_SAMPLES);
|
|
|
|
+ vec3 H = hemisphereImportanceSampleDggx(Xi, alphaG);
|
|
|
|
+
|
|
|
|
+ float NoV = 1.;
|
|
|
|
+ float NoH = H.z;
|
|
|
|
+ float NoH2 = H.z * H.z;
|
|
|
|
+ float NoL = 2. * NoH2 - 1.;
|
|
|
|
+ vec3 L = vec3(2. * NoH * H.x, 2. * NoH * H.y, NoL);
|
|
|
|
+ L = normalize(L);
|
|
|
|
+
|
|
|
|
+ if (NoL > 0.) {
|
|
|
|
+ float pdf_inversed = 4. / normalDistributionFunction_TrowbridgeReitzGGX(NoH, alphaG);
|
|
|
|
+
|
|
|
|
+ float omegaS = NUM_SAMPLES_FLOAT_INVERSED * pdf_inversed;
|
|
|
|
+ float l = log4(omegaS) - log4(omegaP) + log4(K);
|
|
|
|
+ float mipLevel = clamp(float(l), 0.0, maxLevel);
|
|
|
|
+
|
|
|
|
+ weight += NoL;
|
|
|
|
+
|
|
|
|
+ vec3 c = textureCubeLodEXT(inputTexture, tbn * L, mipLevel).rgb;
|
|
|
|
+ #ifdef GAMMA_INPUT
|
|
|
|
+ c = toLinearSpace(c);
|
|
|
|
+ #endif
|
|
|
|
+ result += c * NoL;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- result = result / weight;
|
|
|
|
|
|
+ result = result / weight;
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|
|
#endif
|