2018-07-22 17:20:27 +02:00
|
|
|
tool
|
|
|
|
extends "res://addons/procedural_material/node_base.gd"
|
|
|
|
|
2018-07-29 23:43:24 +02:00
|
|
|
var texture_albedo = null
|
|
|
|
var texture_metallic = null
|
|
|
|
var texture_roughness = null
|
|
|
|
var texture_emission = null
|
|
|
|
var texture_normal_map = null
|
|
|
|
var texture_depth_map = null
|
|
|
|
|
2018-08-03 08:16:38 +02:00
|
|
|
const TEXTURE_LIST = [
|
|
|
|
{ port= 0, texture= "albedo" },
|
|
|
|
{ port= 1, texture= "metallic" },
|
|
|
|
{ port= 2, texture= "roughness" },
|
|
|
|
{ port= 3, texture= "emission" },
|
|
|
|
{ port= 4, texture= "normal_map" },
|
|
|
|
{ port= 5, texture= "depth_map" }
|
|
|
|
]
|
2018-07-29 23:43:24 +02:00
|
|
|
|
2018-07-22 17:20:27 +02:00
|
|
|
func _ready():
|
2018-07-29 23:43:24 +02:00
|
|
|
pass
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-07-26 08:31:28 +02:00
|
|
|
func _get_shader_code(uv):
|
2018-07-25 06:20:36 +02:00
|
|
|
var rv = { defs="", code="", f="0.0" }
|
2018-07-22 17:20:27 +02:00
|
|
|
var src = get_source()
|
2018-07-24 08:04:25 +02:00
|
|
|
if src != null:
|
|
|
|
rv = src.get_shader_code(uv)
|
2018-07-25 06:20:36 +02:00
|
|
|
rv.albedo = get_source_rgb(rv)
|
|
|
|
src = get_source(1)
|
|
|
|
if src != null:
|
|
|
|
var src_code = src.get_shader_code(uv)
|
|
|
|
rv.defs += src_code.defs
|
|
|
|
rv.code += src_code.code
|
|
|
|
rv.normal_map = get_source_rgb(src_code)
|
2018-07-22 23:25:05 +02:00
|
|
|
return rv
|
|
|
|
|
|
|
|
func _get_state_variables():
|
|
|
|
return [ ]
|
2018-07-29 23:43:24 +02:00
|
|
|
|
2018-08-03 08:16:38 +02:00
|
|
|
func update_materials(material_list):
|
|
|
|
for t in TEXTURE_LIST:
|
|
|
|
var source = get_source(t.port)
|
|
|
|
if source == null:
|
|
|
|
set("texture_"+t.texture, null)
|
2018-07-29 23:43:24 +02:00
|
|
|
else:
|
2018-08-03 08:16:38 +02:00
|
|
|
get_parent().precalculate_texture(source, 1024, self, "store_texture", [ t.texture, material_list ])
|
2018-07-29 23:43:24 +02:00
|
|
|
|
2018-08-03 08:16:38 +02:00
|
|
|
func store_texture(texture_name, material_list, texture):
|
2018-07-29 23:43:24 +02:00
|
|
|
set("texture_"+texture_name, texture)
|
|
|
|
for m in material_list:
|
|
|
|
if m is SpatialMaterial:
|
|
|
|
m.albedo_texture = texture_albedo
|
|
|
|
m.metallic_texture = texture_metallic
|
|
|
|
m.roughness_texture = texture_roughness
|
|
|
|
if texture_emission != null:
|
|
|
|
m.emission_enabled = true
|
|
|
|
m.emission_texture = texture_emission
|
|
|
|
else:
|
|
|
|
m.emission_enabled = false
|
|
|
|
if texture_normal_map != null:
|
|
|
|
m.normal_enabled = true
|
|
|
|
m.normal_texture = texture_normal_map
|
|
|
|
else:
|
|
|
|
m.normal_enabled = false
|
|
|
|
if texture_depth_map != null:
|
|
|
|
m.depth_enabled = true
|
|
|
|
m.depth_texture = texture_depth_map
|
|
|
|
else:
|
|
|
|
m.depth_enabled = false
|
|
|
|
|
2018-08-03 08:16:38 +02:00
|
|
|
func export_textures(prefix):
|
|
|
|
for t in TEXTURE_LIST:
|
|
|
|
get_parent().export_texture(get_source(t.port), prefix+"_"+t.texture+".png", 1024)
|