Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Giuseppe |
How can i get a list of all params in a shader loaded
into a material with gdscript?
thanks
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Giuseppe |
How can i get a list of all params in a shader loaded
into a material with gdscript?
thanks
Reply From: | Giuseppe |
Ok,
this should work for most shader (I hope).
This code assume that uniform name is always in the second place of the line,
and that the shader is written without double space.
I hope there’s something simpler as i think that this feature is quite useful for shader
newbies like me.
func load_file(file):
var f = File.new()
f.open(file, File.READ)
var index = 1
while not f.eof_reached(): # iterate through all lines until the end of file is reached
var line = f.get_line()
line += " "
#print(line + str(index))
if "uniform" in line:
var l
l = line.split(" ")
print(l[2]) # assume that the shadere is written
# like this: uniform space vartype space varname
index += 1
f.close()
return
Better
#file is the current shader path
func get_shader_param(file):
var f = File.new()
f.open(file, File.READ)
var index = 1
var param =[]
while not f.eof_reached(): # iterate through all lines until the end of file is reached
var line = f.get_line()
line += " "
#print(line + str(index))
if "uniform" in line:
var l
l = line.split(" ")
print(l[2])
param.append(l[2])
index += 1
f.close()
return param
Giuseppe | 2023-01-06 17:41
This is not how shaders are meant to work.
Please tell me when you will ever need to do this?
Wakatta | 2023-01-06 18:13
Infact my question was:
Blockquote
How can i get a list of all params in a shader loaded into a material with gdscript?
Blockquote
If you have a better solution it would be nice to hear you.
Mine is quite unclean, but works for my needs.
The final purpose is to have a control for every uniform found in the shader.
Giuseppe | 2023-01-06 22:35