[Bf-viewport] OpenGL low level shader API proposal
Brecht Van Lommel
brechtvanlommel at pandora.be
Sun Dec 6 02:46:34 CET 2015
On Sun, Dec 6, 2015 at 12:34 AM, Mike Erwin <significant.bit at gmail.com> wrote:
> For passing in the current transformation, I don't think the lowest-level
> API should treat this or any other inputs special. Do like the convenience
> of not having to specify CTM every time though... maybe I'm on the fence
> about this one! Since a lot of this has to do with UI drawing, how about a
> dedicated 2D transformation system, stack or otherwise? See bottom part of:
> 3D shaders would automatically get a 3x4 ModelView and 4x4 Projection
> matrix, maybe a 4x4 MVP for efficiency. 2D shaders would automatically get a
> 2x3 ModelView matrix and that's it.
At the very lowest level it indeed does not need to be treated special.
I don't have a specific design in mind here. There's both the
projection and modelview matrices that need to be passed to every
shader, and I would like to avoid having too much boilerplate code for
that, one way or another.
Keeping some kind of modelview matrix stack and current projection
matrix seems reasonable to me, also to make porting existing code
> GPUShader is a compiled & linked set of Vertex shader, optional Geometry
> shader, and Fragment shader.
Right, and I also imagine that things like blend mode and culling
would be included in the GPUShader. It's a full shader pipeline.
> Inputs for the GPUShader are the active uniforms (which could be from any of
> the above shader stages) and vertex attributes from the first stage.
> Uniform values are set once per draw. Attribute values are typically set per
> vertex from data in VBOs. Attributes can also be set once per draw using
> glVertexAttrib, acting more like uniforms from client program's point of
Uniforms and attributes could be set per draw or they could already be
cached on the GPU as a uniform buffer object, both should work. For
example light uniforms could be cached in the 3D view, or uniforms for
drawing a particular type of button could be cached in the UI code.
When initially porting code to shaders we could just always set them
per draw, and later on we do caching if it helps to reduce CPU
> Uniforms can have default values in GLSL. Is there any way to query the
> program to see if an input *requires* us to set a value? Beyond parsing the
> GLSL source text.
Not that I can find. I think we can just define the default values in
the C code, I don't see much advantage to doing it in GLSL?
If you're making a nontrivial shader interface, I think you should
already provide a struct (e.g. FunkyMaterialParams ) initialized with
default values, and then let the user fill it in. If all uniforms in
the shaders are covered that way, it doesn't really help to initialize
them to default values in the shader too, and pulling the default
values from the shader would not simplify the code overall.
More information about the Bf-viewport