mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Reimplemented normal map generation as 3x3 sobel
This commit is contained in:
parent
0c062563c1
commit
0fda03ca42
@ -15,14 +15,20 @@ func _get_shader_code(uv):
|
|||||||
return rv
|
return rv
|
||||||
var variant_index = generated_variants.find(uv)
|
var variant_index = generated_variants.find(uv)
|
||||||
if variant_index == -1:
|
if variant_index == -1:
|
||||||
|
var epsilon = 0.005
|
||||||
variant_index = generated_variants.size()
|
variant_index = generated_variants.size()
|
||||||
generated_variants.append(uv)
|
generated_variants.append(uv)
|
||||||
var src_code0 = src.get_shader_code(uv+"+vec2(0.01, 0.0)")
|
var src_code_tl = src.get_shader_code(uv+"+vec2(-%.9f, -%.9f)" % [ epsilon, epsilon ])
|
||||||
var src_code1 = src.get_shader_code(uv+"+vec2(-0.01, 0.0)")
|
var src_code_l = src.get_shader_code(uv+"+vec2(-%.9f, 0.0)" % [ epsilon, ])
|
||||||
var src_code2 = src.get_shader_code(uv+"+vec2(0.0, 0.01)")
|
var src_code_bl = src.get_shader_code(uv+"+vec2(-%.9f, %.9f)" % [ epsilon, epsilon ])
|
||||||
var src_code3 = src.get_shader_code(uv+"+vec2(0.0, -0.01)")
|
var src_code_tr = src.get_shader_code(uv+"+vec2(%.9f, -%.9f)" % [ epsilon, epsilon ])
|
||||||
rv.defs = src_code0.defs
|
var src_code_r = src.get_shader_code(uv+"+vec2(%.9f, 0.0)" % [ epsilon ])
|
||||||
rv.code = src_code0.code+src_code1.code+src_code2.code+src_code3.code
|
var src_code_br = src.get_shader_code(uv+"+vec2(%.9f, %.9f)" % [ epsilon, epsilon ])
|
||||||
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"
|
var src_code_t = src.get_shader_code(uv+"+vec2(0.0, -%.9f)" % [ epsilon ])
|
||||||
|
var src_code_b = src.get_shader_code(uv+"+vec2(0.0, %.9f)" % [ epsilon ])
|
||||||
|
rv.defs = src_code_tl.defs
|
||||||
|
rv.code = src_code_tl.code+src_code_l.code+src_code_bl.code+src_code_tr.code
|
||||||
|
rv.code += src_code_r.code+src_code_br.code+src_code_t.code+src_code_b.code
|
||||||
|
rv.code += "vec3 %s_%d_rgb = vec3(0.5, 0.5, 0.5) + 0.5*normalize(%.9f*vec3(%s+2.0*%s+%s-%s-2.0*%s-%s, %s+2.0*%s+%s-%s-2.0*%s-%s, 0.0) + vec3(0.0, 0.0, 1.0));\n" % [ name, variant_index, amount, src_code_tr.f, src_code_r.f, src_code_br.f, src_code_tl.f, src_code_l.f, src_code_bl.f, src_code_bl.f, src_code_b.f, src_code_br.f, src_code_tl.f, src_code_t.f, src_code_tr.f ]
|
||||||
rv.rgb = name+"_"+str(variant_index)+"_rgb"
|
rv.rgb = name+"_"+str(variant_index)+"_rgb"
|
||||||
return rv
|
return rv
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
[sub_resource type="Theme" id=1]
|
[sub_resource type="Theme" id=1]
|
||||||
|
|
||||||
|
|
||||||
[node name="NormalMap" type="GraphNode"]
|
[node name="NormalMap" type="GraphNode" index="0"]
|
||||||
|
|
||||||
anchor_left = 0.0
|
anchor_left = 0.0
|
||||||
anchor_top = 0.0
|
anchor_top = 0.0
|
||||||
|
Loading…
Reference in New Issue
Block a user