Forum: Poser - OFFICIAL


Subject: Shader challenge: increasing contrast

danamongden opened this issue on Jul 17, 2005 ยท 21 posts


danamongden posted Sun, 17 July 2005 at 12:23 PM

I've got a challenge for my fellow shader-node enthusiasts. At various times I've gotten a greyscale node that I intend to use as a mask (either for multiply, blender node, etc.), but I'd like more black and white and less grey, i.e. higher contrast. Values less than 0.5 should move towards 0.0, while values greater than 0.5 should move towards 1.0.

So, I'm trying to design a generic shader node network that will take two parameters: a greyscale mask and a contrast level between 0 and 1. The image above should give some idea of the kind of curve response I'm looking for. I've thought about just averaging in the ROUNDed value, but I don't see how I'll get the kind of curved response I want. It's almost like an inverse-tangent with an offset origin, but we don't have such a node available to us.

Any suggestions? This just seems like a useful sub-network to have.


nruddock posted Sun, 17 July 2005 at 1:30 PM

Here's my attempt.

Control values are :-
"Math_Functions.Value_1", range 0.0 to 1.0, controls contrast as specified.

"Math_Functions_4.Value_1", adjust to give the required suddeness of transistion at a value 1.0 for the contrast control.

Plug your greyscale image into "ColorRamp.Input".

If you really want a true step a 1.0, some extra nodes could be used to switch between this network and one using the "Step" math function.

Attached image shows output with contrast control at 0.5


nruddock posted Sun, 17 July 2005 at 1:32 PM

Contrast control value at 0.0

nruddock posted Sun, 17 July 2005 at 1:32 PM

Contrast control value at 1.0

nruddock posted Sun, 17 July 2005 at 1:35 PM

And finally the MT5 file (saved from P6) so that you can play with the colours and values.

JohnRickardJR posted Sun, 17 July 2005 at 1:43 PM

How about the Gain node? The higher the second value, the more the contrast is adjusted

JohnRickardJR posted Sun, 17 July 2005 at 1:44 PM

0.5 is contrast unadjusted, less than 0.1 spreads out the greys in the middle, more than 0.5 increased the black and white, 1 gets you almost pure black and white.


danamongden posted Sun, 17 July 2005 at 1:54 PM

Wow, both of these look pretty good, though obviously the Gain is simpler. I had completely overlooked it, mostly because I never understood what "gain" and "bias" were. The manual just gives the oh-so-useful explaination of "Gain adjusts the gain of value 1." Thanks!


JohnRickardJR posted Sun, 17 July 2005 at 2:00 PM

Gain gives the curves you are looking for, while bias gives a simpler curve, adjusting the entire thing towards light or dark. One of the many not useful explainations in the manual - I still don't really get the smoothstep node.


nruddock posted Sun, 17 July 2005 at 2:08 PM

Attached Link: http://www.keindesign.de/stefan/poser/matroomtut2.html

See attached link for stewer's explanation.

Qualien posted Sun, 17 July 2005 at 3:21 PM

bookmark


JohnRickardJR posted Sun, 17 July 2005 at 5:03 PM

The problem is that the key bit of stewer's explanation is: 'In between them, it returns a value between 0 and 1 (although not exactly the same value you gave it on the input, it is "smoothing" it a little).' This is effectively what the book says. I've also found detailed explanations of the smoothstep algorithm, which make it look almost like a blur command, although the output doesn't quite match that. As far as I can tell, it sort of blurs already smooth images, while leaving sharp edges alone. As a practical node, it appears to make pictures sharper and brighter, so possibly quite useful, but I wish it was controlable. The rest of that tutorial is fantastic, and has given me quite a few ideas.


nruddock posted Sun, 17 July 2005 at 6:11 PM

The following two paragraphs in stewer's explaination seem to indicate that it uses a non-linear function similar to the middle graph in the original post, where as the Step Math_Function is like the right-hand graph.
Both nodes clamp the output.


JohnRickardJR posted Mon, 18 July 2005 at 12:37 AM

That's put me on the right lines. Having just experimented with SmoothStep and comparing it to Gain, it appears that the SmoothStep function is identical to the Gain function with Value_2 set to .66 for normal maths, or .85 in colour maths. Step actually does something very different, only ever producing output of 0 or 1, comparing input_1 and input_2 and returning 0 if value_1 is lower, and 1 if it is higher. With a single input map set into Input 1 this tends to invert the output, with dark becoming white and light becoming black. If you plug your input into Value_2, set that to 1 and set Value_1 to a lower number, you get a white for anything brighter than value_2. It can produce some interesting effects when you plug two input nodes in.


nruddock posted Mon, 18 July 2005 at 2:37 AM

Like you, it took me a while to really get the Smoothstep, but no problem with Step.
It's very useful for creating masks from texture maps and for other thresholding tasks.


JohnRickardJR posted Mon, 18 July 2005 at 2:49 AM

I'm not entirely sure that SmoothStep is doing what it's meant to at the moment. The description in the manual mentions the algorithm it's using, which is meant to be for smoothing/ bluring images. I wonder if the current uncontrolable gain feature is a mistake (similar to the Du crashes firefly problem). Must have a play with small textures and see if it produces obviously smoothed images or not. I've found Step very handing for splitting U and V into bands. I've got a inteligent mini-material using the trick that I'm polishing at the moment.


JohnRickardJR posted Mon, 18 July 2005 at 10:27 AM

I've had a quick play with very small textures, and SmoothStep does appear to improve them somewhat. I've created a 10 pixel square, and drawn a one pixel line across it. SmoothStep has then made quite a big improvement to the overall result, so it looks like it does work as a blur, but only on textures. Might be an interesting node to play with for improving smaller skin textures etc.


danamongden posted Mon, 18 July 2005 at 1:58 PM

Might be an interesting node to play with for improving smaller skin textures etc. Or for smoothing out displacement maps.


JohnRickardJR posted Mon, 18 July 2005 at 2:16 PM

Having had another play, it only works to smooth thing out when the texture size is smaller than it will appear on screen. Could be a way to solve un-renderable pictures - plug smoothstep in everywhere and then reduce max texture size to something tiny! I've not been convinced by the alledged problems with 8 bit displacement maps. If you consider that on most models the displacement map is making changes on a relatively small scale - ten to twenty pixels at most on a large render for skin maps for instance, then 256 levels of displacement should be enough to produce entirely smooth results - thats ten levels of displacement more than actually needed! The problem must be with the original maps - perhaps in the dithering algorithm used to convert 16 bit to 8 bit maps? Having said that, it could allow a very very small displacement map to produce smooth effects. A very small 10x10 displacement map was used to produce this effect, and the smoothsteped one on the right is somewhat smoother. The problem is that the smoothing effect (as opposed to the contrast change) only works with significantly smaller files - the texture map being used must be smaller than it will appear on your render, so that smoothstep has some intermediate pixels to alter.

nruddock posted Mon, 18 July 2005 at 2:38 PM

Changing the Shading Rate might make a difference.


JohnRickardJR posted Mon, 18 July 2005 at 4:39 PM

I've had a longer play with it now, and as far as I can tell, the only visual impact the smoothshade has is the same as the Gain set to .85 - if you use gain to reduce the contrast back down, there is little or no difference. I've tried large textures, small textures and tiny tiny textures (a 256 pixel face texture - does surprisingly well at normal distances!), as well as a variety of pixel rates, shading rates and max texture sizes. The only textures that appear to be modified are things like ferns, but again, this appears to be the contrast changes.