Procedural shore foam preset (Sorta surf?)

Started by Hannes, March 09, 2022, 08:38:24 AM

Previous topic - Next topic

Hannes

Maybe this will be something for the file sharing section, but it's not finished yet, I guess.

For my last (tropical) images I tried to create a procedural shore foam preset. I carried on with some stuff that was mentioned here:
https://planetside.co.uk/forums/index.php/topic,28028.msg278689.html#msg278689

So far I created three "rows" of foam in real world scale (the cube in the image has the average size of a human). As you can see the setup uses displacement to scalar nodes and some following color adjust shaders, which use the water object's level to create different distances and falloffs to create the foam lines. Additionally I used the "ocean foam texture" setup I shared once in the file sharing section to create the foam patterns. I managed to put all the foam texture nodes into a grouped shader to make it a bit cleaner.
It works with procedural terrains and with loaded ones. So far so good. This setup works nicely with a water level of 1. Of course I could change all parameters of the color adjust shaders by hand, if my water object's level would be different, but that would be rather inconvenient. So, I need some help!

Is there any function or whatever, that I could put somewhere (probably after the displacement to scalar nodes?) to just enter the water level, and that would change the color adjust shaders' values automatically? I guess, they would only have to be shifted up or down, since the relations between the values should stay the same.

So, I hope, someone has a good idea!!

WAS

This looks rather convincing, and the face it isn't really sinus waves means it should be faster. And for distant stuff wouldn't even matter. 

Dune

#2
Quote from: Hannes on March 09, 2022, 08:38:24 AMIs there any function or whatever, that I could put somewhere (probably after the displacement to scalar nodes?) to just enter the water level
Just add an add scalar with the water depth after the displ to scalar indeed. Either minus of plus.
EDIT: it seems you have to deduct the new water level from the displ to scalar. And it's probably not needed to diverse from the compute terrain, which is faster.

I like the foam pattern trailing behind the edge, very cool.

Hannes

So, I put Add scalars behind each Displacement to scalar function. Do I have to use a Constant scalar to input the value? If you say I  have to deduct the new water level from the Displ to scalar, what does it mean, if I have a water level of 100 for example?
Sorry, but I'm an absolute node idiot... :(

WAS

Also, since the disp to scalar is dispalcement in range with height, you probably can use a smooth step to end it at your water level (or start it at water level, not sure if the scalar logic is reversed as Ulco mentioned).

I really like this and I'll play around with it in a bit... after I try to remake my old sombrero galaxy... :P

Hannes

Looking forward to your input, guys! When it comes to nodes I'm really stuck...

Dune

Exactly, so 2 of them. And use constant scalar of -100 for level 100, indeed. You can probably also add a vector after the terrain, and add a constant vector or so, with Y as minus water level.

Hannes

In the meantime I put a Smooth step scalar with a constant scalar of 100 (new water level) plugged into the step end behind the Displacement to scalar node, and connected everything. It all shows up, but the foam stuff seems to be a hundred times larger except the foam pattern of course. So it seems, the values aren't just shifted up, but somehow multiplied by 100. Without knowing what I was doing, I put a Divide scalar with a value of 100 behind the Smooth step scalar, and all the foam disappeared... :( :( :(

Hannes

Quote from: Dune on March 09, 2022, 12:39:08 PMExactly, so 2 of them. And use constant scalar of -100 for level 100, indeed. You can probably also add a vector after the terrain, and add a constant vector or so, with Y as minus water level.
I tried it with a divide scalar with a value of 100. Did the same like the Add scalar with -100. But it didn't work out.
Do you mean an Add vector (or Divide)?

Hannes

Add vector with a constant vector Y -100 didn't work either. And the (100 times larger) coastline is pink.

Nala1977

these kind of stuff should be in the software by default.

pixelpusher636

This looks extremely promising @Hannes ! 
I'm even more lost when it comes to nodes so I'm no help but I do hope you get the help you need. Really looking forward to the final solution. 
The more I use Terragen, the more I realize the world is not so small.

Dune

#12
I'll have another look and save what I did this time ;)  But divide won't work and smooth step neither, because then you'd need another step that's very close to the 100. It just softens the lot.

It's actually a lot simpler if you just add a surface shader and a transform shader like this (I just figured it out). The transform stretches the terrain Y so the foam is right around the coastline, and not diverging, and the surface shader can be used to compensate (minus offset) for the water level. In my example I set it at 50m (so -50 in surface shader).
That is why I usually start my terrain with a PF stretched in Y, to be sure foam follows coastline.

WAS

First of all, sorry for the delay. I honestly forgot. It's been a rough day. Second, sorry for the node OCD.

Anyways, here is my take at the problem. This uses a sphere for global water coverage, and allows for two general inputs. Water level, and Shore Precision Multiplier.

This should work well for positive water level, but maybe for negative? I forgot to check and am getting tired.

As a note though. In situations like this where your adjustments all rely on 0 level in texture space, the surface layer offset is super handy. Apply one before your compute terrain, and just offset the terrain up or down to desired "water level" without adjusting the lake level. You also don't need to stretch the scalar which may make masking slower.

Hannes

Cool, guys!!! Thanks a lot! :) :) :)  I'll have a look asap.