From fafa5fbb1b7d9933464cf03eaeb7146ed90dd50e Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Fri, 21 Sep 2018 08:14:20 +0200 Subject: [PATCH] Added a "Rays" shape and a radiations logo example --- addons/material_maker/common.shader | 27 +++++++++++++------ addons/material_maker/examples/radiation.ptex | 1 + addons/material_maker/main_window.tscn | 2 +- addons/material_maker/nodes/shape.gd | 2 +- addons/material_maker/nodes/shape.tscn | 4 +-- 5 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 addons/material_maker/examples/radiation.ptex diff --git a/addons/material_maker/common.shader b/addons/material_maker/common.shader index 37e008b..3b48408 100644 --- a/addons/material_maker/common.shader +++ b/addons/material_maker/common.shader @@ -13,32 +13,43 @@ vec3 rand3(vec2 x) { dot(x, vec2(13.254, 5.867)))) * 43758.5453); } -float circle(vec2 uv, float sides, float radius, float edge) { +float circle(vec2 uv, float sides, float size, float edge) { uv = 2.0*uv-1.0; edge = max(edge, 1.0e-8); float distance = length(uv); - return clamp((1.0-distance/radius)/edge, 0.0, 1.0); + return clamp((1.0-distance/size)/edge, 0.0, 1.0); } -float polygon(vec2 uv, float sides, float radius, float edge) { +float polygon(vec2 uv, float sides, float size, float edge) { uv = 2.0*uv-1.0; + edge = max(edge, 1.0e-8); float angle = atan(uv.x, uv.y)+3.14159265359; float slice = 6.28318530718/sides; - return clamp((radius-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*radius), 0.0, 1.0); + return clamp((size-cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/(edge*size), 0.0, 1.0); } -float star(vec2 uv, float sides, float radius, float edge) { +float star(vec2 uv, float sides, float size, float edge) { uv = 2.0*uv-1.0; + edge = max(edge, 1.0e-8); float angle = atan(uv.x, uv.y); float slice = 6.28318530718/sides; - return clamp((radius-cos(floor(1.5+angle/slice-2.0*step(0.5*slice, mod(angle, slice)))*slice-angle)*length(uv))/(edge*radius), 0.0, 1.0); + 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); } -float curved_star(vec2 uv, float sides, float radius, float edge) { +float curved_star(vec2 uv, float sides, float size, float edge) { uv = 2.0*uv-1.0; + edge = max(edge, 1.0e-8); float angle = 2.0*(atan(uv.x, uv.y)+3.14159265359); float slice = 6.28318530718/sides; - return clamp((radius-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*radius), 0.0, 1.0); + return clamp((size-cos(floor(0.5+0.5*angle/slice)*2.0*slice-angle)*length(uv))/(edge*size), 0.0, 1.0); +} + +float rays(vec2 uv, float sides, float size, float edge) { + uv = 2.0*uv-1.0; + edge = 0.5*max(edge, 1.0e-8)*size; + float slice = 6.28318530718/sides; + float angle = mod(atan(uv.x, uv.y)+3.14159265359, slice)/slice; + return clamp(min((size-angle)/edge, angle/edge), 0.0, 1.0); } float wave_constant(float x) { diff --git a/addons/material_maker/examples/radiation.ptex b/addons/material_maker/examples/radiation.ptex new file mode 100644 index 0000000..dad585b --- /dev/null +++ b/addons/material_maker/examples/radiation.ptex @@ -0,0 +1 @@ +{"connections":[{"from":"shape_0","from_port":0,"to":"blend_0","to_port":1},{"from":"blend_1","from_port":0,"to":"blend_0","to_port":0},{"from":"shape_2","from_port":0,"to":"blend_1","to_port":0},{"from":"shape_1","from_port":0,"to":"blend_1","to_port":1},{"from":"blend_0","from_port":0,"to":"blend_2","to_port":0},{"from":"shape_3","from_port":0,"to":"blend_2","to_port":1},{"from":"blend_2","from_port":0,"to":"colorize_0","to_port":0},{"from":"colorize_0","from_port":0,"to":"Material","to_port":0}],"nodes":[{"edge":0.05,"name":"shape_3","node_position":{"x":-35,"y":36},"radius":0.18,"shape":0,"sides":3,"type":"shape"},{"edge":0.02,"name":"shape_0","node_position":{"x":-373,"y":13},"radius":0.5,"shape":4,"sides":3,"type":"shape"},{"edge":0.02,"name":"shape_1","node_position":{"x":-359,"y":-99},"radius":0.87,"shape":0,"sides":3,"type":"shape"},{"edge":0.02,"name":"shape_2","node_position":{"x":-358,"y":-200},"radius":0.34,"shape":0,"sides":3,"type":"shape"},{"amount":1,"blend_type":11,"name":"blend_1","node_position":{"x":-236,"y":-159},"type":"blend"},{"amount":1,"blend_type":2,"name":"blend_0","node_position":{"x":-53,"y":-74},"type":"blend"},{"amount":1,"blend_type":3,"name":"blend_2","node_position":{"x":148,"y":-34},"type":"blend"},{"gradient":{"points":[{"b":0,"g":0.820313,"pos":0,"r":0.9375},{"b":0,"g":0,"pos":1,"r":0}],"type":"Gradient"},"name":"colorize_0","node_position":{"x":354.081177,"y":-39.5},"type":"colorize"},{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"name":"Material","node_position":{"x":528,"y":-57},"normal_scale":1,"resolution":1,"roughness":1,"type":"material"}]} \ No newline at end of file diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 5ae8cf6..43850a8 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -6,7 +6,7 @@ [ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=4] [ext_resource path="res://addons/material_maker/renderer.tscn" type="PackedScene" id=5] -[node name="MainWindow" type="Panel" index="0"] +[node name="MainWindow" type="Panel"] anchor_left = 0.0 anchor_top = 0.0 diff --git a/addons/material_maker/nodes/shape.gd b/addons/material_maker/nodes/shape.gd index 8350f47..6c3d01b 100644 --- a/addons/material_maker/nodes/shape.gd +++ b/addons/material_maker/nodes/shape.gd @@ -6,7 +6,7 @@ var sides var radius var edge -const SHAPES = [ "circle", "polygon", "star", "curved_star" ] +const SHAPES = [ "circle", "polygon", "star", "curved_star", "rays" ] func _ready(): initialize_properties([ $shape, $sides, $radius, $edge ]) diff --git a/addons/material_maker/nodes/shape.tscn b/addons/material_maker/nodes/shape.tscn index 75f202b..5e80245 100644 --- a/addons/material_maker/nodes/shape.tscn +++ b/addons/material_maker/nodes/shape.tscn @@ -81,7 +81,7 @@ group = null text = "Circle" flat = false align = 0 -items = [ "Circle", null, false, 0, null, "Polygon", null, false, 1, null, "Star", null, false, 2, null, "Curved star", null, false, 3, null ] +items = [ "Circle", null, false, 0, null, "Polygon", null, false, 1, null, "Star", null, false, 2, null, "Curved star", null, false, 3, null, "Rays", null, false, 4, null ] selected = 0 [node name="sides" type="HSlider" parent="." index="1"] @@ -102,7 +102,7 @@ mouse_filter = 0 mouse_default_cursor_shape = 0 size_flags_horizontal = 1 size_flags_vertical = 0 -min_value = 3.0 +min_value = 1.0 max_value = 16.0 step = 1.0 page = 0.0