From 2f573803c48ab94635c6f4e510b634ea69c083ed Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Mon, 2 May 2022 17:01:23 -0700 Subject: [PATCH] Implement DrawGraph.BlendAMapBright --- include/gfx/gfx.h | 3 ++- shaders/blend_amap_bright.f.glsl | 26 ++++++++++++++++++++++++++ src/draw.c | 27 +++++++++++++++++++++------ src/hll/DrawGraph.c | 8 ++++++-- 4 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 shaders/blend_amap_bright.f.glsl diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index c5b8e36..6a0faf1 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -116,8 +116,9 @@ void gfx_blend_add_satur(Texture *dst, int dx, int dy, Texture *src, int sx, int 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_src_only(Texture *dst, int dx, int dy, 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_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_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_bright.f.glsl b/shaders/blend_amap_bright.f.glsl new file mode 100644 index 0000000..069e740 --- /dev/null +++ b/shaders/blend_amap_bright.f.glsl @@ -0,0 +1,26 @@ +/* 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); + frag_color = vec4(texel.rgb * threshold, texel.a); +} diff --git a/src/draw.c b/src/draw.c index 3a23976..79039e9 100644 --- a/src/draw.c +++ b/src/draw.c @@ -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_shader; +static struct copy_shader blend_amap_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; @@ -119,6 +120,9 @@ void gfx_draw_init(void) // 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"); + // basic fill shader load_copy_shader(&fill_shader, "shaders/render.v.glsl", "shaders/fill.f.glsl"); @@ -369,6 +373,20 @@ void gfx_blend_amap_color(Texture *dst, int dx, int dy, Texture *src, int sx, in restore_blend_mode(); } +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) +{ + 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 = r / 255.0; + data.g = g / 255.0; + data.b = b / 255.0; + data.a = a / 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); @@ -380,16 +398,13 @@ void gfx_blend_amap_alpha(Texture *dst, int dx, int dy, Texture *src, int sx, in restore_blend_mode(); } -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_bright(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, 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 = r / 255.0; - data.g = g / 255.0; - data.b = b / 255.0; - data.a = a / 255.0; - run_copy_shader(&blend_amap_color_shader.s, dst, src, &data); + data.threshold = rate / 255.0; + run_copy_shader(&blend_amap_bright_shader.s, dst, src, &data); restore_blend_mode(); } diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index 3b8b701..ac06803 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -121,7 +121,11 @@ static void DrawGraph_BlendAMapAlpha(int dst, int dx, int dy, int src, int sx, i gfx_blend_amap_alpha(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, alpha); } -//void DrawGraph_BlendAMapBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int rate); +static void DrawGraph_BlendAMapBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int rate) +{ + 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); //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); @@ -371,7 +375,7 @@ HLL_LIBRARY(DrawGraph, HLL_EXPORT(BlendAMapColor, DrawGraph_BlendAMapColor), HLL_EXPORT(BlendAMapColorAlpha, DrawGraph_BlendAMapColorAlpha), HLL_EXPORT(BlendAMapAlpha, DrawGraph_BlendAMapAlpha), - //HLL_EXPORT(BlendAMapBright, DrawGraph_BlendAMapBright), + HLL_EXPORT(BlendAMapBright, DrawGraph_BlendAMapBright), //HLL_EXPORT(BlendAMapAlphaSrcBright, DrawGraph_BlendAMapAlphaSrcBright), //HLL_EXPORT(BlendUseAMapColor, DrawGraph_BlendUseAMapColor), //HLL_EXPORT(BlendScreen, DrawGraph_BlendScreen),