Does anyone know a good way to detect the shoreline for water materials? I have a shader to generate waves, but I’m trying so hard to figure out how to get a nice shoreline to no avail.
I tried the easiest to implement method, using depth fade to generate a mask where the water reaches the shoreline, but the waves vary greatly depending on your viewing angle. A sharp cliff going down into the water, for instance, would only generate a small wave while a more gradual incline has waves all over, even in shallow areas where waves are seriously unwelcome.
I tried what should be the cheapest method of taking an orthographic screenshot from above with the landscape set at LOD0, then making a mask in Photoshop of only the shoreline, and then using that mask to generate the smooth waves. The only problem with this method is the manual alignment, and so far I have not found a good method for aligning a texture using this method. A small, tiny hair of misalignment can lead to being several meters off. At the moment I’m modulating the shore line so the discrepancies won’t be so painfully obvious, but a better method is definitely necessary.
there’s other threads that cover this, did you try checking against the distance field?
atm it’s unclear to me if a landscape will generate a usable distance field, but for UE4 it’s becoming the preferred method.
a topdown capture would work for static stuff but anything that moves will have no effect. which is the nice thing of the other methods.
going for the depth fade method requires soft slopes under the water, yes.
if you end up going that way you can still make it work: you should make sharp cliffs become soft slopes as soon as they go underwater.
Yeah, it still seems like distance fields are experimental, so I’m avoiding them for now, and I’m not even sure if they work with landscape. Top down capture was the preferred method for a long time, so I’m trying to figure out a good way to use it. I found that distorting the waves a bit will help prevent issues from looking obvious. Typically an ocean shore would not move anyways, so it makes sense to do it that way.
The depth fade method is out of the question. It will always distort at oblique angles, and ocean shores are always seen at oblique angles.
Haha, thanks, but that is not amusing. I have a large and complex shoreline with multiple islands, all of which need a proper shore. Having a distinct mesh for each one that also connects to the larger ocean mesh would be positively insane.
Landscapes, at least in final releases, don’t have a distance field, so Distance To Nearest Surface or any distance field functions in materials won’t work with landscapes, at least in final releases. If I remember correctly someone at Epic did add a “distance field” function for landscapes, roughly using the landscape heightfield as a “distance field”, so rudimentary height is recorded in the global distance field.
The other mesh doesn’t have to be seamed up to the water plane. I would just have it be a few units either above or below depending on how you blend it. I have done this in the past where the ocean itself is opaque but the shoreline material is a translucent and has a soft transition to the beach and the opaque water. The mesh just needs to be shaped like a christmas tree skirt.
You can make them seamless in motion by using the same worldpositionoffset shader between both, but generally you want to fade out the wave intensity near the shoreline anyways otherwise they tend to travel too far up the beach. So whatever masking you use for one works for both.
I have a landscape that ranges from mountains and cliffs to valleys and beaches with shallow areas, small islands, and tons of shoreline. Opaque water is almost impossible to build in this scenario because most of the level is covered with shallow areas anyways. The mesh solution would require a LOT of work to build a custom shoreline for something that will have to overlap with the translucency and look incorrect anyways. So it’s both tedious and highly expensive to render. It’s just impractical. I also want to experiment with swimming physics and gameplay underwater, so in order to see below the surface, translucent water is absolutely necessary.
I’ll see if I can find a better method for aligning textures because that is a real concern: maybe make a blueprint that takes a perfect orthographic projection based on the location and size of the landscape piece. Then the mask will fit perfectly. Once I have the shoreline, I can probably use the material editor to code a neat shoreline into the landscape, something that matches up with the animation of the waves offshore.
I missed the very last part of your 1st post before:
There is a material function for this. I think its called “Manual Landscape UVs” or something like that. I made it for pretty much the same reason on the kite demo. It works by having two inputs, Min and Max Position. These are measured in the editor. safest way is to place some kind of ‘marker’ actors in your level at the min/max extents and use those when cropping the image in PS as well as for mapping the texture.
I see what you mean based on that image. The shore is far too broken up and organic to attempt a simple skirt method.
Just to make sure I’m reading this right, you want the waves near the shore to flatten out a bit correct?
added that functionality recently to the Community Ocean Project (link below) where the wave height is modulated based on the landscape heightmap. This is done to the material itself, no extra meshes required.
Below is the material function we use, right click and open the image in a new window to get a better look at it, if it would help you can download the asset from our GitHub repo (it’s in the Content\Ocean\Materials folder named MF_HeightModulation) to try out.
This might be overkill for your situation (is this mobile?), but it could be simplified a bit without too much loss in quality. I hope it helps spark an idea if nothing else.
Ryan B - Thank you, I’ll make sure to check it out!
Few questions: is it possible to export the landscape heightfield to a power of two texture file? It definitely looks like overkill. No, this isn’t mobile, I’m just experimenting with a variety of rendering methods in UE4 on this map.
So far, I’ve managed to sort of get a good alignment by being extremely (extremely) strict with the way I make the texture. Landscape LOD fixed at 0, take the screenshot from two 1920x1080 screencaps, merge them together to create one 2k mask, and every last one of those pixels really do matter. If there is a way to sample the heightfield as though it were a distance field in the material, then use something like distance to nearest surface to drive a shoreline, that dynamic solution would be much more accurate. But I don’t mind using a few MB of memory if it means saving a host of calculations.
I’m experimenting with distance fields, and I have to say I’m really impressed. The shadowing solution is very fast, and I’m not sure if there is heightfield GI going on or if it’s all from the skylight, but this is the best lighting I’ve ever gotten going all-dynamic so far.
I think I used something similar to the manual landscape UVs, using the world position method to planar map the texture in the top left location, then scaling it out to fit. But you will always be off by a meter or two because that’s just the limitations of pixel accuracy. You can use a 4K map for the shoreline, but it’s grossly unnecessary.
Sorry mariomguy, I didn’t see this until just now.
The texture file could be power of 2, but it is restricted to your landscape map size, since the whole map needs to be in the lookup image. I don’t think scaling or cropping would be a good idea though.
I’d say Distance Fields are the way to go, landscape is supported now as of 4.12 so it’s going to be your best bet. Take a look at these 2 threads to see how they can be used (these aren’t to do with landscape, but they should work identically now): TidalWater Foam (post 16 shows distance field setup) Distance Field Flow Map (overkill again, but has good info on DF functions)
I’ve been meaning to try this out with my own material, but haven’t had time yet. Were you able to get them working, or is your solution better suited to your needs? I’m pretty sure you could get more accurate results with them.
I’ll try and test them out over the next couple days and let you know what I find, finally close to completing what I have been working on, so should be able to test them soon.
I always wanted to try distance to nearest because the automatic generation means I can have perfectly accurate shorelines that would also correspond dynamically with any changes in the water. The only problem I can foresee is I can’t continue crashing waves onto the landscape because there is no way for the landscape to detect the mesh’s distance to a certain point unless I use some form of an extended sobel filter from the height. I’ll give it a shot in 4.12 and let you know. Hopefully, HOPEFULLY Landscape is integrated with distance field rendering! Otherwise, there would be no point. It would be awesome if UE4 had a really good scalable fluid surface actor, one that can use different methods for crashing shorelines. I wish I was able to have the shore retract, then dry up before new waves hit. We already have some awesome car paint, metal rendering, just about every other surface imaginable working in UE4 except water and hair. These two things are incredibly difficult to get right, you just always have to settle for “appropriate.”
The texture technique is the only technique that would work properly on mobile that’s even worth mentioning.
OK, so the distance to nearest works, but it doesn’t work exactly the way you think it should. If there’s a low-lying sand bar, those will still show up in the shore mask, even though they don’t perturb from the water at all. And if you want a longer distance, you will get waves skewing in all directions. What you need for a good shore mask is a hard edge where the water meets the surface, and a smooth gradient offset by a set distance equally around the shoreline. Distance to nearest is a smoother function that catches all sorts of objects you don’t want it to. If you want to perform this function procedurally, you could use the depth-based method and then possibly some fancy sobel filtering to expand it to a shore, but that will cost so much expense and the results really won’t be good at all because shores will be detected wherever objects are.
It seems using giant textures will be the best method for determining shorelines for a good long time.
So basically a plane with shoreline foam texture on it? How did you make “foam” to conform to the terrain ? (on that screenie above) Care to post your material setup? :o