1
+ #include ":Shaders/Common/Buffers/LightsSSBO.ovfxh"
2
+ #include ":Shaders/Common/Constants.ovfxh"
1
3
#include ":Shaders/Common/Physics.ovfxh"
2
4
#include ":Shaders/Common/Utils.ovfxh"
3
- #include ":Shaders/Common/Constants.ovfxh"
4
- #include ":Shaders/Common/Buffers/LightsSSBO.ovfxh"
5
- #include ":Shaders/Lighting/Shared.ovfxh"
5
+ #include ":Shaders/Lighting/Shadow.ovfxh"
6
+
7
+ float LuminosityFromAttenuation(mat4 light, vec3 fragPos)
8
+ {
9
+ const vec3 lightPosition = light[0].rgb;
10
+ const float constant = light[0][3];
11
+ const float linear = light[1][3];
12
+ const float quadratic = light[2][3];
13
+
14
+ const float distanceToLight = length(lightPosition - fragPos);
15
+ const float attenuation = (constant + linear * distanceToLight + quadratic * (distanceToLight * distanceToLight));
16
+
17
+ return 1.0 / attenuation;
18
+ }
19
+
20
+ vec3 ComputeAmbientBoxLight(mat4 light, vec3 fragPos)
21
+ {
22
+ const vec3 lightPosition = light[0].rgb;
23
+ const vec3 lightColor = UnPack(light[2][0]);
24
+ const float intensity = light[3][3];
25
+ const vec3 size = vec3(light[0][3], light[1][3], light[2][3]);
26
+
27
+ return IsPointInAABB(fragPos, lightPosition, size) ? lightColor * intensity : vec3(0.0);
28
+ }
29
+
30
+ vec3 ComputeAmbientSphereLight(mat4 light, vec3 fragPos)
31
+ {
32
+ const vec3 lightPosition = light[0].rgb;
33
+ const vec3 lightColor = UnPack(light[2][0]);
34
+ const float intensity = light[3][3];
35
+ const float radius = light[0][3];
36
+
37
+ return IsPointInSphere(fragPos, lightPosition, radius) ? lightColor * intensity : vec3(0.0);
38
+ }
6
39
7
40
float DistributionGGX(vec3 N, vec3 H, float roughness)
8
41
{
9
42
float a = roughness * roughness;
10
43
float a2 = a * a;
11
44
float NdotH = max(dot(N, H), 0.0);
12
45
float NdotH2 = NdotH * NdotH;
13
-
46
+
14
47
float num = a2;
15
48
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
16
49
denom = PI * denom * denom;
17
-
50
+
18
51
return num / denom;
19
52
}
20
53
@@ -25,7 +58,7 @@ float GeometrySchlickGGX(float NdotV, float roughness)
25
58
26
59
float num = NdotV;
27
60
float denom = NdotV * (1.0 - k) + k;
28
-
61
+
29
62
return num / denom;
30
63
}
31
64
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
@@ -34,33 +67,13 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
34
67
float NdotL = max(dot(N, L), 0.0);
35
68
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
36
69
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
37
-
70
+
38
71
return ggx1 * ggx2;
39
72
}
40
73
41
74
vec3 FresnelSchlick(float cosTheta, vec3 F0)
42
75
{
43
76
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
44
- }
45
-
46
- vec3 ComputeAmbientBoxLight(mat4 light, vec3 fragPos)
47
- {
48
- const vec3 lightPosition = light[0].rgb;
49
- const vec3 lightColor = UnPack(light[2][0]);
50
- const float intensity = light[3][3];
51
- const vec3 size = vec3(light[0][3], light[1][3], light[2][3]);
52
-
53
- return IsPointInAABB(fragPos, lightPosition, size) ? lightColor * intensity : vec3(0.0);
54
- }
55
-
56
- vec3 ComputeAmbientSphereLight(mat4 light, vec3 fragPos)
57
- {
58
- const vec3 lightPosition = light[0].rgb;
59
- const vec3 lightColor = UnPack(light[2][0]);
60
- const float intensity = light[3][3];
61
- const float radius = light[0][3];
62
-
63
- return IsPointInSphere(fragPos, lightPosition, radius) ? lightColor * intensity : vec3(0.0);
64
77
}
65
78
66
79
vec3 PBRLightingModel(vec3 albedo, float metallic, float roughness, float ao, vec3 normal, vec3 viewPos, vec3 fragPos, sampler2D shadowMap, mat4 lightSpaceMatrix)
@@ -72,7 +85,7 @@ vec3 PBRLightingModel(vec3 albedo, float metallic, float roughness, float ao, ve
72
85
const vec3 V = normalize(viewPos - fragPos);
73
86
74
87
const vec3 F0 = mix(vec3(0.04), albedo, metallic);
75
-
88
+
76
89
// reflectance equation
77
90
vec3 Lo = vec3(0.0);
78
91
vec3 ambientSum = vec3(0.0);
0 commit comments