Skip to content

Commit 2613015

Browse files
committed
Added bloom and fixed resizing the viewport window.
1 parent a5b6a8e commit 2613015

25 files changed

+1280
-771
lines changed

NeonEngine/NeonEngine.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
</Link>
134134
</ItemDefinitionGroup>
135135
<ItemGroup>
136+
<ClCompile Include="src\bloom.cpp" />
137+
<ClCompile Include="src\shader.cpp" />
138+
<ClCompile Include="src\opengl_utils.cpp" />
136139
<ClCompile Include="src\cubemap.cpp" />
137140
<ClCompile Include="src\model.cpp" />
138141
<ClCompile Include="src\game_object.cpp" />
@@ -147,6 +150,7 @@
147150
<ClCompile Include="src\stb_image.cpp" />
148151
</ItemGroup>
149152
<ItemGroup>
153+
<ClInclude Include="src\bloom.h" />
150154
<ClInclude Include="src\logger.h" />
151155
<ClInclude Include="src\pbr.h" />
152156
<ClInclude Include="src\cubemap.h" />
@@ -171,6 +175,8 @@
171175
<ClInclude Include="src\transform3d.h" />
172176
</ItemGroup>
173177
<ItemGroup>
178+
<None Include="shaders\bloom_upsample.frag" />
179+
<None Include="shaders\bloom_downsample.frag" />
174180
<None Include="shaders\brdf.frag" />
175181
<None Include="shaders\brdf.vert" />
176182
<None Include="shaders\prefilter.frag" />
@@ -185,6 +191,7 @@
185191
<None Include="shaders\vertices_quad.vert" />
186192
<None Include="shaders\skybox.frag" />
187193
<None Include="shaders\skybox.vert" />
194+
<None Include="shaders\hdr_to_ldr.frag" />
188195
</ItemGroup>
189196
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
190197
<ImportGroup Label="ExtensionTargets">

NeonEngine/NeonEngine.vcxproj.filters

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
<ClCompile Include="src\cubemap.cpp">
5555
<Filter>Source Files</Filter>
5656
</ClCompile>
57+
<ClCompile Include="src\opengl_utils.cpp">
58+
<Filter>Source Files</Filter>
59+
</ClCompile>
60+
<ClCompile Include="src\shader.cpp">
61+
<Filter>Source Files</Filter>
62+
</ClCompile>
63+
<ClCompile Include="src\bloom.cpp">
64+
<Filter>Source Files</Filter>
65+
</ClCompile>
5766
</ItemGroup>
5867
<ItemGroup>
5968
<ClInclude Include="src\neon_engine.h">
@@ -122,6 +131,9 @@
122131
<ClInclude Include="src\logger.h">
123132
<Filter>Header Files</Filter>
124133
</ClInclude>
134+
<ClInclude Include="src\bloom.h">
135+
<Filter>Header Files</Filter>
136+
</ClInclude>
125137
</ItemGroup>
126138
<ItemGroup>
127139
<None Include="shaders\phong_lighting.frag">
@@ -166,5 +178,14 @@
166178
<None Include="shaders\brdf.vert">
167179
<Filter>Shaders</Filter>
168180
</None>
181+
<None Include="shaders\bloom_downsample.frag">
182+
<Filter>Shaders</Filter>
183+
</None>
184+
<None Include="shaders\bloom_upsample.frag">
185+
<Filter>Shaders</Filter>
186+
</None>
187+
<None Include="shaders\hdr_to_ldr.frag">
188+
<Filter>Shaders</Filter>
189+
</None>
169190
</ItemGroup>
170191
</Project>

NeonEngine/imgui.ini

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ Collapsed=0
2626

2727
[Window][Viewport]
2828
Pos=0,36
29-
Size=1762,1035
29+
Size=1680,990
3030
Collapsed=0
3131
DockId=0x00000003,0
3232

3333
[Window][Details]
34-
Pos=1764,764
35-
Size=796,676
34+
Pos=1682,776
35+
Size=878,664
3636
Collapsed=0
3737
DockId=0x00000002,0
3838

@@ -43,8 +43,8 @@ Collapsed=0
4343
DockId=0x3BC79352,0
4444

4545
[Window][Content Browser]
46-
Pos=0,1073
47-
Size=1762,367
46+
Pos=0,1028
47+
Size=1680,412
4848
Collapsed=0
4949
DockId=0x00000001,0
5050

@@ -55,20 +55,20 @@ Size=1441,1038
5555
Collapsed=0
5656

5757
[Window][Outliner]
58-
Pos=1764,36
59-
Size=796,726
58+
Pos=1682,36
59+
Size=878,738
6060
Collapsed=0
6161
DockId=0x00000006,0
6262

6363
[Window][Logger]
64-
Pos=0,1073
65-
Size=1762,367
64+
Pos=0,1028
65+
Size=1680,412
6666
Collapsed=0
6767
DockId=0x00000001,1
6868

6969
[Window][World Settings]
70-
Pos=1764,764
71-
Size=796,676
70+
Pos=1682,776
71+
Size=878,664
7272
Collapsed=0
7373
DockId=0x00000002,1
7474

@@ -98,8 +98,8 @@ Column 0 Weight=0.6844
9898
Column 1 Weight=1.3156
9999

100100
[Table][0x8DFD9433,2]
101-
Column 0 Weight=0.6941
102-
Column 1 Weight=1.3059
101+
Column 0 Weight=0.7051
102+
Column 1 Weight=1.2949
103103

104104
[Table][0xBB397ABF,2]
105105
Column 0 Weight=0.6747
@@ -110,20 +110,20 @@ Column 0 Weight=0.6844
110110
Column 1 Weight=1.3156
111111

112112
[Table][0x27A19193,2]
113-
Column 0 Weight=0.8947
114-
Column 1 Weight=1.1053
113+
Column 0 Weight=0.8974
114+
Column 1 Weight=1.1026
115115

116116
[Table][0x292180E1,2]
117117
Column 0 Weight=0.6796
118118
Column 1 Weight=1.3204
119119

120120
[Docking][Data]
121121
DockSpace ID=0x3BC79352 Pos=49,119 Size=2560,1404 CentralNode=1 Selected=0x13926F0B
122-
DockSpace ID=0xD2411A5B Window=0x0FB73749 Pos=353,423 Size=2560,1404 Split=X Selected=0x13926F0B
123-
DockNode ID=0x00000004 Parent=0xD2411A5B SizeRef=1762,1404 Split=Y
124-
DockNode ID=0x00000003 Parent=0x00000004 SizeRef=2560,1035 CentralNode=1 Selected=0x13926F0B
125-
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=2560,367 Selected=0x0340EFE6
126-
DockNode ID=0x00000005 Parent=0xD2411A5B SizeRef=796,1404 Split=Y Selected=0x94263E27
127-
DockNode ID=0x00000006 Parent=0x00000005 SizeRef=721,726 Selected=0x94263E27
128-
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=721,676 Selected=0xFC3EA205
122+
DockSpace ID=0xD2411A5B Window=0x0FB73749 Pos=596,317 Size=2560,1404 Split=X Selected=0x13926F0B
123+
DockNode ID=0x00000004 Parent=0xD2411A5B SizeRef=1680,1404 Split=Y
124+
DockNode ID=0x00000003 Parent=0x00000004 SizeRef=2560,990 CentralNode=1 Selected=0x13926F0B
125+
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=2560,412 Selected=0x0340EFE6
126+
DockNode ID=0x00000005 Parent=0xD2411A5B SizeRef=878,1404 Split=Y Selected=0x94263E27
127+
DockNode ID=0x00000006 Parent=0x00000005 SizeRef=721,738 Selected=0x94263E27
128+
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=721,664 Selected=0xFC3EA205
129129

NeonEngine/log.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
2023-05-10 18:05:53 Loading model: knight
2-
2023-05-10 18:05:53 Model loaded in 0.435242 seconds
3-
2023-05-10 18:05:53 Loading model: mutant
4-
2023-05-10 18:05:54 Model loaded in 0.470512 seconds
5-
2023-05-10 18:05:54 Loading model: android
6-
2023-05-10 18:05:56 Model loaded in 2.365656 seconds
1+
2023-05-20 15:15:57 Loading model: knight
2+
2023-05-20 15:15:58 Model loaded in 0.373683 seconds
3+
2023-05-20 15:15:58 Loading model: mutant
4+
2023-05-20 15:15:58 Model loaded in 0.404307 seconds
5+
2023-05-20 15:15:58 Loading model: android
6+
2023-05-20 15:16:00 Model loaded in 2.243006 seconds

NeonEngine/shaders/PBR.frag

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
layout (location = 0) out vec4 FragColor;
33
layout (location = 1) out vec4 IdColor;
44
layout (location = 2) out vec4 IdColorTransform3d;
5+
layout (location = 3) out vec4 BrightColor;
56

67
in vec3 FragPos;
78
in vec3 Normal;
@@ -22,6 +23,7 @@ uniform int has_texture_roughness;
2223
uniform int has_texture_emission;
2324
uniform int has_texture_ambient_occlusion;
2425

26+
uniform float intensity;
2527
uniform vec3 albedo_model;
2628
uniform float metalness_model;
2729
uniform float roughness_model;
@@ -36,9 +38,11 @@ const float PI = 3.14159265359;
3638

3739
struct PointLight {
3840
vec3 position;
41+
42+
vec3 light_color;
43+
float intensity;
3944

4045
vec3 ambient;
41-
vec3 radiance;
4246
vec3 specular;
4347

4448
float constant;
@@ -48,18 +52,22 @@ struct PointLight {
4852

4953
struct DirectionalLight {
5054
vec3 direction;
55+
56+
vec3 light_color;
57+
float intensity;
5158

5259
vec3 ambient;
53-
vec3 radiance;
5460
vec3 specular;
5561
};
5662

5763
struct SpotLight {
5864
vec3 position;
5965
vec3 direction;
6066

67+
vec3 light_color;
68+
float intensity;
69+
6170
vec3 ambient;
62-
vec3 radiance;
6371
vec3 specular;
6472

6573
float constant;
@@ -76,9 +84,9 @@ uniform int num_point_lights;
7684
uniform int num_directional_lights;
7785
uniform int num_spot_lights;
7886

79-
const int MAX_POINT_LIGHTS = 50;
80-
const int MAX_DIRECTIONAL_LIGHTS = 10;
81-
const int MAX_SPOT_LIGHTS = 50;
87+
const int MAX_POINT_LIGHTS = 20;
88+
const int MAX_DIRECTIONAL_LIGHTS = 5;
89+
const int MAX_SPOT_LIGHTS = 10;
8290

8391
uniform PointLight pointLights[MAX_POINT_LIGHTS];
8492
uniform DirectionalLight directionalLights[MAX_DIRECTIONAL_LIGHTS];
@@ -91,17 +99,12 @@ uniform int is_transform3d;
9199

92100
uniform int material_format;
93101

94-
uniform float exposure;
95-
96102
// Material/File formats
97103
const int Default = 0;
98104
const int glTF = 1;
99105
const int FBX = 2;
100106

101107
// Function declarations
102-
vec3 aces_approx(vec3 v);
103-
vec3 uncharted2_tonemap_partial(vec3 x);
104-
vec3 uncharted2_filmic(vec3 v);
105108
vec3 getNormalFromMap();
106109
float DistributionGGX(vec3 N, vec3 H, float roughness);
107110
float GeometrySchlickGGX(float NdotV, float roughness);
@@ -120,7 +123,8 @@ void main() {
120123
}
121124
if (render_only_ambient == 1) {
122125
if (render_one_color == 1) {
123-
FragColor = vec4(albedo_model, 1.0);
126+
// Used in particular for rendering lights with bloom
127+
FragColor = vec4(albedo_model * intensity, 1.0);
124128
}
125129
else {
126130
FragColor = vec4(vec3(texture(texture_albedo, TexCoords)), 1.0);
@@ -184,7 +188,7 @@ void main() {
184188
float dist = length(pointLights[i].position - FragPos);
185189
float attenuation = 1.0 / (pointLights[i].constant + pointLights[i].linear * dist + pointLights[i].quadratic * (dist * dist));
186190
// radiance
187-
vec3 radiance = pointLights[i].radiance * attenuation;
191+
vec3 radiance = pointLights[i].light_color * pointLights[i].intensity * attenuation;
188192

189193
// Cook-Torrance BRDF
190194
float NDF = DistributionGGX(N, H, roughness);
@@ -219,7 +223,7 @@ void main() {
219223
vec3 L = normalize(-directionalLights[i].direction);
220224
vec3 H = normalize(V + L);
221225
// radiance
222-
vec3 radiance = directionalLights[i].radiance;
226+
vec3 radiance = directionalLights[i].light_color * directionalLights[i].intensity;
223227

224228
// Cook-Torrance BRDF
225229
float NDF = DistributionGGX(N, H, roughness);
@@ -261,7 +265,7 @@ void main() {
261265
float epsilon = spotLights[i].inner_cut_off - spotLights[i].outer_cut_off;
262266
float intensity = clamp((theta - spotLights[i].outer_cut_off) / epsilon, 0.0, 1.0);
263267
// radiance
264-
vec3 radiance = spotLights[i].radiance * attenuation * intensity;
268+
vec3 radiance = spotLights[i].light_color * spotLights[i].intensity * attenuation * intensity;
265269

266270
// Cook-Torrance BRDF
267271
float NDF = DistributionGGX(N, H, roughness);
@@ -310,27 +314,20 @@ void main() {
310314

311315
vec3 color = ambient + Lo;
312316

313-
// Exposure
314-
color *= exposure;
315-
// HDR tonemapping
316-
//color = color / (color + vec3(1.0)); // Reinhard tone mapping
317-
color = aces_approx(color); // Approximated ACES tone mapping
318-
// gamma correct
319-
color = pow(color, vec3(1.0/2.2));
320-
321317
FragColor = vec4(color , 1.0);
322318
}
323-
}
324319

325-
// Approximated ACES (Academy Color Encoding System) tone mapping by Krzysztof Narkowicz
326-
vec3 aces_approx(vec3 v) {
327-
v *= 0.6f;
328-
float a = 2.51f;
329-
float b = 0.03f;
330-
float c = 2.43f;
331-
float d = 0.59f;
332-
float e = 0.14f;
333-
return clamp((v*(a*v+b))/(v*(c*v+d)+e), 0.0f, 1.0f);
320+
float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
321+
if(brightness > 1.0)
322+
BrightColor = vec4(FragColor.rgb, 1.0);
323+
else
324+
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
325+
326+
// For lights, we render the object with only the albedo color, but the bright color takes
327+
// into consideration both the albedo color and the intensity
328+
if (render_one_color == 1 && render_only_ambient == 1) {
329+
FragColor = vec4(albedo_model, 1.0);
330+
}
334331
}
335332

336333
// Easy trick to get tangent-normals to world-space to keep PBR code simplified.

0 commit comments

Comments
 (0)