1
- #version 450 core
1
+ #version 430 core
2
2
3
3
#define M_PI 3.1415926535897932384626433832795
4
4
5
- #define POINT_LIGHTS 1
5
+ // #define POINT_LIGHTS 1
6
6
7
7
const float MAX_REFLECTION_LOD = 4.0 ;
8
8
@@ -11,7 +11,7 @@ in VS_OUT {
11
11
vec3 WorldPos;
12
12
vec3 TangentViewPos;
13
13
vec3 TangentWorldPos;
14
- vec3 TangentLightPositions[POINT_LIGHTS];
14
+ // vec3 TangentLightPositions[POINT_LIGHTS];
15
15
mat3 TBN;
16
16
} fs_in;
17
17
@@ -20,6 +20,8 @@ out vec4 FragColor;
20
20
uniform samplerCube irradianceMap;
21
21
uniform samplerCube prefilterMap;
22
22
uniform sampler2D brdfLUT;
23
+ uniform float skyboxExposure;
24
+ uniform float skyboxColorIntensity;
23
25
24
26
uniform sampler2D albedoMap;
25
27
uniform sampler2D normalMap;
@@ -34,8 +36,18 @@ uniform float colorIntensity;
34
36
35
37
uniform vec3 camPos;
36
38
37
- uniform vec3 lightPositions[POINT_LIGHTS];
38
- uniform vec3 lightColors[POINT_LIGHTS];
39
+ // uniform vec3 lightPositions[POINT_LIGHTS];
40
+ // uniform vec3 lightColors[POINT_LIGHTS];
41
+
42
+ vec3 ApplyExposureAndIntensity(vec3 color, float e, float i)
43
+ {
44
+ vec3 ret = color;
45
+ // Exposure
46
+ ret = vec3 (1.0 ) - exp (- ret * e);
47
+ // Color Intensity
48
+ ret *= i;
49
+ return ret;
50
+ }
39
51
40
52
vec3 GetNormalFromNormalMap(sampler2D map, vec2 coords)
41
53
{
@@ -56,35 +68,35 @@ vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir)
56
68
// depth of current layer
57
69
float currentLayerDepth = 0.0 ;
58
70
// the amount to shift the texture coordinates per layer (from vector P)
59
- vec2 P = viewDir.xy * height_scale;
71
+ vec2 P = viewDir.xy / viewDir.z * height_scale;
60
72
vec2 deltaTexCoords = P / numLayers;
61
73
62
74
// get initial values
63
75
vec2 currentTexCoords = texCoords;
64
- float currentDepthMapValue = texture(displacementMap, texCoords ).r;
76
+ float currentDepthMapValue = texture(displacementMap, currentTexCoords ).r;
65
77
66
78
while (currentLayerDepth < currentDepthMapValue)
67
79
{
68
80
// shift texture coordinates along direction of P
69
81
currentTexCoords -= deltaTexCoords;
70
82
// get depthmap value at current texture coordinates
71
- currentDepthMapValue = texture(displacementMap, texCoords ).r;
83
+ currentDepthMapValue = texture(displacementMap, currentTexCoords ).r;
72
84
// get depth of next layer
73
- currentLayerDepth += layerDepth;
85
+ currentLayerDepth += layerDepth;
74
86
}
75
87
76
88
// get texture coordinates before collision (reverse operations)
77
89
vec2 prevTexCoords = currentTexCoords + deltaTexCoords;
78
90
79
91
// get depth after and before collision for linear interpolation
80
92
float afterDepth = currentDepthMapValue - currentLayerDepth;
81
- float beforeDepth = texture(displacementMap, texCoords ).r - currentLayerDepth + layerDepth;
93
+ float beforeDepth = texture(displacementMap, prevTexCoords ).r - currentLayerDepth + layerDepth;
82
94
83
95
// interpolation of texture coordinates
84
96
float weight = afterDepth / (afterDepth - beforeDepth);
85
97
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
86
98
87
- return finalTexCoords;
99
+ return finalTexCoords;
88
100
}
89
101
90
102
vec3 FresnelSchlick(float cosTheta, vec3 F0)
@@ -132,6 +144,16 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
132
144
return ggx1 * ggx2;
133
145
}
134
146
147
+ vec3 PrefilteredColor(vec3 R, float roughness)
148
+ {
149
+ return ApplyExposureAndIntensity(textureLod(prefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb, skyboxExposure, skyboxColorIntensity);
150
+ }
151
+
152
+ vec3 IrradianceColor(vec3 N)
153
+ {
154
+ return ApplyExposureAndIntensity(texture(irradianceMap, N).rgb, skyboxExposure, skyboxColorIntensity);
155
+ }
156
+
135
157
void main()
136
158
{
137
159
vec3 viewDir = normalize (fs_in.TangentViewPos - fs_in.TangentWorldPos);
@@ -153,8 +175,6 @@ void main()
153
175
float metallic = texture(metallicMap, texCoords).r;
154
176
float roughness = texture(roughnessMap, texCoords).r;
155
177
float ao = texture(aoMap, texCoords).r;
156
- /*
157
- */
158
178
159
179
vec3 N = normalize (normal);
160
180
vec3 V = normalize (camPos - fs_in.WorldPos);
@@ -163,19 +183,18 @@ void main()
163
183
vec3 F0 = vec3 (0.04 );
164
184
F0 = mix (F0, albedo, metallic);
165
185
166
- vec3 Lo = vec3 (0.0 );
167
- // for(int i = 0; i < POINT_LIGHTS; ++i)
168
- for (int i = POINT_LIGHTS; i < POINT_LIGHTS; ++ i)
186
+ // vec3 Lo = vec3(0.0);
187
+ /* for(int i = 0; i < POINT_LIGHTS; ++i)
169
188
{
170
189
vec3 L = normalize(lightPositions[i] - fs_in.WorldPos);
171
190
//vec3 L = normalize(fs_in.TangentLightPositions[i] - fs_in.TangentWorldPos);
172
191
vec3 H = normalize(V + L);
173
-
192
+
174
193
float dist = length(lightPositions[i] - fs_in.WorldPos);
175
194
//float dist = length(fs_in.TangentLightPositions[i] - fs_in.TangentWorldPos);
176
195
float attenuation = 1.0 / (dist * dist);
177
196
vec3 radiance = lightColors[i] * attenuation;
178
-
197
+
179
198
// cook-torrance brdf
180
199
float NDF = DistributionGGX(N, H, roughness);
181
200
float G = GeometrySmith(N, V, L, roughness);
@@ -184,39 +203,43 @@ void main()
184
203
vec3 kS = F;
185
204
vec3 kD = vec3(1.0) - kS;
186
205
kD *= 1.0 - metallic;
187
-
206
+
188
207
vec3 numerator = NDF * G * F;
189
208
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0);
190
209
vec3 specular = numerator / max(denominator, 0.001);
191
-
210
+
192
211
float NdotL = max(dot(N, L), 0.0);
193
212
Lo += (kD * albedo / M_PI + specular) * radiance * NdotL;
194
213
}
214
+ */
195
215
196
216
vec3 F = FresnelSchlickRoughness(max (dot (N, V), 0.0 ), F0, roughness);
197
217
198
218
vec3 kS = F;
199
219
vec3 kD = 1.0 - kS;
200
220
kD *= 1.0 - metallic;
201
221
202
- vec3 irradiance = texture(irradianceMap, N).rgb ;
222
+ vec3 irradiance = IrradianceColor(N) ;
203
223
vec3 diffuse = irradiance * albedo;
204
224
205
- vec3 prefilteredColor = textureLod(prefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb ;
225
+ vec3 prefilteredColor = PrefilteredColor( R, roughness) ;
206
226
vec2 envBRDF = texture(brdfLUT, vec2 (max (dot (N, V), 0.0 ), roughness)).rg;
207
227
vec3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
208
228
209
229
vec3 ambient = (kD * diffuse + specular) * ao;
210
230
211
- vec3 color = ambient + Lo;
231
+ // vec3 color = ambient + Lo;
232
+ vec3 color = ambient;
212
233
213
234
// Exposure
214
235
// color *= exposure;
215
236
// Tonemapping Reinharda
216
237
// color = color / (color + vec3(1.0));
217
- color = vec3 (1.0 ) - exp (- color * exposure);
238
+ // color = vec3(1.0) - exp(-color * exposure);
218
239
// Color Intensity
219
- color *= colorIntensity;
240
+ // color *= colorIntensity;
241
+
242
+ color = ApplyExposureAndIntensity(color, exposure, colorIntensity);
220
243
// Gamma Correction
221
244
color = pow (color, vec3 (1.0 / 2.2 ));
222
245
0 commit comments