diff --git a/Resources/Engine/Shaders/Blit.ovfx b/Resources/Engine/Shaders/Blit.ovfx index ef7037b1..901dff92 100644 --- a/Resources/Engine/Shaders/Blit.ovfx +++ b/Resources/Engine/Shaders/Blit.ovfx @@ -1,24 +1,26 @@ #shader vertex #version 430 core -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inUV; +layout(location = 0) in vec2 geo_Pos; +layout(location = 1) in vec2 geo_TexCoords; -out vec2 fragUV; +out vec2 TexCoords; -void main() { - fragUV = inUV; - gl_Position = vec4(inPos, 0.0, 1.0); +void main() +{ + TexCoords = geo_TexCoords; + gl_Position = vec4(geo_Pos, 0.0, 1.0); } #shader fragment #version 430 core -in vec2 fragUV; -out vec4 fragColor; // Output color +in vec2 TexCoords; +out vec4 FRAGMENT_COLOR; uniform sampler2D _InputTexture; -void main() { - fragColor = texture(_InputTexture, fragUV); +void main() +{ + FRAGMENT_COLOR = texture(_InputTexture, TexCoords); } \ No newline at end of file diff --git a/Resources/Engine/Shaders/PostProcess/Bloom.ovfx b/Resources/Engine/Shaders/PostProcess/Bloom.ovfx index 795590ed..2084a85b 100644 --- a/Resources/Engine/Shaders/PostProcess/Bloom.ovfx +++ b/Resources/Engine/Shaders/PostProcess/Bloom.ovfx @@ -1,28 +1,30 @@ #shader vertex #version 430 core -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inUV; +layout(location = 0) in vec2 geo_Pos; +layout(location = 1) in vec2 geo_TexCoords; -out vec2 fragUV; +out vec2 TexCoords; -void main() { - fragUV = inUV; - gl_Position = vec4(inPos, 0.0, 1.0); +void main() +{ + TexCoords = geo_TexCoords; + gl_Position = vec4(geo_Pos, 0.0, 1.0); } #shader fragment #version 430 core -in vec2 fragUV; -out vec4 fragColor; // Output color +in vec2 TexCoords; +out vec4 FRAGMENT_COLOR; -uniform sampler2D _InputTexture; // Original scene texture -uniform sampler2D _BloomTexture; // Blurred bloom texture -uniform float _BloomIntensity; // Strength of bloom effect +uniform sampler2D _InputTexture; +uniform sampler2D _BloomTexture; +uniform float _BloomIntensity; -void main() { - vec3 sceneColor = texture(_InputTexture, fragUV).rgb; - vec3 bloomColor = texture(_BloomTexture, fragUV).rgb; - fragColor = vec4(sceneColor + _BloomIntensity * bloomColor, 1.0); +void main() +{ + const vec3 sceneColor = texture(_InputTexture, TexCoords).rgb; + const vec3 bloomColor = texture(_BloomTexture, TexCoords).rgb; + FRAGMENT_COLOR = vec4(sceneColor + _BloomIntensity * bloomColor, 1.0); } diff --git a/Resources/Engine/Shaders/PostProcess/Blur.ovfx b/Resources/Engine/Shaders/PostProcess/Blur.ovfx index 745b7d87..45b7441a 100644 --- a/Resources/Engine/Shaders/PostProcess/Blur.ovfx +++ b/Resources/Engine/Shaders/PostProcess/Blur.ovfx @@ -1,44 +1,43 @@ #shader vertex #version 430 core -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inUV; +layout(location = 0) in vec2 geo_Pos; +layout(location = 1) in vec2 geo_TexCoords; -out vec2 fragUV; +out vec2 TexCoords; -void main() { - fragUV = inUV; - gl_Position = vec4(inPos, 0.0, 1.0); +void main() +{ + TexCoords = geo_TexCoords; + gl_Position = vec4(geo_Pos, 0.0, 1.0); } #shader fragment #version 430 core -in vec2 fragUV; -out vec4 fragColor; // Output color +in vec2 TexCoords; +out vec4 FRAGMENT_COLOR; -uniform sampler2D _InputTexture; // Input texture -uniform bool _Horizontal; // Blur direction: horizontal or vertical +uniform sampler2D _InputTexture; +uniform bool _Horizontal; +uniform float _BlurSize; +uniform int _KernelSize; -uniform float _BlurSize; // Controls the spread of the blur -uniform int _KernelSize; // Number of samples in the blur kernel - -void main() { - vec2 texelSize = 1.0 / textureSize(_InputTexture, 0); // Size of one texel in UV coordinates - vec2 direction = _Horizontal ? vec2(texelSize.x, 0.0) : vec2(0.0, texelSize.y); +void main() +{ + const vec2 texelSize = 1.0 / textureSize(_InputTexture, 0); + const vec2 direction = _Horizontal ? vec2(texelSize.x, 0.0) : vec2(0.0, texelSize.y); vec4 color = vec4(0.0); float totalWeight = 0.0; - // Loop through the kernel - for (int i = -_KernelSize; i <= _KernelSize; i++) { + for (int i = -_KernelSize; i <= _KernelSize; i++) + { float weight = exp(-0.5 * (i * i) / (_BlurSize * _BlurSize)); vec2 offset = float(i) * direction; - color += texture(_InputTexture, fragUV + offset) * weight; + color += texture(_InputTexture, TexCoords + offset) * weight; totalWeight += weight; } - // Normalize the result - fragColor = color / totalWeight; + FRAGMENT_COLOR = color / totalWeight; } - diff --git a/Resources/Engine/Shaders/PostProcess/Brightness.ovfx b/Resources/Engine/Shaders/PostProcess/Brightness.ovfx index e49a4e5c..4cbe0511 100644 --- a/Resources/Engine/Shaders/PostProcess/Brightness.ovfx +++ b/Resources/Engine/Shaders/PostProcess/Brightness.ovfx @@ -1,33 +1,35 @@ #shader vertex #version 430 core -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inUV; +layout(location = 0) in vec2 geo_Pos; +layout(location = 1) in vec2 geo_TexCoords; -out vec2 fragUV; +out vec2 TexCoords; -void main() { - fragUV = inUV; - gl_Position = vec4(inPos, 0.0, 1.0); +void main() +{ + TexCoords = geo_TexCoords; + gl_Position = vec4(geo_Pos, 0.0, 1.0); } #shader fragment #version 430 core -in vec2 fragUV; -out vec4 fragColor; // Output color +in vec2 TexCoords; +out vec4 FRAGMENT_COLOR; -uniform sampler2D _InputTexture; // Input scene texture -uniform float _Threshold; // Brightness threshold +uniform sampler2D _InputTexture; +uniform float _Threshold; float luminance(vec3 color) { return dot(color, vec3(0.2126, 0.7152, 0.0722)); } -void main() { - vec3 color = texture(_InputTexture, fragUV).rgb; +void main() +{ + const vec3 color = texture(_InputTexture, TexCoords).rgb; float brightness = luminance(color); brightness = max(0.0, brightness - _Threshold); - fragColor = vec4(color * sign(brightness), 1.0); + FRAGMENT_COLOR = vec4(color * sign(brightness), 1.0); } diff --git a/Resources/Engine/Shaders/PostProcess/FXAA.ovfx b/Resources/Engine/Shaders/PostProcess/FXAA.ovfx index 7d79964b..728176ff 100644 --- a/Resources/Engine/Shaders/PostProcess/FXAA.ovfx +++ b/Resources/Engine/Shaders/PostProcess/FXAA.ovfx @@ -1,26 +1,27 @@ #shader vertex #version 430 core -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inUV; +layout(location = 0) in vec2 geo_Pos; +layout(location = 1) in vec2 geo_TexCoords; -out vec2 fragUV; +out vec2 TexCoords; -void main() { - fragUV = inUV; - gl_Position = vec4(inPos, 0.0, 1.0); +void main() +{ + TexCoords = geo_TexCoords; + gl_Position = vec4(geo_Pos, 0.0, 1.0); } #shader fragment #version 430 core -in vec2 fragUV; -out vec4 fragColor; +in vec2 TexCoords; +out vec4 FRAGMENT_COLOR; uniform sampler2D _InputTexture; -// FXAA function -vec3 applyFXAA(sampler2D tex, vec2 uv) { +vec3 applyFXAA(sampler2D tex, vec2 uv) +{ vec2 resolution = vec2(textureSize(tex, 0)); vec2 pixelSize = 1.0 / resolution; @@ -43,7 +44,9 @@ vec3 applyFXAA(sampler2D tex, vec2 uv) { float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); float lumaRange = lumaMax - lumaMin; - if (lumaRange < 0.1) { // Threshold for edge detection + // Threshold for edge detection + if (lumaRange < 0.1) + { return rgbM; // No significant edge, return original } @@ -62,6 +65,7 @@ vec3 applyFXAA(sampler2D tex, vec2 uv) { texture(tex, uv + dir * (1.0 / 3.0 - 0.5)).rgb + texture(tex, uv + dir * (2.0 / 3.0 - 0.5)).rgb ); + vec3 rgbB = rgbA * 0.5 + 0.25 * ( texture(tex, uv + dir * -0.5).rgb + texture(tex, uv + dir * 0.5).rgb @@ -72,6 +76,7 @@ vec3 applyFXAA(sampler2D tex, vec2 uv) { return (lumaB < lumaMin || lumaB > lumaMax) ? rgbA : rgbB; } -void main() { - fragColor = vec4(applyFXAA(_InputTexture, fragUV), 1.0); +void main() +{ + FRAGMENT_COLOR = vec4(applyFXAA(_InputTexture, TexCoords), 1.0); } \ No newline at end of file diff --git a/Resources/Engine/Shaders/PostProcess/Tonemapping.ovfx b/Resources/Engine/Shaders/PostProcess/Tonemapping.ovfx index aca60d2c..60995e5b 100644 --- a/Resources/Engine/Shaders/PostProcess/Tonemapping.ovfx +++ b/Resources/Engine/Shaders/PostProcess/Tonemapping.ovfx @@ -1,21 +1,21 @@ #shader vertex #version 430 core -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inUV; +layout(location = 0) in vec2 geo_Pos; +layout(location = 1) in vec2 geo_TexCoords; -out vec2 fragUV; +out vec2 TexCoords; void main() { - fragUV = inUV; - gl_Position = vec4(inPos, 0.0, 1.0); + TexCoords = geo_TexCoords; + gl_Position = vec4(geo_Pos, 0.0, 1.0); } #shader fragment #version 430 core -in vec2 fragUV; -out vec4 fragColor; +in vec2 TexCoords; +out vec4 FRAGMENT_COLOR; uniform sampler2D _InputTexture; uniform float _Exposure; @@ -67,12 +67,12 @@ vec3 reinhard_jodie(vec3 v) vec3 uncharted2_tonemap_partial(vec3 x) { - float A = 0.15f; - float B = 0.50f; - float C = 0.10f; - float D = 0.20f; - float E = 0.02f; - float F = 0.30f; + const float A = 0.15f; + const float B = 0.50f; + const float C = 0.10f; + const float D = 0.20f; + const float E = 0.02f; + const float F = 0.30f; return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; } @@ -98,7 +98,7 @@ vec3 ACESFilm(vec3 x) void main() { - vec3 color = texture(_InputTexture, fragUV).rgb * _Exposure; + vec3 color = texture(_InputTexture, TexCoords).rgb * _Exposure; switch(_Mode) { @@ -115,5 +115,5 @@ void main() color = applyGammaCorrection(color); } - fragColor = vec4(color, 1.0); + FRAGMENT_COLOR = vec4(color, 1.0); }