2018-07-23 23:13:14 +02:00
|
|
|
tool
|
|
|
|
extends "res://addons/procedural_material/node_base.gd"
|
|
|
|
|
|
|
|
var amount = 0.0
|
|
|
|
|
2018-08-14 15:09:46 +02:00
|
|
|
var input_shader = ""
|
|
|
|
var input_texture
|
|
|
|
var final_texture
|
|
|
|
|
2018-08-09 22:19:27 +02:00
|
|
|
const CONVOLUTION = {
|
2018-08-14 15:09:46 +02:00
|
|
|
x=1,
|
|
|
|
y=1,
|
2018-08-09 22:19:27 +02:00
|
|
|
kernel=[
|
2018-08-14 15:09:46 +02:00
|
|
|
Vector3(-1, -1, 0), Vector3(0, -2, 0), Vector3(1, -1, 0),
|
|
|
|
Vector3(-2, 0, 0), 0, Vector3(2, 0, 0),
|
|
|
|
Vector3(-1, 1, 0), Vector3(0, 2, 0), Vector3(1, 1, 0),
|
2018-08-09 22:19:27 +02:00
|
|
|
],
|
2018-08-14 15:09:46 +02:00
|
|
|
epsilon=1.0/1024,
|
2018-08-09 22:19:27 +02:00
|
|
|
normalize=true,
|
|
|
|
translate_before_normalize=Vector3(0.0, 0.0, -1.0),
|
|
|
|
scale_before_normalize=0.5,
|
|
|
|
translate=Vector3(0.5, 0.5, 0.5),
|
|
|
|
scale=0.5
|
|
|
|
}
|
|
|
|
|
2018-07-23 23:13:14 +02:00
|
|
|
func _ready():
|
2018-08-14 15:09:46 +02:00
|
|
|
input_texture = ImageTexture.new()
|
|
|
|
final_texture = ImageTexture.new()
|
2018-07-23 23:13:14 +02:00
|
|
|
initialize_properties([ $amount ])
|
|
|
|
|
2018-08-14 15:09:46 +02:00
|
|
|
func _rerender():
|
|
|
|
get_parent().precalculate_shader(input_shader, get_source().get_textures(), 1024, input_texture, self, "pass_1", [])
|
|
|
|
|
|
|
|
func pass_1():
|
|
|
|
var convolution = CONVOLUTION
|
|
|
|
convolution.scale_before_normalize = 8.0*amount
|
|
|
|
get_parent().precalculate_shader(get_convolution_shader(convolution), { input=input_texture}, 1024, final_texture, self, "rerender_targets", [])
|
|
|
|
|
|
|
|
func get_textures():
|
|
|
|
var list = {}
|
|
|
|
list[name] = final_texture
|
|
|
|
return list
|
|
|
|
|
2018-07-26 08:31:28 +02:00
|
|
|
func _get_shader_code(uv):
|
2018-08-14 15:09:46 +02:00
|
|
|
var rv = { defs="", code="" }
|
2018-08-12 19:25:18 +02:00
|
|
|
var src = get_source()
|
|
|
|
if src == null:
|
2018-08-14 15:09:46 +02:00
|
|
|
return rv
|
|
|
|
input_shader = do_generate_shader(src.get_shader_code("UV"))
|
|
|
|
_rerender()
|
|
|
|
if generated_variants.empty():
|
2018-08-20 15:43:03 +02:00
|
|
|
rv.defs = "uniform sampler2D %s_tex;\n" % [ name ]
|
2018-08-14 15:09:46 +02:00
|
|
|
var variant_index = generated_variants.find(uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = generated_variants.size()
|
|
|
|
generated_variants.append(uv)
|
2018-08-20 15:43:03 +02:00
|
|
|
rv.code = "vec3 %s_%d_rgb = texture(%s_tex, %s).rgb;\n" % [ name, variant_index, name, uv ]
|
|
|
|
rv.rgb = "%s_%d_rgb" % [ name, variant_index ]
|
2018-08-14 15:09:46 +02:00
|
|
|
return rv
|