Skip to content

Commit

Permalink
Minor post processing improvement and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
voldien committed Feb 12, 2025
1 parent f852cca commit 31095f9
Show file tree
Hide file tree
Showing 50 changed files with 599 additions and 521 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ Usage:

- **Screen Space Ambient Occlusion**

- **Guassian Blur**

- **FXAA**
- **Gaussian/Box Blur**

- **Mist Fog**

Expand All @@ -192,6 +190,8 @@ Usage:

- **Grain**

- **Bloom**

## Build Instruction

```bash
Expand Down
5 changes: 2 additions & 3 deletions Shaders/common/fog_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ float getFogFactor(const in FogSettings fog_settings, const float depth) {
}
}

float getFogFactor(const in FogSettings fog_settings) { return getFogFactor(fog_settings, gl_FragCoord.z); }
float getFogFactor(const in FogSettings fog_settings) { return getFogFactor(fog_settings, gl_FragCoord.z) * fog_settings.fogItensity; }

vec4 blendFog(const in vec4 color, const in FogSettings fogSettings) {
const float fog_factor = getFogFactor(fogSettings) * fogSettings.fogItensity;

const float fog_factor = getFogFactor(fogSettings);
return mix(color, fogSettings.fogColor, fog_factor);
}

Expand Down
18 changes: 13 additions & 5 deletions Shaders/common/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "light.glsl"
#include "material.glsl"

struct tessellation_settings {
float tessLevel;
float gDispFactor;
};

struct global_rendering_settings {
vec4 ambientColor;
FogSettings fogSettings;
Expand All @@ -24,11 +29,6 @@ struct Node {
mat4 model;
};

struct tessellation_settings {
float tessLevel;
float gDispFactor;
};

struct light_settings {
DirectionalLight directional[16];
PointLight point[64];
Expand Down Expand Up @@ -76,4 +76,12 @@ layout(binding = 12) uniform sampler2D brdfLUT;
material getMaterial() { return MaterialUBO.materials[0]; }
mat4 getModel() { return NodeUBO.node[0].model; }

uint getDirectionalLightCount() { return LightUBO.light.directionalCount; }
uint getPointLightCount() { return LightUBO.light.pointCount; }

DirectionalLight getDirectional(const in int index) { return LightUBO.light.directional[index]; }
PointLight getPointLight(const in int index) { return LightUBO.light.point[index]; }

Camera getCamera() {return constantCommon.constant.camera;}

#endif
4 changes: 1 addition & 3 deletions Shaders/mandelbrot/julia.comp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,5 @@ void main() {

const vec4 pixel = computeMandel(uv);

/* Apply gamma correction. */
const float gamma = 2.2;
imageStore(img_output, pixel_coords, pow(pixel, vec4(1.0 / gamma)));
imageStore(img_output, pixel_coords, pixel);
}
6 changes: 1 addition & 5 deletions Shaders/mandelbrot/mandelbrot.comp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ layout(set = 0, binding = 1, std140) uniform UniformBufferBlock {
}
ubo;



/* */
vec2 squareImaginary(in const vec2 number) {
return vec2((number.x * number.x) - (number.y * number.y), 2 * number.x * number.y);
Expand Down Expand Up @@ -83,7 +81,5 @@ void main() {

const vec4 pixel = computeMandel(uv);

/* Apply gamma correction. */
const float gamma = 2.2;
imageStore(img_output, pixel_coords, pow(pixel, vec4(1.0 / gamma)));
imageStore(img_output, pixel_coords, pixel);
}
2 changes: 1 addition & 1 deletion Shaders/postprocessingeffects/box_blur.comp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ layout(push_constant) uniform Settings {
settings;

#include "postprocessing_base.glsl"
layout(constant_id = 16) const int MAX_SAMPLES = 7 + 7 + 1;
layout(constant_id = 16) const int MAX_SAMPLES = 9 * 9 + 1;

void main() {

Expand Down
3 changes: 3 additions & 0 deletions Shaders/postprocessingeffects/color/sepia.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#version 460
#extension GL_ARB_separate_shader_objects : enable

precision mediump float;
precision mediump int;

layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec2 screenUV;

Expand Down
112 changes: 0 additions & 112 deletions Shaders/postprocessingeffects/gaussian_blur.comp

This file was deleted.

79 changes: 19 additions & 60 deletions Shaders/postprocessingeffects/guassian_blur_horizontal.comp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ precision mediump int;

layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;

layout(set = 0, binding = 0) uniform sampler2D ColorTexture0;
layout(set = 0, binding = 1, rgba16f) uniform coherent image2D ColorTexture;
layout(set = 0, binding = 2, rgba16f) uniform coherent image2D TargetTexture;
layout(set = 0, binding = 0) uniform sampler2D ColorTexture;
layout(set = 0, binding = 1, rgba16f) uniform coherent image2D TargetTexture;

layout(constant_id = 16) const int MAX_SAMPLES = 9 * 9 + 1;

Expand All @@ -30,83 +29,43 @@ settings;

#include "postprocessing_base.glsl"

const uint work_group_nr_samples = (16 + (MAX_SAMPLES - 1) / 2) * (16 + (MAX_SAMPLES - 1) / 2);
shared vec4 localResult[work_group_nr_samples];
shared vec4 localResult2[work_group_nr_samples];

vec4 blurHorizontal(const in float radius, const in float variance, const in int samples) {
int y;

const ivec2 resolution = imageSize(ColorTexture);
vec4 blurVertical(const in float radius, const in float variance, const in int samples) {

const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy);
const vec2 resolution = textureSize(ColorTexture, 0);

const int start = clamp(-((samples - 1) / 2), -MAX_SAMPLES, -1);
const int end = clamp(((samples - 1) / 2), 1, MAX_SAMPLES);
const vec2 texelSize = 1.0 / resolution;
const vec2 TexCoord = vec2(gl_GlobalInvocationID.xy) * texelSize;

vec4 color1 = vec4(0.0);
float total = EPSILON;

for (y = start; y <= end; y++) {

const ivec2 uv = TexCoord + ivec2(vec2(0, y) * radius);
const uint guassIndex = (y + -start);
const float guas = settings.kernel[guassIndex]; // getGuas2D(0, y, variance);
for (uint x = 0; x < samples; x++) {
const vec2 uvP = TexCoord + vec2(0, texelSize.y * x) * radius;
const vec2 uvN = TexCoord + vec2(0, -texelSize.y * x) * radius;

color1 += imageLoad(ColorTexture, uv).rgba * vec4(guas.xxx, 1.0);
}

return color1;
}

vec4 blurVertical(const in float radius, const in float variance, const in int samples) {
int x;
const uint guassPIndex = clamp(samples + x, 0, MAX_SAMPLES - 1);
const uint guassNIndex = clamp(samples - x, 0, MAX_SAMPLES - 1);

const ivec2 resolution = imageSize(ColorTexture);
const float guasP = settings.kernel[guassPIndex];
const float guasN = settings.kernel[guassNIndex];

const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy);

const int start = clamp(-((samples - 1) / 2), -MAX_SAMPLES, -1);
const int end = clamp(((samples - 1) / 2), 1, MAX_SAMPLES);

vec4 color1 = vec4(0.0);
float total = EPSILON;

for (x = start; x <= end; x++) {
const ivec2 uv = TexCoord + ivec2(vec2(x, 0) * radius);
const uint guassIndex = (x + -start);
const float guas = settings.kernel[guassIndex];

color1 += imageLoad(ColorTexture, uv).rgba * vec4(vec3(guas), 1.0);
color1 += texture(ColorTexture, uvP).rgba * vec4(guasP.xxx, 1.0);
color1 += texture(ColorTexture, uvN).rgba * vec4(guasN.xxx, 1.0);
}

// Normalize color.
return color1;
}

void main() {

/* */
if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(ColorTexture)))) {
if (any(greaterThan(gl_GlobalInvocationID.xy, imageSize(TargetTexture)))) {
return;
}

const uint samples = min(settings.samples, MAX_SAMPLES / 2);
const uint samples = min(settings.samples, MAX_SAMPLES);
const ivec2 TexCoord = ivec2(gl_GlobalInvocationID.xy);

/* Vertical Blur. */
{
const vec4 verticalBlur = blurVertical(settings.radius, settings.variance, settings.samples);
memoryBarrierImage();
imageStore(ColorTexture, TexCoord, vec4(verticalBlur.rgb, 1.0));
}

//barrier();

/* Horizontal Blur. */
{
const vec4 blurHorizontalBlur = blurHorizontal(settings.radius, settings.variance, settings.samples);
memoryBarrierImage();
imageStore(ColorTexture, TexCoord, vec4(blurHorizontalBlur.rgb, 1.0));
}
const vec4 verticalBlur = blurVertical(settings.radius, settings.variance, settings.samples / 2);
imageStore(TargetTexture, TexCoord, vec4(verticalBlur.rgb, 1.0));
}
Loading

0 comments on commit 31095f9

Please sign in to comment.