Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 56 additions & 51 deletions Resources/Editor/Shaders/Grid.ovfx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ layout (location = 2) in vec3 geo_Normal;

layout (std140) uniform EngineUBO
{
mat4 ubo_Model;
mat4 ubo_View;
mat4 ubo_Projection;
vec3 ubo_ViewPos;
float ubo_Time;
mat4 ubo_Model;
mat4 ubo_View;
mat4 ubo_Projection;
vec3 ubo_ViewPos;
float ubo_Time;
};

out VS_OUT
Expand All @@ -22,9 +22,8 @@ out VS_OUT

void main()
{
vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
vs_out.TexCoords = vs_out.FragPos.xz;

vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
vs_out.TexCoords = vs_out.FragPos.xz;
gl_Position = ubo_Projection * ubo_View * vec4(vs_out.FragPos, 1.0);
}

Expand All @@ -35,11 +34,11 @@ out vec4 FRAGMENT_COLOR;

layout (std140) uniform EngineUBO
{
mat4 ubo_Model;
mat4 ubo_View;
mat4 ubo_Projection;
vec3 ubo_ViewPos;
float ubo_Time;
mat4 ubo_Model;
mat4 ubo_View;
mat4 ubo_Projection;
vec3 ubo_ViewPos;
float ubo_Time;
};

in VS_OUT
Expand All @@ -50,49 +49,55 @@ in VS_OUT

uniform vec3 u_Color;

float MAG(float p_lp)
float MAG(float lineWidth, float p_lp)
{
const float lineWidth = 1.0f;

const vec2 coord = fs_in.TexCoords / p_lp;
const vec2 grid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
const float line = min(grid.x, grid.y);
const float lineResult = lineWidth - min(line, lineWidth);

return lineResult;
const vec2 coord = fs_in.TexCoords / p_lp;
const vec2 grid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
const float line = min(grid.x, grid.y);
const float lineResult = lineWidth - min(line, lineWidth);
return lineResult;
}

float Grid(float height, float a, float b, float c)
float Grid(float lineWidth, float height, float a, float b, float c)
{
const float cl = MAG(a);
const float ml = MAG(b);
const float fl = MAG(c);

const float cmit = 10.0f;
const float cmet = 40.0f;
const float mfit = 80.0f;
const float mfet = 160.0f;

const float df = clamp((height - cmit) / (cmet - cmit), 0.0f, 1.0f);
const float dff = clamp((height - mfit) / (mfet - mfit), 0.0f, 1.0f);

const float inl = mix(cl, ml, df);
const float fnl = mix(inl, fl, dff);

return fnl;
const float cl = MAG(lineWidth, a);
const float ml = MAG(lineWidth, b);
const float fl = MAG(lineWidth, c);
const float cmit = 10.0f;
const float cmet = 40.0f;
const float mfit = 80.0f;
const float mfet = 160.0f;
const float df = clamp((height - cmit) / (cmet - cmit), 0.0f, 1.0f);
const float dff = clamp((height - mfit) / (mfet - mfit), 0.0f, 1.0f);
const float inl = mix(cl, ml, df);
const float fnl = mix(inl, fl, dff);
return fnl;
}

void main()
{
const float height = distance(ubo_ViewPos.y, fs_in.FragPos.y);

const float gridA = Grid(height, 1.0f, 4.0f, 8.0f);
const float gridB = Grid(height, 4.0f, 16.0f, 32.0f);

const float grid = gridA * 0.5f + gridB;

const vec2 viewdirW = ubo_ViewPos.xz - fs_in.FragPos.xz;
const float viewdist = length(viewdirW);

FRAGMENT_COLOR = vec4(u_Color, grid);
}
const float height = distance(ubo_ViewPos.y, fs_in.FragPos.y);
const float gridA = Grid(0.5f, height, 1.0f, 4.0f, 8.0f);
const float gridB = Grid(0.7f, height, 4.0f, 16.0f, 32.0f);
const float grid = gridA * 0.7f + gridB * 0.7f;

// Calculate view direction vector (from camera to fragment)
const vec3 viewDir = normalize(fs_in.FragPos - ubo_ViewPos);

// Calculate how parallel the view direction is to the horizon
// When looking at horizon, viewDir.y will be close to 0
const float horizonFactor = abs(viewDir.y);

// Define how much we want to fade when looking at horizon
const float horizonMinFade = 0.02f; // Minimum fade at horizon
const float horizonFadeStart = 0.0f; // Start fading at this angle
const float horizonFadeEnd = 1.0f; // Full grid strength at this angle

// Calculate horizon fade factor (1.0 = full grid, 0.0 = fully faded)
const float horizonFade =
horizonMinFade
+ (1.0f - horizonMinFade)
* smoothstep(horizonFadeStart, horizonFadeEnd, horizonFactor);

FRAGMENT_COLOR = vec4(u_Color, grid * horizonFade);
}
93 changes: 75 additions & 18 deletions Resources/Engine/Materials/Default.ovmat
Original file line number Diff line number Diff line change
@@ -1,43 +1,100 @@
<root>
<shader>:Shaders\Standard.ovfx</shader>
<shader>:Shaders\StandardPBR.ovfx</shader>
<settings>
<blendable>false</blendable>
<backface_culling>true</backface_culling>
<frontface_culling>false</frontface_culling>
<depth_test>true</depth_test>
<depth_writing>true</depth_writing>
<color_writing>true</color_writing>
<cast_shadows>true</cast_shadows>
<receive_shadows>true</receive_shadows>
<user_interface>false</user_interface>
<gpu_instances>1</gpu_instances>
<cast_shadows>1</cast_shadows>
<receive_shadows>1</receive_shadows>
</settings>
<uniforms>
<uniform>
<name>diffuseColor</name>
<name>_LightSpaceMatrix</name>
</uniform>
<uniform>
<name>_ShadowMap</name>
<value>?</value>
</uniform>
<uniform>
<name>u_Albedo</name>
<value>
<x>1</x>
<y>0.99998999</y>
<z>0.99998999</z>
<w>0</w>
<y>1</y>
<z>1</z>
<w>1</w>
</value>
</uniform>
<uniform>
<name>diffuseTexture</name>
<name>u_AlbedoMap</name>
<value>?</value>
</uniform>
<uniform>
<name>specularColor</name>
<value>
<x>1e-06</x>
<y>9.9998999e-07</y>
<z>9.9998999e-07</z>
<w>0</w>
</value>
<name>u_AlphaClippingThreshold</name>
<value>0.1</value>
</uniform>
<uniform>
<name>u_AmbientOcclusionMap</name>
<value>?</value>
</uniform>
<uniform>
<name>shineness</name>
<value>64</value>
<name>u_HeightMap</name>
<value>?</value>
</uniform>
<uniform>
<name>u_HeightScale</name>
<value>0.050000001</value>
</uniform>
<uniform>
<name>u_MaskMap</name>
<value>?</value>
</uniform>
<uniform>
<name>u_Metallic</name>
<value>0</value>
</uniform>
<uniform>
<name>specularTexture</name>
<name>u_MetallicMap</name>
<value>?</value>
</uniform>
<uniform>
<name>u_NormalMap</name>
<value>?</value>
</uniform>
<uniform>
<name>u_ParallaxClipEdges</name>
<value>0</value>
</uniform>
<uniform>
<name>u_Roughness</name>
<value>0.5</value>
</uniform>
<uniform>
<name>u_RoughnessMap</name>
<value>?</value>
</uniform>
<uniform>
<name>u_ShadowClippingThreshold</name>
<value>0.5</value>
</uniform>
<uniform>
<name>u_TextureOffset</name>
<value>
<x>0</x>
<y>0</y>
</value>
</uniform>
<uniform>
<name>u_TextureTiling</name>
<value>
<x>1</x>
<y>1</y>
</value>
</uniform>
</uniforms>
<features></features>
</root>
45 changes: 45 additions & 0 deletions Resources/Engine/Materials/Skysphere.ovmat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<root>
<shader>:Shaders\Skysphere.ovfx</shader>
<settings>
<blendable>false</blendable>
<backface_culling>false</backface_culling>
<frontface_culling>true</frontface_culling>
<depth_test>true</depth_test>
<depth_writing>false</depth_writing>
<color_writing>true</color_writing>
<cast_shadows>false</cast_shadows>
<receive_shadows>false</receive_shadows>
<user_interface>false</user_interface>
<gpu_instances>1</gpu_instances>
</settings>
<uniforms>
<uniform>
<name>u_Diffuse</name>
<value>
<x>1</x>
<y>1</y>
<z>1</z>
<w>1</w>
</value>
</uniform>
<uniform>
<name>u_DiffuseMap</name>
<value>:Textures\PureSky.hdr</value>
</uniform>
<uniform>
<name>u_TextureOffset</name>
<value>
<x>0</x>
<y>0</y>
</value>
</uniform>
<uniform>
<name>u_TextureTiling</name>
<value>
<x>1</x>
<y>1</y>
</value>
</uniform>
</uniforms>
<features></features>
</root>
66 changes: 66 additions & 0 deletions Resources/Engine/Shaders/Skysphere.ovfx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#feature OUTLINE_PASS
#feature PICKING_PASS

#shader vertex
#version 450 core

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Utils.ovfxh"

layout (location = 0) in vec3 geo_Pos;
layout (location = 1) in vec2 geo_TexCoords;

out VS_OUT
{
vec3 FragPos;
vec2 TexCoords;
} vs_out;

void main()
{
vs_out.FragPos = ubo_ViewPos + geo_Pos * 1000.0f;
vs_out.TexCoords = geo_TexCoords;

gl_Position = ubo_Projection * ubo_View * vec4(vs_out.FragPos, 1.0);
}

#shader fragment
#version 450 core

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Utils.ovfxh"

in VS_OUT
{
vec3 FragPos;
vec2 TexCoords;
} fs_in;

uniform vec4 u_Diffuse = vec4(1.0);
uniform sampler2D u_DiffuseMap;
uniform vec2 u_TextureTiling = vec2(1.0);
uniform vec2 u_TextureOffset = vec2(0.0);

#if defined(PICKING_PASS)
uniform vec4 _PickingColor;
#endif

#if defined(OUTLINE_PASS)
uniform vec4 _OutlineColor;
#endif

out vec4 FRAGMENT_COLOR;

void main()
{
#if defined(PICKING_PASS)
// The skysphere cannot be picked.
discard;
#elif defined(OUTLINE_PASS)
// The skysphere cannot be outlined.
discard;
#else
vec2 texCoords = TileAndOffsetTexCoords(fs_in.TexCoords, u_TextureTiling, u_TextureOffset);
FRAGMENT_COLOR = texture(u_DiffuseMap, texCoords) * u_Diffuse;
#endif
}
Binary file added Resources/Engine/Textures/PureSky.hdr
Binary file not shown.
1 change: 1 addition & 0 deletions Resources/Engine/Textures/PureSky.hdr.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENABLE_MIPMAPPING=false
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace OvCore::Rendering::PostProcess
*/
struct BloomSettings : public EffectSettings
{
float threshold = 0.8f;
float threshold = 1.0f;
float radius = 5.0f;
int kernelSize = 6;
float intensity = 0.6f;
Expand Down
Loading