So, the first thing that I’m doing is to implement the “no cpu transformation” feature.
Currently I have the following dilema… how to implement it correctly, in a good way?
The idea is that this feature should be invisible for the user. The renderer should do the CPU transformation if:
- the command can be batched
- and it makes sense to batch it (triangles < a certain threshold).
But tricky thing is the shader. If it is going to be batched, it should use shader without “Model View”. If not, it should use a different shader.
But currently Node (and Sprite… and everything except Sprite3d) only have one shader.
So, Node should provide two shaders: one that multiplies Projection* Model View * position.
Another that multiplies Projection * position… Both shaders are exactly the same with just that change in the vertex shader.
option a)
Add Material
into Node
, and material should have two techniques:
- one technique with the MV shader (no batch)
- another technique without it (batch)
and the renderer will use the different techniques according to the situation.
Pros: Material could be a good feature for sprites as well.
Cons: kind of hack-ish… although Material Techniques are supposed to do that… this is kind of abusing it.
option b)
No need to use two shaders. Just one. Kind of unify the multiplication… instead of these two shaders:
Batchable vertex shader:
gl_Position = CC_PMatrix * a_position;
Non-Batchable vertex shader:
gl_Position = CC_MVPMatrix * a_position;
have one:
gl_Position = CC_Matrix * a_position;
And the attribute CC_Matrix
is defined from the renderer… or by GLProgramState
Pros: cleaner approach. simplifies shader creation. Just one.
Cons: not sure yet…
option c)
any other option?