How to control Landscape Tessellation with distance?

Hello,

Is there a way to control the tessellation of a landscape based on distance from camera? I have tried a setup that uses Camera Position and Object Position and shown in this video:

The material setup: http://s1.anyimg.com/img/1bo6qic/DaveTheFreak_DistanceBasedTesselation.jpg

Unfortunately the landscape is treated as one object and therefore this wont work. Can i use another node that can detect how far each vertex or pixel is from the camera and tessellate based on that distance?

Thanks.

I´m having the exact problem. I´ve got a huge 4x4km map and want tesselation only near the player. The object position node does not work, let me know if you find something else.

Hi Emomilol,

I did an experiment that makes me believe this is impossible in UE4. Check out my new thread about this, maybe someone out there knows a way to make it work:

I thought that to, then I found this video

It´s a displacement pack on marketplace and there he clearly have depth fade tesselation. I did find somewhere that you should use the “Pixel Depth” node, but I get these errors that the node cant be used in that material.

try using a material function called “CameraDepthFade”

that has a boolean input called “For Vertex Shader” that should work. it re-creates depth using worldposition data when that box is checked.

That dont work either, getting “view space is only supported for vertex or pixel shader”. And then the engine crashed :frowning:

Here you see my setup.

Awesome that we get some help from you RyanB and good that you are so eager to solve this Emomilol! I’m not sure but maybe it could work if you change object position to absoluteworldposition and plug in two constants into fade length and offset? I will try this out myself tomorrow!

Ah I forgot that function also does the view transform which straightens out the 3d world distance to be a scene depth (which is a flat distance from the view plane not the camera itself). That part isn’t supported.

Try just this:

Note that this distance will be “rounded” and not a straight distance to the camera viewplane (aka camera Y axis).

Also, if you want to make the depth based on the view plane and not cameraposition, you could do the dot product with a CameraX axis that is supplied somewhere in either globalParameters or MID and have your character/camera blueprint supply the vector.

I tried your setup and got it working with base color (White circle around camera) Though the tessellation don’t care about that input :slight_smile:

Aaaaah nevermind got it working! I only had it plugged in to world displacement before.

This is amazing! Thank you RyanB!!!

Even though I can control the tessellation the FPS is 15 with both very high distance and 0 distance/tessellation… Back at square one :slight_smile:

Glad it worked out :slight_smile:

You can also mask in addition by certain landscape layers if you want to. Here is a test I did for the GDC kite demo where a tiling rock pile layer was used with displacement and the layer was used to mask tessellation to only where the rocks were:

The one issue is you sometimes need to “boost” your layer alpha before using it to mask or it can create cracks. I multiplied the layer alpha by 5 or so then clamped to 1 and it worked. The wireframe screenshot kinda sucks (different angle) but you can tell how it sort of meaders to match the rocks. No rock meshes all displacement here.

Yes there is a fairly high fixed cost to using tessellation on landscape. Still though that sounds puzzling that there is no difference at all. It may be that the shader does almost the same amount of work or something weird.

I will enter a Jira ticket to investigate this further.

the most recent screenshot you posted showed that the midground area had high enough tessellation to form a solid wireframe. That might mean there are so many verts to process that the tessellation shader is too slow even before tessellating. Can you try changing the LOD distance factor on the landscape and see if any level of detail causes a performance change with tessellation? Jira bug is logged here to investigate this further.

Wow you worked on the kite demo?! :open_mouth: It is beautiful! I use it as reference and inspiration for my scene :smiley:

I tried changing to LODfalloff to 10 and Max LODLevel to 5. There are the results:

Fadelength: 5000 Offset: 5000 FPS=21
Fadelength: 400 Offset: 200 FPS=24

Ok thanks for the information. That indicates that the setting IS working but the cost is being dwarfed by some fixed cost of simply running the tessellation shader.

FWIW we didn’t end up using tessellation on the landscape for the kite demo. We were already pretty much maxing out with 30million triangle scenes even without any tessellation so we just never got the bandwidth to look into optimizing it fully. I will try to track the issue and keep the pressure on it.

(converting answer to comment since it was a comment not an answer)

Here is a promising new idea that I haven’t had time to try yet but will work in 4.8:

you could try using the new landscape grass system to spawn small meshes that are designed to work with tessellation. You could use world aligned textures for them (including displacement) so the meshes could appear to just add detail to the landscape. but you’d be stick with positive displacement (ie no easy way to lower the terrain) and of course no collision support, but tessellation in general has no collision support. This approach should be much faster and should be able to get similar results.

Hi Ryan, great to hear from you again!

This sounds good but if I get you right this is a way to use tessellated landscape grass?