Comments from scratches.mmg.

This commit is contained in:
Relintai 2021-10-12 11:12:20 +02:00
parent eacc08e69a
commit a5b96ad8f1
2 changed files with 53 additions and 108 deletions

View File

@ -123,6 +123,22 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
#Inputs: #Inputs:
#size, vector2, default: 4, min: 2, max: 32, step: 1 #size, vector2, default: 4, min: 2, max: 32, step: 1
#scratches.mmg
#Draws white scratches on a black background
#Output (float) - Shows white scratches on a black background
#scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0))
#Inputs:
#scratch_size (l, w), vector2, min: 0.1, max: 1, default: (0.25, 0.5), step:0.01
#layers, float, min: 1, max: 10, default: 4, step:1
#waviness, float, min: 0, max: 1, default: 0.5, step:0.01
#angle, float, min: -180, max: 180, default: 0, step:1
#randomness, float, min: 0, max: 1, default: 0.5, step:0.01
enum CombinerAxisType { enum CombinerAxisType {
SINE, SINE,
TRIANGLE, TRIANGLE,
@ -230,6 +246,32 @@ static func sinewavec(uv : Vector2, amplitude : float, frequency : float, phase
static func sinewavef(uv : Vector2, amplitude : float, frequency : float, phase : float) -> float: static func sinewavef(uv : Vector2, amplitude : float, frequency : float, phase : float) -> float:
return 1.0- abs(2.0 * (uv.y-0.5) - amplitude * sin((frequency* uv.x + phase) * 6.28318530718)); return 1.0- abs(2.0 * (uv.y-0.5) - amplitude * sin((frequency* uv.x + phase) * 6.28318530718));
#float scratch(vec2 uv, vec2 size, float waviness, float angle, float randomness, vec2 seed) {
# float subdivide = floor(1.0/size.x);
# float cut = size.x*subdivide;
#
# uv *= subdivide;
#
# vec2 r1 = rand2(floor(uv)+seed);
# vec2 r2 = rand2(r1);
#
# uv = fract(uv);
# vec2 border = 10.0*min(fract(uv), 1.0-fract(uv));
# uv = 2.0*uv-vec2(1.0);
#
# float a = 6.28318530718*(angle+(r1.x-0.5)*randomness);
# float c = cos(a);
# float s = sin(a);
#
# uv = vec2(c*uv.x+s*uv.y, s*uv.x-c*uv.y);
# uv.y += 2.0*r1.y-1.0;
# uv.y += 0.5*waviness*cos(2.0*uv.x+6.28318530718*r2.y);
# uv.x /= cut;
# uv.y /= subdivide*size.y;
#
# return min(border.x, border.y)*(1.0-uv.x*uv.x)*max(0.0, 1.0-1000.0*uv.y*uv.y);
#}
static func scratch(uv : Vector2, size : Vector2, waviness : float, angle : float, randomness : float, pseed : Vector2) -> float: static func scratch(uv : Vector2, size : Vector2, waviness : float, angle : float, randomness : float, pseed : Vector2) -> float:
var subdivide : float = floor(1.0/size.x); var subdivide : float = floor(1.0/size.x);
var cut : float = size.x*subdivide; var cut : float = size.x*subdivide;
@ -251,6 +293,17 @@ static func scratch(uv : Vector2, size : Vector2, waviness : float, angle : floa
return (1.0-uv.x*uv.x)*max(0.0, 1.0-1000.0*uv.y*uv.y); return (1.0-uv.x*uv.x)*max(0.0, 1.0-1000.0*uv.y*uv.y);
#float scratches(vec2 uv, int layers, vec2 size, float waviness, float angle, float randomness, vec2 seed) {
# float v = 0.0;
#
# for (int i = 0; i < layers; ++i) {
# seed = rand2(seed);
# v = max(v, scratch(fract(uv+seed), size, waviness, angle/360.0, randomness, seed));
# }
#
# return v;
#}
static func scratches(uv : Vector2, layers : int, size : Vector2, waviness : float, angle : float, randomness : float, pseed : Vector2) -> float: static func scratches(uv : Vector2, layers : int, size : Vector2, waviness : float, angle : float, randomness : float, pseed : Vector2) -> float:
var v : float = 0.0; var v : float = 0.0;

View File

@ -1,108 +0,0 @@
{
"name": "scratches",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"angle": 0,
"layers": 5,
"length": 0.25,
"randomness": 0.3,
"waviness": 0.3,
"width": 0.4
},
"shader_model": {
"code": "",
"longdesc": "Draws white scratches on a black background",
"global": "float scratch(vec2 uv, vec2 size, float waviness, float angle, float randomness, vec2 seed) {\n\tfloat subdivide = floor(1.0/size.x);\n\tfloat cut = size.x*subdivide;\n\tuv *= subdivide;\n\tvec2 r1 = rand2(floor(uv)+seed);\n\tvec2 r2 = rand2(r1);\n\tuv = fract(uv);\n\tvec2 border = 10.0*min(fract(uv), 1.0-fract(uv));\n\tuv = 2.0*uv-vec2(1.0);\n\tfloat a = 6.28318530718*(angle+(r1.x-0.5)*randomness);\n\tfloat c = cos(a);\n\tfloat s = sin(a);\n\tuv = vec2(c*uv.x+s*uv.y, s*uv.x-c*uv.y);\n\tuv.y += 2.0*r1.y-1.0;\n\tuv.y += 0.5*waviness*cos(2.0*uv.x+6.28318530718*r2.y);\n\tuv.x /= cut;\n\tuv.y /= subdivide*size.y;\n\treturn min(border.x, border.y)*(1.0-uv.x*uv.x)*max(0.0, 1.0-1000.0*uv.y*uv.y);\n}\n\nfloat scratches(vec2 uv, int layers, vec2 size, float waviness, float angle, float randomness, vec2 seed) {\n\tfloat v = 0.0;\n\tfor (int i = 0; i < layers; ++i) {\n\t\tseed = rand2(seed);\n\t\tv = max(v, scratch(fract(uv+seed), size, waviness, angle/360.0, randomness, seed));\n\t}\n\treturn v;\n}\n",
"inputs": [
],
"instance": "",
"name": "Scratches",
"outputs": [
{
"f": "scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0))",
"longdesc": "Shows white scratches on a black background",
"shortdesc": "Output",
"type": "f"
}
],
"parameters": [
{
"control": "None",
"default": 0.25,
"label": "Length",
"longdesc": "The length of scratches (the shorter the scratches,the more they will be)",
"max": 1,
"min": 0.1,
"name": "length",
"shortdesc": "Length",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Width",
"longdesc": "The width of scratches",
"max": 1,
"min": 0.1,
"name": "width",
"shortdesc": "Width",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 4,
"label": "Layers",
"longdesc": "The number of scratches layers",
"max": 10,
"min": 1,
"name": "layers",
"shortdesc": "Layers",
"step": 1,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Waviness",
"longdesc": "The waviness of scratches",
"max": 1,
"min": 0,
"name": "waviness",
"shortdesc": "Waviness",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0,
"label": "Angle",
"longdesc": "The average angle of the scratches (0 generates horizontal scratches)",
"max": 180,
"min": -180,
"name": "angle",
"shortdesc": "Angle",
"step": 1,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Randomness",
"longdesc": "The randomness of the scratches angles",
"max": 1,
"min": 0,
"name": "randomness",
"shortdesc": "Randomness",
"step": 0.01,
"type": "float"
}
]
},
"type": "shader"
}