-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSphericalHarmonics_gl.frag
More file actions
36 lines (30 loc) · 993 Bytes
/
SphericalHarmonics_gl.frag
File metadata and controls
36 lines (30 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#version 330 core
in vec3 worldPos;
out vec4 fragColor;
uniform vec3 shCoeffs[9];
uniform bool displayNormals;
vec3 resolveSH_Opt(vec3 premulCoefficients[9], vec3 dir)
{
vec3 result = premulCoefficients[0] * dir.x;
result += premulCoefficients[1] * dir.y;
result += premulCoefficients[2] * dir.z;
result += premulCoefficients[3];
vec3 dirSq = dir * dir;
result += premulCoefficients[4] * (dir.x * dir.y);
result += premulCoefficients[5] * (dir.x * dir.z);
result += premulCoefficients[6] * (dir.y * dir.z);
result += premulCoefficients[7] * (dirSq.x - dirSq.y);
result += premulCoefficients[8] * (3.0 * dirSq.z - 1.0);
return result;
}
void main()
{
// Compute flat face normal from screen-space position derivatives
vec3 normal = normalize(cross(dFdx(worldPos), dFdy(worldPos)));
if (displayNormals) {
fragColor = vec4(normal, 1.0);
}
else {
fragColor = vec4(resolveSH_Opt(shCoeffs, normal), 1.0);
}
}