What I seek

I'm not sure if "crossfader" is the best way to describe it, but imagine black on one end, white on the other, and a grayscale image in the center. You can lighten or darken the image with a single slider.

I am trying to create a node setup that will either lighten or darken grayscale values, depending on whether an input slider is above or below 0.5. So at a value above 0.5 it would become lighter (with 1.0 fully white), and at a value below 0.5 it would become darker (with 0.0 fully black). If at 0.5 it should remain unchanged.

I'm looking for a solution that will work universally in Cycles or Blender Render, so it shouldn't rely on Shader nodes or other engine-specific nodes, but rather only make use of nodes involving math and color.

Why I need it

I'm trying to emulate the functionality of the Layer Weight node's Blend slider.

The output from the Layer Weight node is lighter or darker depending on how much higher or lower the value is relative to the midway point of 0.5

I know I can emulate most of the functionality of this node using the technique explained by Jerryno here. This gives output equivalent to the default 0.5 value. However there is no way to lighten or darken the result the way the Blend slider does.

Here is a comparison of the two node setups:

Comparing the Cycles node setup for incidence angle versus the Blender Render (Blender Internal) node setup for incidence angle

What I've tried

I first tried to use Math nodes to add or subtract from the 0.5 value and mix that, but I soon realized that's not the same process. Next, I tried using MixRGB nodes with Add and Multiply blend modes. I believe this is producing the correct result, but I can't figure out how to control them using a single slider centered at 0.5, since the lightening and darkening rely on different color blend modes. Here is a screen shot of my latest attempt:

Trying to use MixRGB nodes to control the lightness/darkness of the Layer Weight node's output

The annotation "pretend this cannot be changed" is because, remember, the Layer Weight node will be replaced with the Blender Render incidence angle node setup, which has no Blend slider.

The annotation "how to combine" is because a simple mixing of color values will not suffice. Somehow Multiply must be used if less than 0.5 and Add must be used if higher than 0.5.

There's probably a simple mathematical solution I'm overlooking, but I'm stuck trying to figure out what it might be.

Hopefully I've explained this question well enough. Feel free to ask questions if anything is unclear.


2 Answers 2


Try this:

enter image description here

This mixes between the input and black (0) for the 0-.5 range, then mixes between the input and white (1) for the .5-1 range.

The "Lerp" nodegroup is as follows:

enter image description here

This multiplies one value by an inversion of the "Fac", and the other by the fac itself. Then adds the two together.

0 as the "Fac" returns the top input, while 1 as the "Fac" gives the bottom input. Values in between give a mix.

Note that this should work for extrapolating as well; "Fac" values outside of 0..1 will give a result "past" the input values. If you don't want that, clamp the Fac input to 0..1.

  • $\begingroup$ Thanks gandalf3! Maybe I'm missing something obvious, but how are the two "Value" inputs supposed to be used if I have one source of color data (in this case Layer Weight Blend) and one slider for boosting or reducing the values? I constructed the node group and tried various combinations of routing, but nothing gave the expected result. $\endgroup$
    – Mentalist
    Feb 1, 2017 at 3:26
  • $\begingroup$ @Mentalist Ah, I misunderstood. I've updated my answer $\endgroup$
    – gandalf3
    Feb 1, 2017 at 6:31
  • $\begingroup$ Thank you for the updated answer. That's much more clear. Unfortunately, when I construct the node setup I get this strange artifact - a black ring around the edge of my object. Here is a .blend file to illustrate. Any idea what could be causing this? $\endgroup$
    – Mentalist
    Feb 1, 2017 at 22:02
  • $\begingroup$ @Mentalist One of the multiply nodes in your "Blend" nodegroup is set to subtract instead. $\endgroup$
    – gandalf3
    Feb 2, 2017 at 1:17
  • $\begingroup$ Got it! Thank you! It's working now. When I compared the output, it doesn't give the same exact output as changing the Layer Weight node's Blend value, but I believe this is due to my misunderstanding of how that node's output works - not due to any error with your nodes. It seems your setup does in fact lighten or darken just as I specified in my question, so I consider this solved. I appreciate the help. If you have any thoughts on how one might emulate the Layer Weight node's Blend I'd be curious to hear. Maybe it's worth opening a new question specifically for that. $\endgroup$
    – Mentalist
    Feb 2, 2017 at 1:55

Here's a basic driver solution to this problem.

The nuance to this is that at this point, this is just a manual slider. If you want to have automatic changes, you would have to figure out how to drive the "prop" value from whatever you have in mind.

Things don't quite work on all fronts of the driver categories, so I just used a mesh object's custom property to drive the mix in this case.

That being said, there are python solutions that you can use to trigger from the driver, and that can pretty much get you anything you need.

If you want to show a very specific value that you want to calculate from in response, we should be able to polish this answer and drive the values appropriately.

Driver in action

  • $\begingroup$ Ah, interesting! A driver-based approach won't work for my current case, since I need to use this in Blend4Web, which doesn't support drivers. (Sorry I didn't specifically explain that in my question.) However, this might be a solution for others, and I like that you thought outside the box. Just curious, do you know if it would work in the BGE? (I haven't looked into driver support in the BGE.) $\endgroup$
    – Mentalist
    Feb 1, 2017 at 22:38
  • $\begingroup$ @Mentalist, No my knowledge is fairly weak on the BGE side of things. I will check into it though, as it's worth a check. $\endgroup$
    – Rick Riggs
    Feb 2, 2017 at 2:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .