Skip to content

Commit

Permalink
Updated the Roman numerals node (align parameter, upto 3999).
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 27, 2024
1 parent 76800ab commit 5338bdf
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 13 deletions.
199 changes: 199 additions & 0 deletions addons/material_maker/nodes/roman_numerals2.mmg
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{
"name": "roman_numerals2",
"node_position": {
"x": 0,
"y": 0
},
"parameters": {
"a": 0.5,
"bevel": 0.1,
"h": 0.75,
"n": 5,
"r": 0.05,
"s": 0,
"w": 0.5
},
"seed_int": 0,
"shader_model": {
"code": "",
"global": [
"float roman2_num(vec2 p, float w, float h, float s, int n) {",
"\tif (n == 0) { // I",
"\t\tfloat d = sdLine(abs(p), vec2(w*1.7,h), vec2(0,h)).x;",
"\t\treturn min(d,sdLine(vec2(p.x,abs(p.y)), vec2(0,h), vec2(0,0)).x);",
"\t} else if (n == 1) { // V",
"\t\tp.x = abs(p.x);",
"\t\tfloat d = sdLine(p, vec2(0,h), vec2(w,-h)).x;",
"\t\treturn min(d, sdLine(vec2(abs(p.x-w),p.y+h), vec2(w*0.8,0), vec2(0,0)).x);",
"\t} else if (n == 2) { // X",
"\t\tp = abs(p);",
"\t\tfloat d = sdLine(p, vec2(w,h), vec2(0,0)).x;",
"\t\treturn min(d, sdLine(abs(p-vec2(w,h)), vec2(w*0.8,0), vec2(0,0)).x);",
"\t} else if (n == 3) { // L",
"\t\tfloat w2 = w*1.5;",
"\t\tfloat d = sdLine(p, vec2(-w2,h), vec2(-w2,-h)).x;",
"\t\treturn min(d, sdLine(p, vec2(-w2,h), vec2(w2,h)).x);",
"\t} else if (n == 4) { // C",
"\t\tvec2 b = vec2(w*1.5, h);",
"\t\tvec4 r = 1.6*min(w, h)*vec4(1.0, 1.0, 1.0, 1.0);",
"\t\tfloat d = sdRoundedBox(p, b, r);",
"\t\treturn length(vec2(d, mix(clamp((p.x-abs(2.0*p.y)+h-w)/2.0, 0.0, 1.0), 0.0, step(p.x, 0.0))));",
"\t} else if (n == 5) { // D",
"\t\tvec2 b = vec2(w*1.5, h);",
"\t\tvec4 r = 1.5*min(w, h)*vec4(1.0, 1.0, 0.0, 0.0);",
"\t\treturn abs(sdRoundedBox(p, b, r));",
"\t} else if (n == 6) { // M",
"\t\tfloat w2 = w*1.5;",
"\t\tfloat d = sdLine(p, vec2(-w2,h), vec2(-w2,-h)).x;",
"\t\td = min(d, sdLine(p, vec2(w2,h), vec2(w2,-h)).x);",
"\t\td = min(d, sdLine(p, vec2(w2,-h), vec2(0.0, 0.0)).x);",
"\t\td = min(d, sdLine(p, vec2(-w2,-h), vec2(0.0, 0.0)).x);",
"\t\treturn d;",
"\t} else {",
"\t\treturn 1.0;",
"\t}",
"}",
"",
"float roman2(vec2 p, float w, float h, int n, float bevel, float r, float s, float a)",
"{",
"\tp -= 0.5;",
"\th *= 0.5;",
"\tw *= 0.25;",
"\tconst int val[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};",
"\tconst int c1[] = {\t6, 4, 5, 4, 4, 2, 3, 2, 2, 0, 1, 0, 0};",
"\tconst int c2[] = { -1, 6, -1, 5, -1, 4, -1, 3, -1, 2, -1, 1, -1};",
"\tfloat res = 1.0;",
"\tint n_clamped = clamp(n, 0, 3999);",
"\tn = n_clamped;",
"\tfloat total_width = 0.0;",
"\tfor (int i = 0; i < 13; ++i) {",
"\t\twhile (n - val[i] >= 0) {",
"\t\t\ttotal_width += s;",
"\t\t\tif (c2[i] != -1) {",
"\t\t\t\ttotal_width += s;",
"\t\t\t}",
"\t\t\tn -= val[i]; ",
"\t\t}",
"\t}",
"\tn = n_clamped;",
"\tp.x += total_width*a;",
"\tp.x -= 0.5*s;",
"\tfor (int i = 0; i < 13; ++i) {",
"\t\twhile (n - val[i] >= 0) {",
"\t\t\tres = min(res, roman2_num(p,w,h,s,c1[i]));",
"\t\t\tp -= vec2(s,0);",
"\t\t\tif (c2[i] != -1) {",
"\t\t\t\tres = min(res, roman2_num(p,w,h,s,c2[i]));",
"\t\t\t\tp -= vec2(s,0);",
"\t\t\t}",
"\t\t\tn -= val[i]; ",
"\t\t}",
"\t}",
"\treturn clamp(0.0-(res-0.5*r)/max(bevel*r, 1e-4), 0, 1);",
"}"
],
"includes": [
"sdline2",
"sdroundedbox"
],
"inputs": [
{
"default": "1.0",
"label": "5:",
"longdesc": "Map that affects the bevel parameter.",
"name": "bevel_map",
"shortdesc": "Bevel Map",
"type": "f"
}
],
"instance": "",
"name": "Roman Numerals",
"outputs": [
{
"f": "roman2($uv, $w, $h, int($n), $bevel*$bevel_map($uv), $r*min($w, $h), (1.0+$s)*$w, $a)",
"shortdesc": "Output",
"type": "f"
}
],
"parameters": [
{
"control": "None",
"default": 0.5,
"label": "Width",
"max": 1,
"min": 0,
"name": "w",
"shortdesc": "Glyph Width",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Height",
"max": 1,
"min": 0,
"name": "h",
"shortdesc": "Glyph Height",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Thickness",
"max": 1,
"min": 0,
"name": "r",
"shortdesc": "Glyph Thickness",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 1,
"label": "Number",
"max": 399,
"min": 1,
"name": "n",
"shortdesc": "Roman number to display",
"step": 1,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Bevel",
"max": 1,
"min": 0,
"name": "bevel",
"shortdesc": "Glyph edge width",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Spacing",
"max": 1,
"min": 0,
"name": "s",
"shortdesc": "Spacing between glyphs",
"step": 0.01,
"type": "float"
},
{
"control": "None",
"default": 0.5,
"label": "Align",
"max": 1,
"min": 0,
"name": "a",
"step": 0.01,
"type": "float"
}
],
"shortdesc": "Roman Numerals"
},
"type": "shader"
}
4 changes: 3 additions & 1 deletion material_maker/doc/node_simple_roman_numerals.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Roman numerals node
~~~~~~~~~~~~~~~~~~~

The **Roman numerals** node outputs roman numbers up to 40
The **Roman numerals** node outputs roman numbers up to 3999

.. image:: images/node_simple_roman_numerals.png
:align: center
Expand Down Expand Up @@ -33,6 +33,8 @@ The **Roman numerals** node accepts the following parameters:

* the *Spacing* parameter controls the spacing between glyphs.

* the *Align* parameter controls how the number is aligned (0: left, 0.5: center, 1: right).

Example images
++++++++++++++

Expand Down
15 changes: 8 additions & 7 deletions material_maker/library/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1666,19 +1666,20 @@
"type": "sixteen_segment"
},
{
"display_name": "Roman Numerals",
"icon_data": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAAXNSR0IArs4c6QAAAMJJREFUaIHt2ssOgzAMRFFS9f9/2ey6qKoSB0+sQfesIWhsLJ7HAQC4YSzsExGzq4+xsH3KK7vDM0XEfJkXtt8hG6DquPanUGWAybrWnjx0oJt9gErMwIriAJfVLb9+0YFu9gGKMQNp9QH+1FhxC00HutkHqMcM5EgC/Ky06CmeDnSzDyDBDCSoAnzVW/cikQ50sw+gwgzMEgb4VF36LYMOdLMPIMQMTHlLV9/wLdW+AwR4tg2/FNh3gADd7AMAAG45AdaAaPHzRObEAAAAAElFTkSuQmCC",
"name": "roman_numerals",
"icon_data": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAYJJREFUeJztmsGOgzAQQ1+q/dDwUXzv7KGq1Kosm6TErpSxxHFgZHh2DhQgWFg39wJupQHuBdxKA9wLuLW8AT9X3CRirElLKZfMf6LlvwC4H4SmXLXWiPvrHboiImqt0/YDojD5JBgRw5/qJ7OtWh4BiQG1VsnMiCQIQH9ij871KhGY/YBt2yyzrZqOAIyluaIBIBHQGdCT6qoGACEC0J7oqgaAREBjwEiaKxoARAhAX6qrGgASAa0BLemubAAQIwD/J7uyASAR0BnQk+qqBgAhAtCW7soGgERAb8BZyqsbAAwIwN8Jr24ASAS0BrSku7IBQIwAnKe8ugEgEfAYcJT2jgYAEwLwnvSOBoBEQG/AWcqrGwAMCMBx2jsaABIBnwHPqe9qADAiAO//CCUCBlkMOEp7RwOACQF4TX1XA0AicM2PkqNypv9DVgReFkkEPLIZ8Jz6rgYAIwLgPQA9lAi4F3BreQOs54B9352PB8wh+A1aHoE0wL2AW2mAewG3ljfgFz4S06ZyFqaeAAAAAElFTkSuQmCC",
"name": "roman_numerals2",
"parameters": {
"bevel": 0,
"a": 0.5,
"bevel": 0.1,
"h": 0.75,
"n": 5,
"r": 0.4,
"s": 0.5,
"r": 0.05,
"s": 0,
"w": 0.5
},
"seed_int": 0,
"tree_item": "Simple/Roman Numerals",
"type": "roman_numerals"
"type": "roman_numerals2"
},
{
"display_name": "Runes",
Expand Down
10 changes: 5 additions & 5 deletions splash_screen/backgrounds/unfa_alien_display.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ vec2 transform2(vec2 uv, vec2 translate, float rotate, vec2 scale) {
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += vec2(0.5);
return rv;
return rv;
}
uniform sampler2D texture_3;
const float texture_3_size = 128.0;
Expand All @@ -78,7 +78,7 @@ vec4 brick_corner_bb(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float corner,
float min_size = min(size.x, size.y);
mortar *= brick_height;
corner *= brick_height;

vec2 corner1 = vec2(bmin + mortar);
vec2 corner2 = vec2(bmax.x - mortar - corner, bmin.y + mortar);
vec2 corner3 = vec2(bmin.x + mortar, bmax.y - mortar - corner);
Expand Down Expand Up @@ -107,7 +107,7 @@ vec4 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset) {
}
vec4 bricks_rb3(vec2 uv, vec2 count, float repeat, float offset) {
vec4 bb = bricks_rb(uv, count, repeat, offset);

if ( (uv.x - bb.x) / (bb.z - bb.x) < 1.0/3.0) {
bb.z = bb.x + (bb.z - bb.x) / 3.0;
} else {
Expand Down Expand Up @@ -276,7 +276,7 @@ vec3 hsv_to_rgb(vec3 c) {
}
float anisotropic(vec2 uv, vec2 size, float seed, float smoothness, float interpolation) {
vec2 seed2 = rand2(vec2(seed, 1.0-seed));

vec2 xy = floor(uv*size);
vec2 offset = vec2(rand(seed2 + xy.y), 0.0);
vec2 xy_offset = floor(uv * size + offset );
Expand All @@ -286,7 +286,7 @@ float anisotropic(vec2 uv, vec2 size, float seed, float smoothness, float interp
float smooth_mix = smoothstep(0.0, 1.0, mixer);
float linear = mix(f0, f1, mixer);
float smoothed = mix(f0, f1, smooth_mix);

return mix(linear, smoothed, interpolation);
}
vec2 get_from_tileset(float count, float seed, vec2 uv) {
Expand Down

0 comments on commit 5338bdf

Please sign in to comment.