Fixed a bug where I was loading the wrong shader file for the screen shader, then made the kernel shader for the screen postprocessing.

This commit is contained in:
Zed A. Shaw 2026-09-03 14:35:25 -04:00
parent 6ef367c305
commit 9c75238461
3 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,38 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D screenTexture;
const float offset = 1.0 / 300.0;
void main()
{
vec2 offsets[9] = vec2[](
vec2(-offset, offset), // top-left
vec2( 0.0f, offset), // top-center
vec2( offset, offset), // top-right
vec2(-offset, 0.0f), // center-left
vec2( 0.0f, 0.0f), // center-center
vec2( offset, 0.0f), // center-right
vec2(-offset, -offset), // bottom-left
vec2( 0.0f, -offset), // bottom-center
vec2( offset, -offset) // bottom-right
);
float kernel[9] = float[](
1.0 / 16, 2.0 / 16, 1.0 / 16,
2.0 / 16, 4.0 / 16, 2.0 / 16,
1.0 / 16, 2.0 / 16, 1.0 / 16
);
vec3 col = vec3(0.0);
for(int i = 0; i < 9; i++) {
vec3 sampleTex = vec3(texture(screenTexture, TexCoords.st + offsets[i]));
col += sampleTex * kernel[i];
}
FragColor = vec4(col, 1.0);
}

View file

@ -41,7 +41,7 @@ struct Scene {
Scene(components::Scene& config):
shader{config.shader.vertex_path, config.shader.frag_path},
screen{.shader={config.screen_shader.vertex_path, config.shader.frag_path}},
screen{.shader={config.screen_shader.vertex_path, config.screen_shader.frag_path}},
materials{config.materials},
camera{
.position=config.camera.position,

View file

@ -43,6 +43,7 @@ void check_error(const std::string& what, unsigned int thing, GLenum check_type)
}
unsigned int Shader::load_shader(const std::string& filename, GLenum shader_type) {
dbc::log($F("Loading shader {}", filename));
dbc::check(fs::exists(filename),
std::format("shader file {} does not exist", filename));