How to sample altitude at a particular position in texture

Started by FrankB, December 15, 2012, 02:15:36 PM

Previous topic - Next topic

FrankB

Hi all,

what is the best way to sample the altitude of a given point on the xz plane?

Example: at point (12;y;5), what is y?

Thanks
Frank

Matt

Is that the current Position in Texture? If so, you can just use Get Altitude in Texture:

http://planetside.co.uk/wiki/index.php?title=Get_Altitude_in_Texture

This basically does something like the following:


displacement = GetPositionInTexture - GetPositionInGeometry
altitude = DotProduct(displacement, GetNormalInGeometry)


But if I wanted to compute this for some arbitrary position called A, I would do the following:


displacement = A - GetPositionInGeometry
altitude = DotProduct(displacement, GetNormalInGeometry)


You can do this with the following nodes:


A, GetPositionInGeometry
\/        \/
SubtractVector, GetNormalInGeometry
           \/      \/
           DotProduct


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

FrankB

Hi Matt, thanks!

I think the last example might be what I am looking for.

To be precise, based on the current position, I want to know what the altitude of the point 1m next to the current position is (on e.g. x)

So if I understand correctly, I would construct a vector GetPositionInTexture + (1;0;0) = A

Then follow your last example code, right?

Thanks
Frank

Matt

If you just need to find out the altitude of the point in space that is 1 meter to the right of the current position, it's going to be almost exactly the same altitude as the current position because you haven't changed the Y at all (unless you are far, far from the origin).

Do you want to sample the displacement at a point 1 meter to the right? That's a completely different problem, much more tricky to solve. It should be possible with Transform Shaders but networking the nodes in a way that's useful is quite tricky.

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

FrankB

Correct, that's what I meant. I need the displacement at that point to the right.

Any idea how? I can see no way with the currently available functions, how I could specify a point on xz relative to the current position and THEN get its displacement value.

Frank

bobbystahr

wouldn't a right click > copy altitude, do that for you and then move over 1 m. and do it again or am I missing something esoteric here?
something borrowed,
something Blue.
Ring out the Old.
Bring in the New
Bobby Stahr, Paracosmologist

FrankB

Hi Bobby, what you suggest isn't what I need, because I need to sample continuously as TG renders. I don't need just the position for 1 point, I need it for millions of points, so I need to construct this within the node network itself.

Regards,
Frank

Dune


FrankB

I shall not say. ;-)
It's for a NWDA project. I would like to improve the procedural road and take it to the next level.
There, I rat! :-D

Matt

Try the Transform Shader. That works by changing the texture coordinates that are used by its "shader" input. To translate a shader by (-1, 0, 0) it offsets the texture coordinates by (1, 0, 0).

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

Dune

Ah, then you might as well stop your secret business, Frank  ;) I'm almost there releasing a setup for a mountain road. I guess that's what you're after...

FrankB

That's great, Ulco! Good news!

However I still would like to solve that puzzle. As you may know, the road setup I use is 100% procedural without a SSS or any file based mask. I would really like a way to embed that road in any terrain by accurately sampling its environment and then altering the surrounding displacement based on the sampling result.

Awesome though that you are going to make available your (working) solution to the problem! That's going to be great!

Cheers
Frank

Dune

Thanks, Frank.

Work fast then, because you're about to get the riddle unraveled. Although my setup uses simple shapes (they can be replaced by blue nodes no doubt, but this is easier for everybody I think), it can be fitted into any terrain. Here's a quick and not perfect teaser.

edit: and another one by just hitting the terrain seed...

mhaze

I've been working on this on and off but have only got the basics down so I look forward to both your solutions.  I was looking at sampling altitude but didn't realise how difficult it would be needless to say I got nowhere. In the end I came up with an SSS solution which is very basic but works, just, it could be considerably improved. Mick

FrankB

Hey Ulco, there is no race I'm on - even beyond this project, there's got to be a blue node way to sample the displacement of any given point on the planet, and use that for further calculations. I have a hard time imagining that your solution does that, but I'll let myself be surprised! :-)

Cheers
Frank