|
@@ -1,5 +1,43 @@
|
|
|
export default /* glsl */`
|
|
|
uniform vec3 ambientLightColor;
|
|
|
+uniform vec3 lightProbe[ 9 ];
|
|
|
+
|
|
|
+// get the irradiance (radiance convolved with cosine lobe) at the point 'normal' on the unit sphere
|
|
|
+// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf
|
|
|
+vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
|
|
|
+
|
|
|
+ // normal is assumed to have unit length
|
|
|
+
|
|
|
+ float x = normal.x, y = normal.y, z = normal.z;
|
|
|
+
|
|
|
+ // band 0
|
|
|
+ vec3 result = shCoefficients[ 0 ] * 0.886227;
|
|
|
+
|
|
|
+ // band 1
|
|
|
+ result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
|
|
|
+ result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
|
|
|
+ result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
|
|
|
+
|
|
|
+ // band 2
|
|
|
+ result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
|
|
|
+ result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
|
|
|
+ result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
|
|
|
+ result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
|
|
|
+ result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {
|
|
|
+
|
|
|
+ vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
|
|
|
+
|
|
|
+ vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
|
|
|
+
|
|
|
+ return irradiance;
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
|
|
|
|