mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-14 22:43:53 +01:00
autotile 1
This commit is contained in:
parent
84fa9459b7
commit
058cea8906
@ -403,6 +403,7 @@
|
|||||||
{"name":"__shapes","order":3,"path":"scripts/__shapes/__shapes.yy",},
|
{"name":"__shapes","order":3,"path":"scripts/__shapes/__shapes.yy",},
|
||||||
{"name":"__strandSim","order":2,"path":"scripts/__strandSim/__strandSim.yy",},
|
{"name":"__strandSim","order":2,"path":"scripts/__strandSim/__strandSim.yy",},
|
||||||
{"name":"__surface","order":7,"path":"scripts/__surface/__surface.yy",},
|
{"name":"__surface","order":7,"path":"scripts/__surface/__surface.yy",},
|
||||||
|
{"name":"__tiler_autotile","order":6,"path":"scripts/__tiler_autotile/__tiler_autotile.yy",},
|
||||||
{"name":"__tiler_brush","order":1,"path":"scripts/__tiler_brush/__tiler_brush.yy",},
|
{"name":"__tiler_brush","order":1,"path":"scripts/__tiler_brush/__tiler_brush.yy",},
|
||||||
{"name":"__tiler_tool","order":1,"path":"scripts/__tiler_tool/__tiler_tool.yy",},
|
{"name":"__tiler_tool","order":1,"path":"scripts/__tiler_tool/__tiler_tool.yy",},
|
||||||
{"name":"__vec2","order":7,"path":"scripts/__vec2/__vec2.yy",},
|
{"name":"__vec2","order":7,"path":"scripts/__vec2/__vec2.yy",},
|
||||||
@ -1753,6 +1754,8 @@
|
|||||||
{"name":"sh_texture_remap","order":11,"path":"shaders/sh_texture_remap/sh_texture_remap.yy",},
|
{"name":"sh_texture_remap","order":11,"path":"shaders/sh_texture_remap/sh_texture_remap.yy",},
|
||||||
{"name":"sh_threshold","order":18,"path":"shaders/sh_threshold/sh_threshold.yy",},
|
{"name":"sh_threshold","order":18,"path":"shaders/sh_threshold/sh_threshold.yy",},
|
||||||
{"name":"sh_tile_random","order":32,"path":"shaders/sh_tile_random/sh_tile_random.yy",},
|
{"name":"sh_tile_random","order":32,"path":"shaders/sh_tile_random/sh_tile_random.yy",},
|
||||||
|
{"name":"sh_tiler_autotile_apply","order":8,"path":"shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.yy",},
|
||||||
|
{"name":"sh_tiler_autotile_mask","order":7,"path":"shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.yy",},
|
||||||
{"name":"sh_time_remap","order":2,"path":"shaders/sh_time_remap/sh_time_remap.yy",},
|
{"name":"sh_time_remap","order":2,"path":"shaders/sh_time_remap/sh_time_remap.yy",},
|
||||||
{"name":"sh_trail_filler_pass1","order":26,"path":"shaders/sh_trail_filler_pass1/sh_trail_filler_pass1.yy",},
|
{"name":"sh_trail_filler_pass1","order":26,"path":"shaders/sh_trail_filler_pass1/sh_trail_filler_pass1.yy",},
|
||||||
{"name":"sh_trail_filler_pass2","order":28,"path":"shaders/sh_trail_filler_pass2/sh_trail_filler_pass2.yy",},
|
{"name":"sh_trail_filler_pass2","order":28,"path":"shaders/sh_trail_filler_pass2/sh_trail_filler_pass2.yy",},
|
||||||
|
@ -889,6 +889,7 @@
|
|||||||
{"id":{"name":"__shapes","path":"scripts/__shapes/__shapes.yy",},},
|
{"id":{"name":"__shapes","path":"scripts/__shapes/__shapes.yy",},},
|
||||||
{"id":{"name":"__strandSim","path":"scripts/__strandSim/__strandSim.yy",},},
|
{"id":{"name":"__strandSim","path":"scripts/__strandSim/__strandSim.yy",},},
|
||||||
{"id":{"name":"__surface","path":"scripts/__surface/__surface.yy",},},
|
{"id":{"name":"__surface","path":"scripts/__surface/__surface.yy",},},
|
||||||
|
{"id":{"name":"__tiler_autotile","path":"scripts/__tiler_autotile/__tiler_autotile.yy",},},
|
||||||
{"id":{"name":"__tiler_brush","path":"scripts/__tiler_brush/__tiler_brush.yy",},},
|
{"id":{"name":"__tiler_brush","path":"scripts/__tiler_brush/__tiler_brush.yy",},},
|
||||||
{"id":{"name":"__tiler_tool","path":"scripts/__tiler_tool/__tiler_tool.yy",},},
|
{"id":{"name":"__tiler_tool","path":"scripts/__tiler_tool/__tiler_tool.yy",},},
|
||||||
{"id":{"name":"__vec2","path":"scripts/__vec2/__vec2.yy",},},
|
{"id":{"name":"__vec2","path":"scripts/__vec2/__vec2.yy",},},
|
||||||
@ -2452,6 +2453,8 @@
|
|||||||
{"id":{"name":"sh_texture_repeat","path":"shaders/sh_texture_repeat/sh_texture_repeat.yy",},},
|
{"id":{"name":"sh_texture_repeat","path":"shaders/sh_texture_repeat/sh_texture_repeat.yy",},},
|
||||||
{"id":{"name":"sh_threshold","path":"shaders/sh_threshold/sh_threshold.yy",},},
|
{"id":{"name":"sh_threshold","path":"shaders/sh_threshold/sh_threshold.yy",},},
|
||||||
{"id":{"name":"sh_tile_random","path":"shaders/sh_tile_random/sh_tile_random.yy",},},
|
{"id":{"name":"sh_tile_random","path":"shaders/sh_tile_random/sh_tile_random.yy",},},
|
||||||
|
{"id":{"name":"sh_tiler_autotile_apply","path":"shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.yy",},},
|
||||||
|
{"id":{"name":"sh_tiler_autotile_mask","path":"shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.yy",},},
|
||||||
{"id":{"name":"sh_time_remap","path":"shaders/sh_time_remap/sh_time_remap.yy",},},
|
{"id":{"name":"sh_time_remap","path":"shaders/sh_time_remap/sh_time_remap.yy",},},
|
||||||
{"id":{"name":"sh_trail_filler_pass1","path":"shaders/sh_trail_filler_pass1/sh_trail_filler_pass1.yy",},},
|
{"id":{"name":"sh_trail_filler_pass1","path":"shaders/sh_trail_filler_pass1/sh_trail_filler_pass1.yy",},},
|
||||||
{"id":{"name":"sh_trail_filler_pass2","path":"shaders/sh_trail_filler_pass2/sh_trail_filler_pass2.yy",},},
|
{"id":{"name":"sh_trail_filler_pass2","path":"shaders/sh_trail_filler_pass2/sh_trail_filler_pass2.yy",},},
|
||||||
|
85
scripts/__tiler_autotile/__tiler_autotile.gml
Normal file
85
scripts/__tiler_autotile/__tiler_autotile.gml
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
function tiler_brush_autotile(_type, _index) constructor {
|
||||||
|
type = _type;
|
||||||
|
index = _index;
|
||||||
|
|
||||||
|
mask_surface = noone;
|
||||||
|
update_surface = noone;
|
||||||
|
drawing_surface = noone;
|
||||||
|
target_surface = noone;
|
||||||
|
eraseMode = false;
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case AUTOTILE_TYPE.box3_3 :
|
||||||
|
// - 1 - | 0 1 2
|
||||||
|
// 2 x 4 | 3 4 5
|
||||||
|
// - 8 - | 6 7 8
|
||||||
|
|
||||||
|
bitmask_type = 4;
|
||||||
|
bitmask = [ 4,
|
||||||
|
/* 1 */ 7,
|
||||||
|
/* 2 */ 5, 8,
|
||||||
|
/* 4 */ 3, 6, 4, 7,
|
||||||
|
/* 8 */ 1, 4, 2, 5, 0, 3, 1, 4,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
static drawing_start = function(surface, _erase = false) {
|
||||||
|
target_surface = surface;
|
||||||
|
eraseMode = _erase;
|
||||||
|
|
||||||
|
var _dim = surface_get_dimension(surface);
|
||||||
|
drawing_surface = surface_verify(drawing_surface, _dim[0], _dim[1], surface_r8unorm);
|
||||||
|
|
||||||
|
draw_set_color(c_white);
|
||||||
|
surface_set_target(drawing_surface);
|
||||||
|
DRAW_CLEAR
|
||||||
|
}
|
||||||
|
|
||||||
|
static drawing_end = function() {
|
||||||
|
surface_reset_target();
|
||||||
|
apply_drawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
static apply_drawing = function() {
|
||||||
|
var _dim = surface_get_dimension(target_surface);
|
||||||
|
mask_surface = surface_verify(mask_surface, _dim[0], _dim[1], surface_r8unorm);
|
||||||
|
update_surface = surface_verify(update_surface, _dim[0], _dim[1], surface_r16float);
|
||||||
|
|
||||||
|
// autotile mask
|
||||||
|
// #000000 : not part of autotile
|
||||||
|
// #808080 : part of autotile, read only
|
||||||
|
// #FFFFFF : part of autotile, writable
|
||||||
|
|
||||||
|
surface_set_shader(mask_surface, sh_tiler_autotile_mask);
|
||||||
|
shader_set_surface("drawSurface", drawing_surface);
|
||||||
|
shader_set_i("indexes", index);
|
||||||
|
shader_set_i("indexSize", array_length(index));
|
||||||
|
|
||||||
|
draw_surface(target_surface, 0, 0);
|
||||||
|
surface_reset_shader();
|
||||||
|
|
||||||
|
surface_set_shader(update_surface, sh_tiler_autotile_apply);
|
||||||
|
shader_set_2("dimension", _dim);
|
||||||
|
|
||||||
|
shader_set_surface("maskSurface", mask_surface);
|
||||||
|
shader_set_i("bitmask", bitmask);
|
||||||
|
shader_set_i("bitmaskSize", array_length(bitmask));
|
||||||
|
shader_set_i("bitmaskType", bitmask_type);
|
||||||
|
|
||||||
|
shader_set_i("indexes", index);
|
||||||
|
shader_set_i("indexSize", array_length(index));
|
||||||
|
shader_set_i("erase", eraseMode);
|
||||||
|
|
||||||
|
draw_surface(target_surface, 0, 0);
|
||||||
|
surface_reset_shader();
|
||||||
|
|
||||||
|
surface_set_target(target_surface);
|
||||||
|
DRAW_CLEAR
|
||||||
|
|
||||||
|
BLEND_OVERRIDE
|
||||||
|
draw_surface(update_surface, 0, 0);
|
||||||
|
BLEND_NORMAL
|
||||||
|
surface_reset_target();
|
||||||
|
}
|
||||||
|
}
|
13
scripts/__tiler_autotile/__tiler_autotile.yy
Normal file
13
scripts/__tiler_autotile/__tiler_autotile.yy
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"$GMScript":"v1",
|
||||||
|
"%Name":"__tiler_autotile",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"__tiler_autotile",
|
||||||
|
"parent":{
|
||||||
|
"name":"tools",
|
||||||
|
"path":"folders/nodes/data/tiler/tools.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
@ -51,11 +51,13 @@ function tiler_brush(node) constructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tiler_draw_point_brush(brush, _x, _y) {
|
function tiler_draw_point_brush(brush, _x, _y, _shader = true) {
|
||||||
if(brush.brush_height * brush.brush_width == 0) return;
|
if(brush.brush_height * brush.brush_width == 0) return;
|
||||||
|
|
||||||
|
if(_shader) {
|
||||||
shader_set(sh_draw_tile_brush);
|
shader_set(sh_draw_tile_brush);
|
||||||
BLEND_OVERRIDE
|
BLEND_OVERRIDE
|
||||||
|
}
|
||||||
|
|
||||||
for( var i = 0, n = brush.brush_height; i < n; i++ )
|
for( var i = 0, n = brush.brush_height; i < n; i++ )
|
||||||
for( var j = 0, m = brush.brush_width; j < m; j++ ) {
|
for( var j = 0, m = brush.brush_width; j < m; j++ ) {
|
||||||
@ -64,27 +66,30 @@ function tiler_draw_point_brush(brush, _x, _y) {
|
|||||||
var _xx = _x + j;
|
var _xx = _x + j;
|
||||||
var _yy = _y + i;
|
var _yy = _y + i;
|
||||||
|
|
||||||
if(brush.brush_size <= 1)
|
if(brush.brush_size <= 1) {
|
||||||
draw_point(_xx, _yy);
|
draw_point(_xx, _yy);
|
||||||
|
|
||||||
else if(brush.brush_size < global.FIX_POINTS_AMOUNT) {
|
} else if(brush.brush_size < global.FIX_POINTS_AMOUNT) {
|
||||||
var fx = global.FIX_POINTS[brush.brush_size];
|
var fx = global.FIX_POINTS[brush.brush_size];
|
||||||
|
|
||||||
for( var i = 0, n = array_length(fx); i < n; i++ )
|
for( var i = 0, n = array_length(fx); i < n; i++ )
|
||||||
draw_point(_xx + fx[i][0], _yy + fx[i][1]);
|
draw_point(_xx + fx[i][0], _yy + fx[i][1]);
|
||||||
|
}
|
||||||
} else
|
|
||||||
draw_circle_prec(_xx, _yy, brush.brush_size / 2, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(_shader) {
|
||||||
BLEND_NORMAL
|
BLEND_NORMAL
|
||||||
shader_reset();
|
shader_reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tiler_draw_line_brush(brush, _x0, _y0, _x1, _y1) {
|
function tiler_draw_line_brush(brush, _x0, _y0, _x1, _y1, _shader = true) {
|
||||||
if(brush.brush_height * brush.brush_width == 0) return;
|
if(brush.brush_height * brush.brush_width == 0) return;
|
||||||
|
|
||||||
|
if(_shader) {
|
||||||
shader_set(sh_draw_tile_brush);
|
shader_set(sh_draw_tile_brush);
|
||||||
BLEND_OVERRIDE
|
BLEND_OVERRIDE
|
||||||
|
}
|
||||||
|
|
||||||
for( var i = 0, n = brush.brush_height; i < n; i++ )
|
for( var i = 0, n = brush.brush_height; i < n; i++ )
|
||||||
for( var j = 0, m = brush.brush_width; j < m; j++ ) {
|
for( var j = 0, m = brush.brush_width; j < m; j++ ) {
|
||||||
@ -117,25 +122,27 @@ function tiler_draw_line_brush(brush, _x0, _y0, _x1, _y1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(_shader) {
|
||||||
BLEND_NORMAL
|
BLEND_NORMAL
|
||||||
shader_reset();
|
shader_reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tiler_draw_rect_brush(brush, _x0, _y0, _x1, _y1, _fill) {
|
function tiler_draw_rect_brush(brush, _x0, _y0, _x1, _y1, _fill, _shader = true) {
|
||||||
if(_x0 == _x1 && _y0 == _y1) {
|
if(_x0 == _x1 && _y0 == _y1) {
|
||||||
tiler_draw_point_brush(brush, _x0, _y0);
|
tiler_draw_point_brush(brush, _x0, _y0, _shader);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if(_x0 == _x1) {
|
} else if(_x0 == _x1) {
|
||||||
tiler_draw_point_brush(brush, _x0, _y0);
|
tiler_draw_point_brush(brush, _x0, _y0, _shader);
|
||||||
tiler_draw_point_brush(brush, _x1, _y1);
|
tiler_draw_point_brush(brush, _x1, _y1, _shader);
|
||||||
tiler_draw_line_brush(brush, _x0, _y0, _x0, _y1);
|
tiler_draw_line_brush(brush, _x0, _y0, _x0, _y1, _shader);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if(_y0 == _y1) {
|
} else if(_y0 == _y1) {
|
||||||
tiler_draw_point_brush(brush, _x0, _y0);
|
tiler_draw_point_brush(brush, _x0, _y0, _shader);
|
||||||
tiler_draw_point_brush(brush, _x1, _y1);
|
tiler_draw_point_brush(brush, _x1, _y1, _shader);
|
||||||
tiler_draw_line_brush(brush, _x0, _y0, _x1, _y0);
|
tiler_draw_line_brush(brush, _x0, _y0, _x1, _y0, _shader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,28 +156,28 @@ function tiler_draw_rect_brush(brush, _x0, _y0, _x1, _y1, _fill) {
|
|||||||
if(brush.brush_size == 1 && !is_surface(brush.brush_surface))
|
if(brush.brush_size == 1 && !is_surface(brush.brush_surface))
|
||||||
draw_rectangle(_min_x + 1, _min_y + 1, _max_x - 1, _may_y - 1, 1);
|
draw_rectangle(_min_x + 1, _min_y + 1, _max_x - 1, _may_y - 1, 1);
|
||||||
else {
|
else {
|
||||||
tiler_draw_line_brush(brush, _min_x, _min_y, _max_x, _min_y);
|
tiler_draw_line_brush(brush, _min_x, _min_y, _max_x, _min_y, _shader);
|
||||||
tiler_draw_line_brush(brush, _min_x, _min_y, _min_x, _may_y);
|
tiler_draw_line_brush(brush, _min_x, _min_y, _min_x, _may_y, _shader);
|
||||||
tiler_draw_line_brush(brush, _max_x, _may_y, _max_x, _min_y);
|
tiler_draw_line_brush(brush, _max_x, _may_y, _max_x, _min_y, _shader);
|
||||||
tiler_draw_line_brush(brush, _max_x, _may_y, _min_x, _may_y);
|
tiler_draw_line_brush(brush, _max_x, _may_y, _min_x, _may_y, _shader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tiler_draw_ellp_brush(brush, _x0, _y0, _x1, _y1, _fill) {
|
function tiler_draw_ellp_brush(brush, _x0, _y0, _x1, _y1, _fill, _shader = true) {
|
||||||
if(_x0 == _x1 && _y0 == _y1) {
|
if(_x0 == _x1 && _y0 == _y1) {
|
||||||
tiler_draw_point_brush(brush, _x0, _y0);
|
tiler_draw_point_brush(brush, _x0, _y0, _shader);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if(_x0 == _x1) {
|
} else if(_x0 == _x1) {
|
||||||
tiler_draw_point_brush(brush, _x0, _y0);
|
tiler_draw_point_brush(brush, _x0, _y0, _shader);
|
||||||
tiler_draw_point_brush(brush, _x1, _y1);
|
tiler_draw_point_brush(brush, _x1, _y1, _shader);
|
||||||
tiler_draw_line_brush(brush, _x0, _y0, _x0, _y1);
|
tiler_draw_line_brush(brush, _x0, _y0, _x0, _y1, _shader);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if(_y0 == _y1) {
|
} else if(_y0 == _y1) {
|
||||||
tiler_draw_point_brush(brush, _x0, _y0);
|
tiler_draw_point_brush(brush, _x0, _y0, _shader);
|
||||||
tiler_draw_point_brush(brush, _x1, _y1);
|
tiler_draw_point_brush(brush, _x1, _y1, _shader);
|
||||||
tiler_draw_line_brush(brush, _x0, _y0, _x1, _y0);
|
tiler_draw_line_brush(brush, _x0, _y0, _x1, _y0, _shader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +219,7 @@ function tiler_draw_ellp_brush(brush, _x0, _y0, _x1, _y1, _fill) {
|
|||||||
nx = round(cx + lengthdir_x(rx, 360 / samp * i));
|
nx = round(cx + lengthdir_x(rx, 360 / samp * i));
|
||||||
ny = round(cy + lengthdir_y(ry, 360 / samp * i));
|
ny = round(cy + lengthdir_y(ry, 360 / samp * i));
|
||||||
|
|
||||||
if(i) tiler_draw_line_brush(brush, ox, oy, nx, ny);
|
if(i) tiler_draw_line_brush(brush, ox, oy, nx, ny, _shader);
|
||||||
|
|
||||||
ox = nx;
|
ox = nx;
|
||||||
oy = ny;
|
oy = ny;
|
||||||
|
@ -31,6 +31,8 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
tile_selecting = false;
|
tile_selecting = false;
|
||||||
tile_select_ss = [ 0, 0 ];
|
tile_select_ss = [ 0, 0 ];
|
||||||
|
|
||||||
|
autotile_selector_mask = 0;
|
||||||
|
|
||||||
grid_draw = true;
|
grid_draw = true;
|
||||||
|
|
||||||
tile_selector = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus, _panel = noone) {
|
tile_selector = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus, _panel = noone) {
|
||||||
@ -47,6 +49,7 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _h, c_white, 1);
|
draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, _h, c_white, 1);
|
||||||
tile_selector_surface = surface_verify(tile_selector_surface, _sw, _sh);
|
tile_selector_surface = surface_verify(tile_selector_surface, _sw, _sh);
|
||||||
tile_selector_mask = surface_verify(tile_selector_mask, _sw, _sh);
|
tile_selector_mask = surface_verify(tile_selector_mask, _sw, _sh);
|
||||||
|
autotile_selector_mask = surface_verify(autotile_selector_mask, _sw, _sh);
|
||||||
|
|
||||||
if(!is_surface(_tileSet)) return _h;
|
if(!is_surface(_tileSet)) return _h;
|
||||||
|
|
||||||
@ -54,8 +57,8 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
|
|
||||||
var _tileAmo = [ floor(_tdim[0] / _tileSiz[0]), floor(_tdim[1] / _tileSiz[1]) ];
|
var _tileAmo = [ floor(_tdim[0] / _tileSiz[0]), floor(_tdim[1] / _tileSiz[1]) ];
|
||||||
|
|
||||||
var _tileSel_w =_tileSiz[0] * tile_selector_s;
|
var _tileSel_w = _tileSiz[0] * tile_selector_s;
|
||||||
var _tileSel_h =_tileSiz[1] * tile_selector_s;
|
var _tileSel_h = _tileSiz[1] * tile_selector_s;
|
||||||
|
|
||||||
var _msx = _m[0] - _sx - tile_selector_x;
|
var _msx = _m[0] - _sx - tile_selector_x;
|
||||||
var _msy = _m[1] - _sy - tile_selector_y;
|
var _msy = _m[1] - _sy - tile_selector_y;
|
||||||
@ -106,6 +109,7 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
|
|
||||||
draw_set_color(c_white);
|
draw_set_color(c_white);
|
||||||
draw_rectangle_width(_tileHov_x - 1, _tileHov_y - 1, _tileHov_x + _tileSel_w, _tileHov_y + _tileSel_h, 1);
|
draw_rectangle_width(_tileHov_x - 1, _tileHov_y - 1, _tileHov_x + _tileSel_w, _tileHov_y + _tileSel_h, 1);
|
||||||
|
|
||||||
draw_set_color(c_black);
|
draw_set_color(c_black);
|
||||||
draw_rectangle_width(_tileHov_x, _tileHov_y, _tileHov_x + _tileSel_w - 1, _tileHov_y + _tileSel_h - 1, 1);
|
draw_rectangle_width(_tileHov_x, _tileHov_y, _tileHov_x + _tileSel_w - 1, _tileHov_y + _tileSel_h - 1, 1);
|
||||||
|
|
||||||
@ -174,9 +178,9 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _s = tile_selector_s;
|
var _s = tile_selector_s;
|
||||||
if(mouse_wheel_up()) { tile_selector_s_to = clamp(tile_selector_s_to * 1.1, 0.5, 4); }
|
if(mouse_wheel_up()) { tile_selector_s_to = clamp(tile_selector_s_to * 1.2, 0.5, 4); }
|
||||||
if(mouse_wheel_down()) { tile_selector_s_to = clamp(tile_selector_s_to / 1.1, 0.5, 4); }
|
if(mouse_wheel_down()) { tile_selector_s_to = clamp(tile_selector_s_to / 1.2, 0.5, 4); }
|
||||||
tile_selector_s = lerp_float(tile_selector_s, tile_selector_s_to, 3);
|
tile_selector_s = lerp_float(tile_selector_s, tile_selector_s_to, 2);
|
||||||
|
|
||||||
if(_s != tile_selector_s) {
|
if(_s != tile_selector_s) {
|
||||||
var _ds = tile_selector_s - _s;
|
var _ds = tile_selector_s - _s;
|
||||||
@ -206,23 +210,47 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
draw_surface(tile_selector_mask, _sx, _sy);
|
draw_surface(tile_selector_mask, _sx, _sy);
|
||||||
shader_reset();
|
shader_reset();
|
||||||
|
|
||||||
|
#region autotile
|
||||||
|
|
||||||
|
for( var i = 0, n = array_length(autotiles); i < n; i++ ) {
|
||||||
|
var _att = autotiles[i];
|
||||||
|
|
||||||
|
surface_set_target(autotile_selector_mask);
|
||||||
|
DRAW_CLEAR
|
||||||
|
|
||||||
|
draw_set_color(c_white);
|
||||||
|
for( var j = 0, m = array_length(_att.index); j < m; j++ ) {
|
||||||
|
var _bindex = _att.index[j];
|
||||||
|
var _tileSel_row = floor(_bindex / _tileAmo[0]);
|
||||||
|
var _tileSel_col = safe_mod(_bindex, _tileAmo[0]);
|
||||||
|
var _tileSel_x = tile_selector_x + _tileSel_col * _tileSiz[0] * tile_selector_s;
|
||||||
|
var _tileSel_y = tile_selector_y + _tileSel_row * _tileSiz[1] * tile_selector_s;
|
||||||
|
draw_rectangle(_tileSel_x, _tileSel_y, _tileSel_x + _tileSel_w, _tileSel_y + _tileSel_h, false);
|
||||||
|
}
|
||||||
|
surface_reset_target();
|
||||||
|
|
||||||
|
shader_set(sh_brush_outline);
|
||||||
|
shader_set_f("dimension", _sw, _sh);
|
||||||
|
draw_surface_ext(autotile_selector_mask, _sx, _sy, 1, 1, 0, COLORS._main_accent, 1);
|
||||||
|
shader_reset();
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
return _h;
|
return _h;
|
||||||
});
|
});
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ++++ auto tile ++++
|
#region ++++ auto tile ++++
|
||||||
autotiles = [
|
autotiles = [
|
||||||
{
|
new tiler_brush_autotile(AUTOTILE_TYPE.box3_3, [
|
||||||
type: AUTOTILE_TYPE.box3_3,
|
|
||||||
indexes: [
|
|
||||||
0, 1, 2,
|
0, 1, 2,
|
||||||
3, 4, 5,
|
11, 12, 13,
|
||||||
6, 7, 8,
|
22, 23, 24,
|
||||||
],
|
]),
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
autotile_selecting = noone;
|
autotile_selecting = 0;
|
||||||
|
|
||||||
autotile_selector = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus, _panel = noone) {
|
autotile_selector = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus, _panel = noone) {
|
||||||
var _hh = 0;
|
var _hh = 0;
|
||||||
@ -458,6 +486,8 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou
|
|||||||
shader_reset();
|
shader_reset();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
if(autotiles[0].mask_surface) draw_surface_ext(autotiles[0].mask_surface, 32, 32, 8, 8, 0, c_white, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static processData = function(_outData, _data, _output_index, _array_index) {
|
static processData = function(_outData, _data, _output_index, _array_index) {
|
||||||
|
@ -177,6 +177,7 @@ function Panel_Preview() : PanelContent() constructor {
|
|||||||
view_pan_tool = false;
|
view_pan_tool = false;
|
||||||
view_zoom_tool = false;
|
view_zoom_tool = false;
|
||||||
|
|
||||||
|
sample_color_raw = noone;
|
||||||
sample_color = noone;
|
sample_color = noone;
|
||||||
sample_x = noone;
|
sample_x = noone;
|
||||||
sample_y = noone;
|
sample_y = noone;
|
||||||
@ -1028,6 +1029,7 @@ function Panel_Preview() : PanelContent() constructor {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
if(!instance_exists(o_dialog_menubox)) { // color sample
|
if(!instance_exists(o_dialog_menubox)) { // color sample
|
||||||
|
sample_color_raw = noone;
|
||||||
sample_color = noone;
|
sample_color = noone;
|
||||||
sample_x = noone;
|
sample_x = noone;
|
||||||
sample_y = noone;
|
sample_y = noone;
|
||||||
@ -1039,9 +1041,11 @@ function Panel_Preview() : PanelContent() constructor {
|
|||||||
sample_x = floor((mx - canvas_x) / canvas_s);
|
sample_x = floor((mx - canvas_x) / canvas_s);
|
||||||
sample_y = floor((my - canvas_y) / canvas_s);
|
sample_y = floor((my - canvas_y) / canvas_s);
|
||||||
var surf = getNodePreviewSurface();
|
var surf = getNodePreviewSurface();
|
||||||
sample_color = surface_get_pixel_ext(surf, sample_x, sample_y);
|
sample_color_raw = surface_getpixel_ext(surf, sample_x, sample_y);
|
||||||
|
sample_color = is_array(sample_color_raw)? make_color_rgba(clamp(sample_color_raw[0] * 255, 0, 255),
|
||||||
//print($"{dec_to_hex(sample_color)}: {color_get_alpha(int64(sample_color))}");
|
clamp(sample_color_raw[1] * 255, 0, 255),
|
||||||
|
clamp(sample_color_raw[2] * 255, 0, 255),
|
||||||
|
clamp(sample_color_raw[3] * 255, 0, 255)) : sample_color_raw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2061,8 +2065,13 @@ function Panel_Preview() : PanelContent() constructor {
|
|||||||
drawColor(sample_color, cx, cy, cw, ch);
|
drawColor(sample_color, cx, cy, cw, ch);
|
||||||
|
|
||||||
var tx = cx + cw + ui(8);
|
var tx = cx + cw + ui(8);
|
||||||
var hx = color_get_hex(sample_color);
|
|
||||||
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
|
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
|
||||||
|
|
||||||
|
if(is_array(sample_color_raw)) {
|
||||||
|
draw_text(tx, cy + ch / 2, sample_color_raw);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var hx = color_get_hex(sample_color);
|
||||||
draw_text(tx, cy + ch / 2, hx);
|
draw_text(tx, cy + ch / 2, hx);
|
||||||
|
|
||||||
tx += string_width(hx) + ui(8);
|
tx += string_width(hx) + ui(8);
|
||||||
@ -2070,6 +2079,7 @@ function Panel_Preview() : PanelContent() constructor {
|
|||||||
draw_text(tx, cy + ch / 2, $"({color_get_alpha(sample_color)})");
|
draw_text(tx, cy + ch / 2, $"({color_get_alpha(sample_color)})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var tbx = toolbar_height / 2;
|
var tbx = toolbar_height / 2;
|
||||||
var tby = ty + toolbar_height / 2;
|
var tby = ty + toolbar_height / 2;
|
||||||
|
@ -24,6 +24,8 @@ function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) const
|
|||||||
mouse_cur_x = floor(round((_mx - _x) / _s - 0.5) / tile_size[0]);
|
mouse_cur_x = floor(round((_mx - _x) / _s - 0.5) / tile_size[0]);
|
||||||
mouse_cur_y = floor(round((_my - _y) / _s - 0.5) / tile_size[1]);
|
mouse_cur_y = floor(round((_my - _y) / _s - 0.5) / tile_size[1]);
|
||||||
|
|
||||||
|
var _auto = brush.autotiler;
|
||||||
|
|
||||||
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_presses(SHIFT, CTRL)) {
|
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_presses(SHIFT, CTRL)) {
|
||||||
|
|
||||||
var _dx = mouse_cur_x - mouse_pre_draw_x;
|
var _dx = mouse_cur_x - mouse_pre_draw_x;
|
||||||
@ -54,11 +56,24 @@ function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) const
|
|||||||
tiler_draw_point_brush(brush, mouse_cur_x, mouse_cur_y);
|
tiler_draw_point_brush(brush, mouse_cur_x, mouse_cur_y);
|
||||||
surface_reset_target();
|
surface_reset_target();
|
||||||
|
|
||||||
|
if(_auto != noone) {
|
||||||
|
_auto.drawing_start(drawing_surface, isEraser);
|
||||||
|
tiler_draw_point_brush(brush, mouse_cur_x, mouse_cur_y, false);
|
||||||
|
_auto.drawing_end();
|
||||||
|
}
|
||||||
|
|
||||||
mouse_holding = true;
|
mouse_holding = true;
|
||||||
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT)) {
|
if(mouse_pre_draw_x != undefined && mouse_pre_draw_y != undefined && key_mod_press(SHIFT)) {
|
||||||
surface_set_target(drawing_surface);
|
surface_set_target(drawing_surface);
|
||||||
tiler_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
|
tiler_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
|
||||||
surface_reset_target();
|
surface_reset_target();
|
||||||
|
|
||||||
|
if(_auto != noone) {
|
||||||
|
_auto.drawing_start(drawing_surface, isEraser);
|
||||||
|
tiler_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, false);
|
||||||
|
_auto.drawing_end();
|
||||||
|
}
|
||||||
|
|
||||||
mouse_holding = false;
|
mouse_holding = false;
|
||||||
|
|
||||||
apply_draw_surface();
|
apply_draw_surface();
|
||||||
@ -73,6 +88,13 @@ function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) const
|
|||||||
surface_set_target(drawing_surface);
|
surface_set_target(drawing_surface);
|
||||||
tiler_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
|
tiler_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
|
||||||
surface_reset_target();
|
surface_reset_target();
|
||||||
|
|
||||||
|
if(_auto != noone) {
|
||||||
|
_auto.drawing_start(drawing_surface, isEraser);
|
||||||
|
tiler_draw_line_brush(brush, mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y, false);
|
||||||
|
_auto.drawing_end();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_pre_draw_x = mouse_cur_x;
|
mouse_pre_draw_x = mouse_cur_x;
|
||||||
|
@ -3,6 +3,10 @@ varying vec4 v_vColour;
|
|||||||
|
|
||||||
uniform float index;
|
uniform float index;
|
||||||
|
|
||||||
|
// uniform int autotile_type;
|
||||||
|
// uniform int autotile_bitmask_in[256];
|
||||||
|
// uniform int autotile_bitmask_out[256];
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_FragColor = vec4(index + 1., 0., 0., 1.);
|
gl_FragColor = vec4(index + 1., 0., 0., 1.);
|
||||||
}
|
}
|
||||||
|
68
shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.fsh
Normal file
68
shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.fsh
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
varying vec2 v_vTexcoord;
|
||||||
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
|
uniform sampler2D maskSurface;
|
||||||
|
|
||||||
|
uniform vec2 dimension;
|
||||||
|
uniform int bitmask[1024];
|
||||||
|
uniform int bitmaskSize;
|
||||||
|
uniform int bitmaskType;
|
||||||
|
|
||||||
|
uniform int indexes[1024];
|
||||||
|
uniform int indexSize;
|
||||||
|
uniform int erase;
|
||||||
|
|
||||||
|
vec2 tx = 1. / dimension;
|
||||||
|
|
||||||
|
float msk(float x, float y) { return texture2D( maskSurface, v_vTexcoord + vec2(x, y) * tx )[0]; }
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
float m0 = msk(-1., -1.);
|
||||||
|
float m1 = msk( 0., -1.);
|
||||||
|
float m2 = msk( 1., -1.);
|
||||||
|
|
||||||
|
float m3 = msk(-1., 0.);
|
||||||
|
float m4 = msk( 0., 0.);
|
||||||
|
float m5 = msk( 1., 0.);
|
||||||
|
|
||||||
|
float m6 = msk(-1., 1.);
|
||||||
|
float m7 = msk( 0., 1.);
|
||||||
|
float m8 = msk( 1., 1.);
|
||||||
|
|
||||||
|
float mm = max(m8, max(max(max(m0, m1),
|
||||||
|
max(m2, m3)),
|
||||||
|
max(max(m4, m5),
|
||||||
|
max(m6, m7))
|
||||||
|
));
|
||||||
|
|
||||||
|
vec4 base = texture2D( gm_BaseTexture, v_vTexcoord );
|
||||||
|
gl_FragColor = base;
|
||||||
|
|
||||||
|
if(m4 == 0.) return;
|
||||||
|
if(mm < 1.) return;
|
||||||
|
if(base[0] <= 0.) return;
|
||||||
|
|
||||||
|
int i0 = m0 == 1. && erase == 1? 0 : int(ceil(m0));
|
||||||
|
int i1 = m1 == 1. && erase == 1? 0 : int(ceil(m1));
|
||||||
|
int i2 = m2 == 1. && erase == 1? 0 : int(ceil(m2));
|
||||||
|
|
||||||
|
int i3 = m3 == 1. && erase == 1? 0 : int(ceil(m3));
|
||||||
|
int i4 = m4 == 1. && erase == 1? 0 : int(ceil(m4));
|
||||||
|
int i5 = m5 == 1. && erase == 1? 0 : int(ceil(m5));
|
||||||
|
|
||||||
|
int i6 = m6 == 1. && erase == 1? 0 : int(ceil(m6));
|
||||||
|
int i7 = m7 == 1. && erase == 1? 0 : int(ceil(m7));
|
||||||
|
int i8 = m8 == 1. && erase == 1? 0 : int(ceil(m8));
|
||||||
|
|
||||||
|
int bitIndex;
|
||||||
|
|
||||||
|
if(bitmaskType == 4) bitIndex = i1 * 1 + i3 * 2 + i5 * 4 + i7 * 8;
|
||||||
|
else if(bitmaskType == 8) bitIndex = i0 * 1 + i1 * 2 + i2 * 4
|
||||||
|
+ i3 * 8 + i5 * 16
|
||||||
|
+ i6 * 32 + i7 * 64 + i8 * 128;
|
||||||
|
|
||||||
|
float res = float(indexes[bitmask[bitIndex]]);
|
||||||
|
gl_FragColor = vec4(res + 1., 0., 0., 0.);
|
||||||
|
|
||||||
|
}
|
19
shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.vsh
Normal file
19
shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.vsh
Normal 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;
|
||||||
|
}
|
12
shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.yy
Normal file
12
shaders/sh_tiler_autotile_apply/sh_tiler_autotile_apply.yy
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$GMShader":"",
|
||||||
|
"%Name":"sh_tiler_autotile_apply",
|
||||||
|
"name":"sh_tiler_autotile_apply",
|
||||||
|
"parent":{
|
||||||
|
"name":"shaders",
|
||||||
|
"path":"folders/nodes/data/tiler/shaders.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMShader",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
"type":1,
|
||||||
|
}
|
23
shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.fsh
Normal file
23
shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.fsh
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
varying vec2 v_vTexcoord;
|
||||||
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
|
uniform sampler2D drawSurface;
|
||||||
|
|
||||||
|
uniform int indexes[1024];
|
||||||
|
uniform int indexSize;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
int ss = int(texture2D( gm_BaseTexture, v_vTexcoord )[0] - 1.);
|
||||||
|
float dd = texture2D( drawSurface, v_vTexcoord )[0];
|
||||||
|
|
||||||
|
vec4 res = vec4(0.);
|
||||||
|
|
||||||
|
for(int i = 0; i < indexSize; i++) {
|
||||||
|
if(ss == indexes[i])
|
||||||
|
res[0] = .5;
|
||||||
|
}
|
||||||
|
|
||||||
|
res[0] = max(res[0], dd);
|
||||||
|
|
||||||
|
gl_FragColor = res;
|
||||||
|
}
|
19
shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.vsh
Normal file
19
shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.vsh
Normal 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;
|
||||||
|
}
|
12
shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.yy
Normal file
12
shaders/sh_tiler_autotile_mask/sh_tiler_autotile_mask.yy
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$GMShader":"",
|
||||||
|
"%Name":"sh_tiler_autotile_mask",
|
||||||
|
"name":"sh_tiler_autotile_mask",
|
||||||
|
"parent":{
|
||||||
|
"name":"shaders",
|
||||||
|
"path":"folders/nodes/data/tiler/shaders.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMShader",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
"type":1,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user