Implement DrawGraph.BlendUseAMapColor

This commit is contained in:
Nunuhara Cabbage
2022-05-02 20:35:02 -07:00
parent 9108ce19ea
commit 65be47e05b
4 changed files with 57 additions and 2 deletions
+1
View File
@@ -120,6 +120,7 @@ void gfx_blend_amap_color_alpha(Texture *dst, int dx, int dy, Texture *src, int
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_blend_amap_bright(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int rate);
void gfx_blend_amap_alpha_src_bright(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int alpha, int rate);
void gfx_blend_use_amap_color(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int r, int g, int b, int rate);
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);
+31
View File
@@ -0,0 +1,31 @@
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* 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 <http://gnu.org/licenses/>.
*/
uniform sampler2D tex;
uniform float threshold;
uniform vec4 color;
in vec2 tex_coord;
out vec4 frag_color;
void main() {
// alpha values at or above `rate + 16` get an alpha of 0
// alpha values below `rate` get an alpha of 255
// alpha values between `rate` and `rate + 16` are blended
float delta = texture(tex, tex_coord).a - threshold;
float alpha = 1.0 - clamp(delta * 16.0, 0.0, 1.0);
frag_color = vec4(color.rgb, alpha);
}
+19
View File
@@ -64,6 +64,7 @@ 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_bright_shader;
static struct copy_shader blend_use_amap_color_shader;
static struct copy_shader fill_shader;
static struct copy_shader fill_amap_over_border_shader;
static struct copy_shader fill_amap_under_border_shader;
@@ -119,6 +120,8 @@ void gfx_draw_init(void)
// copy shader that multiples the source color and alpha by a constant
load_copy_shader(&blend_amap_alpha_bright_shader, "shaders/render.v.glsl", "shaders/blend_amap_alpha_bright.f.glsl");
load_copy_shader(&blend_use_amap_color_shader, "shaders/render.v.glsl", "shaders/blend_use_amap_color.f.glsl");
// basic fill shader
load_copy_shader(&fill_shader, "shaders/render.v.glsl", "shaders/fill.f.glsl");
@@ -425,6 +428,22 @@ void gfx_blend_amap_alpha_src_bright(Texture *dst, int dx, int dy, Texture *src,
restore_blend_mode();
}
void gfx_blend_use_amap_color(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int r, int g, int b, int rate)
{
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;
data.a = 1.0;
data.threshold = rate / 255.0;
run_copy_shader(&blend_use_amap_color_shader.s, dst, src, &data);
restore_blend_mode();
}
void gfx_fill(Texture *dst, int x, int y, int w, int h, int r, int g, int b)
{
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ONE);
+6 -2
View File
@@ -131,7 +131,11 @@ static void DrawGraph_BlendAMapAlphaSrcBright(int dst, int dx, int dy, int src,
gfx_blend_amap_alpha_src_bright(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, alpha, rate);
}
//void DrawGraph_BlendUseAMapColor(int dst, int dx, int dy, int alpha, int ax, int ay, int w, int h, int r, int g, int b, int rate);
static void DrawGraph_BlendUseAMapColor(int dst, int dx, int dy, int alpha, int ax, int ay, int w, int h, int r, int g, int b, int rate)
{
gfx_blend_use_amap_color(DTEX(dst), dx, dy, STEX(alpha), ax, ay, w, h, r, g, b, rate);
}
//void DrawGraph_BlendScreen(int dst, int dx, int dy, int src, int sx, int sy, int w, int h);
//void DrawGraph_BlendMultiply(int dst, int dx, int dy, int src, int sx, int sy, int w, int h);
//void DrawGraph_BlendScreenAlpha(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha);
@@ -381,7 +385,7 @@ HLL_LIBRARY(DrawGraph,
HLL_EXPORT(BlendAMapAlpha, DrawGraph_BlendAMapAlpha),
HLL_EXPORT(BlendAMapBright, DrawGraph_BlendAMapBright),
HLL_EXPORT(BlendAMapAlphaSrcBright, DrawGraph_BlendAMapAlphaSrcBright),
//HLL_EXPORT(BlendUseAMapColor, DrawGraph_BlendUseAMapColor),
HLL_EXPORT(BlendUseAMapColor, DrawGraph_BlendUseAMapColor),
//HLL_EXPORT(BlendScreen, DrawGraph_BlendScreen),
//HLL_EXPORT(BlendMultiply, DrawGraph_BlendMultiply),
//HLL_EXPORT(BlendScreenAlpha, DrawGraph_BlendScreenAlpha),