From 3d892249d974a6174bf16df50df29d4b0dc5ee49 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sat, 21 Dec 2024 11:31:03 +0700 Subject: [PATCH] [Displace] Fix random output when displace map has no data. --- .../distribution_function.gml | 8 ++-- scripts/node_displace/node_displace.gml | 20 ++++++-- scripts/random_function/random_function.gml | 48 +++++++++---------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/scripts/distribution_function/distribution_function.gml b/scripts/distribution_function/distribution_function.gml index 6a162a172..a11a05119 100644 --- a/scripts/distribution_function/distribution_function.gml +++ b/scripts/distribution_function/distribution_function.gml @@ -1,4 +1,4 @@ -function get_point_from_dist(distMap, attempt = 4) { #region +function get_point_from_dist(distMap, attempt = 4) { if(!is_surface(distMap)) return noone; var w = surface_get_width_safe(distMap); @@ -20,9 +20,9 @@ function get_point_from_dist(distMap, attempt = 4) { #region } return res; -} #endregion +} -function get_points_from_dist(distMap, amount, seed = 0, attempt = 8) { #region +function get_points_from_dist(distMap, amount, seed = 0, attempt = 8) { if(amount < 1) return []; if(!is_surface(distMap)) return []; @@ -66,4 +66,4 @@ function get_points_from_dist(distMap, amount, seed = 0, attempt = 8) { #region buffer_delete(b); return pos; -} #endregion \ No newline at end of file +} \ No newline at end of file diff --git a/scripts/node_displace/node_displace.gml b/scripts/node_displace/node_displace.gml index c7c9c26af..4f1bc064c 100644 --- a/scripts/node_displace/node_displace.gml +++ b/scripts/node_displace/node_displace.gml @@ -66,7 +66,7 @@ If set, then strength value control how many times the effect applies on itself. attribute_oversample(); attribute_interpolation(); - static step = function() { #region + static step = function() { __step_mask_modifier(); inputs[3].mappableStep(); @@ -90,9 +90,21 @@ If set, then strength value control how many times the effect applies on itself. } else { inputs[ 1].setName("Displace map"); } - } #endregion + } - static processData = function(_outSurf, _data, _output_index, _array_index) { #region + static processData = function(_outSurf, _data, _output_index, _array_index) { + var _map = _data[1]; + var _sep = _data[16]; + var _map2 = _data[17]; + + var _mode = _data[5]; + if(!is_surface(_map) || (_sep && !is_surface(_map2))) { + surface_set_shader(_outSurf); + draw_surface_safe(_data[0]); + surface_reset_shader() + return _outSurf; + } + var ww = surface_get_width_safe(_data[0]); var hh = surface_get_height_safe(_data[0]); var mw = surface_get_width_safe(_data[1]); @@ -120,5 +132,5 @@ If set, then strength value control how many times the effect applies on itself. _outSurf = channel_apply(_data[0], _outSurf, _data[12]); return _outSurf; - } #endregion + } } \ No newline at end of file diff --git a/scripts/random_function/random_function.gml b/scripts/random_function/random_function.gml index aa5e7388e..6bb6ff117 100644 --- a/scripts/random_function/random_function.gml +++ b/scripts/random_function/random_function.gml @@ -1,4 +1,4 @@ -function UUID_generate(length = 32) { #region +function UUID_generate(length = 32) { randomize(); static str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static month = "JFRAMJYASOND" @@ -14,23 +14,23 @@ function UUID_generate(length = 32) { #region repeat(length - string_length(_id)) _id += string_char_at(str, irandom_range(1, string_length(str))); return _id; -} #endregion +} -function irandom_seed(val, seed) { #region +function irandom_seed(val, seed) { random_set_seed(floor(seed)); return irandom(val); -} #endregion +} -function irandom_range_seed(from, to, seed) { #region +function irandom_range_seed(from, to, seed) { random_set_seed(floor(seed)); return irandom_range(from, to); -} #endregion +} -function seed_random(digits = 6) { #region +function seed_random(digits = 6) { return irandom_range(power(10, digits - 1), power(10, digits) - 1); -} #endregion +} -function random_seed(val, seed) { #region +function random_seed(val, seed) { random_set_seed(floor(seed)); var _s0 = random(val); @@ -38,9 +38,9 @@ function random_seed(val, seed) { #region var _s1 = random(val); return lerp(_s0, _s1, frac(seed)); -} #endregion +} -function random_range_seed(from, to, seed) { #region +function random_range_seed(from, to, seed) { random_set_seed(floor(seed)); var _s0 = random_range(from, to); @@ -48,9 +48,9 @@ function random_range_seed(from, to, seed) { #region var _s1 = random_range(from, to); return lerp(_s0, _s1, frac(seed)); -} #endregion +} -function random1D(seed, startRange = 0, endRange = 1) { #region +function random1D(seed, startRange = 0, endRange = 1) { if(startRange == endRange) return startRange; var _f = frac(seed); @@ -66,9 +66,9 @@ function random1D(seed, startRange = 0, endRange = 1) { #region var f2 = random_range(startRange, endRange); return lerp(f1, f2, _f); -} #endregion +} -function __noise(_x) { #region +function __noise(_x) { var i = floor(_x); var f = frac(_x); @@ -78,9 +78,9 @@ function __noise(_x) { #region var u = f * f * (3.0 - 2.0 * f); return lerp(a, b, u); -} #endregion +} -function perlin1D(pos, seed, scale = 1, octave = 1, startRange = 0, endRange = 1) { #region +function perlin1D(pos, seed, scale = 1, octave = 1, startRange = 0, endRange = 1) { var amp = power(2., octave - 1.) / (power(2., octave) - 1.); var n = 0.; @@ -92,13 +92,13 @@ function perlin1D(pos, seed, scale = 1, octave = 1, startRange = 0, endRange = 1 } return lerp(startRange, endRange, n); -} #endregion +} -function wiggle(_min = 0, _max = 1, _freq = 1, _time = 0, _seed = 0, _octave = 1) { #region +function wiggle(_min = 0, _max = 1, _freq = 1, _time = 0, _seed = 0, _octave = 1) { return perlin1D(_time, _seed, _freq, _octave, _min, _max); -} #endregion +} -function getWiggle(_min = 0, _max = 1, _freq = 1, _time = 0, _seed = 0, startTime = noone, endTime = noone) { #region +function getWiggle(_min = 0, _max = 1, _freq = 1, _time = 0, _seed = 0, startTime = noone, endTime = noone) { _freq = max(1, _freq); var sdMin = floor(_time / _freq) * _freq; @@ -113,9 +113,9 @@ function getWiggle(_min = 0, _max = 1, _freq = 1, _time = 0, _seed = 0, startTim t = -(cos(pi * t) - 1) / 2; var _lrp = lerp(_x0, _x1, t); return lerp(_min, _max, _lrp); -} #endregion +} -function wiggleMap(_seed, _freq, _length) constructor { #region +function wiggleMap(_seed, _freq, _length) constructor { seed = _seed; freq = _freq; len = _length; @@ -149,4 +149,4 @@ function wiggleMap(_seed, _freq, _length) constructor { #region if(amp == 0) return 0; return map[abs(i) % len] * amp; } -} #endregion \ No newline at end of file +} \ No newline at end of file