Skip to content

Commit 64c8f42

Browse files
authored
Improved default scene: skysphere + post-processing + better grid (#511)
* Added skysphere and updated default scene * Fixed missing hdr extension from asset importer * Fixed HDR texture were 16bits while 32bits was expected * Cleaned up grid shader * Enabled default skysphere in asset view * Added options to create skysphere shader and material * Reworked `CreateNewMaterial` to not use hard coded XML, and updated skysphere material creation to not use backface culling * Changed default grid color to 100% white, and adjusted grid fading * Remove grid render pass stencil clear (as it doesnt use it anymore) and added it to DebugSceneRenderer for outline * Update grid line width and fading
1 parent 95610e4 commit 64c8f42

File tree

21 files changed

+444
-170
lines changed

21 files changed

+444
-170
lines changed

Resources/Editor/Shaders/Grid.ovfx

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ layout (location = 2) in vec3 geo_Normal;
77

88
layout (std140) uniform EngineUBO
99
{
10-
mat4 ubo_Model;
11-
mat4 ubo_View;
12-
mat4 ubo_Projection;
13-
vec3 ubo_ViewPos;
14-
float ubo_Time;
10+
mat4 ubo_Model;
11+
mat4 ubo_View;
12+
mat4 ubo_Projection;
13+
vec3 ubo_ViewPos;
14+
float ubo_Time;
1515
};
1616

1717
out VS_OUT
@@ -22,9 +22,8 @@ out VS_OUT
2222

2323
void main()
2424
{
25-
vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
26-
vs_out.TexCoords = vs_out.FragPos.xz;
27-
25+
vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
26+
vs_out.TexCoords = vs_out.FragPos.xz;
2827
gl_Position = ubo_Projection * ubo_View * vec4(vs_out.FragPos, 1.0);
2928
}
3029

@@ -35,11 +34,11 @@ out vec4 FRAGMENT_COLOR;
3534

3635
layout (std140) uniform EngineUBO
3736
{
38-
mat4 ubo_Model;
39-
mat4 ubo_View;
40-
mat4 ubo_Projection;
41-
vec3 ubo_ViewPos;
42-
float ubo_Time;
37+
mat4 ubo_Model;
38+
mat4 ubo_View;
39+
mat4 ubo_Projection;
40+
vec3 ubo_ViewPos;
41+
float ubo_Time;
4342
};
4443

4544
in VS_OUT
@@ -50,49 +49,55 @@ in VS_OUT
5049

5150
uniform vec3 u_Color;
5251

53-
float MAG(float p_lp)
52+
float MAG(float lineWidth, float p_lp)
5453
{
55-
const float lineWidth = 1.0f;
56-
57-
const vec2 coord = fs_in.TexCoords / p_lp;
58-
const vec2 grid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
59-
const float line = min(grid.x, grid.y);
60-
const float lineResult = lineWidth - min(line, lineWidth);
61-
62-
return lineResult;
54+
const vec2 coord = fs_in.TexCoords / p_lp;
55+
const vec2 grid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
56+
const float line = min(grid.x, grid.y);
57+
const float lineResult = lineWidth - min(line, lineWidth);
58+
return lineResult;
6359
}
6460

65-
float Grid(float height, float a, float b, float c)
61+
float Grid(float lineWidth, float height, float a, float b, float c)
6662
{
67-
const float cl = MAG(a);
68-
const float ml = MAG(b);
69-
const float fl = MAG(c);
70-
71-
const float cmit = 10.0f;
72-
const float cmet = 40.0f;
73-
const float mfit = 80.0f;
74-
const float mfet = 160.0f;
75-
76-
const float df = clamp((height - cmit) / (cmet - cmit), 0.0f, 1.0f);
77-
const float dff = clamp((height - mfit) / (mfet - mfit), 0.0f, 1.0f);
78-
79-
const float inl = mix(cl, ml, df);
80-
const float fnl = mix(inl, fl, dff);
81-
82-
return fnl;
63+
const float cl = MAG(lineWidth, a);
64+
const float ml = MAG(lineWidth, b);
65+
const float fl = MAG(lineWidth, c);
66+
const float cmit = 10.0f;
67+
const float cmet = 40.0f;
68+
const float mfit = 80.0f;
69+
const float mfet = 160.0f;
70+
const float df = clamp((height - cmit) / (cmet - cmit), 0.0f, 1.0f);
71+
const float dff = clamp((height - mfit) / (mfet - mfit), 0.0f, 1.0f);
72+
const float inl = mix(cl, ml, df);
73+
const float fnl = mix(inl, fl, dff);
74+
return fnl;
8375
}
8476

8577
void main()
8678
{
87-
const float height = distance(ubo_ViewPos.y, fs_in.FragPos.y);
88-
89-
const float gridA = Grid(height, 1.0f, 4.0f, 8.0f);
90-
const float gridB = Grid(height, 4.0f, 16.0f, 32.0f);
91-
92-
const float grid = gridA * 0.5f + gridB;
93-
94-
const vec2 viewdirW = ubo_ViewPos.xz - fs_in.FragPos.xz;
95-
const float viewdist = length(viewdirW);
96-
97-
FRAGMENT_COLOR = vec4(u_Color, grid);
98-
}
79+
const float height = distance(ubo_ViewPos.y, fs_in.FragPos.y);
80+
const float gridA = Grid(0.5f, height, 1.0f, 4.0f, 8.0f);
81+
const float gridB = Grid(0.7f, height, 4.0f, 16.0f, 32.0f);
82+
const float grid = gridA * 0.7f + gridB * 0.7f;
83+
84+
// Calculate view direction vector (from camera to fragment)
85+
const vec3 viewDir = normalize(fs_in.FragPos - ubo_ViewPos);
86+
87+
// Calculate how parallel the view direction is to the horizon
88+
// When looking at horizon, viewDir.y will be close to 0
89+
const float horizonFactor = abs(viewDir.y);
90+
91+
// Define how much we want to fade when looking at horizon
92+
const float horizonMinFade = 0.02f; // Minimum fade at horizon
93+
const float horizonFadeStart = 0.0f; // Start fading at this angle
94+
const float horizonFadeEnd = 1.0f; // Full grid strength at this angle
95+
96+
// Calculate horizon fade factor (1.0 = full grid, 0.0 = fully faded)
97+
const float horizonFade =
98+
horizonMinFade
99+
+ (1.0f - horizonMinFade)
100+
* smoothstep(horizonFadeStart, horizonFadeEnd, horizonFactor);
101+
102+
FRAGMENT_COLOR = vec4(u_Color, grid * horizonFade);
103+
}
Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,100 @@
11
<root>
2-
<shader>:Shaders\Standard.ovfx</shader>
2+
<shader>:Shaders\StandardPBR.ovfx</shader>
33
<settings>
44
<blendable>false</blendable>
55
<backface_culling>true</backface_culling>
6+
<frontface_culling>false</frontface_culling>
67
<depth_test>true</depth_test>
8+
<depth_writing>true</depth_writing>
9+
<color_writing>true</color_writing>
10+
<cast_shadows>true</cast_shadows>
11+
<receive_shadows>true</receive_shadows>
12+
<user_interface>false</user_interface>
713
<gpu_instances>1</gpu_instances>
8-
<cast_shadows>1</cast_shadows>
9-
<receive_shadows>1</receive_shadows>
1014
</settings>
1115
<uniforms>
1216
<uniform>
13-
<name>diffuseColor</name>
17+
<name>_LightSpaceMatrix</name>
18+
</uniform>
19+
<uniform>
20+
<name>_ShadowMap</name>
21+
<value>?</value>
22+
</uniform>
23+
<uniform>
24+
<name>u_Albedo</name>
1425
<value>
1526
<x>1</x>
16-
<y>0.99998999</y>
17-
<z>0.99998999</z>
18-
<w>0</w>
27+
<y>1</y>
28+
<z>1</z>
29+
<w>1</w>
1930
</value>
2031
</uniform>
2132
<uniform>
22-
<name>diffuseTexture</name>
33+
<name>u_AlbedoMap</name>
2334
<value>?</value>
2435
</uniform>
2536
<uniform>
26-
<name>specularColor</name>
27-
<value>
28-
<x>1e-06</x>
29-
<y>9.9998999e-07</y>
30-
<z>9.9998999e-07</z>
31-
<w>0</w>
32-
</value>
37+
<name>u_AlphaClippingThreshold</name>
38+
<value>0.1</value>
39+
</uniform>
40+
<uniform>
41+
<name>u_AmbientOcclusionMap</name>
42+
<value>?</value>
3343
</uniform>
3444
<uniform>
35-
<name>shineness</name>
36-
<value>64</value>
45+
<name>u_HeightMap</name>
46+
<value>?</value>
47+
</uniform>
48+
<uniform>
49+
<name>u_HeightScale</name>
50+
<value>0.050000001</value>
51+
</uniform>
52+
<uniform>
53+
<name>u_MaskMap</name>
54+
<value>?</value>
55+
</uniform>
56+
<uniform>
57+
<name>u_Metallic</name>
58+
<value>0</value>
3759
</uniform>
3860
<uniform>
39-
<name>specularTexture</name>
61+
<name>u_MetallicMap</name>
4062
<value>?</value>
4163
</uniform>
64+
<uniform>
65+
<name>u_NormalMap</name>
66+
<value>?</value>
67+
</uniform>
68+
<uniform>
69+
<name>u_ParallaxClipEdges</name>
70+
<value>0</value>
71+
</uniform>
72+
<uniform>
73+
<name>u_Roughness</name>
74+
<value>0.5</value>
75+
</uniform>
76+
<uniform>
77+
<name>u_RoughnessMap</name>
78+
<value>?</value>
79+
</uniform>
80+
<uniform>
81+
<name>u_ShadowClippingThreshold</name>
82+
<value>0.5</value>
83+
</uniform>
84+
<uniform>
85+
<name>u_TextureOffset</name>
86+
<value>
87+
<x>0</x>
88+
<y>0</y>
89+
</value>
90+
</uniform>
91+
<uniform>
92+
<name>u_TextureTiling</name>
93+
<value>
94+
<x>1</x>
95+
<y>1</y>
96+
</value>
97+
</uniform>
4298
</uniforms>
99+
<features></features>
43100
</root>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<root>
2+
<shader>:Shaders\Skysphere.ovfx</shader>
3+
<settings>
4+
<blendable>false</blendable>
5+
<backface_culling>false</backface_culling>
6+
<frontface_culling>true</frontface_culling>
7+
<depth_test>true</depth_test>
8+
<depth_writing>false</depth_writing>
9+
<color_writing>true</color_writing>
10+
<cast_shadows>false</cast_shadows>
11+
<receive_shadows>false</receive_shadows>
12+
<user_interface>false</user_interface>
13+
<gpu_instances>1</gpu_instances>
14+
</settings>
15+
<uniforms>
16+
<uniform>
17+
<name>u_Diffuse</name>
18+
<value>
19+
<x>1</x>
20+
<y>1</y>
21+
<z>1</z>
22+
<w>1</w>
23+
</value>
24+
</uniform>
25+
<uniform>
26+
<name>u_DiffuseMap</name>
27+
<value>:Textures\PureSky.hdr</value>
28+
</uniform>
29+
<uniform>
30+
<name>u_TextureOffset</name>
31+
<value>
32+
<x>0</x>
33+
<y>0</y>
34+
</value>
35+
</uniform>
36+
<uniform>
37+
<name>u_TextureTiling</name>
38+
<value>
39+
<x>1</x>
40+
<y>1</y>
41+
</value>
42+
</uniform>
43+
</uniforms>
44+
<features></features>
45+
</root>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#feature OUTLINE_PASS
2+
#feature PICKING_PASS
3+
4+
#shader vertex
5+
#version 450 core
6+
7+
#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
8+
#include ":Shaders/Common/Utils.ovfxh"
9+
10+
layout (location = 0) in vec3 geo_Pos;
11+
layout (location = 1) in vec2 geo_TexCoords;
12+
13+
out VS_OUT
14+
{
15+
vec3 FragPos;
16+
vec2 TexCoords;
17+
} vs_out;
18+
19+
void main()
20+
{
21+
vs_out.FragPos = ubo_ViewPos + geo_Pos * 1000.0f;
22+
vs_out.TexCoords = geo_TexCoords;
23+
24+
gl_Position = ubo_Projection * ubo_View * vec4(vs_out.FragPos, 1.0);
25+
}
26+
27+
#shader fragment
28+
#version 450 core
29+
30+
#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
31+
#include ":Shaders/Common/Utils.ovfxh"
32+
33+
in VS_OUT
34+
{
35+
vec3 FragPos;
36+
vec2 TexCoords;
37+
} fs_in;
38+
39+
uniform vec4 u_Diffuse = vec4(1.0);
40+
uniform sampler2D u_DiffuseMap;
41+
uniform vec2 u_TextureTiling = vec2(1.0);
42+
uniform vec2 u_TextureOffset = vec2(0.0);
43+
44+
#if defined(PICKING_PASS)
45+
uniform vec4 _PickingColor;
46+
#endif
47+
48+
#if defined(OUTLINE_PASS)
49+
uniform vec4 _OutlineColor;
50+
#endif
51+
52+
out vec4 FRAGMENT_COLOR;
53+
54+
void main()
55+
{
56+
#if defined(PICKING_PASS)
57+
// The skysphere cannot be picked.
58+
discard;
59+
#elif defined(OUTLINE_PASS)
60+
// The skysphere cannot be outlined.
61+
discard;
62+
#else
63+
vec2 texCoords = TileAndOffsetTexCoords(fs_in.TexCoords, u_TextureTiling, u_TextureOffset);
64+
FRAGMENT_COLOR = texture(u_DiffuseMap, texCoords) * u_Diffuse;
65+
#endif
66+
}

Resources/Engine/Textures/PureSky.hdr

19.7 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ENABLE_MIPMAPPING=false

Sources/Overload/OvCore/include/OvCore/Rendering/PostProcess/BloomEffect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace OvCore::Rendering::PostProcess
1717
*/
1818
struct BloomSettings : public EffectSettings
1919
{
20-
float threshold = 0.8f;
20+
float threshold = 1.0f;
2121
float radius = 5.0f;
2222
int kernelSize = 6;
2323
float intensity = 0.6f;

0 commit comments

Comments
 (0)