-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSphericalHarmonics.frag
More file actions
65 lines (59 loc) · 1.8 KB
/
SphericalHarmonics.frag
File metadata and controls
65 lines (59 loc) · 1.8 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#version 450 core
layout(location = 0) in vec3 worldPos;
layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 uncorrectedProjectionMatrix;
mat4 clipCorrectionMatrix;
mat4 viewProjectionMatrix;
mat4 inverseViewMatrix;
mat4 inverseProjectionMatrix;
mat4 inverseViewProjectionMatrix;
mat4 viewportMatrix;
mat4 inverseViewportMatrix;
vec4 textureTransformMatrix;
vec3 eyePosition;
float aspectRatio;
float gamma;
float exposure;
float time;
};
layout(std140, binding = 1) uniform qt3d_command_uniforms {
mat4 modelMatrix;
mat4 inverseModelMatrix;
mat4 modelViewMatrix;
mat3 modelNormalMatrix;
mat4 inverseModelViewMatrix;
mat4 mvp;
mat4 inverseModelViewProjectionMatrix;
};
layout(std140, binding = 2) uniform input_uniforms {
vec3 shCoeffs[9];
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);
}
}