Home Unreal Engine

UE4: Curved Translucent Surface

d0d118fb2b964ab1a05022dd732906f7.png9ca220514328df69b2543d3ce6820aa1.jpg

This is a staticmesh with one material applied to it. The material is a translucent type material. It uses vertex painting to tell the staticmesh that only the "skirt edges" should have DepthFade, but the rest of the staticmesh should be opaque.

In the second picture, you can see that the material is not being rendered properly. I guess this is a sorting issue.

In UDK, I was able to get around this problem by forcing the material to sort properly by playing around with the translucency settings in the material editor (I can't remember exactly which boxes I ticked, but it definitely worked). But I cannot seem to find anything in UE4's material editor that does the same thing. Am I correct in thinking it is no longer possible to have translucent materials that sort properly in UE4?


I could assign the staticmesh 2 materials (1 opaque, 1 translucent) to fix this problem, but I consider that a last resort because I really want to make this work using only 1 material.

Replies

  • tharle
    Offline / Send Message
    tharle polycounter lvl 9
    unfortunately Unreal has problems with self sorting translucent materials.

    sorting between different objects migbt be better, so you could try splitting the mesh along the bottom of the curved surface so you're never looking through the mesh at itself.
  • Nightingale
    In that case, I guess I'll have to use 2 sub-materials in the mesh.

    Which one would you say is the least performance-demanding?

    A.) One material is translucent, and the other is the exact same but is an opaque type with no vertex-painting.
    B.) Both materials are the same translucent material.
  • Nightingale
    I tried setting it up to have 2 sub-materials (one opaque, one translucent) today. No more sorting issues, but for whatever reason the translucent portion has a slightly different appearance from the opaque portion:
    78e3bbbe351206a4276dabf62685c3bb.jpg
    Anybody have any ideas why it is doing this? Even if I simply plugged the constant '1' into the opacity node of the material, it will still have a slightly different appearance from the opaque material. :poly134:
  • tharle
    Offline / Send Message
    tharle polycounter lvl 9
    basically you're hitting the problem of how unreal renders things. opaque materials are rendered using a differred renderer which allows you to have lots of lights and nice shading etc. translucent materials are still rendered using a forward renderer which makes the much more expensive, difficult to sort and generally not look as good.

    there's some research into better translucent rendering with modern engines but basically you're hitting a technical wall and there's not a lot you can do to get around it.

    on the other hand this is where some smart artistic decision making comes in - why are you trying to make translucent bricks in the first place? and could you not add a curb strip or similar to be the translucent material? without having the two similar materials next to each other to compare you probably wouldnt see that the curb was rendering wrong.
  • Nightingale
    Thanks for the explanation. :)

    I'll explain why I have such a strange staticmesh/material setup:

    The bricks are actually a placeholder texture. It's meant to be replaced by dirt (or snow). These are slit trenches for soldiers to hide in, meant to be used in FPS games. The translucent skirt exists only to smooth the transition between mesh and landscape. I've tried a lot of other ways to remove the mesh-terrain seam, but this translucency method I know of that actually works.

    I think I'm going to have to seperate the mesh into the skirt and body, and then apply a common translucent material to both (solves the sorting problem), and then use vertex painting only on the skirt to define the DepthFade area.

    EDIT: Nope. Even if I split the mesh, the sorting issues still persist. It just causes too many issues when I try to use translucency like this, but at the same time I need translucency to soften the edge between mesh and terrain. :poly127:

    ...is there a way for me to create a forward-rendering opaque material?
  • Joopson
    Online / Send Message
    Joopson quad damage
    You could try, instead of translucency, to use a noisy dithered transition texture, and set it to "opacity mask", instead. Something like below:

    8n7kF5I.jpg

    Not sure if you could figure out a way to use it with vertex colors, though; but an extra UV channel could be used. I don't think it'd be noticeable, and I think Skyrim used a similar technique. Opacity mask objects won't have issues with sorting, and they'll be shaded the same as solid objects.
  • Nightingale
    I've never thought about using dithering before. That's really interesting. :) I'll try playing around with the material editor to make a vertex-controlled dither. It should be doable with some fancier math and a noise map.

    However, I am also quite invested into using DepthFade to smooth the transition (because my Landscape will not always be perfectly flat, and the vertex-density of these trenches is actually not very high). A dither-transition will probably work, but I'd like to use it as a last-resort if I can't use DepthFade.

    So if there is any way for me to create a forward-rendered opaque material, so I can use it just for this trench mesh, I'd love to know how to do it.
  • ghaztehschmexeh
    I might be wrong in this, but couldn't you use the World position node to match up your textures? From the docs:

    "Common uses are to find the radial distance from the camera to a pixel (as opposed to the orthogonal distance from PixelDepth). WorldPosition is also useful to use as a texture coordinate and have unrelated meshes using the texture coord match up when they are near each other."

    https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/ExpressionReference/Coordinates/index.html
  • Nightingale
    Actually, that's what I'm doing already. It's a bit hard to tell with the bricks, but they are actually being mapped via Triplanar Projection Mapping (although, I use Martin Palko's method, not WorldAlignedTexture).

    But simply matching UVs up isn't enough to soften the seam, because if a player walks over it then there is a hard lighting seam at the mesh-terrain intersection. It's very ugly and noticeable. That's why I want to use translucency (because it allows me to use DepthFade, which allows me to blend smoothly anywhere, without increasing vertex density).

    Here's a picture of a game which has accomplished smoothly-transitioning trench meshes with the terrain:
    MamayevKurgan.png
    Red Orchestra 2 (UE3) also uses DepthBiasedAlpha to smooth the transition between mesh and Terrain Actor. An opaque material is used inside the trench. The skirt has the exact same material, but it is translucent with a DepthBiasedAlpha node (the equivalent in UE4 is DepthFade). And because UE3 only had forward-rendering, they didn't have to do any special magic tricks to make it work.
  • ActionDawg
    Offline / Send Message
    ActionDawg greentooth
    tharle wrote: »
    basically you're hitting the problem of how unreal renders things. opaque materials are rendered using a differred renderer which allows you to have lots of lights and nice shading etc. translucent materials are still rendered using a forward renderer which makes the much more expensive, difficult to sort and generally not look as good.

    there's some research into better translucent rendering with modern engines but basically you're hitting a technical wall and there's not a lot you can do to get around it.

    on the other hand this is where some smart artistic decision making comes in - why are you trying to make translucent bricks in the first place? and could you not add a curb strip or similar to be the translucent material? without having the two similar materials next to each other to compare you probably wouldnt see that the curb was rendering wrong.
    This is wrong. Translucent materials are rendered with deferred shading as well as opaque. The issue is the lack of a forward renderer which CAN render translucency without problems (other than how depth sorting is handled). The reason deferred transparent does not work well is because everything is being rendered all at once in screen space: How do you separate the normals/roughness/etc of a translucent object from whatever is behind it? Forward rendering basically renders each object and then composites, which allows translucent materials to sit over opaque correctly.

    Forward is more expensive, which is why there was an industry shift towards deferred. One of the solutions is a proper Deferred + Forward, which was supported in Unreal at one point. There has been little talk about the issue since though.
  • tharle
    Offline / Send Message
    tharle polycounter lvl 9
    oh i stand corrected. interesting.
  • Nightingale
    I found a way to fix the sorting issue and still have DepthFade! :D

    1553a901f68955615af78678aed6da2d.png
    84bfd36167101d8ab1c829ea45678785.png
    65689ae9dc0a623a54c35b6df7af8900.png
    8d5a55c0b6db1b801ab71b970ffb3920.png
    06097272b4840b73ed9ba25a0c837c5a.png

    Principle of this Setup
    • Use Triplanar Projection Mapping (World Aligned Texture) to eliminate all UV seams and UV distortions.
    • There are two materials: One translucent, the other opaque (black).
    • Use vertex-painting to tell the mesh which part of the skirt should have DepthFade.
    • Behind every face of the trench mesh, there is pyramidal geometry with a black material applied to it. This geometry exists only to occlude every face on the mesh from every other face, which eliminates any sorting issues.


    The cost of this is that you have to add an empty "blocking material" and a lot of triangles to create the proper occlusion geometry. It's not elegant, but hey, it actually works, and it achieves the effect I want. I thought I'd share it here in case there are other people who are trying accomplish a similar terrain-blending effect.
  • billymcguffin
    Offline / Send Message
    billymcguffin polycounter lvl 11
    Rather than having the whole mesh transparent (which is pretty expensive), try using a blend mesh like they did in Gears of War. See this thread: http://www.polycount.com/forum/showthread.php?t=124482&page=3
    As you can see, for the transition between the stairs and the wall is handled by a separate mesh which uses depth blend to make a smooth transition.
Sign In or Register to comment.