diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index 018d772..36c791e 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -106,11 +106,13 @@ void gfx_copy_amap_max(struct texture *dst, int dx, int dy, struct texture *src, void gfx_copy_amap_min(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); void gfx_blend(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int a); void gfx_blend_amap(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); +void gfx_blend_amap_color(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int r, int g, int b); void gfx_blend_amap_alpha(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int a); void gfx_fill(struct texture *dst, int x, int y, int w, int h, int r, int g, int b); void gfx_fill_alpha_color(struct texture *dst, int x, int y, int w, int h, int r, int g, int b, int a); void gfx_fill_amap(struct texture *dst, int x, int y, int w, int h, int a); void gfx_add_da_daxsa(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); +void gfx_blend_da_daxsa(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); void gfx_sub_da_daxsa(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h); void gfx_copy_stretch(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_amap(struct texture *dst, int dx, int dy, int dw, int dh, struct texture *src, int sx, int sy, int sw, int sh); diff --git a/shaders/blend_amap_color.f.glsl b/shaders/blend_amap_color.f.glsl new file mode 100644 index 0000000..c1c4353 --- /dev/null +++ b/shaders/blend_amap_color.f.glsl @@ -0,0 +1,28 @@ +/* Copyright (C) 2019 Nunuhara Cabbage + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#version 140 + +uniform sampler2D tex; +uniform vec4 color; + +in vec2 tex_coord; +out vec4 frag_color; + +void main() { + vec4 texel = texture(tex, tex_coord); + frag_color = vec4(color.rgb, texel.a); +} diff --git a/src/draw.c b/src/draw.c index b19f61d..3210b87 100644 --- a/src/draw.c +++ b/src/draw.c @@ -59,6 +59,7 @@ static struct copy_shader copy_color_reverse_shader; static struct copy_shader copy_key_shader; static struct copy_shader copy_use_amap_under_shader; static struct copy_shader copy_use_amap_border_shader; +static struct copy_shader blend_amap_color_shader; static struct copy_shader blend_amap_alpha_shader; static struct copy_shader fill_shader; static struct copy_shader hitbox_shader; @@ -103,6 +104,9 @@ void gfx_draw_init(void) // copy shader that only keeps fragments above a certain alpha threshold load_copy_shader(©_use_amap_border_shader, "shaders/render.v.glsl", "shaders/copy_use_amap_border.f.glsl"); + // copy shader that sets source RGB to a constant + load_copy_shader(&blend_amap_color_shader, "shaders/render.v.glsl", "shaders/blend_amap_color.f.glsl"); + // copy shader that multiples the source alpha by a constant load_copy_shader(&blend_amap_alpha_shader, "shaders/render.v.glsl", "shaders/blend_amap_alpha.f.glsl"); @@ -285,6 +289,21 @@ void gfx_blend_amap(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, restore_blend_mode(); } +void gfx_blend_amap_color(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int r, int g, int b) +{ + // color = (r,g,b) * src_alpha + dst_color * (1 - src_alpha) + // alpha = dst_alpha + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE); + + struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); + data.r = r / 255.0; + data.g = g / 255.0; + data.b = b / 255.0; + run_copy_shader(&blend_amap_color_shader.s, dst, src, &data); + + restore_blend_mode(); +} + void gfx_blend_amap_alpha(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int a) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -337,7 +356,21 @@ void gfx_fill_amap(Texture *dst, int x, int y, int w, int h, int a) void gfx_add_da_daxsa(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h) { - glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ONE); // ??? + // color = dst_color + // alpha = src_alpha + dst_alpha + glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ONE); + + struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); + run_copy_shader(©_shader.s, dst, src, &data); + + restore_blend_mode(); +} + +void gfx_blend_da_daxsa(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h) +{ + // color = dst_color + // alpha = src_alpha * dst_alpha + glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ZERO, GL_SRC_ALPHA); struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); run_copy_shader(©_shader.s, dst, src, &data); @@ -347,7 +380,10 @@ void gfx_add_da_daxsa(Texture *dst, int dx, int dy, Texture *src, int sx, int sy void gfx_sub_da_daxsa(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h) { - glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // color = dst_color + // alpha = dst_alpha - src_alpha + glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_REVERSE_SUBTRACT); + glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ONE); struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); run_copy_shader(©_shader.s, dst, src, &data); diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index de94a40..aaf2a65 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -91,6 +91,11 @@ static void DrawGraph_BlendAMap(int dst, int dx, int dy, int src, int sx, int sy gfx_blend_amap(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h); } +static void DrawGraph_BlendAMapColor(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int r, int g, int b) +{ + gfx_blend_amap_color(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, r, g, b); +} + static void DrawGraph_BlendAMapAlpha(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha) { gfx_blend_amap_alpha(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, alpha); @@ -116,7 +121,12 @@ static void DrawGraph_AddDA_DAxSA(int dst, int dx, int dy, int src, int sx, int gfx_add_da_daxsa(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h); } -void DrawGraph_SubDA_DAxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +static void DrawGraph_BlendDA_DAxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) +{ + gfx_blend_da_daxsa(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h); +} + +static void DrawGraph_SubDA_DAxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h) { gfx_sub_da_daxsa(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h); } @@ -193,7 +203,6 @@ static void DrawGraph_SetFontName(struct string *text) //void DrawGraph_BlendSrcBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); //void DrawGraph_BlendAddSatur(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); //void DrawGraph_BlendAMapSrcOnly(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); -//void DrawGraph_BlendAMapColor(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int r, int g, int b); //void DrawGraph_BlendAMapColorAlpha(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int r, int g, int b, int a); //void DrawGraph_BlendAMapBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int rate); //void DrawGraph_BlendAMapAlphaSrcBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); @@ -209,7 +218,6 @@ static void DrawGraph_SetFontName(struct string *text) //void DrawGraph_SaturDP_DPxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); //void DrawGraph_ScreenDA_DAxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h); //void DrawGraph_SpriteCopyAMap(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int key); -//void DrawGraph_BlendDA_DAxSA, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); //void DrawGraph_BrightDestOnly(int dst, int x, int y, int w, int h, int rate); //void DrawGraph_CopyTextureWrap(int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh, int u, int v); //void DrawGraph_CopyTextureWrapAlpha(int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh, int u, int v, int alpha); @@ -272,7 +280,7 @@ HLL_LIBRARY(DrawGraph, //HLL_EXPORT(BlendAddSatur, DrawGraph_BlendAddSatur), HLL_EXPORT(BlendAMap, DrawGraph_BlendAMap), //HLL_EXPORT(BlendAMapSrcOnly, DrawGraph_BlendAMapSrcOnly), - //HLL_EXPORT(BlendAMapColor, DrawGraph_BlendAMapColor), + HLL_EXPORT(BlendAMapColor, DrawGraph_BlendAMapColor), //HLL_EXPORT(BlendAMapColorAlpha, DrawGraph_BlendAMapColorAlpha), HLL_EXPORT(BlendAMapAlpha, DrawGraph_BlendAMapAlpha), //HLL_EXPORT(BlendAMapBright, DrawGraph_BlendAMapBright), @@ -293,7 +301,7 @@ HLL_LIBRARY(DrawGraph, //HLL_EXPORT(ScreenDA_DAxSA, DrawGraph_ScreenDA_DAxSA), HLL_EXPORT(AddDA_DAxSA, DrawGraph_AddDA_DAxSA), //HLL_EXPORT(SpriteCopyAMap, DrawGraph_SpriteCopyAMap), - //HLL_EXPORT(BlendDA_DAxSA, DrawGraph_BlendDA_DAxSA), + HLL_EXPORT(BlendDA_DAxSA, DrawGraph_BlendDA_DAxSA), HLL_EXPORT(SubDA_DAxSA, DrawGraph_SubDA_DAxSA), //HLL_EXPORT(BrightDestOnly, DrawGraph_BrightDestOnly), //HLL_EXPORT(CopyTextureWrap, DrawGraph_CopyTextureWrap),