How to render specular highlights as a separate image with alpha channel? I'm using the Blender Cycles engine to create graphics for a game; specifically, I want to display a grid of coloured ellipsoid counters for the player to move around.  To avoid creating a separate image for each colour, I want to store a single greyscale image in the resources, and apply a colour tint at runtime:



However, with this approach, the specular highlights would also be tinted; so I would like to store the highlights as a separate image with an alpha channel, and overlay it on top of the tinted image.

I've tried Googling for ways to do this in Blender, and cannot find anything.  The best solution I can think of is to set the glossy BSDF colour to red (1.0, 0.0, 0.0) and the diffuse BSDF colour to green (0.0, 1.0, 0.0):




I would then need to create a mask from the red channel, and create base and overlay greyscale images from the green and red channels respectively, either as a manual step in Gimp, or (better) store a single image in the resources and do the channel operations in code:




While I realise that I'm probably subverting the properties of light for the sake of coding simplicity, I am concerned that I may not be getting the most believable results.  Given that the rendering engine knows more about the light paths than I do from the final image, is there a way to do this in Blender?

Thanks!

UPDATE

For posterity, these are the material nodes I ended up with:



With a further change to adjust the alpha channel on the highlight image, these are the compositing nodes I created:



Finally, this is the end result, after tinting and overlaying in the game source code:
You should add in the specular with color, not mix shaders. In that way you will get a white highlight. 

Here I'm using color ramps to make a mask for transparency and removing some of the gray on the specular before adding it to a solid color.



You can also render out Diffuse and Glossy and use the Compositor to choose color.



You need to add light passes for gloss direct and diffuse direct


The new passes can be then be exported from the Compositor via Image editor (set the image to be "Viewer Node") and then saved from there Image->Save As...