Question about redirect shader and merge shader (and warp shader)

Started by Elegy, July 19, 2009, 07:52:49 AM

Previous topic - Next topic

Elegy

Firstly, I'm quite confused about what exactly the difference is between lateral displacement, such as when you select 'Lateral Only' from within the Power Fractal, and a redirect shader with a displacement plugged into both the X and Z shaders.

In both cases, displacement is applied along only two axes - X and Z - and yet the displacements produced seem to be very different. Why is this? I know that redirect shaders 'redirect' the input along any axis but what does that mean exactly?

Secondly, I know that the Merge Shader when left to default settings is set to 'Mix' displacement. I take it this means that the mean altitude of both inputs is used as the output. But what if one of the inputs has two altitudes at one point (ie, has overhangs)? Does it simply take the mean of all altitudes at a given set of 2D coordinates?

I appreciate any answers.

Matt

#1
Quote from: Elegy on July 19, 2009, 07:52:49 AM
Firstly, I'm quite confused about what exactly the difference is between lateral displacement, such as when you select 'Lateral Only' from within the Power Fractal, and a redirect shader with a displacement plugged into both the X and Z shaders.

In both cases, displacement is applied along only two axes - X and Z - and yet the displacements produced seem to be very different. Why is this? I know that redirect shaders 'redirect' the input along any axis but what does that mean exactly?

The Redirect Shader "tricks" the shaders which are attached to it into thinking that the surface normal points along the positive X axis, positive Y axis or positive Z axis. Basically it modifies the shading state variable for the surface normal before calling the shaders, so that they think they are displacing a surface with a different normal. Any shader that displaces along the normal will then displace along these directions. Displacement in the negative X,Y,Z directions is accomplished if the displacement shader displaces negatively (e.g. if it indents a surface rather than raising it).

Some shaders make more complicated decisions about the displacement direction, or they let you choose. The Power Fractal defaults to displacing "Along Normal", but some of its other settings allow for interesting effects. "Lateral Only" still uses the surface normal, but it cancels out any amount of displacement which occurs directly upwards/downwards away from the planet's centre. On a level surface, the surface normal points directly upwards, and the displacement will be completely cancelled out. On the side of a cliff, however, where the surface normal points away from the usual up-down direction, the displacement is much stronger. They only displacement allowed is displacement not in the up-down direction. It's a simple way to get the appearance of horizontal layers in your displacements, especially if you combine it with XYZ stretching of the noise pattern.

"Lateral Normalized" is similar to "Lateral Only" except that the magnitude (length) of the displacement is kept, and only the direction of the displacement is changed. This means that the displacement won't fade out on surfaces which are nearly pointing upwards, and you'll always get strong lateral displacement.

"Vertical Only" is the opposite to "Lateral Only", and cancels out any displacement which does not occur along the up-down vector which points away from the centre of the planet.

"Along Vertical" ignores the surface normal completely, and uses the up-down vector which points away from the centre of the planet.

Some of these names include the words "requires computed normal". A Compute Terrain node is sufficient to give you a computed normal anywhere downstream from that node. You don't need another Compute Normal node.

Quote
Secondly, I know that the Merge Shader when left to default settings is set to 'Mix' displacement. I take it this means that the mean altitude of both inputs is used as the output. But what if one of the inputs has two altitudes at one point (ie, has overhangs)? Does it simply take the mean of all altitudes at a given set of 2D coordinates?

I appreciate any answers.

The displacement vector (which includes the direction and distance of the displacement provided by a shader) is simply the weighted mean of the two input displacement vectors.

Overhangs are the result of bending the 2D surface over itself through the use of interesting displacement vectors, but each point on the terrain only comes from a single point on the undisplaced planet. It is still a 1-1 mapping from the flat surface of the planet to any point on the displaced surface. The upper part of an overhang comes from a completely different part of the surface than the lower part which it overhangs. So there is no averaging of overhanging points that overlap in 2D space, because the shaders don't even know that is happening.

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

Henry Blewer

Matt, this is the comprehensive explanation of this I have seen so far. Thanks!
http://flickr.com/photos/njeneb/
Forget Tuesday; It's just Monday spelled with a T

Elegy

Thank you, this is very helpful. This explains why I wasn't getting the results I was expecting in a project I was working on a while back - I was using Lateral Displacements when I should have been using a redirect shader.

While I'm here, may I ask how the warp shader works exactly? I've been experimenting but as yet, I've only been able to muster up a very vague idea of what it does.

Matt

With the Warp Shader, the displacement vector from the warper is used to offset the texture coordinates before they are used by the shader. This almost looks like the warper bends the final result, but it's actually bending the space before it is read by the shader. It's hard to explain without examples, but a simplistic way you can think about it is that the shapes from the warper will bend the final texture (but in the opposite direction).

The reason the Warp Shader and the Redirect Shader often work well together is because the Redirect Shader allows you to construct displacement vectors which go in all directions, which can be useful for warping a 3D function such as the Power Fractal. If you just use a single fractal operating along the normal as your warper, you might not easily see its warping effect.

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

Hetzen

Ahh, this makes some sense now. Thanks for the explaination.

Would you mind giving an over view on the transform shader too.

Elegy

It's at times like this I wish I hadn't forgotten my maths A-level but I think I understand and this will definitely be useful. Thanks again.

If I might make a suggestion - these explanations would significantly improve the node reference guide you have on your website. The current explanations for the redirect and warp shaders ("The Warp Shader warps one shader by the input of another." and "The Redirect Shader allows you to "redirect" the effect of the input shader along a specific axis.") are pretty much just stating the obvious and aren't too helpful.

dandelO

As I see it, the transform shader simply moves the coordinates of the input shader so, if you have a displacement(for example) at X=0, Y=0, Z=0, changing the transform shader's parameters simply moves that displacement to the transformed coord's.

Or, it rescales the entire shader input by the factor you specify in the scale boxes. To double the size of the original shader, you'd have 2,2,2 in the XYZ - to half it, you'd use 0.5, 0.5, 0.5 in the XYZ.

It just moves or rescales the original shader input.

Oshyan

Quote from: Elegy on July 23, 2009, 09:47:49 PM
It's at times like this I wish I hadn't forgotten my maths A-level but I think I understand and this will definitely be useful. Thanks again.

If I might make a suggestion - these explanations would significantly improve the node reference guide you have on your website. The current explanations for the redirect and warp shaders ("The Warp Shader warps one shader by the input of another." and "The Redirect Shader allows you to "redirect" the effect of the input shader along a specific axis.") are pretty much just stating the obvious and aren't too helpful.

These kinds of more in-depth explanations will definitely be added to the Node Reference soon. Lots to do behind the scenes at the moment! ;D

- Oshyan

efflux

Let me get this straight. The warp node takes the warper input and uses it to domain distort the shader? Could have been useful to know this a while back, especially on the Why Mojo users won't use TG2 thread. I never used warp node before but now I see why people have got some of the effects I've seen in some renders.

old_blaggard

Thanks for the explanations. I've long suspected many of these things, but it's really good to get clear descriptions of where each operation takes place in the rendering pipeline. The bit about the redirect shader also clears up some of the weird texturing results I was getting after having used it to displace parts of the terrain.
http://www.terragen.org - A great Terragen resource with models, contests, galleries, and forums.

Matt

@Efflux: yes. I'm sorry you didn't know about this shader already. I thought I'd seen plenty of TG2 renders from you that use it... ?
Just because milk is white doesn't mean that clouds are made of milk.

glen5700

I'm not trying to hijack your thread but I do have a question about the warp shader and thought maybe we could benefit from it.

I'm trying to get an even warping affect across the Voronoi noise function. Please see the attached images-

Voronoi warp and Voronoi no warp images are from TG2 and the dt_cell is from DarkTree, I realize I am not comparing apples to apples but I'm hoping to get closer than were I'm at right now. Look at the two images from TG2 and you can tell the warping is very uneven - some areas have a lot of warping and some ares almost none, the Power fractal shader (used for warping) noise is pretty even, you can view it using the shader preview(see uploaded clip file). Power fractal shader seems to hold the key, I've tried scale settings and have gotten some improvement but it still needs more. The other thing I found is the displacement amount (Power fractal shader) controls how much warp is applied.

The DarkTree image just shows Voronoi with a warp applied to it, I don't expect to get the same look (different noise functions- Terragen vs DarkTree), just a even warp.

I might even be going about this all wrong...

Any thoughts comments would be appreciated - Thanks,
Glen



efflux

I am real happy I found it. I have been doing similar things but not with this shader.

On the Planetside site, under node references, the warp shader has no proper description.

I haven't tended to download many files from the forums. Maybe if I had I would have found out about this shader.

First test:


efflux

glen5700,

What you are after is maybe a voronoi fractal - the powerfractal but with an option for voronoi basis. This I would badly like to have.

However, I am going to work a bit more with this warp shader now and see what I can get.