Fixed shader generation problems revealed by Godot 3.2

This commit is contained in:
RodZill4 2019-10-18 08:35:54 +02:00
parent c61b630122
commit 53c5fd4f56
4 changed files with 23 additions and 22 deletions

View File

@ -143,4 +143,4 @@ func serialize():
rv.type = model rv.type = model
else: else:
rv = _serialize(rv) rv = _serialize(rv)
return rv return rv

View File

@ -208,13 +208,13 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
rv.defs += subst_output.string rv.defs += subst_output.string
for t in subst_output.textures.keys(): for t in subst_output.textures.keys():
rv.textures[t] = subst_output.textures[t] rv.textures[t] = subst_output.textures[t]
for p in shader_model.parameters: for p in shader_model.parameters:
if p.type == "gradient": if p.type == "gradient":
var g = parameters[p.name] var g = parameters[p.name]
if !(g is MMGradient): if !(g is MMGradient):
g = MMGradient.new() g = MMGradient.new()
g.deserialize(parameters[p.name]) g.deserialize(parameters[p.name])
rv.defs += g.get_shader(genname+"__"+p.name+"_gradient_fct") rv.defs += g.get_shader(genname+"__"+p.name+"_gradient_fct")
# Add inline code # Add inline code
if shader_model.has("code"): if shader_model.has("code"):
var variant_index = context.get_variant(self, uv) var variant_index = context.get_variant(self, uv)

View File

@ -21,4 +21,4 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ genname, variant_index, texture_name, uv ] rv.code = "vec4 %s_%d = texture(%s, %s);\n" % [ genname, variant_index, texture_name, uv ]
rv.rgba = "%s_%d" % [ genname, variant_index ] rv.rgba = "%s_%d" % [ genname, variant_index ]
rv.textures = { texture_name:texture } rv.textures = { texture_name:texture }
return rv return rv

View File

@ -2,7 +2,7 @@ tool
extends Viewport extends Viewport
class_name MMGenRenderer class_name MMGenRenderer
export(String) var debug_path = null export(String) var debug_path = ""
var debug_file_index : int = 0 var debug_file_index : int = 0
var rendering : bool = false var rendering : bool = false
@ -42,15 +42,14 @@ static func generate_combined_shader(red_code, green_code, blue_code):
file.open("res://addons/material_maker/common.shader", File.READ) file.open("res://addons/material_maker/common.shader", File.READ)
code += file.get_as_text() code += file.get_as_text()
code += "\n" code += "\n"
if red_code.has("globals"): var globals = []
for g in red_code.globals: for c in [ red_code, green_code, blue_code ]:
code += g if c.has("globals"):
if green_code.has("globals"): for g in c.globals:
for g in green_code.globals: if globals.find(g) == -1:
code += g globals.push_back(g)
if blue_code.has("globals"): for g in globals:
for g in blue_code.globals: code += g
code += g
var shader_code = "" var shader_code = ""
shader_code += red_code.defs shader_code += red_code.defs
shader_code += green_code.defs shader_code += green_code.defs
@ -71,15 +70,17 @@ func setup_material(shader_material, textures, shader_code):
shader_material.shader.code = shader_code shader_material.shader.code = shader_code
func render_shader(shader, textures, render_size): func render_shader(shader, textures, render_size):
while rendering:
yield(self, "done")
rendering = true
if debug_path != null and debug_path != "": if debug_path != null and debug_path != "":
var file_name = debug_path+str(debug_file_index)+".shader"
var f = File.new() var f = File.new()
f.open(debug_path+str(debug_file_index)+".shader", File.WRITE) f.open(debug_path+str(debug_file_index)+".shader", File.WRITE)
f.store_string(shader) f.store_string(shader)
f.close() f.close()
debug_file_index += 1 debug_file_index += 1
print("shader saved as "+file_name)
while rendering:
yield(self, "done")
rendering = true
size = Vector2(render_size, render_size) size = Vector2(render_size, render_size)
$ColorRect.rect_position = Vector2(0, 0) $ColorRect.rect_position = Vector2(0, 0)
$ColorRect.rect_size = size $ColorRect.rect_size = size