Shader1 AND shader2 ?

Started by Alfamike, October 28, 2007, 06:44:58 PM

Previous topic - Next topic

Alfamike

Hello All,

I've been struggling to AND the output of two shaders. One is of a spherical distance shader and the other of a distribution shader, restricting by slope.

I AND these outputs with a colour multiply function.

Now, the thing is that it works fine restricting by distance and altitude, but for some reason not for distance and slope...?

Anybody got any ideas how to change to a proper AND function or work around the above? I have tried a few other functions, like a merge function, but all to no avail. Seems like the colour multiplier is the way to go here.



I am trying to constrain the big rocks to near the volcano (crater) and constrain them by slope as well so they will not show up where they would naturally roll down hill. I could do so by altitude - in this case- since the higher up the hill the steeper the slope, but that is beside the point.

My main goal was to find an AND port (macro/function) that would take two shader inputs and output the results of an AND-operation.

This is why I created the volcano, easy to work with 'cause you can sort of guess the slopes.


I attached the TGD file I am playing with.

Thanks for your help.

AM.

bigben

I normally use surface shaders for masks, but the distribution shader is not that different. Rather than adding another node, set the coverage of your distribution shader to 0.5, fractal breakup to 1 and connect your distance shader to the fractal breakup input.

Another way, would be to use a surface shader. Set the colour to white!  Connect the distance shader to the child input and then set your slope/altitude constraints in the surface shader. This still leaves your fractal breakup free to provide some additional fractal breakup.

jo

Hi AM,

Have you tried either of these two nodes ? :

Conditional Scalar
http://forums.planetside.co.uk/index.php?topic=10

Conditional Boolean Scalar
http://forums.planetside.co.uk/index.php?topic=2267

These are for scalar values, but you could use them to mix between other types of values. I'll haven't looked at your project file yet to see if this is actually worthwhile advice :-), but I will a little later today.

Regards,

Jo

Alfamike

Hi bigben and Jo,

Thanks for your replies. I'll look at your suggestions later today.

I did play with shader inputs into a boolean scalar function, but that did not seem to work. I will check that out again too.


AM.


Alfamike

Hello again,

Just tried bigben's first solution. It does not appear to work for the Fake Stone Shader with "Blend by shader" and "Blend as stone density" both ticked on and AND-ed shading result plugged in.

However, when I plug the final shader result (as mentioned above) into a power fractal shader and give it a contrasting colour it does work indeed.

Thanks. Maybe there's a bug behind the blending input of the Fake stone shader, as they keep showing up at too steep slopes, way past the constraints I set for them.

AM.

Alfamike

Re my latest post:

Please see attached image and note that the same constraints were used for the brown surface layer (correct result) as for the large fake stones ("Blend by shader" and "Blend as stone density" both ticked on ), incorrect.....?

AM.

bigben

#6
Had a look at your file...

Part of the problem is the order in which you have placed things.  I moved the crater shader into the terrain section so that it is before the computer terrain. With large displacements after the Computer terrain node it is usually necessary to add a compute normals node for slope restrictions to work properly. This makes render times longer, so it's better to do as much of the large displacements as possible in the terrains section.

I also wouldn't put anything between the Computer Terrain and Base Colour nodes.

[edit] Ran a quick render. You will also find that there are some fake stones near the crater rim.  That's because the slope drops below 20° as you pass over the rim. As the mask is controlling the density and not the exact placement, they can appear a short distance from the rim. You may also need to exclude the rim from the mask using another distance shader.

Functions may give you a more useful mask in this situation than the camera/distance shader combination.[/edit]

dhavalmistry

dont get me wrong but whats up with all the "ANDs"
"His blood-terragen level is 99.99%...he is definitely drunk on Terragen!"

bigben

It's a way of describing what he wants...  or what he's trying to do. Converting this into TG2 nodes isn't necessarily going to be using an "AND" function, but how it's best done takes time to learn.  With more complex masking, this is the first step ... describing each of the components of a mask and how they combine with each other. I do this on paper first, build each of the components in TG2 and then find a way to join them up. AM managed most of it, but just needed a little help with the last bit, and the description actually helped provide an answer ;)

bigben

And out of my last answer came the fix for stones on the rim.... The rim can be defined in this case by two properties... distance from the centre of the crater, or altitude. The latter in this case is much simpler to mask by adding an altitude restriction (see attached).

bigben

Quote from: Alfamike on October 29, 2007, 05:14:16 AM
Hi bigben and Jo,

Thanks for your replies. I'll look at your suggestions later today.

I did play with shader inputs into a boolean scalar function, but that did not seem to work. I will check that out again too.

AM.

I may have to do some more testing on these too.  I have tried them  in some masking tests and had similar problems, while the conditional scalar setup to do the same function worked (but required more connections). In principle the boolean scalar can be more practical in certain situations.

Alfamike

Thanks bigben, looking into this now.

I actually ran into this problem before with one of the images I submitted to the Terranuts site, after which I figured to do all the major terrain building before the "compute terrain" node. Completely forgot about it, though, so thanks for your help!

AM.