renderer: Pass frame dimmensions to damage shader

shader-damage-experiments
Andri Yngvason 2020-03-29 14:29:06 +00:00
parent dc7adf8f3b
commit 96e8c63042
3 changed files with 21 additions and 1 deletions

View File

@ -59,6 +59,8 @@ struct renderer {
GLuint program;
GLint u_tex0;
GLint u_tex1;
GLint u_width;
GLint u_height;
} damage_shader;
};

View File

@ -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);
}

View File

@ -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);