diff --git a/include/render.h b/include/render.h index f11d18e..c3d9e08 100644 --- a/include/render.h +++ b/include/render.h @@ -59,6 +59,8 @@ struct renderer { GLuint program; GLint u_tex0; GLint u_tex1; + GLint u_width; + GLint u_height; } damage_shader; }; diff --git a/shaders/damage-fragment.glsl b/shaders/damage-fragment.glsl index 25020b8..05837ee 100644 --- a/shaders/damage-fragment.glsl +++ b/shaders/damage-fragment.glsl @@ -3,10 +3,18 @@ precision mediump float; uniform sampler2D u_tex0; uniform sampler2D u_tex1; +uniform int u_width; +uniform int u_height; + varying vec2 v_texture; +bool is_damaged(vec2 pos) +{ + return texture2D(u_tex0, pos).rgb != texture2D(u_tex1, pos).rgb; +} + void main() { - float r = float(texture2D(u_tex0, v_texture).rgb != texture2D(u_tex1, v_texture).rgb); + float r = float(is_damaged(v_texture)); gl_FragColor = vec4(r); } diff --git a/src/render.c b/src/render.c index 3892800..c64e4f8 100644 --- a/src/render.c +++ b/src/render.c @@ -423,6 +423,12 @@ void render_damage(struct renderer* self) glUniform1i(self->damage_shader.u_tex0, 0); glUniform1i(self->damage_shader.u_tex1, 1); + uint32_t width = output_get_transformed_width(self->output); + uint32_t height = output_get_transformed_height(self->output); + + glUniform1i(self->damage_shader.u_width, width); + glUniform1i(self->damage_shader.u_height, height); + gl_draw(); glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -605,6 +611,10 @@ int renderer_init(struct renderer* self, const struct output* output, glGetUniformLocation(self->damage_shader.program, "u_tex0"); self->damage_shader.u_tex1 = glGetUniformLocation(self->damage_shader.program, "u_tex1"); + self->damage_shader.u_width = + glGetUniformLocation(self->damage_shader.program, "u_width"); + self->damage_shader.u_height = + glGetUniformLocation(self->damage_shader.program, "u_height"); self->output = output; glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &self->read_format);