Added basic normal map node

This commit is contained in:
RodZill4 2018-07-23 23:13:14 +02:00
parent 0cd0609541
commit 3afa9e9715
7 changed files with 118 additions and 15 deletions

View File

@ -2,7 +2,6 @@
[ext_resource path="res://addons/procedural_material/nodes/iqnoise.gd" type="Script" id=1]
[sub_resource type="Theme" id=1]
@ -15,7 +14,7 @@ anchor_bottom = 0.0
margin_left = 1.0
margin_top = 2.0
margin_right = 161.0
margin_bottom = 139.0
margin_bottom = 111.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1

View File

@ -0,0 +1,28 @@
tool
extends "res://addons/procedural_material/node_base.gd"
var amount = 0.0
func _ready():
set_slot(0, true, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1))
set_slot(1, true, 0, Color(0.5, 0.5, 1), false, 0, Color(0.5, 0.5, 1))
initialize_properties([ $amount ])
func get_shader_code(uv):
var rv = { defs="", code="" }
var src = get_source()
if src == null:
return rv
var variant_index = generated_variants.find(uv)
if variant_index == -1:
variant_index = generated_variants.size()
generated_variants.append(uv)
var src_code0 = src.get_shader_code(uv+"+vec2(0.01, 0.0)")
var src_code1 = src.get_shader_code(uv+"+vec2(-0.01, 0.0)")
var src_code2 = src.get_shader_code(uv+"+vec2(0.0, 0.01)")
var src_code3 = src.get_shader_code(uv+"+vec2(0.0, -0.01)")
rv.defs = src_code0.defs
rv.code = src_code0.code+src_code1.code+src_code2.code+src_code3.code
rv.code += "vec3 "+name+"_"+str(variant_index)+"_rgb = vec3(0.5, 0.5, 0.5) + 0.5*normalize("+str(amount)+"*vec3("+get_source_f(src_code0)+"-"+get_source_f(src_code1)+", "+get_source_f(src_code2)+"-"+get_source_f(src_code3)+", 0.0) + vec3(0.0, 0.0, 1.0));\n"
rv.rgb = name+"_"+str(variant_index)+"_rgb"
return rv

View File

@ -0,0 +1,69 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/procedural_material/nodes/normal_map.gd" type="Script" id=1]
[sub_resource type="Theme" id=1]
[node name="NormalMap" type="GraphNode" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1.0
margin_top = 1.0
margin_right = 124.0
margin_bottom = 54.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
theme = SubResource( 1 )
title = "Normal Map"
offset = Vector2( 0, 0 )
show_close = true
resizable = false
selected = false
comment = false
overlay = 0
slot/0/left_enabled = true
slot/0/left_type = 0
slot/0/left_color = Color( 0.5, 0.5, 1, 1 )
slot/0/right_enabled = true
slot/0/right_type = 0
slot/0/right_color = Color( 0.5, 0.5, 1, 1 )
script = ExtResource( 1 )
_sections_unfolded = [ "Theme" ]
[node name="amount" type="LineEdit" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 24.0
margin_right = 107.0
margin_bottom = 48.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 1
size_flags_horizontal = 1
size_flags_vertical = 1
text = "0.5"
focus_mode = 2
context_menu_enabled = true
placeholder_alpha = 0.6
caret_blink = false
caret_blink_speed = 0.65
caret_position = 0
_sections_unfolded = [ "Caret", "Placeholder" ]
[connection signal="close_request" from="." to="." method="queue_free"]

View File

@ -12,8 +12,8 @@ anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 1.0
margin_right = 133.0
margin_bottom = 163.0
margin_right = 90.0
margin_bottom = 79.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
@ -51,7 +51,7 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 24.0
margin_right = 117.0
margin_right = 74.0
margin_bottom = 48.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
@ -77,7 +77,7 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 48.0
margin_right = 117.0
margin_right = 74.0
margin_bottom = 72.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false

View File

@ -13,8 +13,8 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1.0
margin_top = 1.0
margin_right = 134.0
margin_bottom = 163.0
margin_right = 110.0
margin_bottom = 54.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
@ -46,7 +46,7 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 24.0
margin_right = 117.0
margin_right = 93.0
margin_bottom = 48.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false

View File

@ -13,6 +13,7 @@ const MENU = [
{ name="transform", description="Transform" },
{ name="warp", description="Warp" },
{ name="colorize", description="Colorize" },
{ name="normal_map", description="Normal Map" },
{ name="blend", description="Blend" }
]

View File

@ -100,17 +100,23 @@ float perlin(vec2 uv, int iterations, float turbulence) {
return f/m;
}
float Perlin_f(vec2 uv) { return perlin(uv, 9, 0.5); }
float Bricks_f(vec2 uv) { return bricks(uv, vec2(3, 6), 0.5, 0.1, 0.1); }
float Perlin_f(vec2 uv) { return perlin(uv, 6, 0.8); }
void fragment() {
float Bricks_0_f = Bricks_f(UV+vec2(0.01, 0.0));
float Perlin_0_f = Perlin_f(UV+vec2(0.01, 0.0));
vec3 Blend_0_rgb = mix(vec3(Bricks_0_f), vec3(Perlin_0_f), 0.5);
float Bricks_1_f = Bricks_f(UV-vec2(0.01, 0.0));
float Perlin_1_f = Perlin_f(UV-vec2(0.01, 0.0));
vec3 Blend_1_rgb = mix(vec3(Bricks_1_f), vec3(Perlin_1_f), 0.5);
float Bricks_2_f = Bricks_f(UV+vec2(0.0, 0.01));
float Perlin_2_f = Perlin_f(UV+vec2(0.0, 0.01));
vec3 Blend_2_rgb = mix(vec3(Bricks_2_f), vec3(Perlin_2_f), 0.5);
float Bricks_3_f = Bricks_f(UV-vec2(0.0, 0.01));
float Perlin_3_f = Perlin_f(UV-vec2(0.0, 0.01));
vec2 Warp_0_uv = UV+0.5*vec2(Perlin_0_f-Perlin_1_f, Perlin_2_f-Perlin_3_f);
float Bricks_0_f = Bricks_f(Warp_0_uv);
vec3 Warp_0_rgb = vec3(Bricks_0_f);
vec3 Material_rgb = Warp_0_rgb;
vec3 Blend_3_rgb = mix(vec3(Bricks_3_f), vec3(Perlin_3_f), 0.5);
vec3 NormalMap_0_rgb = vec3(0.5, 0.5, 0.5) + 0.5*normalize(3.1*vec3(Blend_0_rgb.r-Blend_1_rgb.r, Blend_2_rgb.r-Blend_3_rgb.r, 0.0) + vec3(0.0, 0.0, 1.0));
vec3 Material_rgb = NormalMap_0_rgb;
COLOR = vec4(Material_rgb, 1.0);
}
"
@ -183,7 +189,7 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
popup_exclusive = false
items = [ "Load texture", null, 0, false, false, 0, 0, null, "", false, "Save texture", null, 0, false, false, 1, 0, null, "", false, "Sine", null, 0, false, false, 2, 0, null, "", false, "Bricks", null, 0, false, false, 3, 0, null, "", false, "IQ Noise", null, 0, false, false, 4, 0, null, "", false, "Perlin noise", null, 0, false, false, 5, 0, null, "", false, "Transform", null, 0, false, false, 6, 0, null, "", false, "Warp", null, 0, false, false, 7, 0, null, "", false, "Colorize", null, 0, false, false, 8, 0, null, "", false, "Blend", null, 0, false, false, 9, 0, null, "", false ]
items = [ "Load texture", null, 0, false, false, 0, 0, null, "", false, "Save texture", null, 0, false, false, 1, 0, null, "", false, "Sine", null, 0, false, false, 2, 0, null, "", false, "Bricks", null, 0, false, false, 3, 0, null, "", false, "IQ Noise", null, 0, false, false, 4, 0, null, "", false, "Perlin noise", null, 0, false, false, 5, 0, null, "", false, "Transform", null, 0, false, false, 6, 0, null, "", false, "Warp", null, 0, false, false, 7, 0, null, "", false, "Colorize", null, 0, false, false, 8, 0, null, "", false, "Normal Map", null, 0, false, false, 9, 0, null, "", false, "Blend", null, 0, false, false, 10, 0, null, "", false ]
hide_on_state_item_selection = false
_sections_unfolded = [ "Rect" ]