mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Emboss node.
This commit is contained in:
parent
2f4912c2b9
commit
61c6ea476e
@ -1,4 +1,4 @@
|
||||
[gd_resource type="Resource" load_steps=128 format=2]
|
||||
[gd_resource type="Resource" load_steps=132 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/noise.gd" type="Script" id=2]
|
||||
@ -33,6 +33,7 @@
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/filter/filter.gd" type="Script" id=31]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/filter/grayscale.gd" type="Script" id=32]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/filter/blend.gd" type="Script" id=33]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/filter/emboss.gd" type="Script" id=34]
|
||||
|
||||
[sub_resource type="Resource" id=3]
|
||||
script = ExtResource( 5 )
|
||||
@ -181,7 +182,7 @@ default_color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="Resource" id=24]
|
||||
script = ExtResource( 10 )
|
||||
graph_position = Vector2( -140, -220 )
|
||||
graph_position = Vector2( 640, 140 )
|
||||
image = SubResource( 23 )
|
||||
image_path = "/home/relintai/Projects/broken_seals/game/icon.png"
|
||||
|
||||
@ -704,7 +705,7 @@ input_property = SubResource( 44 )
|
||||
|
||||
[sub_resource type="Resource" id=100]
|
||||
script = ExtResource( 28 )
|
||||
graph_position = Vector2( 1140, -220 )
|
||||
graph_position = Vector2( 1120, -200 )
|
||||
image = SubResource( 98 )
|
||||
input = SubResource( 102 )
|
||||
a = Vector2( -0.35, -0.2 )
|
||||
@ -820,7 +821,6 @@ default_float = 0.0
|
||||
default_vector2 = Vector2( 0, 0 )
|
||||
default_vector3 = Vector3( 0, 0, 0 )
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
input_property = SubResource( 37 )
|
||||
|
||||
[sub_resource type="Resource" id=118]
|
||||
script = ExtResource( 5 )
|
||||
@ -830,7 +830,6 @@ default_float = 0.0
|
||||
default_vector2 = Vector2( 0, 0 )
|
||||
default_vector3 = Vector3( 0, 0, 0 )
|
||||
default_color = Color( 1, 1, 1, 1 )
|
||||
input_property = SubResource( 17 )
|
||||
|
||||
[sub_resource type="Resource" id=119]
|
||||
script = ExtResource( 5 )
|
||||
@ -850,7 +849,35 @@ input2 = SubResource( 118 )
|
||||
blend_type = 0
|
||||
opacity = SubResource( 119 )
|
||||
|
||||
[sub_resource type="Resource" id=121]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 5
|
||||
default_int = 0
|
||||
default_float = 0.0
|
||||
default_vector2 = Vector2( 0, 0 )
|
||||
default_vector3 = Vector3( 0, 0, 0 )
|
||||
default_color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="Resource" id=122]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 1
|
||||
default_int = 0
|
||||
default_float = 0.0
|
||||
default_vector2 = Vector2( 0, 0 )
|
||||
default_vector3 = Vector3( 0, 0, 0 )
|
||||
default_color = Color( 0, 0, 0, 1 )
|
||||
input_property = SubResource( 98 )
|
||||
|
||||
[sub_resource type="Resource" id=123]
|
||||
script = ExtResource( 34 )
|
||||
graph_position = Vector2( 1020, 380 )
|
||||
image = SubResource( 121 )
|
||||
input = SubResource( 122 )
|
||||
angle = 20.0
|
||||
amount = 5.0
|
||||
width = 6.0
|
||||
|
||||
[resource]
|
||||
script = ExtResource( 1 )
|
||||
image_size = Vector2( 128, 128 )
|
||||
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ), SubResource( 78 ), SubResource( 82 ), SubResource( 85 ), SubResource( 88 ), SubResource( 90 ), SubResource( 92 ), SubResource( 96 ), SubResource( 100 ), SubResource( 108 ), SubResource( 110 ), SubResource( 112 ), SubResource( 113 ), SubResource( 115 ), SubResource( 120 ) ]
|
||||
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ), SubResource( 78 ), SubResource( 82 ), SubResource( 85 ), SubResource( 88 ), SubResource( 90 ), SubResource( 92 ), SubResource( 96 ), SubResource( 100 ), SubResource( 108 ), SubResource( 110 ), SubResource( 112 ), SubResource( 113 ), SubResource( 115 ), SubResource( 120 ), SubResource( 123 ) ]
|
||||
|
@ -561,6 +561,7 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
|
||||
#----------------------
|
||||
#emboss.mmg
|
||||
#Creates highlights and shadows from an input heightmap
|
||||
|
||||
#{
|
||||
# "connections": [
|
||||
@ -583,13 +584,6 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
# "to_port": 0
|
||||
# }
|
||||
# ],
|
||||
# "label": "Emboss",
|
||||
# "longdesc": "Creates highlights and shadows from an input heightmap",
|
||||
# "name": "emboss",
|
||||
# "node_position": {
|
||||
# "x": 0,
|
||||
# "y": 0
|
||||
# },
|
||||
# "nodes": [
|
||||
# {
|
||||
# "name": "buffer",
|
||||
@ -4682,5 +4676,3 @@ static func blend_difference(uv : Vector2, c1 : Vector3, c2 : Vector3, opacity :
|
||||
# return out_min+input*(out_max-out_min);\n
|
||||
#}
|
||||
|
||||
|
||||
|
||||
|
112
game/addons/mat_maker_gd/nodes/filter/emboss.gd
Normal file
112
game/addons/mat_maker_gd/nodes/filter/emboss.gd
Normal file
@ -0,0 +1,112 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Filter = preload("res://addons/mat_maker_gd/nodes/common/filter.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(Resource) var input : Resource
|
||||
export(float) var angle : float = 0
|
||||
export(float) var amount : float = 5
|
||||
export(float) var width : float = 1
|
||||
|
||||
var size : int = 0
|
||||
|
||||
func _init_properties():
|
||||
if !image:
|
||||
image = MMNodeUniversalProperty.new()
|
||||
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
|
||||
|
||||
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
|
||||
|
||||
if !input:
|
||||
input = MMNodeUniversalProperty.new()
|
||||
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
|
||||
input.set_default_value(1)
|
||||
|
||||
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||
input.slot_name = ">>> Input1 "
|
||||
|
||||
register_input_property(input)
|
||||
register_output_property(image)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_texture_universal(image)
|
||||
mm_graph_node.add_slot_label_universal(input)
|
||||
|
||||
mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 0.1)
|
||||
mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.1)
|
||||
mm_graph_node.add_slot_float("get_width", "set_width", "Width", 1)
|
||||
|
||||
|
||||
func _render(material) -> void:
|
||||
size = max(material.image_size.x, material.image_size.y)
|
||||
|
||||
var img : Image = render_image(material)
|
||||
|
||||
image.set_value(img)
|
||||
|
||||
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
var f : float = 0
|
||||
|
||||
f = emboss(uv, size, angle, amount, width)
|
||||
|
||||
return Color(f, f, f, 1)
|
||||
|
||||
func get_angle() -> float:
|
||||
return angle
|
||||
|
||||
func set_angle(val : float) -> void:
|
||||
angle = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
func get_amount() -> float:
|
||||
return amount
|
||||
|
||||
func set_amount(val : float) -> void:
|
||||
amount = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
func get_width() -> float:
|
||||
return width
|
||||
|
||||
func set_width(val : float) -> void:
|
||||
width = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#float $(name)_fct(vec2 uv) {
|
||||
# float pixels = max(1.0, $width);
|
||||
# float e = 1.0/$size;
|
||||
# float rv = 0.0;
|
||||
#
|
||||
# for (float dx = -pixels; dx <= pixels; dx += 1.0) {
|
||||
# for (float dy = -pixels; dy <= pixels; dy += 1.0) {
|
||||
# if (abs(dx) > 0.5 || abs(dy) > 0.5) {
|
||||
# rv += $in(uv+e*vec2(dx, dy))*cos(atan(dy, dx)-$angle*3.14159265359/180.0)/length(vec2(dx, dy));
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# return $amount*rv/pixels+0.5;
|
||||
#}
|
||||
|
||||
func emboss(uv : Vector2, psize : float, pangle : float, pamount : float, pwidth : float) -> float:
|
||||
var pixels : float = max(1.0, pwidth)
|
||||
var e : float = 1.0 / psize
|
||||
var rv : float = 0.0
|
||||
|
||||
var dx : float = -pixels
|
||||
var dy : float = -pixels
|
||||
|
||||
while dx <= pixels: #for (float dx = -pixels; dx <= pixels; dx += 1.0) {
|
||||
while dy <= pixels: #for (float dy = -pixels; dy <= pixels; dy += 1.0) {
|
||||
if (abs(dx) > 0.5 || abs(dy) > 0.5):
|
||||
rv += input.get_value(uv + e * Vector2(dx, dy)) * cos(atan2(dy, dx) - pangle * 3.14159265359 / 180.0) / Vector2(dx, dy).length()
|
||||
|
||||
dx += 1
|
||||
dy += 1
|
||||
|
||||
return pamount * rv / pixels + 0.5
|
||||
|
Loading…
Reference in New Issue
Block a user