palettte mixer things

This commit is contained in:
Tanasart 2024-05-20 15:50:32 +07:00
parent 12e5eeb0e1
commit 8f3027a315
16 changed files with 328 additions and 25 deletions

View file

@ -157,7 +157,7 @@
{"name":"find_boundary","order":7,"path":"folders/shader/misc/find_boundary.yy",},
{"name":"Flag","order":3,"path":"folders/shader/MK effects/Flag.yy",},
{"name":"Tile","order":4,"path":"folders/shader/MK effects/Tile.yy",},
{"name":"atlas expand","order":2,"path":"folders/shader/UI/atlas expand.yy",},
{"name":"palette mixer","order":2,"path":"folders/shader/UI/palette mixer.yy",},
],
"ResourceOrderSettings":[
{"name":"ac_disappear","order":2,"path":"animcurves/ac_disappear/ac_disappear.yy",},
@ -1420,6 +1420,8 @@
{"name":"sh_outline_only","order":19,"path":"shaders/sh_outline_only/sh_outline_only.yy",},
{"name":"sh_outline","order":9,"path":"shaders/sh_outline/sh_outline.yy",},
{"name":"sh_override_channel","order":21,"path":"shaders/sh_override_channel/sh_override_channel.yy",},
{"name":"sh_palette_mixer_atlas_expand_apply","order":2,"path":"shaders/sh_palette_mixer_atlas_expand_apply/sh_palette_mixer_atlas_expand_apply.yy",},
{"name":"sh_palette_mixer_atlas_expand_iterate","order":1,"path":"shaders/sh_palette_mixer_atlas_expand_iterate/sh_palette_mixer_atlas_expand_iterate.yy",},
{"name":"sh_palette_replace","order":24,"path":"shaders/sh_palette_replace/sh_palette_replace.yy",},
{"name":"sh_palette_shift","order":19,"path":"shaders/sh_palette_shift/sh_palette_shift.yy",},
{"name":"sh_path_fill_profile","order":15,"path":"shaders/sh_path_fill_profile/sh_path_fill_profile.yy",},
@ -1504,6 +1506,7 @@
{"name":"sh_widget_rotator_range","order":5,"path":"shaders/sh_widget_rotator_range/sh_widget_rotator_range.yy",},
{"name":"sh_widget_rotator","order":4,"path":"shaders/sh_widget_rotator/sh_widget_rotator.yy",},
{"name":"sh_zigzag","order":2,"path":"shaders/sh_zigzag/sh_zigzag.yy",},
{"name":"sh_palette_mixer_atlas_expand_palette","order":3,"path":"shaders/sh_palette_mixer_atlas_expand_palette/sh_palette_mixer_atlas_expand_palette.yy",},
{"name":"credit_badge_popular","order":2,"path":"sprites/credit_badge_popular/credit_badge_popular.yy",},
{"name":"credit_badge_value","order":1,"path":"sprites/credit_badge_value/credit_badge_value.yy",},
{"name":"s_biterator_b_grey_long","order":7,"path":"sprites/s_biterator_b_grey_long/s_biterator_b_grey_long.yy",},

View file

@ -295,7 +295,7 @@
{"$GMFolder":"","%Name":"sprites","folderPath":"folders/shader/sprites.yy","name":"sprites","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"transition","folderPath":"folders/shader/transition.yy","name":"transition","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"UI","folderPath":"folders/shader/UI.yy","name":"UI","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"atlas expand","folderPath":"folders/shader/UI/atlas expand.yy","name":"atlas expand","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"palette mixer","folderPath":"folders/shader/UI/palette mixer.yy","name":"palette mixer","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"sprites","folderPath":"folders/sprites.yy","name":"sprites","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"bs","folderPath":"folders/sprites/bs.yy","name":"bs","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"gameframe","folderPath":"folders/sprites/gameframe.yy","name":"gameframe","resourceType":"GMFolder","resourceVersion":"2.0",},
@ -1945,6 +1945,9 @@
{"id":{"name":"sh_outline_only","path":"shaders/sh_outline_only/sh_outline_only.yy",},},
{"id":{"name":"sh_outline","path":"shaders/sh_outline/sh_outline.yy",},},
{"id":{"name":"sh_override_channel","path":"shaders/sh_override_channel/sh_override_channel.yy",},},
{"id":{"name":"sh_palette_mixer_atlas_expand_apply","path":"shaders/sh_palette_mixer_atlas_expand_apply/sh_palette_mixer_atlas_expand_apply.yy",},},
{"id":{"name":"sh_palette_mixer_atlas_expand_coord","path":"shaders/sh_palette_mixer_atlas_expand_coord/sh_palette_mixer_atlas_expand_coord.yy",},},
{"id":{"name":"sh_palette_mixer_atlas_expand_iterate","path":"shaders/sh_palette_mixer_atlas_expand_iterate/sh_palette_mixer_atlas_expand_iterate.yy",},},
{"id":{"name":"sh_palette_replace","path":"shaders/sh_palette_replace/sh_palette_replace.yy",},},
{"id":{"name":"sh_palette_shift","path":"shaders/sh_palette_shift/sh_palette_shift.yy",},},
{"id":{"name":"sh_path_fill_profile","path":"shaders/sh_path_fill_profile/sh_path_fill_profile.yy",},},
@ -2042,6 +2045,7 @@
{"id":{"name":"sh_widget_rotator_range","path":"shaders/sh_widget_rotator_range/sh_widget_rotator_range.yy",},},
{"id":{"name":"sh_widget_rotator","path":"shaders/sh_widget_rotator/sh_widget_rotator.yy",},},
{"id":{"name":"sh_zigzag","path":"shaders/sh_zigzag/sh_zigzag.yy",},},
{"id":{"name":"sh_palette_mixer_atlas_expand_palette","path":"shaders/sh_palette_mixer_atlas_expand_palette/sh_palette_mixer_atlas_expand_palette.yy",},},
{"id":{"name":"credit_badge_popular","path":"sprites/credit_badge_popular/credit_badge_popular.yy",},},
{"id":{"name":"credit_badge_value","path":"sprites/credit_badge_value/credit_badge_value.yy",},},
{"id":{"name":"node_credit","path":"sprites/node_credit/node_credit.yy",},},

View file

@ -6,7 +6,9 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
w = ui(320);
h = ui(400);
connect_surf = surface_create(1, 1);
connect_surf = surface_create(1, 1);
connect_blend_surf = surface_create(1, 1);
content_surf = surface_create(1, 1);
var _def = load_palette_mixer();
@ -59,6 +61,8 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
connection_drag = noone;
conn_menu_ctx = noone;
shade_mode = 0;
pr_palette = ds_priority_create();
function setColor(clr) {
@ -74,6 +78,9 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
var _connections = palette_data.connections;
var _blends = palette_data.blends;
if(key_mod_press(SHIFT)) shade_mode = lerp_float(shade_mode, 1, 5);
else shade_mode = lerp_float(shade_mode, 0, 5);
if(!in_dialog) draw_sprite_stretched(THEME.ui_panel_bg, 1, 0, 0, w, h);
#region blend points
@ -108,7 +115,7 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
draw_sprite_stretched(THEME.button_def, 0, pbg_x, pbg_y, pbg_w, pbg_h);
if(pHOVER && point_in_rectangle(mx, my, pbg_x, pbg_x, pbg_w, pbg_h)) {
if(pHOVER && point_in_rectangle(mx, my, pbg_x, pbg_y, pbg_x + pbg_w, pbg_y + pbg_h)) {
draw_sprite_stretched_ext(THEME.button_def, 3, pbg_x, pbg_y, pbg_w, pbg_h, c_white, 0.5);
if(mouse_press(mb_right)) {
@ -210,6 +217,9 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
connect_surf = surface_verify(connect_surf, pw, ph);
content_surf = surface_verify(content_surf, pw, ph);
// for (var i = 0, n = array_length(atlas_surfs); i < n; i++)
// atlas_surfs = surface_verify(atlas_surfs, pw, ph);
var _mx_x = pw / 2 + mixer_x;
var _mx_y = ph / 2 + mixer_y;
@ -223,7 +233,7 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
surface_set_target(connect_surf)
DRAW_CLEAR
var _gs = node_size;
var _gs = shade_mode > 0? ui(12) : node_size;
var _gs2 = _gs / 2;
var _ind = noone;
var _hov = node_hovering;
@ -248,7 +258,7 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
var _toy = round(_mx_y + _to.y);
var _hv = _hov == noone && _con_hover == i;
if(!key_mod_press(SHIFT)) {
if(shade_mode == 0) {
draw_set_alpha(0.75);
draw_line_width_color(_frx, _fry, _tox, _toy, (_hv? 8 : 4) + 2, c_white, c_white);
draw_set_alpha(1);
@ -256,7 +266,7 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
draw_line_width_color(_frx, _fry, _tox, _toy, _hv? 8 : 4, _fr.color, _to.color);
if(_pHover && _bln_hover == noone && distance_to_line(_msx, _msy, _frx, _fry, _tox, _toy) < 6) {
if(_pHover && _bln_hover == noone && shade_mode == 0 && distance_to_line(_msx, _msy, _frx, _fry, _tox, _toy) < 6) {
conn_hovering = i;
var _d0 = point_distance(_frx, _fry, _msx, _msy);
@ -265,7 +275,7 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
}
}
var _bs = node_size * 0.75;
var _bs = shade_mode > 0? ui(12) : node_size * 0.75;
for (var i = 0, n = array_length(_blends); i < n; i++) {
var _blend = _blends[i];
@ -276,7 +286,7 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
draw_sprite_stretched_ext(THEME.menu_button_mask, 0, _px - _bs / 2, _py - _bs / 2, _bs, _bs, _c, 1);
if(key_mod_press(SHIFT))
if(shade_mode > 0)
continue;
BLEND_ADD
@ -313,16 +323,16 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
var _py = round(_mx_y + pal.y);
var _hv = _pHover && point_in_rectangle(_msx, _msy, _px - _gs2, _py - _gs2, _px + _gs2, _py + _gs2);
if(!key_mod_press(SHIFT))
if(shade_mode == 0)
draw_sprite_stretched(THEME.button_def, _hov == pal, _px - _gs2, _py - _gs2, _gs, _gs);
draw_sprite_stretched_ext(THEME.menu_button_mask, 0, _px - _gs2 + 2, _py - _gs2 + 2, _gs - 4, _gs - 4, _c, 1);
if(key_mod_press(SHIFT)) continue;
BLEND_ADD
draw_sprite_stretched_ext(THEME.menu_button_mask, 1, _px - _gs2 + 2, _py - _gs2 + 2, _gs - 4, _gs - 4, c_white, 0.25);
BLEND_NORMAL
if(shade_mode > 0) continue;
if(pal == node_selecting)
draw_sprite_stretched_ext(THEME.menu_button_mask, 1, _px - _gs2, _py - _gs2, _gs, _gs, COLORS._main_accent, 1);
@ -548,17 +558,75 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
surface_reset_target();
#endregion
shader_set(sh_FXAA);
gpu_set_tex_filter(true);
shader_set_f("dimension", pw, ph);
shader_set_f("cornerDis", 0.5);
shader_set_f("mixAmo", 1);
#region draw surfaces
if(shade_mode > 0) {
var _shade_pal = array_create(array_length(palette) * 4);
var _shade_pos = array_create(array_length(palette) * 2);
var _ind = 0;
for (var i = 0, n = array_length(_palettes); i < n; i++) {
var _x = _palettes[i].x;
var _y = _palettes[i].y;
var _c = _palettes[i].color;
_shade_pal[_ind * 4 + 0] = _color_get_red(_c);
_shade_pal[_ind * 4 + 1] = _color_get_green(_c);
_shade_pal[_ind * 4 + 2] = _color_get_blue(_c);
_shade_pal[_ind * 4 + 3] = _color_get_alpha(_c);
_shade_pos[_ind * 2 + 0] = _mx_x + _x;
_shade_pos[_ind * 2 + 1] = _mx_y + _y;
_ind++;
}
for (var i = 0, n = array_length(_blends); i < n; i++) {
var _x = _blends[i].x;
var _y = _blends[i].y;
var _c = _blends[i].color;
_shade_pal[_ind * 4 + 0] = _color_get_red(_c);
_shade_pal[_ind * 4 + 1] = _color_get_green(_c);
_shade_pal[_ind * 4 + 2] = _color_get_blue(_c);
_shade_pal[_ind * 4 + 3] = _color_get_alpha(_c);
_shade_pos[_ind * 2 + 0] = _mx_x + _x;
_shade_pos[_ind * 2 + 1] = _mx_y + _y;
_ind++;
}
connect_blend_surf = surface_verify(connect_blend_surf, pw, ph);
surface_set_shader(connect_blend_surf, sh_palette_mixer_atlas_expand_palette);
shader_set_f("dimension", pw, ph);
shader_set_i("paletteSize", array_length(palette));
shader_set_f("palette", _shade_pal);
shader_set_f("positions", _shade_pos);
shader_set_f("influence", node_size / ui(4));
shader_set_f("progress", shade_mode);
draw_surface(connect_surf, 0, 0);
surface_reset_shader();
draw_surface(connect_blend_surf, px, py);
} else {
shader_set(sh_FXAA);
gpu_set_tex_filter(true);
shader_set_f("dimension", pw, ph);
shader_set_f("cornerDis", 0.5);
shader_set_f("mixAmo", 1);
draw_surface(connect_surf, px, py);
gpu_set_tex_filter(false);
shader_reset();
}
draw_surface(connect_surf, px, py);
gpu_set_tex_filter(false);
shader_reset();
draw_surface(content_surf, px, py);
draw_surface(content_surf, px, py);
#endregion
if(_pHover && mouse_press(mb_middle)) {
mixer_dragging = true;
@ -583,9 +651,13 @@ function Panel_Palette_Mixer() : PanelContent() constructor {
var _cc = noone;
var _txt = "";
if(node_hovering) {
if(shade_mode > 0) {
_cc = surface_getpixel(connect_blend_surf, mx - px, my - py);
_txt = $"Sampled #{color_get_hex(_cc)}";
} else if(node_hovering) {
_cc = node_hovering.color;
_txt = $"Node #{color_get_hex(node_hovering.color)}";
_txt = $"Node #{color_get_hex(_cc)}";
} else if(blnd_hovering >= 0) {
_cc = palette_data.blends[blnd_hovering].color;

View file

@ -0,0 +1,9 @@
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D map;
void main() {
vec4 cord = texture2D( map, v_vTexcoord );
gl_FragColor = texture2D( gm_BaseTexture, cord.xy );
}

View file

@ -0,0 +1,19 @@
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}

View file

@ -0,0 +1,12 @@
{
"$GMShader":"",
"%Name":"sh_palette_mixer_atlas_expand_apply",
"name":"sh_palette_mixer_atlas_expand_apply",
"parent":{
"name":"palette mixer",
"path":"folders/shader/UI/palette mixer.yy",
},
"resourceType":"GMShader",
"resourceVersion":"2.0",
"type":1,
}

View file

@ -0,0 +1,9 @@
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main() {
vec4 c = texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor = vec4(v_vTexcoord, 0., 1.);
if(c.a == 0.) gl_FragColor = vec4(0.);
}

View file

@ -0,0 +1,19 @@
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}

View file

@ -0,0 +1,12 @@
{
"$GMShader":"",
"%Name":"sh_palette_mixer_atlas_expand_coord",
"name":"sh_palette_mixer_atlas_expand_coord",
"parent":{
"name":"palette mixer",
"path":"folders/shader/UI/palette mixer.yy",
},
"resourceType":"GMShader",
"resourceVersion":"2.0",
"type":1,
}

View file

@ -0,0 +1,32 @@
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform float dist;
vec4 sample(vec4 curr, vec2 samp) {
vec4 s = texture2D( gm_BaseTexture, clamp(samp, 0., 1.) );
if(s.a == 0.)
return curr;
if(curr.a == 0.)
return s;
if(distance(v_vTexcoord, s.xy) < distance(v_vTexcoord, curr.xy))
return s;
return curr;
}
void main() {
vec2 tx = 1. / dimension;
vec4 pos = texture2D( gm_BaseTexture, v_vTexcoord );
pos = sample( pos, v_vTexcoord + vec2( tx.x, 0.) * dist );
pos = sample( pos, v_vTexcoord + vec2(-tx.x, 0.) * dist );
pos = sample( pos, v_vTexcoord + vec2(0., tx.y) * dist );
pos = sample( pos, v_vTexcoord + vec2(0., -tx.y) * dist );
gl_FragColor = pos;
}

View file

@ -0,0 +1,19 @@
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}

View file

@ -0,0 +1,12 @@
{
"$GMShader":"",
"%Name":"sh_palette_mixer_atlas_expand_iterate",
"name":"sh_palette_mixer_atlas_expand_iterate",
"parent":{
"name":"palette mixer",
"path":"folders/shader/UI/palette mixer.yy",
},
"resourceType":"GMShader",
"resourceVersion":"2.0",
"type":1,
}

View file

@ -0,0 +1,50 @@
#define PALETTE_LIMIT 128
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform int paletteSize;
uniform vec4 palette[PALETTE_LIMIT];
uniform vec2 positions[PALETTE_LIMIT];
uniform float influence;
uniform float progress;
void main() {
vec4 c = texture2D( gm_BaseTexture, v_vTexcoord );
if(c.a > 0.) {
gl_FragColor = c;
return;
}
vec4 cc = vec4(0.);
float w = 0.;
float minDist = 999.;
for(int i = 0; i < paletteSize; i++) {
vec4 pal = palette[i];
vec2 pos = positions[i] / dimension;
if(v_vTexcoord == pos) {
gl_FragColor = pal;
return;
}
float dist = distance(v_vTexcoord, pos);
dist = 1. / pow(dist, influence);
cc += pal * dist;
w += dist;
minDist = min(minDist, dist);
}
if(w > 0.) cc /= w;
if(progress < 1.) {
cc.a = smoothstep(0., cc.a, progress * minDist);
}
gl_FragColor = cc;
}

View file

@ -0,0 +1,19 @@
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}

View file

@ -0,0 +1,12 @@
{
"$GMShader":"",
"%Name":"sh_palette_mixer_atlas_expand_palette",
"name":"sh_palette_mixer_atlas_expand_palette",
"parent":{
"name":"palette mixer",
"path":"folders/shader/UI/palette mixer.yy",
},
"resourceType":"GMShader",
"resourceVersion":"2.0",
"type":1,
}

View file

@ -117,7 +117,7 @@ void main() {
c = pow(c, vec3(gam));
c = floor(c * colors) / (colors - 1.);
c = pow(c, vec3(1.0 / gam));
_col = vec4(cMin + c * cRan, 1.);
_col = vec4(cMin + c * cRan, 1.);
_col.a = alpha == 1? 1. : _col.a;