Skip to content

Commit

Permalink
fix rendering of lasers and a few effects during view shake
Browse files Browse the repository at this point in the history
this is a regression introduced in eea6aa0
  • Loading branch information
Akaricchi committed Apr 14, 2019
1 parent 48b0e31 commit f554768
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/00-taisei.pkgdir/shader/lasers/common.vert.glslh
Expand Up @@ -19,7 +19,7 @@ void main(void) {
vec2 d = p - pos_rule(gl_InstanceID * 0.5 + timeshift - 0.1);

vec2 pos = laser_vertex_pos(p, d);
gl_Position = r_modelViewMatrix * r_projectionMatrix * vec4(pos, 0.0, 1.0);
gl_Position = r_projectionMatrix * r_modelViewMatrix * vec4(pos, 0.0, 1.0);
texCoord = (r_textureMatrix * vec4(texCoordRawIn, 0.0, 1.0)).xy;
texCoordRaw = texCoordRawIn;
}
3 changes: 3 additions & 0 deletions src/laser.c
Expand Up @@ -285,6 +285,8 @@ static void lasers_ent_predraw_hook(EntityInterface *ent, void *arg) {

FBPair *fbpair = stage_get_fbpair(FBPAIR_FG_AUX);

stage_draw_begin_noshake();

r_framebuffer(lasers.saved_fb);
r_state_push();

Expand Down Expand Up @@ -327,6 +329,7 @@ static void lasers_ent_predraw_hook(EntityInterface *ent, void *arg) {
draw_framebuffer_tex(fbpair->front, VIEWPORT_W, VIEWPORT_H);

r_state_pop();
stage_draw_end_noshake();
lasers.saved_fb = NULL;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/player.c
Expand Up @@ -642,7 +642,9 @@ static void powersurge_distortion_draw(Projectile *p, int t) {
r_shader_standard();
r_color4(1.0, 0.9, 0.8, 1.0);
r_blend(BLEND_PREMUL_ALPHA);
stage_draw_begin_noshake();
draw_framebuffer_tex(fb_aux, VIEWPORT_W, VIEWPORT_H);
stage_draw_end_noshake();
}

static void player_powersurge_expired(Player *plr) {
Expand Down
4 changes: 4 additions & 0 deletions src/plrmodes/marisa_a.c
Expand Up @@ -230,6 +230,8 @@ static void marisa_laser_renderer_visual(Enemy *renderer, int t, bool render) {
r_blend(BLEND_PREMUL_ALPHA);
fbpair_swap(fbp_aux);

stage_draw_begin_noshake();

r_framebuffer(fbp_aux->back);
r_clear(CLEAR_COLOR, RGBA(0, 0, 0, 0), 1);
r_shader("max_to_alpha");
Expand All @@ -242,6 +244,8 @@ static void marisa_laser_renderer_visual(Enemy *renderer, int t, bool render) {
draw_framebuffer_tex(fbp_aux->front, VIEWPORT_W, VIEWPORT_H);
r_shader_ptr(shader);

stage_draw_end_noshake();

r_uniform_vec4(u_clr0, 0.5, 0.0, 0.0, 0.0);
r_uniform_vec4(u_clr1, 1.0, 0.0, 0.0, 0.0);

Expand Down
36 changes: 36 additions & 0 deletions src/stagedraw.c
Expand Up @@ -970,6 +970,42 @@ static inline void end_viewport_shake(void) {
}
}

/*
* Small helpers for entities draw code that might want to suppress viewport shake temporarily.
* This is mostly useful when multiple framebuffers are involved.
*/
static int shake_suppressed = 0;

void stage_draw_begin_noshake(void) {
assert(!shake_suppressed);
shake_suppressed = 1;

if(global.shake_view) {
shake_suppressed = 2;
MatrixMode mm = r_mat_mode_current();
r_mat_mode(MM_MODELVIEW);
r_mat_push();
r_mat_identity();
r_mat_mode(mm);
}
}

void stage_draw_end_noshake(void) {
assert(shake_suppressed);

if(global.shake_view) {
// make sure shake_view doesn't change in-between the begin/end calls;
// that would've been *really* nasty to debug.
assert(shake_suppressed == 2);
MatrixMode mm = r_mat_mode_current();
r_mat_mode(MM_MODELVIEW);
r_mat_pop();
r_mat_mode(mm);
}

shake_suppressed = 0;
}

void stage_draw_viewport(void) {
FloatRect dest_vp;
r_framebuffer_viewport_current(r_framebuffer_current(), &dest_vp);
Expand Down
3 changes: 3 additions & 0 deletions src/stagedraw.h
Expand Up @@ -32,6 +32,9 @@ bool stage_should_draw_particle(Projectile *p);

void stage_display_clear_screen(const StageClearBonus *bonus);

void stage_draw_begin_noshake(void);
void stage_draw_end_noshake(void);

FBPair* stage_get_fbpair(StageFBPair id) attr_returns_nonnull;
Framebuffer* stage_add_foreground_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]);
Framebuffer* stage_add_background_framebuffer(const char *label, float scale_worst, float scale_best, uint num_attachments, FBAttachmentConfig attachments[num_attachments]);
Expand Down
8 changes: 8 additions & 0 deletions src/stages/stage6_events.c
Expand Up @@ -780,7 +780,9 @@ static void BaryonCenter(Enemy *bcenter, int t, bool render) {
return;
}

stage_draw_begin_noshake();
r_state_push();

r_shader("baryon_feedback");
r_uniform_vec2("blur_resolution", 0.5*VIEWPORT_W, 0.5*VIEWPORT_H);
r_uniform_float("hue_shift", 0);
Expand All @@ -792,6 +794,7 @@ static void BaryonCenter(Enemy *bcenter, int t, bool render) {
// r_uniform_float("hue_shift", 0.04 * sin(global.frames/30.0));
r_uniform_float("hue_shift", 0.01);
r_color4(0.95, 0.88, 0.9, 0.5);

draw_framebuffer_tex(baryon_fbpair.front, VIEWPORT_W, VIEWPORT_H);

fbpair_swap(&baryon_fbpair);
Expand All @@ -805,15 +808,20 @@ static void BaryonCenter(Enemy *bcenter, int t, bool render) {
// r_shader("sprite_default");
// draw_baryons(e, t);
r_state_pop();
stage_draw_end_noshake();

r_shader("sprite_default");
draw_baryons(bcenter, t);

stage_draw_begin_noshake();

r_shader_standard();
fbpair_swap(&baryon_fbpair);
r_color4(0.7, 0.7, 0.7, 0.7);
draw_framebuffer_tex(baryon_fbpair.front, VIEWPORT_W, VIEWPORT_H);

stage_draw_end_noshake();

r_color4(1, 1, 1, 1);
r_framebuffer(baryon_fbpair.front);
r_shader("sprite_default");
Expand Down

0 comments on commit f554768

Please sign in to comment.