## Coastal waves/foam thru functions?

Started by Dune, April 17, 2009, 03:13:55 am

#### Dune

##### April 17, 2009, 03:13:55 am
Perhaps this has already been discussed (I've read a few discussions on water displacement near the coast), but I wonder if it would be possible to somehow get the depth (Get Altitude?)and 'transfer' this to the waterplane with a certain displacement. It would in theory be possible to raise the water level at certain depths (waterlevel minus 1, waterlevel minus 2, etc) , and lower at others (with a little overall displacement to roughen the water). Not physically correct maybe, but perhaps good enough to get the idea of coastal wave displacement.
Foam slightly behind or on top of the upward displacement might also be done this way, perhaps???

I am awfully terrible at maths (one of my greater frustrations when studying biology), as you can probably see in the attached screendump of my feeble attempt at functions to get foam at certain depths. Can anybody shed some light on a better approach?

---Dune

#### Matt

##### April 17, 2009, 03:48:15 am #1
There currently isn't a way to get the altitude of the terrain below the water. In your configuration Get Altitude would return a value associated with the surface of the lake, not the terrain below it. Actually, Get Altitude compares a surface position with its original undisplaced surface position (because this gives the "altitude" of a terrain when applied to a planet), so on a lake object this would return the wave displacement function.

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

#### Kranky

##### April 17, 2009, 05:15:48 am #2
You can use the "Get terrain altitude", but you have to do this with your terrain. It's hard for me to explain - so look at the file in the attachment... this is my method to create waves. You can optimize and adjust the functions so that you get your needed shape.

#### Dune

##### April 17, 2009, 05:39:09 am #3
Thanks for explaining Matt, and thanks for your testfile, Kranky. I'll have a look at it.

---Dune

#### moodflow

##### April 17, 2009, 04:30:32 pm #4
Great question.  I actually tried this EXACT thing nearly a year ago to create foam near the edges of the water, based on altitude (as are real breaking waves).  I was unsuccessful, and Matt's input now explains why.

Matt, any plans to resolve this?
http://www.moodflow.com
mood-inspiring images and music

#### Kranky

##### April 17, 2009, 06:11:41 pm #5
@moodflow: I'm not Matt, but you can look at my attached testfile in my above post.

#### Hetzen

##### April 17, 2009, 07:05:35 pm #6
Thanks for posting the tgd Cranky. I've been looking at the effect away from the shore, were it looks like you have ripples over the whole water surface, rather than just increasing in amplitude at the shore edges.

Looking at your node network, it would seem possible you could trick the system to work. I'll have a play with it over the weekend as it ties in with something I've been playing with today, that being getting white horses on peaks of waves, which I think I've managed. I used a compute terrain after the water shader fed into a surface shader set at minimum altitude. have a look at the attached image, excuse the land, haven't realy spent much time on that.

#### old_blaggard

##### April 17, 2009, 07:09:40 pm #7
I did this for my Boundary Waters image to control the depths to which my little ripples went out (http://www.terragen.org/gallery/displayimage.php?pos=-5397). I used a surface layer on the terrain to define a mask based on the terrain depth, and then used the resulting color values (stripped of all displacement - that's important, because having anything other than color data there messes things up for the following bit) as a mask for the displacement function for the waves, which itself was created with functions. I don't have time to look at the example file, so forgive me if I'm just repeating what's already been said, but this method has worked well for me.
http://www.terragen.org - A great Terragen resource with models, contests, galleries, and forums.

#### Hetzen

##### April 17, 2009, 07:20:16 pm #8
Looks like there could be a solution using a combination of both methods to achieve the ripples along the edge contour of the landscape fading out into the sea.

So OB, what did you use to create the wave displacement? Was it a bitmap of concetric rings?

#### mogn

##### April 17, 2009, 11:06:50 pm #9
@Dune: It's a pity that this does not work. You uses some conversion nodes, that's not needed. Most conversions are implicit.
Some conversion can be used in tricky ways to simplify the network, e.g length(scalar(x)) instead of multiply(scalar(x),sqrt(scalar(3)).

#### old_blaggard

##### April 18, 2009, 12:31:31 am #10
Hetzen - I constructed the concentric network using function nodes.
http://www.terragen.org - A great Terragen resource with models, contests, galleries, and forums.

#### Kranky

##### April 18, 2009, 08:00:04 am #11
Quote from: Hetzen on April 17, 2009, 07:05:35 pm
Thanks for posting the tgd Cranky. I've been looking at the effect away from the shore, were it looks like you have ripples over the whole water surface, rather than just increasing in amplitude at the shore edges.

Looking at your node network, it would seem possible you could trick the system to work. I'll have a play with it over the weekend as it ties in with something I've been playing with today, that being getting white horses on peaks of waves, which I think I've managed. I used a compute terrain after the water shader fed into a surface shader set at minimum altitude. have a look at the attached image, excuse the land, haven't realy spent much time on that.

Of course you have to build more complex functions to limit the waves and decrease the size far away from the shore. The testfile is as easy as possible to show how to get waves. My own network looks like this:

#### Hetzen

##### April 18, 2009, 08:52:07 am #12 Last Edit: April 18, 2009, 08:55:41 am by Hetzen
Cheers Kranky.

Looks kind of involved. What further stages are you using to develop the technique? I undestand the displacement of terrain with the sin function, then taking the terrain away from that, just leaving the modulation (the reason being that it then can be conditional to altitude compared to the lake altitude), so I guess that's what the other functions are doing.

I suppose you could also somehow shear the distortion to create a rolling wave shape, or laterally space out the sin peaks with a boolean function clipping the modulation half way up it's positive range. Hrmm, food for thought.

Is there any way of decreasing/increasing the frequency within the sin function?

#### Hetzen

##### April 18, 2009, 09:41:29 am #13
Ok, I've answered my own question with the Sin function, I think. The higher the input, the higher the frequency. To increase the amplitude, you then multply the output.

Here's a little progression on Cranky's .TGD. It's not right, but it's giving me a better understanding of this, and shows how higher inputs into the Sin function the closer to the shoreline works, and does indeed proove his method as being workable.

#### Hetzen

##### April 18, 2009, 10:38:54 am #14 Last Edit: April 18, 2009, 10:45:36 am by Hetzen
Sorry to hijack this thread somewhat, I'll be happy to post the fruits of my labours here as a TGD. Could someone help me with something....

Is there a way of determining whether a vector is positive or negative in it's direction? The application here would be to apply a bias of something like .9 on the Sin rise then .2 on it's fall. Is this possible?