mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-14 01:59:19 +03:00
Implement PartsEngine.SetPartsAlphaClipperPartsNumber
This allows a specified part to be used as an alpha map (clipper) during rendering. A dedicated vertex shader (parts.v.glsl) is introduced to calculate clipping coordinates using an inverse transformation matrix. Refactored parts_render_text() to use parts_render_texture() so that alpha clipping is applied to text. This also enables color modifications for text, while rotation and scaling remain unsupported, matching the original PartsEngine behavior. Incremented the parts save version since alpha_clipper_parts_no is now persisted.
This commit is contained in:
+11
-1
@@ -21,7 +21,11 @@ uniform vec2 top_right;
|
||||
uniform vec3 add_color;
|
||||
uniform vec3 multiply_color;
|
||||
|
||||
uniform int use_clipper;
|
||||
uniform sampler2D clipper_tex;
|
||||
|
||||
in vec2 tex_coord;
|
||||
in vec2 clip_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
float point_in_rect(vec2 p, vec2 bot_left, vec2 top_right) {
|
||||
@@ -36,5 +40,11 @@ void main() {
|
||||
|
||||
vec4 tex_color = texture(tex, tex_coord);
|
||||
vec3 mod_color = (tex_color.rgb + add_color) * multiply_color;
|
||||
frag_color = vec4(mod_color, tex_color.a * blend_rate) * point_in_rect(tex_coord, bl, tr);
|
||||
|
||||
float alpha = tex_color.a * blend_rate;
|
||||
if (use_clipper != 0) {
|
||||
alpha *= texture(clipper_tex, clip_coord).a * point_in_rect(clip_coord, vec2(0.0), vec2(1.0));
|
||||
}
|
||||
|
||||
frag_color = vec4(mod_color, alpha) * point_in_rect(tex_coord, bl, tr);
|
||||
}
|
||||
|
||||
@@ -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 mat4 world_transform;
|
||||
uniform mat4 view_transform;
|
||||
uniform mat4 inv_clipper_transform;
|
||||
|
||||
in vec4 vertex_pos;
|
||||
in vec2 vertex_uv;
|
||||
out vec2 tex_coord;
|
||||
out vec2 clip_coord;
|
||||
|
||||
void main() {
|
||||
vec4 world_pos = world_transform * vertex_pos;
|
||||
gl_Position = view_transform * world_pos;
|
||||
tex_coord = vertex_uv;
|
||||
clip_coord = (inv_clipper_transform * world_pos).xy;
|
||||
}
|
||||
Reference in New Issue
Block a user