-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[12.0] Proposal: Shader:getUniforms #2137
Comments
I've see a potential flaw with my example output, tables with non-number keys aren't sorted. Another way of implementing the function could be: {
{name = 'time', type = 'float'},
{name = 'scroll_dir', type = 'vec2'}
} When you print it out the result would always be read in the same order in from the graphics api, which shouldn't change. for _, uniform in ipairs(example_shader:getUniforms()) do
print("Name: ".. uniform.name .." , Type: ".. uniform.type)
end
--Result:
--[[
Name: time, Type: float,
Name: scroll_dir, Type: vec2
]] In case the uniforms are in the wrong order, then you can use |
What's the right order? In what situation would you need uniforms to be sorted? There isn't any inherent order internally or in your shader code. |
You do make a good point. I believe the right order would be the location of the uniforms. OpenGL might already do this when you call |
Location for individual numeric uniforms is actually not really a thing in Metal/Vulkan/Direct3D. If you want to have a live editor, you should probably do your own sorting based on whatever parameters you think are good (for example separating textures from vectors from floats etc, and then sorting based on name within those separations, or something). |
Probably the output of the latter format is the best for both cases, you can decide sort the table or not. |
For a key/value table, you can sort by putting the keys into an array an sorting that array, and then the values are accessed by going through the array to get the sorted key. |
That would make much more sense since the order isn't guaranteed. I didn't really think of doing that trick in hindsight. |
The idea with this proposal is that you could have an in-game shader editor, and you want to edit values without parsing the shader file or hardcoding values in scripts.
This proposed function would make be it quicker (and easier) to know what shader uniforms are available.
It would similarly to
GL_ACTIVE_UNIFORMS
in OpenGL 3.x.You can look at the Program_Introspection Khronos wiki page for reference on how to get this data.
NOTE: I am aware that Love 12.0 has a few more rendering backends (than OpenGL) in version 11.x. Not quite sure how easy that would be implement in for all of them.
Example output:
The text was updated successfully, but these errors were encountered: