2018-07-22 23:25:05 +02:00
|
|
|
tool
|
2018-09-03 21:35:44 +02:00
|
|
|
extends "res://addons/material_maker/node_base.gd"
|
2018-07-22 23:25:05 +02:00
|
|
|
|
2018-07-29 11:55:17 +02:00
|
|
|
const BLEND_TYPES = [
|
|
|
|
{ name="Normal", shortname="normal" },
|
|
|
|
{ name="Dissolve", shortname="dissolve" },
|
|
|
|
{ name="Multiply", shortname="multiply" },
|
|
|
|
{ name="Screen", shortname="screen" },
|
|
|
|
{ name="Overlay", shortname="overlay" },
|
|
|
|
{ name="Hard Light", shortname="hard_light" },
|
2018-08-09 22:19:27 +02:00
|
|
|
{ name="Soft Light", shortname="soft_light" },
|
|
|
|
{ name="Burn", shortname="burn" },
|
|
|
|
{ name="Dodge", shortname="dodge" },
|
|
|
|
{ name="Lighten", shortname="lighten" },
|
2018-08-18 01:53:07 +02:00
|
|
|
{ name="Darken", shortname="darken" },
|
|
|
|
{ name="Difference", shortname="difference" }
|
2018-07-28 21:21:05 +02:00
|
|
|
]
|
|
|
|
|
2018-07-22 23:25:05 +02:00
|
|
|
func _ready():
|
2018-07-29 11:55:17 +02:00
|
|
|
$blend_type.clear()
|
|
|
|
for i in range(BLEND_TYPES.size()):
|
|
|
|
$blend_type.add_item(BLEND_TYPES[i].name, i)
|
|
|
|
initialize_properties([ $blend_type, $HBoxContainer/amount ])
|
2018-07-22 23:25:05 +02:00
|
|
|
|
2018-11-04 15:43:02 +01:00
|
|
|
func _get_shader_code(uv, slot = 0):
|
2018-07-23 22:18:43 +02:00
|
|
|
var rv = { defs="", code="" }
|
2018-07-22 23:25:05 +02:00
|
|
|
var src0 = get_source(0)
|
|
|
|
var src1 = get_source(1)
|
|
|
|
var src2 = get_source(2)
|
|
|
|
if src0 == null or src1 == null:
|
|
|
|
return rv
|
|
|
|
var src0_code = src0.get_shader_code(uv)
|
|
|
|
var src1_code = src1.get_shader_code(uv)
|
|
|
|
var src2_code = { defs="", code="" }
|
2018-10-02 07:46:20 +02:00
|
|
|
var amount_str = "%.9f" % parameters.amount
|
2018-07-22 23:25:05 +02:00
|
|
|
if src2 != null:
|
|
|
|
src2_code = src2.get_shader_code(uv)
|
2018-07-28 09:37:51 +02:00
|
|
|
amount_str = src2_code.f
|
2018-07-23 22:18:43 +02:00
|
|
|
if generated_variants.empty():
|
2018-07-22 23:25:05 +02:00
|
|
|
rv.defs = src0_code.defs+src1_code.defs+src2_code.defs
|
2018-07-23 22:18:43 +02:00
|
|
|
var variant_index = generated_variants.find(uv)
|
|
|
|
if variant_index == -1:
|
|
|
|
variant_index = generated_variants.size()
|
|
|
|
generated_variants.append(uv)
|
2018-07-22 23:25:05 +02:00
|
|
|
rv.code = src0_code.code+src1_code.code+src2_code.code
|
2018-10-26 22:44:47 +02:00
|
|
|
rv.code += "vec4 %s_%d_rgba = vec4(blend_%s(%s, %s, %s, %s * %s.a), min(1.0, %s.a + %s * %s.a));\n" % [ name, variant_index, BLEND_TYPES[parameters.blend_type].shortname, uv, src0_code.rgb, src1_code.rgb, amount_str, src0_code.rgba, src1_code.rgba, amount_str, src0_code.rgba ]
|
|
|
|
rv.rgba = "%s_%d_rgba" % [ name, variant_index ]
|
2018-07-22 23:25:05 +02:00
|
|
|
return rv
|
|
|
|
|
|
|
|
func _get_state_variables():
|
|
|
|
return [ "amount" ]
|