mattdesl / glo

dibble-dabbling with a frameworky 3D engine
MIT License
25 stars 0 forks source link

shader core #4

Open mattdesl opened 9 years ago

mattdesl commented 9 years ago

shader

see dev branch for progress

mattdesl commented 9 years ago

will log to console.error by default unless quiet: true (for unit tests etc)

screen shot 2015-05-21 at 2 47 17 pm

though console.warn looks nice too

screen shot 2015-05-21 at 1 37 27 pm

mattdesl commented 9 years ago

looking into this a bit more. the shader wrapper that stackgl uses is quite nice since it allows for a clean way of handling structs and arrays:

shader.uniforms.lights[0] = {
   position: ...
}

Compare with string-based access.

The downside is that you end up very easily calling glGetUniform which can destroy framerate, and also it doesn't behave like you would expect. Generally using getter/setter to perform a complex action can lead to surprises IMHO.

//does not work as expected
vec3.add(shader.uniforms.lightPosition, aVec, bVec)

EDIT:

Alternative syntax where the discrete uniforms are functions:

//query current uniform looks like this
var pos = shader.uniforms.lights[0].position()

//set uniform, no ambiguity here since it's a function
vec3.add(tmp, aVec, bVec)
shader.uniforms.lights[0].position(tmp)

Or more verbose:

shader.uniforms.lights[0].position.set(tmp)
shader.uniforms.lights[0].position.get()
mikolalysenko commented 9 years ago

I actually think that maybe it is worth killing gl-shader long term. A more ideal solution would be to have a "draw command" that could take the shader source as a string argument, along with all uniforms that need to be set. Then these could be grouped using some "draw list" that would combine and reorder draw commands so that the number of shader state changes and uniform updates are minimized.

mattdesl commented 9 years ago

Interesting idea. Definitely going to think about it and how it could all look for the end-user.