material-maker/addons/material_maker/nodes/shape.mmg

89 lines
2.7 KiB
Plaintext
Raw Normal View History

2019-10-27 14:36:16 +01:00
{
"name": "shape",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
2020-02-15 11:16:18 +01:00
"edge": 0.5,
"radius": 0.9,
"shape": 1,
"sides": 6
2019-10-27 14:36:16 +01:00
},
"shader_model": {
2020-02-15 11:16:18 +01:00
"code": "",
2019-10-27 14:36:16 +01:00
"global": "float shape_circle(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float distance = length(uv);\n return clamp((1.0-distance/size)/edge, 0.0, 1.0);\n}\n\nfloat shape_polygon(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y)+3.14159265359;\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = atan(uv.x, uv.y);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_curved_star(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = max(edge, 1.0e-8);\n float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359);\n float slice = 6.28318530718/sides;\n return clamp((size-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*size), 0.0, 1.0);\n}\n\nfloat shape_rays(vec2 uv, float sides, float size, float edge) {\n uv = 2.0*uv-1.0;\n\tedge = 0.5*max(edge, 1.0e-8)*size;\n\tfloat slice = 6.28318530718/sides;\n float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice;\n return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0);\n}\n\n",
2020-02-15 11:16:18 +01:00
"inputs": [
],
2019-10-27 14:36:16 +01:00
"instance": "",
"name": "Shape",
"outputs": [
{
2020-02-15 11:16:18 +01:00
"f": "shape_$(shape)($(uv), $(sides), $(radius), $(edge))",
"type": "f"
2019-10-27 14:36:16 +01:00
}
],
"parameters": [
{
"default": 0,
"label": "",
"name": "shape",
"type": "enum",
"values": [
{
"name": "Circle",
"value": "circle"
},
{
"name": "Polygon",
"value": "polygon"
},
{
"name": "Star",
"value": "star"
},
{
"name": "Curved star",
"value": "curved_star"
},
{
"name": "Rays",
"value": "rays"
}
]
},
{
2020-02-15 11:16:18 +01:00
"control": "None",
2019-10-27 14:36:16 +01:00
"default": 3,
"label": "",
"max": 32,
"min": 2,
"name": "sides",
"step": 1,
"type": "float"
},
{
2020-02-15 11:16:18 +01:00
"control": "None",
2019-10-27 14:36:16 +01:00
"default": 1,
"label": "",
"max": 1,
"min": 0,
"name": "radius",
2020-02-15 11:16:18 +01:00
"step": 0.01,
2019-10-27 14:36:16 +01:00
"type": "float"
},
{
2020-02-15 11:16:18 +01:00
"control": "None",
2019-10-27 14:36:16 +01:00
"default": 0.2,
"label": "",
"max": 1,
"min": 0,
"name": "edge",
2020-02-15 11:16:18 +01:00
"step": 0.01,
2019-10-27 14:36:16 +01:00
"type": "float"
}
]
2020-02-15 11:16:18 +01:00
},
"type": "shader"
2019-10-27 14:36:16 +01:00
}