From 803bb1a8a4cd5d8bfebdfc7a4d2bd10c2671c476 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 11 Sep 2022 20:58:57 +0900 Subject: [PATCH] ReignEngine: Fix BackCG issues - Enable both alpha map and alpha mod, using the new drawing function gfx_copy_stretch_blend_amap_alpha(). - Do not draw if `bcg->show` flag is false. - Do not WARNING() for SetBackCGNum(0) as it's used to unload the CG. --- include/gfx/gfx.h | 1 + src/3d/reign.c | 3 +++ src/3d/renderer.c | 4 ++-- src/draw.c | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index e98d78c..188c334 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -144,6 +144,7 @@ void gfx_copy_stretch(struct texture *dst, int dx, int dy, int dw, int dh, struc void gfx_copy_stretch_amap(struct texture *dst, int dx, int dy, int dw, int dh, struct texture *src, int sx, int sy, int sw, int sh); void gfx_copy_stretch_blend(struct texture *dst, int dx, int dy, int dw, int dh, struct texture *src, int sx, int sy, int sw, int sh, int a); void gfx_copy_stretch_blend_amap(struct texture *dst, int dx, int dy, int dw, int dh, struct texture *src, int sx, int sy, int sw, int sh); +void gfx_copy_stretch_blend_amap_alpha(struct texture *dst, int dx, int dy, int dw, int dh, struct texture *src, int sx, int sy, int sw, int sh, int a); void gfx_copy_rot_zoom(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag); void gfx_copy_rot_zoom_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag); void gfx_copy_rot_zoom_use_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag); diff --git a/src/3d/reign.c b/src/3d/reign.c index 51e2017..30eae28 100644 --- a/src/3d/reign.c +++ b/src/3d/reign.c @@ -888,6 +888,9 @@ bool RE_back_cg_set(struct RE_back_cg *bcg, int no) bcg->no = no; gfx_delete_texture(&bcg->texture); + if (!no) // unload only. + return true; + struct cg *cg = asset_cg_load(no); if (!cg) { WARNING("cannot load back CG: %d", no); diff --git a/src/3d/renderer.c b/src/3d/renderer.c index d595e18..2d668a0 100644 --- a/src/3d/renderer.c +++ b/src/3d/renderer.c @@ -505,11 +505,11 @@ static void render_shadow_map(struct RE_plugin *plugin, mat4 light_space_transfo static void render_back_cg(struct texture *dst, struct RE_back_cg *bcg, struct RE_renderer *r) { - if (!bcg->texture.handle) + if (!bcg->show || !bcg->texture.handle) return; int sw = bcg->texture.w; int sh = bcg->texture.h; - gfx_copy_stretch_blend(dst, bcg->x, bcg->y, sw * bcg->mag, sh * bcg->mag, &bcg->texture, 0, 0, sw, sh, bcg->blend_rate * 255); + gfx_copy_stretch_blend_amap_alpha(dst, bcg->x, bcg->y, sw * bcg->mag, sh * bcg->mag, &bcg->texture, 0, 0, sw, sh, bcg->blend_rate * 255); } static void setup_lights(struct RE_plugin *plugin) diff --git a/src/draw.c b/src/draw.c index 0afbb18..98ba36a 100644 --- a/src/draw.c +++ b/src/draw.c @@ -712,6 +712,20 @@ void gfx_copy_stretch_blend_amap(struct texture *dst, int dx, int dy, int dw, in restore_blend_mode(); } +void gfx_copy_stretch_blend_amap_alpha(struct texture *dst, int dx, int dy, int dw, int dh, struct texture *src, int sx, int sy, int sw, int sh, int a) +{ + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + struct copy_data data = STRETCH_DATA(dx, dy, dw, dh, sx, sy, sw, sh); + data.r = 1.0; + data.g = 1.0; + data.b = 1.0; + data.a = a / 255.0; + run_copy_shader(&blend_amap_alpha_bright_shader.s, dst, src, &data); + + restore_blend_mode(); +} + // FIXME: this doesn't work correctly when the src rectangle crosses the edge of the CG. static void copy_rot_zoom(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag, Shader *shader) {