Hi all! :)
We have an outline shader which works by using an unlit scene to determine edges, and then compositing those edges onto a lit scene. The problem is we have a large number of skinned models on screen, and due to needing the outline map separate from the lit scene, this means drawing the entire scene twice. This is the same shader that both does the outline map and the final lit model, depending on a boolean parameter.
I've optimised it as much as I can, but one issue is that since vertex shader transforms all the vertices by the bones, this is happening twice for each skinned model. Ideally I'd do what I've done everywhere else in the C# code, and preserve all the data / shader parameters from the first draw to make the second as quick as possible.
However since I have the skin transformations in the vertex shader, the second time around I have no choice but to redo these transformations. Ideally since the same shader does both, I would somehow store the resultant world matrix for a boneindex in the shader itself, and next time around when it draws the lit model it just refers to these. However it seems that is impossible and all variable states are lost between an Effect.End and Effect.Begin. I suspect this may not be the case when using passes, though i'm not sure, but I can't do this because a lot of my optimisations aka avoiding any setting of parameters would be lost and I'd probably just be making it worse.
In case you're wondering using a depth map didn't produce the desired results for the outliner, where using unlit colour did. I'm aware if using depth I could probably sneak it into the alpha component of the output colour and do both with one shader pass, but there isn't enough resolution for what we need.
If anyone's got any advice on a good way to handle outlined skinned models in an optimised way I would much appreciate it. :)
Thanks!
lemmy