Download

Does Landscape contribute to global distance field?

Sorry I’m not at my workstation but curious about this so though I’d quickly ask.

Does the landscape system get entered into the global distance field? I want to have some grid planes that wrap to the surface of the landscape and want to use the material to offset the verts.

It does not, but it should. That would provide a speedup to DFAO, allow full scene particle collision to work against landscape, and DistanceToNearestSurface material node would operate more consistently.

Thanks Daniel

This line in the docs here threw me so thats why I asked as well.

“The entire level is represented by instanced distance fields stored in volume textures. Landscape has a separate representation through heightfields.”

I’m guessing the image on that page is using static meshes.

I think a DistanceToNearestSurface (and gradient) that works with landscape would be really useful (Or even a separate DistanceToLandscape and GradientToLandScape).

One idea that I had that sprang to mind after your particle collision example code in another thread was to create a slide along surface particle operation. In conjunction with a flowmap/vector field, you could do either water or even use the mesh particles with the vertex animation offsets to do some rudimentary crowds that followed a predefined path.

But my primary goal is do grass and moss patches that follow the contour of the landscape ground using worldposition offset and distance to nearest surface. I’ll make a proof of concept with a static mesh ground.

Hello,

So I was just looking EVERYWHERE for a way to get DistanceToNearestSurface working with landscapes. No luck so far.
Is there any alternative I can do?

Thanks.

There is a bit of a long winded thing you could do. I’ve been meaning to try it to test an idea I have.

the basic idea is that you have your heightmap in your material, and pass in the landscape transform as a parameter. You then take worldposition, work out the UV that you would need to sample based on the input paramter and then sample the heightmap using that UV. You can then do distance(worldPosition-heighMapPos). The heightMap pos would be a float3 with worldPosition.xy as the first two floats and the single heightmap sample as the .z. Gradient ‘could’ be calculated but would be expensive because 4 texture samples would be needed. If there was a gather4 node (which is a HLSL hardware call) then that would be a little bit quicker maybe.

Sounds like that’d not correspond to the landscape anymore if the landscape was sculpted/edited afterwards right?
I’m looking for a real time way of doing it.
Thanks for the input though.

Yeah if you edited the heightmap, then you would need to rebake out the heightmap. Ideally, landscape would support global distance field but I was just thinking about workarounds. In my case, I usually import from world macine or sculpt and its done. Are you talking about editing during runtime?

I’m talking about the in engine sculpt tools. Generally, we’d want to keep sculpting it and implement gameplay elements so it’s gonna be edited for a long while and it’d be nice to have the blending sorted out without recompiling the material with new heightmap etc. every time a change is made.

Yeah not ideal. The texture itself could be a textureparameter and then you would only need to reexport/reimport the texture asset without having to compile the material. It wouldn’t be worth doing that whole process for each small change for just visual purposes. But if you had no other way you would just do your editing for a while without the ‘realtime’ feedback and when you are happy do a bake to see the results. But danielw if you listening, please add the option to include the landscape in the global distance field!

Just coming back on this thread to see if any dev had thought about this a bit more?

DanielW added this feature recently so I would expect to see it in either 4.12 or 4.13

Excellent, thanks guys :slight_smile:

I wonder if the distance value is just vertical distance (as its from a height field) so gradient will be given as 0,0,1 or if the distance field is actually from the mesh and is accurate?

Would be nice to have a control somewhere for distance fields to specify the bandwith (how far away the sdf is generated). I’ve run into a couple of times where there is no valid gradient (ie 0,0,0) and it messes up some shaders. If we could pad out the distance field generation distance per mesh that would be handy. But definitely being able to sample the landscape distance and gradient from far away would be nice. I havn’t looked at any commits yet but I would think that filling the global field first with the landscape distance would make sense and then ‘min’ in all the mesh sdfs to the field would make sense (but then if the mesh bandwidth is small then you run the risk of getting a distance value to the default landscape value which might not be true if there is a mesh on the landscape underneath it. But for most cases that would be ok).

It is the vertical distance from what I understand, since actually converting it into a true 3d distance would be incredibly computationally expensive, whereas the heightmap lookup is a relatively affordable heigtmap lookup. In most cases it will work great. You could simply adjust the width of the gradient if you know you have steep cliffs in the terrain, but usually steep cliffs will be meshes anyways.

Does this feature work without using distance fields for anything else? It would be really handy to get landscape height from material.(Shorelines)

I’m planning on using this for shorelines/riverbanks too. If you dont want to use shorelines, you could just read heightmap texture directly which wouldnt have to read from the global distance field.

But do I have access for global heightmap texture? I don’t want to dublicate any data for memory reason.

I think that the distance from the landscape will he added to the global distance field. So it will be available but it will be combined (min) with everything else as well (unless they all have their distance fields disabled)

Any chance of seeing this get committed for 4.12? I can’t see it on github.

Cheers
Dan

Hmm seems like it works in 4.12. Had to refresh the viewport by changing view or something get it to update. But nice work guys. The only thing I would love to have is a control in the static mesh editor to expand the ‘bounds’ of the individual static meshes (the max distance that will get calculated). In the image you can see that the column gets its distance from the landscap but doesn’t really get the distance to the cube. Thats because the cube DF only extends out a small amount . I we could expand static meshes DF range, we could control how far these have an effect.

4ecc1a5a8ba4e984d00ca3314901069e0a6e9892.jpeg

Check under world settings, there is a max setting for DF in there. not 100% sure if it made it for 4.12 but take a look. Note that that distance may have to be a bit larger than the distance you want to detect.