Texture making its way into custom depth

I am trying to use custom depth with a translucent material to get a post process fog effect working under water. I need my water shader to draw to custom depth so the fog will affect the water plane as well. I can draw to custom depth just fine, I have ‘Allow Custom Depth Writes’ on in the material and have Custom Depth enabled in the rendering settings. However the depth that is drawn seems to also take values from a texture that is being used in the scene.

The underwater fog should make all of the screen blue but where I am drawing custom depth some values are being taken from a texture. I have no idea how this is happening, it seems almost like the custom depth buffer is overrunning graphics memory to a location where there is texture data. I am using UE 4.14 with the deferred renderer with a NVidia Geforce GTX 980.

Hi QSBen,

I’m going to need a bit more information. Could you provide screenshots of your material graphs. I have a few questions about your setup as well.

  • Are you using a post process material (AKA Blendable) to create the fog like effect?
  • How is the fog effect having difficulty with the water shader? Could you elaborate on how/why you are using custom depth.

I put together my own underwater effect to get an idea of what you are doing. First I made the post process material:

Then I applied it to an unbound post process volume. Once the fog looked like how I wanted I used a water plane “BP_OceanWater” from our “Water Plane Examples” assets and put it above some boxes.

This is where I get a bit confused as to where the Translucent material utilizing Custom Depth comes into play. If I have your workflow all wrong could you please elaborate on how you are putting together this effect so that I may reproduce this issue on my end.

,

Sure thing Ed.

I am working with a scene that is both above and below water. The reason I felt the need to use custom depth is that when using scene depth the fog extends above the surface of the water even though my post process volume is not unbound. Using scene depth alone also incorrectly fogs things less that are close but out of the water as seen in this image

Using custom depth allows me to get the depth of the water surface and fog only to that extent in the scene which solves both of the issues when using only scene depth as seen in this image

But to be honest the reason behind why I’m using custom depth is less important than the fact that I’m getting artifacts in my custom depth buffer, regardless of what I plan on using it for. For your reference here is my post process material, used as a blendable in my post process volume.

Thank you for clarifying your workflow. Asking how and why someone is doing something really reveals a lot. Mainly because you would be surprised the crazy odd ball methods users can come up with. I just needed some extra clarification.

Regarding the artifacts where you describe scene depth fogging things incorrectly that are outside the water. This is actually occurring because DOF is blurring the “silhouette” of the assets where the scene depth does not.

When using the scene depth as an alpha between scene color or a 3 vector (rgb) you will see a hard outline of things that would normally be blurred since the alpha has this hard outline (notice the colors are blurred).

I got around this by enabling a few things, I also fixed some minor artifacts with the water shader I was using. However, I never got anything as wild as what you showed in your first screenshot.

First to assist with the scene depth artifact I went into the Postprocess material and set the blendable location to “Before Translucency”

Here is a before and after example:

To further remove artifacts caused by objects in front of a translucent plane I had to uncheck “Separate Translucency” in the water shader settings so that DOF could influence it and the objects in front of it.

Let me know if this helps, If it doesn’t could you narrow down what asset(s) are causing the artifact specifically. If it is related to a texture in a material I may need information on both the material and texture in question so that I may experience that artifact on my end.

,

Setting my material blendable location to ‘before translucency’ did indeed help with the sharp outlining issue. However scene depth itself has the other issue of fogging things out of the water more the further they are away even though they are viewed through the same amount of water. In this image both of the places the arrows indicate should be fogged about the same amount since they are viewed through the same amount of water.

By using custom depth I can get the distance to the surface of the water (since I can’t get regular scene depth from a translucent material). This allows me to get more accurate fogging underwater if not for the artifacts I am seeing.

The amount of artifacting I see changes depending on view direction which is confusing and interesting. It also isn’t always the same texture that ends up in the custom depth buffer. However the textures I’ve seen seem to all come from Instanced Foliage Actor in my scene. The only actor set to draw to the custom depth buffer in my scene is the water plane.

Would it be possible to provide a video of the artifacts. I’ve tried a few different scenarios in my test and haven’t been able to reproduce anything that looks similar.

If that isn’t possible could you answer these questions.

  • Do you see the artifacts when looking through the water and only then or do they appear in other situations.
  • If so, could you provide a screenshot of your water shader’s material graph.

,

[Here’s a video][1] of the bug. As you can see when I look around the artifacts appear to change which texture they are coming from as well as, when looking up and down, the data from a single texture appears to change somewhat.

In addition, to prove that this is a bug with custom depth and not something else, here is a render of the custom depth buffer showing the artifacts.

These artifacts appear both above and below water. In game they are only visible below water since that’s where the fog post process is applied, but when rendering the custom depth buffer it is visible both above and below. Here’s my water material graph.

Hey QSBen,

I appreciate all of the info, I haven’t been able to get those strange flashing artifacts.

I assume that this issue is only occurring in that map, for example if you create a default map and visualize your custom depth buffer you wont see any artifacts.

Could you either provide a small sample project that reproduces the issue OR narrow down what assets in the map seem to be causing this to happen.

Unfortunately, I haven’t seen this error before and am unaware of what may be the cause. Getting a project that reproduces the issue would make it much easier to figure out what is going on as I feel that it is related to your content.

,

I’ve stripped down the project to the bare essentials and I’m still seeing the issue although I’m starting to thing the bug may be independent of the engine. Either way Here’s the project.

To see the issue you simply need to open the map, fly the camera under the water and look around.

Hey QSBen,

Thank you for all of the help and cooperation. This issue is very specific and was a pain to lock down to an exact cause. I was able to narrow down the issue and file a report here: Unreal Engine Issues and Bug Tracker (UE-40252)

It seems that the new “Allow Custom Depth Writes” feature has some kinks to work out so you may need to do the old work around. This involves having a duplicate mesh with “render in main pass” unchecked occupying the same space. It needs to have an opaque material and render to custom depth as well.

That should create the custom depth info you need from the water mesh. There are a few specific conditions that need to be met in order for this issue to occur so be sure to check out the report for more info!

again!

Ed

a lot for looking into this for me Ed. I know this is probably an edge case for this feature but I’m glad you were able to find the source of the issue.