Home Unreal Engine

UE4: Terrain/mesh Normal Blending

[ame]https://www.youtube.com/watch?v=pv8wjMGGGDM[/ame]

I just watched a video about a Unity3D feature that allows Level Designers to seamlessly blend staticmeshes into the terrain. It seems to be doing two separate things: [1] painting the terrain texture onto the mesh without a UV seam, and [2] blending the normals of the mesh with that of the terrain, creating a smooth lighting transition.

Any ideas on how they are accomplishing this?

Is it something Unreal users can recreate with the material editor? I can see how [1] might be recreated in UE4 (I'd just use worldspace-projection mapping on both the terrain and staticmesh), but I am much more interested in how [2] is accomplished. [2] would solve a lot of problems I am having right now with my staticmeshes.

I've never used Unity3D before and don't know very much about it, but this strikes me as an absolutely fantastic feature for LDs.

Replies

  • Finalhart
    Offline / Send Message
    Finalhart polycounter lvl 6
    Yes they can, look at 1:23 https://www.youtube.com/watch?v=ZLZtQYMkQ1k#t=83 I have no ideas now, long time i don't practice materials.
  • Harbinger
    Offline / Send Message
    Harbinger polycounter lvl 8
    The UE4 video looks like he's using vertex deformation to push out the geo when it intersects the ground plane. This would be pretty straight forward to do in the material itself based on world position, but you'd have to make an assumption that your ground is always at the same level. You could probably set something up in Blueprint to raycast from your mesh to the terrain to figure out the intersection point, but it might get tricky to blend along slopes. I'd be curious if anybody has set up similar systems, it's been something I've been thinking about for awhile now but haven't had time to tinker with.
  • Nightingale
    The WPO-based blending is really interesting, but unfortunately I don't think I can make use of this particular solution.

    It's not pretty, but here's a pic of the problem I'm trying to solve:
    4bae148afec7d23cf8bb1e3fafe70b45.jpg

    As you can see, I need only the "skirt" of my mesh to blend with the terrain, but not the inner portions. And not only that, but I want to be able to blend on slopes and different heights.

    As WPO can't work here, the only way I can think of doing this at the moment is to use translucency to soften the transition from mesh to terrain, but it's a really inelegant and expensive solution and I think a better solution should be possible somehow (eg. the Unity3D one I linked).

    Maybe I'll have to learn coding and make some kind of custom actor like StaticMesh_Blendable that allows the user to bend the vertex normals so they match the terrain, or something. Just throwing ideas around.
  • repete
    Offline / Send Message
    repete polycounter lvl 6
    Just seen this post and I am very interested in this as it's a logical step forward for level design.

    @Nightingale

    Have you asked about this over at the unreal forums?


    going to look into it myself as it would be a massive "hassle" saver.
  • repete
    Offline / Send Message
    repete polycounter lvl 6
    Finalhart wrote: »
    Yes they can, look at 1:23 https://www.youtube.com/watch?v=ZLZtQYMkQ1k#t=83 I have no ideas now, long time i don't practice materials.


    This is not the same as the Unity solution as you can see when the rock is moved into the terrain surface, you still get a material difference which causes a seam. The unity solution is just like vertex painting only your painting on both the terrain layer and the mesh at the same time so you don't get seams or a difference in material.

    As far as I can see this is not currently possible in UE4 because you can't use vertex painting on the terrain and a mesh at the same time. I would welcome it as it would be very useful.
  • Harbinger
    Offline / Send Message
    Harbinger polycounter lvl 8
    I think the problem is hiding/blending different normal directions, not getting materials to match. I've blended terrain in the past by simply using world space projection to get textures to match, but you still get the ugly lighting from the abrupt normal direction change. The Unity plugin looks like it's generating some kind of mesh decal on top of the terrain/asset intersection, which might be why the video mentions a caveat of not being able to use the technique with static lighting.
  • repete
    Offline / Send Message
    repete polycounter lvl 6
    Harbinger wrote: »
    I think the problem is hiding/blending different normal directions, not getting materials to match. I've blended terrain in the past by simply using world space projection to get textures to match, but you still get the ugly lighting from the abrupt normal direction change. The Unity plugin looks like it's generating some kind of mesh decal on top of the terrain/asset intersection, which might be why the video mentions a caveat of not being able to use the technique with static lighting.


    You can see it here: https://www.youtube.com/watch?v=rxM6QVwrzBg&feature=player_detailpage#t=1196

    but once you start adding drastic meshs the technique goes out the window. It's an age old problem and that Unity script solves it but I wonder were the con is, if it is indeed a type of decal then the draw calls would increase tenfold.
  • repete
    Offline / Send Message
    repete polycounter lvl 6
    Digging further I found this: https://sites.google.com/site/seamlessandunique/

    Near the bottom you can see a viable solution as long as your static meshs are curved. This is for UDK but the principal is the same in UE4.

    Worth looking into :poly121:

    object_blending_comparison.jpg
  • Nightingale
    That's exactly what I was looking for! :D Thanks, repete!

    I just wish Mr. Lazarski would have included a screenshot of the entire master material, to make it more clear exactly what each part is doing. I don't really understand how the material works, and it's not obvious to me how the different parts fit together.

    If I understand this correctly, then:

    1.) WorldAlignedTexture accomplishes triplanar projection mapping without using a vector transform node.
    2.) The material uses the emissive channel to "cancel out" any shadows that might be casted by the staticmesh. Vertex painting determines which parts of the mesh will have the shading cancelled out.
    3.) But then what is the purpose of the flat shading? How does it work together with emissive?
  • Ramseus
    Offline / Send Message
    Ramseus polycounter lvl 12
    That really doesn't apply to ue4 as far as I know. You don't have custom lighting anymore with all the fancy deferred pbr shading. And I never really understood that method, it seemed to just make things basically unlit, which works fine if it's in direct sunlight but only then - unless I missed something.

    Without using hacky emissive materials I think the biggest hurdle is the lighting seam caused by the difference in normals. I suppose you could export your landscape and any meshes you want to blend, match the meshes' normals to the landscape and reimport as unique meshes. That's ridiculous though.

    There's always the option to not try to blend things seamlessly and just throw a rock onto the ground, a non seamless, say, moss border where it meets the ground will probably end up looking better than an obvious seam where there isn't supposed to be one.
  • Nightingale
    I haven't asked about this yet on Unreal Forums, but I think I'll go post about it right now on there. As you say, repete, it is the logical step forward for level design.
  • Goobatastic
    Offline / Send Message
    Goobatastic polycounter lvl 8
    DID you get any answers on the unreal forums?
  • Nightingale
    Most Unity solutions that does this either modifies the normals of the mesh by creating another version of that mesh, or by creating a blend mesh that just covers the area of the intersection, and blend between the terrain and mesh vertex normals with a script.

    In UE4, you could create a custom actor that copies the mesh and adjust its normals according to the landscapes, but like with Unity solution, this means creating a copy of the entire mesh every time you place it on the map. For small scenes it could be very useful, but for larger scenes, memory requirements could sky rocket depending on how many meshes you place on the map.

    I haven't used the procedural mesh generation in Unreal yet, but it should be possible. You could even create a new asset type for it so that you do the setup just one time, and then drag and drop it from the content browser.
    This was the most informative answer on there.

    I just wish I was a programmer. :(


    In the case of my trench meshes, I think I will have to resort to a translucent skirt to get the job done.
  • Tetranome
    Offline / Send Message
    Tetranome polycounter lvl 6
    [ame]https://www.youtube.com/watch?v=UlCCP47mngM[/ame]


    https://www.youtube.com/watch?v=rxM6QVwrzBg#t=1099

    It is certainly possible, and I've been trying to figure it out for the past month. Unfortunately neither video shows a breakdown of the process.
  • Steppenwolf
    Offline / Send Message
    Steppenwolf polycounter lvl 15
    Tetranome you can use PixelNormalWS as a mask for lerping the grass and the rock in that way.
  • Nightingale
    Tetranome wrote: »
    https://www.youtube.com/watch?v=UlCCP47mngM


    https://www.youtube.com/watch?v=rxM6QVwrzBg#t=1099

    It is certainly possible, and I've been trying to figure it out for the past month. Unfortunately neither video shows a breakdown of the process.
    I don't think either of these videos shows a "true" solution to the lighting-seam between the mesh and the landscape. Both of them appear to be only using the World Aligned Textures to make the UVs seamless with the terrain, but if you look closely at both of those videos you'll see that there is still a lighting seam depending on the lighting in the environment. In a very brightly lit environment, the seams will be very subtle, sometimes imperceptible, but in a dimly lit environment or if the world directional-light is pointing at an extreme angle, then the seam will be very obvious.
  • Harbinger
    Offline / Send Message
    Harbinger polycounter lvl 8
    Tetranome you can use PixelNormalWS as a mask for lerping the grass and the rock in that way.

    The technique shown in the vid is just a UV trick, essentially tri-planar projection of UV's based on world space. What it doesn't do is blend geometry or normals when meshes intersect, so you still get lighting seams.

    I think there's a material function already built in to UE4 to do projected textures like this, but essentially it's:

    For each axis: Use world position, component mask out the two corresponding coordinates, divide by a 2 vector constant for scale, plug into your texture UV's. Then use world normal, dotted against an axis, fed into an abs, and use that to lerp between your different projections.
  • teaandcigarettes
    Offline / Send Message
    teaandcigarettes polycounter lvl 12
    That's exactly what I was looking for! :D Thanks, repete!

    I just wish Mr. Lazarski would have included a screenshot of the entire master material, to make it more clear exactly what each part is doing. I don't really understand how the material works, and it's not obvious to me how the different parts fit together.

    If I understand this correctly, then:

    1.) WorldAlignedTexture accomplishes triplanar projection mapping without using a vector transform node.
    2.) The material uses the emissive channel to "cancel out" any shadows that might be casted by the staticmesh. Vertex painting determines which parts of the mesh will have the shading cancelled out.
    3.) But then what is the purpose of the flat shading? How does it work together with emissive?

    Damn, I completely forgot that thing is still out there. It's something I had to do as a part of my university dissertation, so it was always more of an experiment than a complete, game ready solution. Looking back, my materials probably make little sense and having looked at the images now I'm not entirely sure what's going on either. That emissive thing is pretty dumb and if I recall correctly it was a hack that was meant to fix my shadows looking really weird in places.

    The other principles are probably still relevant, so if you could figure out a way to make sure the normals of your mesh match those of the terrain you would end up with a seamless results.
    But either way, you'd probably be better off looking into that Unity plugin, or other solutions, as mine is most likely hampered by my lack of technical knowledge.
  • Nightingale
    Thanks for the explanation teaandcigarettes!

    Unfortunately I'm not a programmer, but I guess it's safe to conclude that nobody has yet found a reliable and inexpensive method of accomplish normal-blending between staticmeshes and the landscape in Unreal Engine 4.

    Maybe the Unreal devs will do it themselves one day, or a programmer will figure it out in the future.
  • alecchalmers
    Offline / Send Message
    alecchalmers polycounter lvl 10
    I recently ran into this issue after creating a river spline blueprint. We should put a request in for it to be added I guess.

    Just want to point out that the end result of that nicely blended rock isn't much different to just raising the terrain and painting it. I would argue that the transition ended up being too smooth.
  • PINS_012
    In UE4 change you can change your terrain materials shading model to not use "Tangent Space Normal" This will give you smooth blends.
  • Nightingale
    ???

    I've never heard of this before. How does the terrain material know how to blend selectively into a certain staticmesh?
  • dorodo
    Offline / Send Message
    dorodo polycounter lvl 3
    Sorry for bumping the thread, but DICE talked a little bit on that topic during their photogrammetry talk. I don't know if I'm allowed to post pictures, but basically these were some of the key points:

    - A lot of work was put in to reduce the visible disconnect between assets and terrain
    -Most assets have terrain radiosity projected onto them
    -Texture Arrays (Detail textures) world projected and details match
    -Terrain color and normals applied to most assets.

    If anybody has more info on that matter (It's been a year, so Iunno), I'd love to find more content on the subject.

    Cheers!
  • PaulH
    Offline / Send Message
    PaulH polycounter lvl 7
    Glad this got necroed.

    Check Ryan B's answer below, which chimes with what PINS said (a year ago) seems pretty straight forward but I'm not having much luck D:

    https://answers.unrealengine.com/questions/61109/how-do-you-manipulate-light-vectors-in-blueprints.html


  • dorodo
    Offline / Send Message
    dorodo polycounter lvl 3
    Hey @PaulH ! Thanks for the link. I'll give it a shot now and tell you if it works. In the meanwhile, I think the discussion's been moved to a similar topic here: http://polycount.com/discussion/165817/star-wars-environment-art-questions
  • PaulH
    Offline / Send Message
    PaulH polycounter lvl 7
    No worries Dorodo! Ah yeah I've had my eye on that thread too, I'll post the link in there just in case someone can make sense of it.
  • Olmo
    Offline / Send Message
    Olmo polycounter lvl 4
    Hey guys, I'm currently working on a tool in Unreal Engine to achieve this effect. Its still a WIP but I'm pretty pleased with the results. I made a post about it here : http://polycount.com/discussion/181140/unreal-4-terrain-blending-tool-inspired-by-star-wars-battlefront







  • duke
    Offline / Send Message
    duke polycounter lvl 13
    The way this is typically done is to project the terrain's whole normal map (derived from the heightmap) and project that in worldspace onto the prop. Turn off tangent basis normals in the material option to get it to effectively ignore the meshes own normals.
Sign In or Register to comment.