Skip to content

Commit

Permalink
Fixed polycurve node
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 1, 2023
1 parent a6007d8 commit e5ec108
Showing 1 changed file with 72 additions and 30 deletions.
102 changes: 72 additions & 30 deletions addons/material_maker/nodes/polycurve.mmg
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,90 @@
"curve": {
"points": [
{
"x": 0.771812,
"y": 0.319911
"x": 0.826151967048645,
"y": 0.787355065345764
},
{
"x": 0.838926,
"y": 0.550335
"x": 0.639999985694885,
"y": 0.917500019073486
},
{
"x": 0.624161,
"y": 0.888143
"x": 0.407499998807907,
"y": 0.9375
},
{
"x": 0.288591,
"y": 0.856823
"x": 0.19081699848175,
"y": 0.869726002216339
},
{
"x": 0.0783,
"y": 0.615213
"x": 0.107500001788139,
"y": 0.732500016689301
},
{
"x": 0.114094,
"y": 0.346757
"x": 0.217896997928619,
"y": 0.63400399684906
},
{
"x": 0.362416,
"y": 0.185682
"x": 0.455000013113022,
"y": 0.722500026226044
},
{
"x": 0.72035801410675,
"y": 0.69351202249527
},
{
"x": 0.837499976158142,
"y": 0.535000026226044
},
{
"x": 0.661969006061554,
"y": 0.406711995601654
},
{
"x": 0.407499998807907,
"y": 0.497500002384186
},
{
"x": 0.181207999587059,
"y": 0.355704009532928
},
{
"x": 0.230000004172325,
"y": 0.144999995827675
},
{
"x": 0.494720995426178,
"y": 0.130715996026993
}
],
"type": "Polygon"
},
"ends": true,
"repeat": 3,
"width": 0.2
"repeat": 10,
"width": 0.1
},
"seed_int": 0,
"shader_model": {
"code": "",
"global": [
"vec2 curve(float t, vec2 a, vec2 b, vec2 c, vec2 d) {",
"\tvec2 bc = c-b;",
"\tvec2 da = a-d;",
"\treturn (b+0.5*t*(bc+b-a+t*(a-b+bc+t*3.0*(bc*3.0+da+t*5.0/3.0*(-bc*3.0-da+t*0.4*(bc*3.0+da))))));",
"\tvec2 e = c-b;",
"\tvec2 f = a-d;",
"\tvec2 g = a-b;",
"\treturn (b+0.5*t*(e-g+t*(g+e+t*3.0*(e*3.0+f+t*5.0/3.0*(-e*3.0-f+t*0.4*(e*3.0+f))))));",
"}",
"",
"vec2 dcurve(float t, vec2 a, vec2 b, vec2 c, vec2 d) {",
"\treturn (curve(t+0.0001, a, b, c, d)-curve(t, a, b, c, d))/0.0001;",
"\tvec2 e = c-b;",
"\tvec2 f = a-d;",
"\tvec2 g = a-b;",
"\treturn 0.5*((((f+3.0*e)*((10.0*t-20.0)*t+9.0))*t+2.0*(g+e))*t+e-g);",
"}",
"vec2 solve_cubic(vec2 uv, vec2 a, vec2 b, vec2 c, vec2 d) {",
"\tfloat t = 0.5;",
"\tvec2 pos, dv;",
"\tfloat current_sign = 0.0;",
"\tfloat dt = 1.0;",
"\tfloat dt = 0.25;",
"\tfor (int i = 0; i < 20; ++i) {",
"\t\tpos = curve(t, a, b, c, d);",
"\t\tdv = dcurve(t, a, b, c, d);",
Expand Down Expand Up @@ -113,20 +145,30 @@
"\t\t}",
"\t}",
"\tfloat width;",
"\tfloat offset_min;",
"\tfloat offset_max;",
"\tif (ends) {",
"\t\tvec2 bezier = solve_cubic(uv, v[l-3], v[l-2], v[l-1], v[l-1]);",
"\t\tif (abs(bezier.y) < abs(best_bezier).y) {",
"\t\t\tbest_bezier = bezier;",
"\t\t\toffset = float(l-3)+1.0;",
"\t\t\toffset = float(l-2);",
"\t\t}",
"\t\twidth = $width*$width_map(vec2((best_bezier.x+offset)/float(l-1), 0.0));",
"\t\toffset_min = 0.0;",
"\t\toffset_max = float(l-2);",
"\t} else {",
"\t\twidth = $width*$width_map(vec2((best_bezier.x+offset-1.0)/float(l-3), 0.0));",
"\t\toffset_min = 1.0;",
"\t\toffset_max = float(l-3);",
"\t}",
"\tvec2 local_uv = vec2(best_bezier.x, best_bezier.y/width+0.5);",
"\tvec2 uvtest = step(vec2(0.5), abs(local_uv-vec2(0.5)));",
"\tvec2 uvtest = vec2(0.0);",
"\tif (offset <= offset_min && local_uv.x <= 0.0 || offset >= offset_max && local_uv.x >= 1.0) {",
"\t\tuvtest = step(vec2(0.5), abs(local_uv-vec2(0.5)));",
"\t}",
"\treturn mix(vec2(fract($repeat*local_uv.x), local_uv.y), vec2(0.0), max(uvtest.x, uvtest.y));",
"}"
"}",
""
],
"name": "PolyCurve",
"outputs": [
Expand All @@ -142,16 +184,16 @@
"default": {
"points": [
{
"x": 0.2,
"y": 0.2
"x": 0.200000002980232,
"y": 0.200000002980232
},
{
"x": 0.7,
"y": 0.4
"x": 0.699999988079071,
"y": 0.400000005960464
},
{
"x": 0.4,
"y": 0.7
"x": 0.400000005960464,
"y": 0.699999988079071
}
],
"type": "Polygon"
Expand Down

0 comments on commit e5ec108

Please sign in to comment.