2
$\begingroup$

I'm trying to put a displacement map into the alpha channel of a normal map. As per answer to question "Bake displacement to alpha channel" I am trying to use the Node editor for this purpose. The result washes out the colour. I have my problem demonstrated in a test case as follows. I have two (RGB only) images: PaleBlue is coloured (0.5, 0.5, 1.0); DarkGrey is coloured (0.25, 0.25, 0.25). I am trying to combine the colour channels of PaleBlue with the red from DarkGrey as alpha. The screen shot shows my results. On the left are the two input images (RGB only). In the middle is my node structure - a bit more complex than needed, but I think this explicitly shows what I want done. On the right are two views of the output - actually the Viewer Node, but the Render Result is the same. The top view is the colour component, the bottom the alpha channel. Note that the colour is white - not pale blue and that the alpha channel is black. First screen shot removed to be within link limit.

Question Update: I've made the recommended change. It improves my result, but still have somewhat washed out colour and 'brightened' alpha. enter image description here

Question Update 2: Here are views of a parallax mapping texture (obtained from other sources) and what it should look like in the image viewer.Screen Shot

$\endgroup$
  • $\begingroup$ Before trying to answer your question, I'd like to ask why are you adding an alpha channel to a normal map? That doesn't make any sense. Normal maps are supposed to be used as non-colour data in shaders or compositing, they don't have transparency. $\endgroup$ – Gez Nov 24 '16 at 23:28
  • $\begingroup$ Hi Gez, Thanks for taking an interest, but I was happy with the replies I received back in March. The reason for the alpha channel was that I was adding a height map to the normal information for use in a parallax mapping algorithm. - Cheers / Bill $\endgroup$ – Bill Dec 4 '16 at 8:56
  • $\begingroup$ Ah, so it's not used as transparency, but as an added channel to be used as a height map. Gotcha. Well, in that case, the problem you're having is alpha association. You need your file to be stored in a format that manages unassociated alpha, and you have to make sure that the program (Blender or whatever you use to deal with these maps) doesn't EVER multiply your texture by alpha channel. The only way I know to do this is to connect your pure RGB to the the "image" socket in the compositor and connect your alpha to the Alpha socket and saving to, say PNG which stores unassociated alpha. $\endgroup$ – Gez Dec 4 '16 at 23:46
  • $\begingroup$ I.e.: don't assign the alpha channel to the RGB image, just plug them separated to each socket of the output. $\endgroup$ – Gez Dec 4 '16 at 23:48
1
$\begingroup$

Connect your image node to your Alpha inputs

enter image description here

If Im Looking strictly at the color values and ignoring the alpha, then the value results will be as follows:

enter image description here

And If you are looking to come at this from the polar opposite, then here is the result:

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for the reply Rick. It certainly improves my result. However the colour channel and the alpha channel are still not the colours expected. Note that the blue is still somewhat washed out and the alpha channel has a value of 0.5 instead of 0.25. Sorry, haven't been able to add a screen shot to this reply. $\endgroup$ – Bill Mar 24 '16 at 18:47
  • $\begingroup$ Thanks again for the reply. I've added a new screen shot to the original question. @Rick Riggs $\endgroup$ – Bill Mar 24 '16 at 19:01
  • $\begingroup$ I think that this should be the expected result, as your Red value is already starting @ 0.5 (0.25 = 0.5 * the Original Red information on the PaleBlue image). Simplifying this down to the red channel only you started with a red value of 0.5, and the delta between this red channel and the one on the Grey image (0.25) = you subtracted 50% from the original, by making half of this red channel transparent. @Bill $\endgroup$ – Rick Riggs Mar 24 '16 at 19:07
  • $\begingroup$ I'll include a little context to this as part of my answer. @Bill $\endgroup$ – Rick Riggs Mar 24 '16 at 19:13
  • $\begingroup$ Hmm. Maybe I am doing completely the wrong thing then. My goal is to make a texture for parallax mapping, with normals in the colour channel and a height map in the alpha channel. I just require the node system to assemble the unmodified values from my two sources. I don't understand why any scaling to the colour values should occur with the node rig. If red was modified by alpha, it would get darker, not lighter. I'll add an image to my post showing a parallax mapping texture obtainef from another source, displayed with view = combined/colour only/alpha only. @Rick Riggs $\endgroup$ – Bill Mar 24 '16 at 19:42
0
$\begingroup$

I'm answering this myself - but thanks to @RickRiggs who gave me lots of advice and ideas on the way. There were many issues. It turned out that part of the issue was alpha pre-multiply (aaarrrggghhh - whoever thought of that idea). I found it very hard to tell when and if it might apply, but putting in an Alpha Convert node with setting "Straight to Premultiply" definitely prevented it, despite the fact that its wording kind of suggests the opposite - bit of a theme begins here (maybe its because I am in the Southern Hemisphere and see things the other way up) - possibly the node marks the image as having been premultiplied and therefore prevents it? At that stage putting a constant value in as alpha to the CombineRGBA node worked - the value ended up in the alpha channel of the finished image without changing any of the colours. Unfortunately connecting the Red channel from the Displacement Map image caused colour damage to recur. I tracked this down (I think) to the fact that the Displacement map was in sRGB. When I changed it to 'Non Color' and regenerated, everything worked. Maybe I should have thought of it, but it was fortunate that I didn't. It is important that the Normal Map is in sRGB space, else pre-multiply occurs again. The only other unexpected feature was that baking the displacement map gave displacements in the range 0 to 0.5, hence the Math node to double displacement values. The only other thing that gave me persistent problems was the fact that it the displacement map 'Normalizes' rather more when the Normalize switch is turned off - maybe that's a Southern Hemisphere view again. Finally Rick - connecting the alpha input to the Viewer and Composite nodes causes trouble now that I have the Alpha Convert in place, so I removed those connections. Screen Shot

$\endgroup$
  • 1
    $\begingroup$ Wish I had spotted this earlier. Short answer: associated alpha is the one true alpha (premultiplied) but you always must unassociate (unpremult) when doing colour operations, then re-associate. Search for more answer from @gez for more information. Also, file formats matter; use EXR. $\endgroup$ – troy_s Jun 26 '16 at 19:16
0
$\begingroup$

What you do looks fine but you have to be careful with math node. If you don't check "clamp", you'll get alpha values greater than 1. It can be a problem or not, but you have to know it. If you want fine control, you can use a color ramp to find the position where you want full white and full black (or anything else). You can use the node "set alpha" to make things easier.
result

$\endgroup$
  • $\begingroup$ Thanks for the comments - I wasn't aware of the colour ramp option and will probably use it in other situations. In this case a linear ramp is needed. I prefer not to use clamp, because I need the values to be in the range 0 to 1 naturally. If they are not then I have something else wrong and it's probably best to know about it. On a positive note, I found out more about how to use depth baking and now have the depth scaled correctly. $\endgroup$ – Bill May 27 '16 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.