Implement DrawGraph.FillAMapGradationUD

This commit is contained in:
Nunuhara Cabbage
2022-05-03 18:49:40 -07:00
parent 3b75b6b545
commit 54f6ece82d
4 changed files with 56 additions and 4 deletions
+3 -2
View File
@@ -127,6 +127,9 @@ void gfx_blend_screen_alpha(Texture *dst, int dx, int dy, Texture *src, int sx,
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_fill_amap_over_border(Texture *dst, int x, int y, int w, int h, int alpha, int border);
void gfx_fill_amap_under_border(Texture *dst, int x, int y, int w, int h, int alpha, int border);
void gfx_fill_amap_gradation_ud(Texture *dst, int x, int y, int w, int h, int up_a, int down_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);
@@ -139,8 +142,6 @@ void gfx_copy_rot_zoom_amap(Texture *dst, Texture *src, int sx, int sy, int w, i
void gfx_copy_rot_zoom_use_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag);
void gfx_copy_reverse_LR(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h);
void gfx_copy_reverse_amap_LR(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h);
void gfx_fill_amap_over_border(Texture *dst, int x, int y, int w, int h, int alpha, int border);
void gfx_fill_amap_under_border(Texture *dst, int x, int y, int w, int h, int alpha, int border);
void gfx_copy_rotate_y(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag);
void gfx_copy_rotate_y_use_amap(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag);
void gfx_copy_rotate_x(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag);
+27
View File
@@ -0,0 +1,27 @@
/* 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 float threshold2;
in vec2 tex_coord;
out vec4 frag_color;
void main() {
float rate = threshold + (threshold2 - threshold) * tex_coord.y;
frag_color = vec4(texture(tex, tex_coord).rgb, rate);
}
+20
View File
@@ -34,6 +34,7 @@ struct copy_shader {
// optional
GLint color;
GLint threshold;
GLint threshold2;
};
struct copy_data {
@@ -43,6 +44,7 @@ struct copy_data {
// optional
float r, g, b, a;
float threshold;
float threshold2;
};
#define ROTATE_DATA(dst, _sx, _sy, _w, _h) \
@@ -68,6 +70,7 @@ 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;
static struct copy_shader fill_amap_gradation_ud_shader;
static struct copy_shader hitbox_shader;
static struct copy_shader hitbox_noblend_shader;
static struct copy_shader dilate_shader;
@@ -81,6 +84,7 @@ static void prepare_copy_shader(struct gfx_render_job *job, void *data)
glUniform4f(s->color, d->r, d->g, d->b, d->a);
glUniform1f(s->threshold, d->threshold);
glUniform1f(s->threshold2, d->threshold2);
}
static void load_copy_shader(struct copy_shader *s, const char *v_path, const char *f_path)
@@ -90,6 +94,7 @@ static void load_copy_shader(struct copy_shader *s, const char *v_path, const ch
s->top_right = glGetUniformLocation(s->s.program, "top_right");
s->color = glGetUniformLocation(s->s.program, "color");
s->threshold = glGetUniformLocation(s->s.program, "threshold");
s->threshold2 = glGetUniformLocation(s->s.program, "threshold2");
s->s.prepare = prepare_copy_shader;
}
@@ -131,6 +136,9 @@ void gfx_draw_init(void)
// fill shader that only fills fragments below a certain alpha threshold
load_copy_shader(&fill_amap_under_border_shader, "shaders/render.v.glsl", "shaders/fill_amap_under_border.f.glsl");
// fill shader that fills the alpha map with a gradient
load_copy_shader(&fill_amap_gradation_ud_shader, "shaders/render.v.glsl", "shaders/fill_amap_gradation_ud.f.glsl");
// shader that discards texels that fail a hitbox test
load_copy_shader(&hitbox_shader, "shaders/render.v.glsl", "shaders/hitbox.f.glsl");
@@ -541,6 +549,18 @@ void gfx_fill_amap_under_border(Texture *dst, int x, int y, int w, int h, int al
restore_blend_mode();
}
void gfx_fill_amap_gradation_ud(Texture *dst, int x, int y, int w, int h, int up_a, int down_a)
{
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO);
struct copy_data data = COPY_DATA(x, y, 0, 0, w, h);
data.threshold = up_a / 255.0;
data.threshold2 = down_a / 255.0;
run_fill_shader(&fill_amap_gradation_ud_shader.s, dst, &data);
restore_blend_mode();
}
void gfx_add_da_daxsa(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h)
{
// color = dst_color
+6 -2
View File
@@ -176,7 +176,11 @@ static void DrawGraph_FillAMapUnderBorder(int dst, int x, int y, int w, int h, i
gfx_fill_amap_under_border(DTEX(dst), x, y, w, h, alpha, border);
}
//void DrawGraph_FillAMapGradationUD(int dst, int x, int y, int w, int h, int up_a, int down_a);
static void DrawGraph_FillAMapGradationUD(int dst, int x, int y, int w, int h, int up_a, int down_a)
{
gfx_fill_amap_gradation_ud(DTEX(dst), x, y, w, h, up_a, down_a);
}
//void DrawGraph_FillScreen(int dst, int x, int y, int w, int h, int r, int g, int b);
//void DrawGraph_FillMultiply(int dst, int x, int y, int w, int h, int r, int g, int b);
//void DrawGraph_SaturDP_DPxSA(int dst, int dx, int dy, int src, int sx, int sy, int w, int h);
@@ -405,7 +409,7 @@ HLL_LIBRARY(DrawGraph,
HLL_EXPORT(FillAMap, DrawGraph_FillAMap),
HLL_EXPORT(FillAMapOverBorder, DrawGraph_FillAMapOverBorder),
HLL_EXPORT(FillAMapUnderBorder, DrawGraph_FillAMapUnderBorder),
//HLL_EXPORT(FillAMapGradationUD, DrawGraph_FillAMapGradationUD),
HLL_EXPORT(FillAMapGradationUD, DrawGraph_FillAMapGradationUD),
//HLL_EXPORT(FillScreen, DrawGraph_FillScreen),
//HLL_EXPORT(FillMultiply, DrawGraph_FillMultiply),
//HLL_EXPORT(SaturDP_DPxSA, DrawGraph_SaturDP_DPxSA),