New Sample gradient node

This commit is contained in:
Tanasart 2024-11-30 14:40:42 +07:00
parent 9b50a34e46
commit 09e6a34ba7
8 changed files with 160 additions and 0 deletions

View file

@ -812,6 +812,7 @@
{"name":"node_gradient_palette","order":11,"path":"scripts/node_gradient_palette/node_gradient_palette.yy",},
{"name":"node_gradient_points","order":1,"path":"scripts/node_gradient_points/node_gradient_points.yy",},
{"name":"node_gradient_replace_color","order":12,"path":"scripts/node_gradient_replace_color/node_gradient_replace_color.yy",},
{"name":"node_gradient_sample","order":16,"path":"scripts/node_gradient_sample/node_gradient_sample.yy",},
{"name":"node_gradient_shift","order":10,"path":"scripts/node_gradient_shift/node_gradient_shift.yy",},
{"name":"node_grain","order":19,"path":"scripts/node_grain/node_grain.yy",},
{"name":"node_graph_preview","order":20,"path":"scripts/node_graph_preview/node_graph_preview.yy",},
@ -2207,6 +2208,7 @@
{"name":"s_node_gradient_out","order":10,"path":"sprites/s_node_gradient_out/s_node_gradient_out.yy",},
{"name":"s_node_gradient_palette","order":11,"path":"sprites/s_node_gradient_palette/s_node_gradient_palette.yy",},
{"name":"s_node_gradient_replace","order":12,"path":"sprites/s_node_gradient_replace/s_node_gradient_replace.yy",},
{"name":"s_node_gradient_sample","order":22,"path":"sprites/s_node_gradient_sample/s_node_gradient_sample.yy",},
{"name":"s_node_gradient_shift","order":13,"path":"sprites/s_node_gradient_shift/s_node_gradient_shift.yy",},
{"name":"s_node_gradient_type","order":6,"path":"sprites/s_node_gradient_type/s_node_gradient_type.yy",},
{"name":"s_node_gradient","order":1,"path":"sprites/s_node_gradient/s_node_gradient.yy",},

View file

@ -1370,6 +1370,7 @@
{"id":{"name":"node_gradient_palette","path":"scripts/node_gradient_palette/node_gradient_palette.yy",},},
{"id":{"name":"node_gradient_points","path":"scripts/node_gradient_points/node_gradient_points.yy",},},
{"id":{"name":"node_gradient_replace_color","path":"scripts/node_gradient_replace_color/node_gradient_replace_color.yy",},},
{"id":{"name":"node_gradient_sample","path":"scripts/node_gradient_sample/node_gradient_sample.yy",},},
{"id":{"name":"node_gradient_shift","path":"scripts/node_gradient_shift/node_gradient_shift.yy",},},
{"id":{"name":"node_gradient","path":"scripts/node_gradient/node_gradient.yy",},},
{"id":{"name":"node_grain","path":"scripts/node_grain/node_grain.yy",},},
@ -2935,6 +2936,7 @@
{"id":{"name":"s_node_gradient_out","path":"sprites/s_node_gradient_out/s_node_gradient_out.yy",},},
{"id":{"name":"s_node_gradient_palette","path":"sprites/s_node_gradient_palette/s_node_gradient_palette.yy",},},
{"id":{"name":"s_node_gradient_replace","path":"sprites/s_node_gradient_replace/s_node_gradient_replace.yy",},},
{"id":{"name":"s_node_gradient_sample","path":"sprites/s_node_gradient_sample/s_node_gradient_sample.yy",},},
{"id":{"name":"s_node_gradient_shift","path":"sprites/s_node_gradient_shift/s_node_gradient_shift.yy",},},
{"id":{"name":"s_node_gradient_type","path":"sprites/s_node_gradient_type/s_node_gradient_type.yy",},},
{"id":{"name":"s_node_gradient","path":"sprites/s_node_gradient/s_node_gradient.yy",},},

View file

@ -0,0 +1,52 @@
function Node_Gradient_Sample(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Sample Gradient";
setDimension(96);
newInput(0, nodeValue_Gradient("Gradient", self, new gradientObject([cola(c_black), cola(c_white)])) )
.setVisible(true, true);
newInput(1, nodeValue_Int("Step", self, 16));
newInput(2, nodeValue_Float("Shift", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range: [-1, 1, 0.01] });
newOutput(0, nodeValue_Output("Colors", self, VALUE_TYPE.color, [ c_black ]))
.setDisplay(VALUE_DISPLAY.palette);
_pal = -1;
static processData_prebatch = function() {
setDimension(96, process_length[0] * 32);
}
static processData = function(_outSurf, _data, _output_index, _array_index) {
var grad = _data[0];
var stp = _data[1];
var shf = _data[2];
_outSurf = array_verify(_outSurf, stp);
for( var i = 0; i < stp; i++ ) {
var _t = frac(shf + i / stp);
_outSurf[i] = grad.eval(_t);
}
return _outSurf;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
if(bbox.h < 1) return;
var pal = outputs[0].getValue();
if(array_empty(pal)) return;
if(!is_array(pal[0])) pal = [ pal ];
var _y = bbox.y0;
var gh = bbox.h / array_length(pal);
for( var i = 0, n = array_length(pal); i < n; i++ ) {
drawPalette(pal[i], bbox.x0, _y, bbox.w, gh);
_y += gh;
}
}
}

View file

@ -0,0 +1,13 @@
{
"$GMScript":"v1",
"%Name":"node_gradient_sample",
"isCompatibility":false,
"isDnD":false,
"name":"node_gradient_sample",
"parent":{
"name":"color",
"path":"folders/nodes/data/value/color.yy",
},
"resourceType":"GMScript",
"resourceVersion":"2.0",
}

View file

@ -1037,6 +1037,7 @@ function __initNodes() {
addNodeObject(color, "Gradient Shift", s_node_gradient_shift, "Node_Gradient_Shift", [1, Node_Gradient_Shift],, "Move gradients keys.");
addNodeObject(color, "Gradient Replace", s_node_gradient_replace, "Node_Gradient_Replace_Color", [1, Node_Gradient_Replace_Color],, "Replace color inside a gradient.").setVersion(1135);
addNodeObject(color, "Gradient Data", s_node_gradient_data, "Node_Gradient_Extract", [1, Node_Gradient_Extract],, "Get palatte and array of key positions from gradient.").setVersion(1135);
addNodeObject(color, "Sample Gradient", s_node_gradient_sample, "Node_Gradient_Sample", [1, Node_Gradient_Sample], ["gradient sample"], "Sample gradient into palette.").setVersion(1_18_04_1);
#endregion
#region animation

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,90 @@
{
"$GMSprite":"",
"%Name":"s_node_gradient_sample",
"bboxMode":0,
"bbox_bottom":63,
"bbox_left":2,
"bbox_right":61,
"bbox_top":0,
"collisionKind":1,
"collisionTolerance":0,
"DynamicTexturePage":false,
"edgeFiltering":false,
"For3D":false,
"frames":[
{"$GMSpriteFrame":"","%Name":"2b4cc30b-1457-4a03-aa42-bdf4086ca7b9","name":"2b4cc30b-1457-4a03-aa42-bdf4086ca7b9","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
],
"gridX":0,
"gridY":0,
"height":64,
"HTile":false,
"layers":[
{"$GMImageLayer":"","%Name":"f91fe59c-c806-4364-901c-861258a8525c","blendMode":0,"displayName":"default","isLocked":false,"name":"f91fe59c-c806-4364-901c-861258a8525c","opacity":100.0,"resourceType":"GMImageLayer","resourceVersion":"2.0","visible":true,},
],
"name":"s_node_gradient_sample",
"nineSlice":null,
"origin":4,
"parent":{
"name":"color",
"path":"folders/nodes/icons/value/color.yy",
},
"preMultiplyAlpha":false,
"resourceType":"GMSprite",
"resourceVersion":"2.0",
"sequence":{
"$GMSequence":"",
"%Name":"s_node_gradient_sample",
"autoRecord":true,
"backdropHeight":768,
"backdropImageOpacity":0.5,
"backdropImagePath":"",
"backdropWidth":1366,
"backdropXOffset":0.0,
"backdropYOffset":0.0,
"events":{
"$KeyframeStore<MessageEventKeyframe>":"",
"Keyframes":[],
"resourceType":"KeyframeStore<MessageEventKeyframe>",
"resourceVersion":"2.0",
},
"eventStubScript":null,
"eventToFunction":{},
"length":1.0,
"lockOrigin":false,
"moments":{
"$KeyframeStore<MomentsEventKeyframe>":"",
"Keyframes":[],
"resourceType":"KeyframeStore<MomentsEventKeyframe>",
"resourceVersion":"2.0",
},
"name":"s_node_gradient_sample",
"playback":1,
"playbackSpeed":30.0,
"playbackSpeedType":0,
"resourceType":"GMSequence",
"resourceVersion":"2.0",
"showBackdrop":true,
"showBackdropImage":false,
"timeUnits":1,
"tracks":[
{"$GMSpriteFramesTrack":"","builtinName":0,"events":[],"inheritsTrackColour":true,"interpolation":1,"isCreationTrack":false,"keyframes":{"$KeyframeStore<SpriteFrameKeyframe>":"","Keyframes":[
{"$Keyframe<SpriteFrameKeyframe>":"","Channels":{
"0":{"$SpriteFrameKeyframe":"","Id":{"name":"2b4cc30b-1457-4a03-aa42-bdf4086ca7b9","path":"sprites/s_node_gradient_sample/s_node_gradient_sample.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"adece9c5-dc7d-489a-8527-89cc9b78e9da","IsCreationKey":false,"Key":0.0,"Length":1.0,"resourceType":"Keyframe<SpriteFrameKeyframe>","resourceVersion":"2.0","Stretch":false,},
],"resourceType":"KeyframeStore<SpriteFrameKeyframe>","resourceVersion":"2.0",},"modifiers":[],"name":"frames","resourceType":"GMSpriteFramesTrack","resourceVersion":"2.0","spriteId":null,"trackColour":0,"tracks":[],"traits":0,},
],
"visibleRange":null,
"volume":1.0,
"xorigin":32,
"yorigin":32,
},
"swatchColours":null,
"swfPrecision":0.5,
"textureGroupId":{
"name":"Default",
"path":"texturegroups/Default",
},
"type":0,
"VTile":false,
"width":64,
}