From 9108ce19ea805e9a5653748659ef5be03fc8fc92 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Mon, 2 May 2022 18:19:09 -0700 Subject: [PATCH] Implement DrawGraph.BlendAMapAlphaSrcBright --- include/gfx/gfx.h | 1 + shaders/blend_amap_alpha.f.glsl | 27 ------------- ....f.glsl => blend_amap_alpha_bright.f.glsl} | 5 +-- src/draw.c | 38 +++++++++++++------ src/hll/DrawGraph.c | 8 +++- 5 files changed, 36 insertions(+), 43 deletions(-) delete mode 100644 shaders/blend_amap_alpha.f.glsl rename shaders/{blend_amap_bright.f.glsl => blend_amap_alpha_bright.f.glsl} (86%) diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index 6a0faf1..61ab1b8 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -119,6 +119,7 @@ void gfx_blend_amap_color(struct texture *dst, int dx, int dy, struct texture *s void gfx_blend_amap_color_alpha(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int r, int g, int b, int a); 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_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); diff --git a/shaders/blend_amap_alpha.f.glsl b/shaders/blend_amap_alpha.f.glsl deleted file mode 100644 index 1f46f9d..0000000 --- a/shaders/blend_amap_alpha.f.glsl +++ /dev/null @@ -1,27 +0,0 @@ -/* 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 . - */ - -uniform sampler2D tex; -uniform float threshold; - -in vec2 tex_coord; -out vec4 frag_color; - -void main() { - vec4 texel = texture(tex, tex_coord); - texel.a *= threshold; - frag_color = texel; -} diff --git a/shaders/blend_amap_bright.f.glsl b/shaders/blend_amap_alpha_bright.f.glsl similarity index 86% rename from shaders/blend_amap_bright.f.glsl rename to shaders/blend_amap_alpha_bright.f.glsl index 069e740..3b3fe62 100644 --- a/shaders/blend_amap_bright.f.glsl +++ b/shaders/blend_amap_alpha_bright.f.glsl @@ -15,12 +15,11 @@ */ uniform sampler2D tex; -uniform float threshold; +uniform vec4 color; in vec2 tex_coord; out vec4 frag_color; void main() { - vec4 texel = texture(tex, tex_coord); - frag_color = vec4(texel.rgb * threshold, texel.a); + frag_color = texture(tex, tex_coord) * color; } diff --git a/src/draw.c b/src/draw.c index 79039e9..d882798 100644 --- a/src/draw.c +++ b/src/draw.c @@ -63,8 +63,7 @@ static struct copy_shader copy_alpha_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 blend_amap_bright_shader; +static struct copy_shader blend_amap_alpha_bright_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; @@ -117,11 +116,8 @@ void gfx_draw_init(void) // 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"); - - // copy shader that multiples the source color by a constant - load_copy_shader(&blend_amap_bright_shader, "shaders/render.v.glsl", "shaders/blend_amap_bright.f.glsl"); + // 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"); // basic fill shader load_copy_shader(&fill_shader, "shaders/render.v.glsl", "shaders/fill.f.glsl"); @@ -392,8 +388,11 @@ void gfx_blend_amap_alpha(Texture *dst, int dx, int dy, Texture *src, int sx, in glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); - data.threshold = a / 255.0; - run_copy_shader(&blend_amap_alpha_shader.s, dst, src, &data); + 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(); } @@ -403,8 +402,25 @@ void gfx_blend_amap_bright(Texture *dst, int dx, int dy, Texture *src, int sx, i glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); - data.threshold = rate / 255.0; - run_copy_shader(&blend_amap_bright_shader.s, dst, src, &data); + data.r = rate / 255.0; + data.g = rate / 255.0; + data.b = rate / 255.0; + data.a = 1.0; + run_copy_shader(&blend_amap_alpha_bright_shader.s, dst, src, &data); + + restore_blend_mode(); +} + +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) +{ + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h); + data.r = rate / 255.0; + data.g = rate / 255.0; + data.b = rate / 255.0; + data.a = alpha / 255.0; + run_copy_shader(&blend_amap_alpha_bright_shader.s, dst, src, &data); restore_blend_mode(); } diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index ac06803..87ddcd6 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -126,7 +126,11 @@ static void DrawGraph_BlendAMapBright(int dst, int dx, int dy, int src, int sx, gfx_blend_amap_bright(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, rate); } -//void DrawGraph_BlendAMapAlphaSrcBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); +static void DrawGraph_BlendAMapAlphaSrcBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate) +{ + 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); //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); @@ -376,7 +380,7 @@ HLL_LIBRARY(DrawGraph, HLL_EXPORT(BlendAMapColorAlpha, DrawGraph_BlendAMapColorAlpha), HLL_EXPORT(BlendAMapAlpha, DrawGraph_BlendAMapAlpha), HLL_EXPORT(BlendAMapBright, DrawGraph_BlendAMapBright), - //HLL_EXPORT(BlendAMapAlphaSrcBright, DrawGraph_BlendAMapAlphaSrcBright), + HLL_EXPORT(BlendAMapAlphaSrcBright, DrawGraph_BlendAMapAlphaSrcBright), //HLL_EXPORT(BlendUseAMapColor, DrawGraph_BlendUseAMapColor), //HLL_EXPORT(BlendScreen, DrawGraph_BlendScreen), //HLL_EXPORT(BlendMultiply, DrawGraph_BlendMultiply),