Multiple Distance Shaders

Started by Blonderator, July 07, 2008, 10:56:16 PM

Previous topic - Next topic

Blonderator

I'm having trouble with the node network. I'm trying to use multiple distance shaders to control cloud coverage. There are multiple cameras and distance shaders used to isolate a single cloud cell in one layer.

However I can't seem to blend the cloud layer by both distance shaders. I've tried plugging both of them into a multi-shader, to try and combine them - however, only the distance shader in the "shader 1" input of the multi-shader has an effect on the clouds. The other distance shaders do nothing.


Can anyone help? I've attached an image showing my setup. In the image, "Distance shader 01" is the only one having an effect on the cloud layer.

mogn

As far as I know, the multishader can only be used in objects, which is a pity.

Blonderator

That is a shame.

Would there be any other way to use 2 distance shaders with my clouds? I've tried function shaders like Add, but those don't seem to work too well either.

moodflow

Instead of the multishader (which is likely only for objects), try the merge shader.  The merge method (you'll see it in the shader which defaults to "mix") will be up to what you want for effect.

http://www.moodflow.com
mood-inspiring images and music

jo

Hi,

I've attached a clip file which uses a conditional shader to create a donut of cloud about a camera. Connect the conditional node output to the cloud's density fractal output and away you go. The first distance shader defines the "hole", the second defines the circumference. The second distance shader is inverted compared to the first, I made the far colour black and the near colour white. I then combined the two with the conditional node, which uses the "Less than" condition. This basically means that the conditional node outputs the minimum value of the two distance shaders.

There are probably other ways you could do this, but right now I'm too tired to think what they are :-).

Regards,

Jo

Mr_Lamppost

#5
Here's another way, this one makes a "lens" shaped cloud

Two cameras, two distance shaders both inverted (Far distance black), combine them with a Multiply Colour, use the result as the blend shader.

<edit>P.S.  if you use his camera and distance shaders this will also make Jo's doughnut  ;D  </edit>
Smoke me a kipper I'll be back for breakfast.

jo

#6
Hi again,

There is an improved version of my previous clip attached. This uses the Smooth step scalar node to smooth out the fade in/fade out parts of the donut. With my previous one just using the distance shader directly gives you a linear ramp from black to white. The problem with this is that there is an abrupt change from, for example, all black to the start of the ramp. Imagine drawing a ramp. Where it starts to leave the ground and head upward there is an abrupt change of direction, you could call it a discontinuity between the flat ground and the surface of the ramp, rather than a smooth transition. This can lead to aliasing or "jaggies", just as you might see the difference between an antialiased line and one which isn't antialiased ( aliased in fact :-).

This is where the Smooth step node comes in. If you look at its documentation you will see that it can be used to create smooth transitions between values. Using the example of the ramp, it creates a smooth run in to the ramp. This removes the discontinuity. Basically it helps you create an antialiased shader. As well as the clip I've attached a screenshot showing the network. As you can see it's easy to add in the Smooth step nodes in this case. Sometimes it takes more thinking about :-).

Another thing to consider with this particular shader setup is that you want to make sure you don't have the far distance of Distance shader 01 greater than the near distance of Distance shader 02. If you did you would get an overlap of the ramping areas of each shader. Hold a ruler in each hand, with the tops sloping in toward each other, but with the tops a few inches apart. Imagine a line connection the tops of the rulers, this is a plateau area. If you move the rulers toward each other so that they overlap you will notice you now have a hard angle between them and no plateau. Instead you have what amounts to a ridge. The sharp top of this ridge is another discontinuity and will cause aliasing. By having a plateau with a smooth transition on each side you will always have a better quality shader.

Of course for the scale of these shaders the aliasing might not be noticeable, but it's a good bad to get into the habit of thinking how your shaders/networks might exhibit aliasing artifacts and how you can address that.

Regards,

Jo


jo

Hi,

Disclaimer - even more tired than I was before, may talk nonsense :-).

M_L, I don't think your shader has quite the same effect as mine. For example if you get places where the values are 0.5 my shader will output 0.5 and yours will output 0.25. With my donut setup you will get the same effect, because one or both of the shaders will be outputting either 1 or 0, but if differing areas overlapped you would have a different result. No big deal, depends on what you're looking for really, but there are differences.

Messing with this stuff makes me think we need a function node which takes a vector as input and then works out its distance to the current render position. I don't think cameras need to be part of the equation, and they're a bit of a nuisance to deal with really. In the example of your lens cloud, rather than having to create cameras wherever you wanted to place a cloud seems like overkill. This would be a handy place where it be handy to use a Null object to position the cloud in the 3D Preview, and then have the position of the Null used as the input to a non-camera-related distance shader. You could make a distance shader with function nodes, but it would a useful thing to have already made.

Regards,

Jo

Tangled-Universe

Why so complicated guys? :)

Just use the "multiply" and "add" function nodes...

If you need some help with it, I can show you an example, my Finally Spring image uses 5 masks created using this technique.

Martin

Mr_Lamppost

Jo.

I agree that the outputs from the Multiply Colour and Conditional Scalar are different and which one would be best will depend on what you are trying to achieve, there are probably other ways to combine distance shaders that will give yet different results.

For distance shaders based on spherical distance from a point is there any need to reference an external node at all?  The distance from point could be incorporated into the shader itself, although the ability to link the distance shader to a camera or null node would need to be retained.  The difficulty would come if the distance shader were operating in the planar mode where both a reference point and direction are requited.   :-\

Thanks for the tip for using a smooth step to soften the blend edges that will be useful. 
Smoke me a kipper I'll be back for breakfast.

jo

Hi Martin,

Quote from: Tangled-Universe on July 08, 2008, 08:15:17 AM
Why so complicated guys? :)

Just use the "multiply" and "add" function nodes...

What's complicated about one node ( conditional ) ? :-) I'm a bit surprised we don't have min and max function nodes already, you can implement them using the conditional as I've done, but just needing the two connections would be a bit simpler.

Regards,

Jo

jo

Hi,

Quote from: Mr_Lamppost on July 08, 2008, 09:11:31 AM
For distance shaders based on spherical distance from a point is there any need to reference an external node at all?  The distance from point could be incorporated into the shader itself, although the ability to link the distance shader to a camera or null node would need to be retained.

You might notice that the design of the function nodes is generally that they take another node as inputs for their values. This is the most flexible way to do it, if not perhaps always the most convenient.

QuoteThe difficulty would come if the distance shader were operating in the planar mode where both a reference point and direction are requited.   :-\

That's actually pretty easy to deal with. The orientation can be specified either through providing another vector as a reference point ( where the node works out the direction to that reference point ), providing a vector as an actual direction vector or providing a vector set up as heading/pitch/bank.

Regards,

Jo

Matt

#12
Quote from: jo on July 08, 2008, 06:28:10 AM
Messing with this stuff makes me think we need a function node which takes a vector as input and then works out its distance to the current render position.

That would probably be useful, yes, but it can also be done by subtracting Get Camera Position from Get Position in Texture. (This gives a vector, so you might want to use Convert -> Length Scalar unless the value is plugged into something that will expect a scalar and therefore do the conversion automatically.)

We'd have to make different versions for each of the types of position that can be used: Position (which usually means "final position"), Position in Texture and Position in Geometry. The more of these slightly-higher-level functions we build, the more functions have to support these different kinds of positions.

Perhaps a simple function to calculate the distance between two positions would be a good compromise. You could plug in the two position vectors you're interested in, giving you all the flexibility you need, without forcing to you think about whether you need to convert the vector to a scalar.

Matt
Just because milk is white doesn't mean that clouds are made of milk.

Mr_Lamppost

I had noticed and agree on both points, which I guess is why distance shaders are controlled via cameras that already have both position and direction.   Saves a lot of special cases.  

Quote from: jo on July 08, 2008, 10:20:58 AM
I'm a bit surprised we don't have min and max function nodes already, you can implement them using the conditional as I've done, but just needing the two connections would be a bit simpler.

They would make node networks easier to follow, a while ago I remember posting an example that used a conditional which gave people problems as they hadn't noticed that I had changed the comparison condition even though I had noted the change in the name of the node.   ::)

A really handy addition would be a Comment Node.
Smoke me a kipper I'll be back for breakfast.

Blonderator

Thanks so much for all the help guys! I really appreciate it.

The conditional scalar method works great, but how would you do that with 3 or more cameras? Can you plug in the smooth step scalar from the third camera into a second conditional scalar node, and the output from the first conditional scalar into the second one?