Is it possible to access the material and object data in the compositor?
I am specifically interested in getting specular color and roughness, but there might be some interesting possibilities if there is some basic read-access to all of the data. I do want to note that I am NOT talking about the specular highlights.
I am fairly new to Blender and as such I may have not noticed some functions. However, that being said, I did not find any solutions myself (or obvious to me personally). Even searching in Google resulted in “How to use specular maps” or “How to bake specular maps” (and a bunch of more useless results), the latter of which caught my interest. However, upon more closer examination baking is an extremely tedious solution as it requires several steps to perform. Even after creating a specular map I would have to apply it to the model and do another render using that. Why would I need to render the specular map?
Details: I am working on creating sprites from 3D-models. The initial part of this is very simple, set a camera to rotate the object to render it from multiple angles. This will get me the diffuse colors of the sprite. To get more advanced effects I will also need view-space normals, depth, and specular color / intensity and roughness. The normals can be grabbed from the compositor’s normal-pass, which is in range [-1, 1], so it needs to be converted to [0, 1]. Next up is depth which I can get from the Z-pass. I can pass the Z-values through some compositor nodes to get it in the range that I want it to be and finally replace the normal-map’s alpha with it. Lastly, specular… Oh, dear…
Now, I’ve tried a quite a few different things to get the specular, for example:
- Material with a specular ramp that spreads the specular value across the object. Initial tests with a material with specular color of (1, 0.75, 0.5) resulted in exactly that. Another test with color of (0.75, 0.5, 0.25) resulted in (1, 0.66…, 0.33…) which tells me that the result is normalized to the [0, 1] range.
- Material with a specular roughness of 1, and overwriting the normals with a static value in the material nodes, and then replacing normals again with the correct normals… Don’t ask, it was a weird setup which had to be done in a very specific order to keep the normals intact and to get the specular color. Not something I want to use as it’s too complicated to setup and breaks if you do anything in the nodes…
So, many experiments with varying success, but none of them are easily automated (not to mention getting the roughness value).
One thing I do not know if it would allow me to get the data is scripts. I do not know if you can add custom scripts to the compositor and whether they would be able to do what I want (I don’t know really anything about Python or the scripting API that blender has).
If it would be possible to access to the data using material index and object index values, it would allow me to get the data I need while having many more possibilities.
TL;DR - Need specular data (not a map, but as a sprite (in other words wrapped around the model) ), have tried many crazy things, few work barely. Baking and wrapping and rendering too slow (but a possibility). Scripts a possibility?
Need more information? Ask away, and I’ll get back to you as soon as I can!