material-maker/addons/material_maker/nodes/perlin_rgb.mmg
2019-11-22 07:50:17 +01:00

67 lines
1.8 KiB
Plaintext

{
"name": "perlin_rgb",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"iterations": 3,
"persistence": 0.5,
"scale_x": 4,
"scale_y": 4
},
"shader_model": {
"code": "",
"global": "vec3 perlin_color(vec2 uv, vec2 size, int iterations, float persistence, int seed) {\n\tvec2 seed2 = rand2(vec2(float(seed), 1.0-float(seed)));\n vec3 rv = vec3(0.0);\n float coef = 1.0;\n float acc = 0.0;\n for (int i = 0; i < iterations; ++i) {\n \tvec2 step = vec2(1.0)/size;\n\t\tvec2 xy = floor(uv*size);\n vec3 f0 = rand3(seed2+mod(xy, size));\n vec3 f1 = rand3(seed2+mod(xy+vec2(1.0, 0.0), size));\n vec3 f2 = rand3(seed2+mod(xy+vec2(0.0, 1.0), size));\n vec3 f3 = rand3(seed2+mod(xy+vec2(1.0, 1.0), size));\n vec2 mixval = smoothstep(0.0, 1.0, fract(uv*size));\n rv += coef * mix(mix(f0, f1, mixval.x), mix(f2, f3, mixval.x), mixval.y);\n acc += coef;\n size *= 2.0;\n coef *= persistence;\n }\n \n return rv / acc;\n}\n",
"inputs": [
],
"instance": "",
"name": "PerlinRGB",
"outputs": [
{
"rgb": "perlin_color($(uv), vec2($(scale_x), $(scale_y)), int($(iterations)), $(persistence), $(seed))",
"type": "rgb"
}
],
"parameters": [
{
"default": 4,
"label": "Scale X",
"max": 32,
"min": 1,
"name": "scale_x",
"step": 1,
"type": "float"
},
{
"default": 4,
"label": "Scale Y",
"max": 32,
"min": 1,
"name": "scale_y",
"step": 1,
"type": "float"
},
{
"default": 3,
"label": "Iterations",
"max": 10,
"min": 1,
"name": "iterations",
"step": 1,
"type": "float"
},
{
"default": 0.5,
"label": "Persistance",
"max": 1,
"min": 0,
"name": "persistence",
"step": 0.05,
"type": "float"
}
]
},
"type": "shader"
}