Most of this patch was created by Daniel Stokes, I'm mostly just cleaning
it up and testing it. Still todo: hardness. I need to figure out how to
handle the integer -> float conversion on a dynamic uniform.
Details
Diff Detail
- Repository
- rB Blender
Event Timeline
I know one of the concerns with this will be performance (we're changing some constants to uniforms). I'm noticing no performance difference with my GeForce GT 425M. Also, I'm guessing Blender is just recompiling shaders when animating material properties? Uniforms would probably be a lot faster, especially on GPUs that don't have a shader cache (AMD? Intel?).
I'm not sure how to handle the hardness value. GPU_shadeinput_set() converts ma->har from a short to a float before using it as a constant. How can we set this up with a dynamic uniform? Can the pointer to ma->har just be passed in to GPU_dynamic_uniform()?
Regarding performance, I imagine GLSL shaders are rarely the bottleneck now, due to Blender's drawing code being mostly CPU bottlenecked. Anyway, you can make the decision, performance here mostly matters for the game engine.
Blender only (re)compiles shaders when the user is editing, opening files, starting the game etc. Never during animation playback or something like that, it would be much too slow.
Regarding hardness, that's tricky. I guess there's a few options:
- Add some special type of GPU_dynamic_uniform function that knows how to convert short to float
- Store it as a float in GPUMaterial somewhere and update that each time. With the latter solution you would have to be careful then because with node materials where you can have multiple such values.
- Pass it as an integer to the GLSL shader (not sure which GLSL versions supports ints)
Adding support for hardness by converting the short to a float in GPU_pass_update_uniforms().
@Antonis Ryakiotakis (psy-fi)
You seem to be the most active with bf_gpu these days, could you give this a quick look over? I'm mostly concerned with the oddness around hardness (gpu_codegen.c).
LGTM, I'd like to be able to detect non dynamic inputs at some point, but I guess it's fine for now.