- New Repeat texture node.

This commit is contained in:
Tanasart 2024-06-13 17:28:02 +07:00
parent 8a9b5277ac
commit c5fcb15580
17 changed files with 326 additions and 5 deletions

View file

@ -166,6 +166,7 @@
{"name":"blinker","order":19,"path":"folders/shader/generator/blinker.yy",},
{"name":"cell","order":20,"path":"folders/shader/generator/cell.yy",},
{"name":"grid","order":18,"path":"folders/shader/generator/grid.yy",},
{"name":"texture repeat","order":28,"path":"folders/shader/generator/texture repeat.yy",},
{"name":"interpret","order":17,"path":"folders/shader/generator/interpret.yy",},
{"name":"random_shape","order":21,"path":"folders/shader/generator/random_shape.yy",},
{"name":"reaction_diffusion","order":22,"path":"folders/shader/generator/reaction_diffusion.yy",},
@ -986,6 +987,7 @@
{"name":"node_rd","order":4,"path":"scripts/node_rd/node_rd.yy",},
{"name":"node_region_fill","order":1,"path":"scripts/node_region_fill/node_region_fill.yy",},
{"name":"node_registry","order":11,"path":"scripts/node_registry/node_registry.yy",},
{"name":"node_repeat_texture","order":23,"path":"scripts/node_repeat_texture/node_repeat_texture.yy",},
{"name":"node_repeat","order":5,"path":"scripts/node_repeat/node_repeat.yy",},
{"name":"node_rigid_activate","order":1,"path":"scripts/node_rigid_activate/node_rigid_activate.yy",},
{"name":"node_rigid_force_apply","order":2,"path":"scripts/node_rigid_force_apply/node_rigid_force_apply.yy",},
@ -1953,6 +1955,7 @@
{"name":"s_node_regex_search","order":11,"path":"sprites/s_node_regex_search/s_node_regex_search.yy",},
{"name":"s_node_region_fill","order":29,"path":"sprites/s_node_region_fill/s_node_region_fill.yy",},
{"name":"s_node_repeat_axis","order":16,"path":"sprites/s_node_repeat_axis/s_node_repeat_axis.yy",},
{"name":"s_node_repeat_texture","order":55,"path":"sprites/s_node_repeat_texture/s_node_repeat_texture.yy",},
{"name":"s_node_repeat","order":23,"path":"sprites/s_node_repeat/s_node_repeat.yy",},
{"name":"s_node_replace_palette","order":44,"path":"sprites/s_node_replace_palette/s_node_replace_palette.yy",},
{"name":"s_node_RGB_combine","order":46,"path":"sprites/s_node_RGB_combine/s_node_RGB_combine.yy",},

View file

@ -288,6 +288,7 @@
{"$GMFolder":"","%Name":"blinker","folderPath":"folders/shader/generator/blinker.yy","name":"blinker","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"cell","folderPath":"folders/shader/generator/cell.yy","name":"cell","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"grid","folderPath":"folders/shader/generator/grid.yy","name":"grid","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"texture repeat","folderPath":"folders/shader/generator/texture repeat.yy","name":"texture repeat","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"interpret","folderPath":"folders/shader/generator/interpret.yy","name":"interpret","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"random_shape","folderPath":"folders/shader/generator/random_shape.yy","name":"random_shape","resourceType":"GMFolder","resourceVersion":"2.0",},
{"$GMFolder":"","%Name":"reaction_diffusion","folderPath":"folders/shader/generator/reaction_diffusion.yy","name":"reaction_diffusion","resourceType":"GMFolder","resourceVersion":"2.0",},
@ -1414,6 +1415,7 @@
{"id":{"name":"node_region_fill","path":"scripts/node_region_fill/node_region_fill.yy",},},
{"id":{"name":"node_registry","path":"scripts/node_registry/node_registry.yy",},},
{"id":{"name":"node_render_sprite_sheet","path":"scripts/node_render_sprite_sheet/node_render_sprite_sheet.yy",},},
{"id":{"name":"node_repeat_texture","path":"scripts/node_repeat_texture/node_repeat_texture.yy",},},
{"id":{"name":"node_repeat","path":"scripts/node_repeat/node_repeat.yy",},},
{"id":{"name":"node_rgb_channel","path":"scripts/node_rgb_channel/node_rgb_channel.yy",},},
{"id":{"name":"node_rigid_activate","path":"scripts/node_rigid_activate/node_rigid_activate.yy",},},
@ -2083,6 +2085,7 @@
{"id":{"name":"sh_svg_fill","path":"shaders/sh_svg_fill/sh_svg_fill.yy",},},
{"id":{"name":"sh_texture_atlas","path":"shaders/sh_texture_atlas/sh_texture_atlas.yy",},},
{"id":{"name":"sh_texture_remap","path":"shaders/sh_texture_remap/sh_texture_remap.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_tile_random","path":"shaders/sh_tile_random/sh_tile_random.yy",},},
{"id":{"name":"sh_time_remap","path":"shaders/sh_time_remap/sh_time_remap.yy",},},
@ -2517,6 +2520,7 @@
{"id":{"name":"s_node_regex_search","path":"sprites/s_node_regex_search/s_node_regex_search.yy",},},
{"id":{"name":"s_node_region_fill","path":"sprites/s_node_region_fill/s_node_region_fill.yy",},},
{"id":{"name":"s_node_repeat_axis","path":"sprites/s_node_repeat_axis/s_node_repeat_axis.yy",},},
{"id":{"name":"s_node_repeat_texture","path":"sprites/s_node_repeat_texture/s_node_repeat_texture.yy",},},
{"id":{"name":"s_node_repeat","path":"sprites/s_node_repeat/s_node_repeat.yy",},},
{"id":{"name":"s_node_replace_palette","path":"sprites/s_node_replace_palette/s_node_replace_palette.yy",},},
{"id":{"name":"s_node_RGB_combine","path":"sprites/s_node_RGB_combine/s_node_RGB_combine.yy",},},

View file

@ -745,6 +745,7 @@ function __initNodes() {
ds_list_add(generator, "Populate");
addNodeObject(generator, "Repeat", s_node_repeat, "Node_Repeat", [1, Node_Repeat],, "Repeat image multiple times linearly, or in grid pattern.").setVersion(1100);
addNodeObject(generator, "Scatter", s_node_scatter, "Node_Scatter", [1, Node_Scatter],, "Scatter image randomly multiple times.");
addNodeObject(generator, "Repeat Texture", s_node_repeat_texture, "Node_Repeat_Texture", [1, Node_Repeat_Texture],, "Repeat texture over larger surface without repeating patterns.");
ds_list_add(generator, "Simulation");
addNodeObject(generator, "Particle", s_node_particle, "Node_Particle", [1, Node_Particle],, "Generate particle effect.");

View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "generator",
"path": "folders/nodes/data/generator.yy",
},
"resourceVersion": "1.0",
"name": "node_checkerboard",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -0,0 +1,49 @@
function Node_Repeat_Texture(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Repeat Texture";
dimension_index = 1;
inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone );
inputs[| 1] = nodeValue("Target dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF)
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 2] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Tile", "Scatter", "Cell" ]);
inputs[| 3] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, seed_random(6))
.setDisplay(VALUE_DISPLAY._default, { side_button : button(function() { randomize(); inputs[| 3].setValue(seed_random(6)); }).setIcon(THEME.icon_random, 0, COLORS._main_icon) })
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
input_display_list = [ 3,
["Surfaces", false], 0,
["Repeat", false], 1, 2,
];
attribute_surface_depth();
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _surf = _data[0];
var _dim = _data[1];
var _type = _data[2];
var _seed = _data[3];
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
var _sdim = surface_get_dimension(_surf);
gpu_set_texrepeat(1);
surface_set_shader(_outSurf, sh_texture_repeat);
shader_set_f("seed", _seed);
shader_set_f("dimension", _dim);
shader_set_f("surfaceDimension", _sdim);
shader_set_surface("surface", _surf);
shader_set_i("type", _type);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1]);
surface_reset_shader();
gpu_set_texrepeat(0);
return _outSurf;
}
}

View file

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

View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "generator",
"path": "folders/nodes/data/generator.yy",
},
"resourceVersion": "1.0",
"name": "node_stripe",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -134,6 +134,8 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
inputs[| 37] = nodeValue("Triplanar Smoothing", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1.)
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 10, 0.1 ] });
inputs[| 38] = nodeValue("Texture Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1.);
outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
input_display_list = [ 0,
@ -141,7 +143,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
["Modify", false], 12, 11,
["Deform", true], 15, 16, 17, 18, 19,
["Transform", false], 2, 3, 4,
["Material", false], 9, 36, 35, 37,
["Material", false], 9, 36, 35, 37, 38,
["Camera", false], 13, 14, 5, 6,
["Render", false], 31, 30, 34, 10, 7, 8,
["Tile", false], 20, 29,
@ -290,6 +292,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
var _text = _data[36];
var _triS = _data[37];
var _texs = _data[38];
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);
@ -379,6 +382,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro
shader_set_i("volumetric", _vol);
shader_set_f("volumeDensity", _vden);
shader_set_f("triplanar", _triS);
shader_set_f("textureScale", _texs);
shader_set_i("useEnv", is_surface(bgEnv));
shader_set_i("useTexture", is_surface(_text));

View file

@ -123,7 +123,6 @@ void main() {
float angle = atan(vecPc.y, vecPc.x);
float dist = length(vecPc);
vec4 clr = vec4(0.);
vec4 res = vec4(0.);
float weight = 0.;
float maxBright = 0.;

View file

@ -13,7 +13,7 @@ uniform int strengthUseSurf;
uniform sampler2D strengthSurf;
uniform int sampleMode;
uniform int gamm;
uniform int gamma;
vec2 tx;
vec2 txMap;
@ -142,7 +142,7 @@ void main() {
}
vec4 res = colr / alpha;
if(gamma == 1) res.rgb = pow(result.rgb, vec3(1. / 2.2));
if(gamma == 1) res.rgb = pow(res.rgb, vec3(1. / 2.2));
gl_FragColor = res;
}

View file

@ -61,6 +61,7 @@ uniform float reflective;
uniform int useEnv;
uniform int useTexture;
uniform float textureScale;
uniform float triplanar;
uniform int volumetric;
@ -530,7 +531,7 @@ void main() {
if(dist > viewRange.y - EPSILON) // Not hitting anything.
return;
vec3 c = useTexture == 1? boxmap(1, coll, norm, triplanar).rgb * ambient.rgb : ambient.rgb;
vec3 c = useTexture == 1? boxmap(1, coll * textureScale, norm, triplanar).rgb * ambient.rgb : ambient.rgb;
///////////////////////////////////////////////////////////

View file

@ -0,0 +1,102 @@
// Tiling algorithms
// Copyright © 2015 Inigo Quilez
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform vec2 surfaceDimension;
uniform sampler2D surface;
uniform int type;
uniform float seed;
vec4 hash4( vec2 p ) { return fract(sin(vec4( 1.0 + seed + dot(p, vec2(37.0, 17.0)),
2.0 + seed + dot(p, vec2(11.0, 47.0)),
3.0 + seed + dot(p, vec2(41.0, 29.0)),
4.0 + seed + dot(p, vec2(23.0, 31.0)))) * 103.0); }
vec4 randomSample( in vec2 uv ) {
vec2 iuv = floor( uv );
vec2 fuv = fract( uv );
vec4 ofa = hash4( iuv + vec2(0.0, 0.0) );
vec4 ofb = hash4( iuv + vec2(1.0, 0.0) );
vec4 ofc = hash4( iuv + vec2(0.0, 1.0) );
vec4 ofd = hash4( iuv + vec2(1.0, 1.0) );
// transform per-tile uvs
ofa.zw = vec2(sign(ofa.zw - 0.5));
ofb.zw = vec2(sign(ofb.zw - 0.5));
ofc.zw = vec2(sign(ofc.zw - 0.5));
ofd.zw = vec2(sign(ofd.zw - 0.5));
// uv's, and derivarives (for correct mipmapping)
vec2 uva = uv * ofa.zw + ofa.xy;
vec2 uvb = uv * ofb.zw + ofb.xy;
vec2 uvc = uv * ofc.zw + ofc.xy;
vec2 uvd = uv * ofd.zw + ofd.xy;
// fetch and blend
vec2 b = smoothstep(0.25, 0.75, fuv);
return mix( mix( texture2D( surface, fract(uva) ),
texture2D( surface, fract(uvb) ), b.x ),
mix( texture2D( surface, fract(uvc) ),
texture2D( surface, fract(uvd) ), b.x), b.y );
}
vec3 cellSample( in vec2 uv, float v ) {
vec2 p = floor( uv );
vec2 f = fract( uv );
vec3 va = vec3(0.0);
float w1 = 0.0;
float w2 = 0.0;
for( int j=-1; j<=1; j++ )
for( int i=-1; i<=1; i++ ) {
vec2 g = vec2( float(i), float(j) );
vec4 o = hash4( p + g );
vec2 r = g - f + o.xy;
float d = dot(r, r);
float w = exp(-5.0 * d );
vec3 c = texture2D( surface, fract(uv + v * o.zw) ).xyz;
va += w * c;
w1 += w;
w2 += w * w;
}
return va / w1;
}
float sum( vec3 v ) { return v.x + v.y + v.z; }
vec3 onionSample( in vec2 x, float v ) {
float k = hash4( x * 0.005 ).x;
float l = k * 8.0;
float f = fract(l);
float ia = floor(l); // my method
float ib = ia + 1.0;
vec2 offa = sin(vec2(3.0, 7.0) * ia); // can replace with any other hash
vec2 offb = sin(vec2(3.0, 7.0) * ib); // can replace with any other hash
vec3 cola = texture2D( surface, fract(x + v * offa) ).xyz;
vec3 colb = texture2D( surface, fract(x + v * offb) ).xyz;
return mix( cola, colb, smoothstep(0.2, 0.8, f - 0.1 * sum(cola - colb)) );
}
void main() {
vec2 surfRat = dimension / surfaceDimension;
vec2 posRat = v_vTexcoord * surfRat;
if(type == 0) gl_FragColor = texture2D( surface, fract(posRat) );
else if(type == 1) gl_FragColor = randomSample( posRat );
else if(type == 2) gl_FragColor = vec4(cellSample( posRat, 4. ), 1.);
else if(type == 3) gl_FragColor = vec4(onionSample( posRat, 4. ), 1.);
}

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_texture_repeat",
"name":"sh_texture_repeat",
"parent":{
"name":"texture repeat",
"path":"folders/shader/generator/texture repeat.yy",
},
"resourceType":"GMShader",
"resourceVersion":"2.0",
"type":1,
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,90 @@
{
"$GMSprite":"",
"%Name":"s_node_repeat_texture",
"bboxMode":0,
"bbox_bottom":63,
"bbox_left":0,
"bbox_right":63,
"bbox_top":0,
"collisionKind":1,
"collisionTolerance":0,
"DynamicTexturePage":false,
"edgeFiltering":false,
"For3D":false,
"frames":[
{"$GMSpriteFrame":"","%Name":"9caa5873-4b8b-4c78-bb8a-02280e105ecc","name":"9caa5873-4b8b-4c78-bb8a-02280e105ecc","resourceType":"GMSpriteFrame","resourceVersion":"2.0",},
],
"gridX":0,
"gridY":0,
"height":64,
"HTile":false,
"layers":[
{"$GMImageLayer":"","%Name":"b9a0e9f1-11af-449c-96dc-ea3267ddd217","blendMode":0,"displayName":"default","isLocked":false,"name":"b9a0e9f1-11af-449c-96dc-ea3267ddd217","opacity":100.0,"resourceType":"GMImageLayer","resourceVersion":"2.0","visible":true,},
],
"name":"s_node_repeat_texture",
"nineSlice":null,
"origin":4,
"parent":{
"name":"generator",
"path":"folders/nodes/icons/generator.yy",
},
"preMultiplyAlpha":false,
"resourceType":"GMSprite",
"resourceVersion":"2.0",
"sequence":{
"$GMSequence":"",
"%Name":"s_node_repeat_texture",
"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_repeat_texture",
"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":"9caa5873-4b8b-4c78-bb8a-02280e105ecc","path":"sprites/s_node_repeat_texture/s_node_repeat_texture.yy",},"resourceType":"SpriteFrameKeyframe","resourceVersion":"2.0",},
},"Disabled":false,"id":"b20617d4-4ebc-4262-a68d-be1350725147","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,
}