-
Notifications
You must be signed in to change notification settings - Fork 4
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
discussion on attribute locations #2
Comments
I think we could also just have gl-shader cache the different program objects. That way, you would only pay a 1-time cost associated with recompiling the shader under a different permutation of attributes. This could also reuse the shader objects, so the overhead would be relatively lower than compiling a new program object from scratch. |
I think there are a few issues with this:
Most game engines order their scene by shaders first. Allowing many meshes to take advantage of the same shader (and by that I mean same GL shader object, not gl-shader object) is the first step to efficient rendering. |
On the topic of shader first rendering, I wholeheartedly agree and think that the current system enables applications to take advantage of this quite nicely, assuming that they are designed with it in mind. |
To me this is a massive problem and red flag for a game engine. And it prevents you from ordering your objects shader-first since the actual GL shader objects are muddled under a caching layer. So in edge cases, even if your There is also the subject of uniforms. Let's say you do Further; it becomes more complicated when somebody wants to use the raw webgl api alongside stackgl. Using |
Obviously shader switching is bad, and the current system in no way promotes this or encourages it. It is up to the application to handle these details (as there are practically infinite ways to set this up). Regarding uniforms, setting the uniform value shouldn't change the value for all shaders. If you do change a location using Maybe the solution would be to just make it more clear in the documentation that changing attribute locations triggers relinking? The current strategy for promoting reusability in graphics code is that users would still control vertex formats, buffers, and geometry and they would still write custom shader code. However, there would be plenty of tools to make this process as streamlined as possible, with reusable glsl subroutines (via glslify) and common geometry processing libraries via ndarray and others. |
I agree sphere/cube should be in the form of cells/positions/normals, but I also think most users will want a higher-level wrapper so they don't need to manually set up buffers. Hooking up buffers and shaders manually is where things will crap out if you aren't really conscious of attribute locations (and who in their right mind wants to worry about those). I ran into this in development of So maybe the best approach is to have another module like Then modules like |
I just ran into a tricky situation where the same shader compiled in Chrome with |
@mattdesl maybe the solution there is to make gl-shader-core sort the attributes lexicographically unless otherwise specified, so that there is no ambiguity. |
@mattdesl , maybe I misunderstand the problem, but couldn't you guys use reflection over the shader program to get a mapping of uniform & attributes to locations? See: https://github.com/nickdesaulniers/webgl-shader-loader/blob/master/webGLShaderLoader.js#L123-L143 This uses That way, it doesn't matter what browser compiles your shader, you get webgl implementation non-specific shader locations. |
leaving this here for future discussion.
The problem: let's say we have a utility mesh like
gl-sphere
and it expects attributes in the order[ position, colors, normals ]
. However, we want to give the user the ability to render it with a custom shader -- but their shader might have attributes in the order[position, normals, colors]
.The solution should not need to re-compile shaders since it's expensive and doesn't allow for shader re-use.
One idea is to use string aliases when defining the attributes of a VAO, and have the user pass a shader to
vao.bind()
. Then the VAO always knows which attribute locations to bind, assuming thegl-shader
has them listed in the correct order.The text was updated successfully, but these errors were encountered: