1
\$\begingroup\$

I've encountered and error I can't seem to find online. I get it on all the water shaders I test, and any thing else that I have a depth node + depth render script on the camera for.

I'll share a bit more information about what we're doing in the game.

  1. This artifact changes as we pinch-zoom on Android. So I wonder if the Render Depth script doesn't like that we are changing the zoom/depth for some reason? Maybe it has something to do with how we are handling out cameras movement in Unity?

  2. It is adding more depth information somehow, because the shader is reacting to the artifact. Depending on where the line cuts, the other details will warp to meet it.

  3. This problem doesn't show on all phones. Mostly Android, newer versions, but wasn't showing up on an older S5.

Some other things I've tried within the shader are different shader models 2.5 & 3.0.

Any suggestions on tests I can do, or ideas on what might be the issue?

Render Issues

Here are the nodes I use for the opacity / depth

Nodes Camera Setup

Currently we've got the controls on one camera, and the depth script on another. Update, I've found someone talking about a similar sounding problem, but I'm not sure how to do this myself.

Thread here -- https://forum.unity.com/threads/depth-texture-not-working-on-some-devices.319568/

"If I set my RenderTexture Depth format to 16 bits instead of 24 bits it's working!" -- How do I do this? Can I edit my Camera script to do this?

The Camera script seems simple, but I'm not sure how to make it render 16bits instead of 24 bits to test this out.

// Toony Colors Pro+Mobile 2
// (c) 2014-2018 Jean Moreno

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

// Makes the Camera render a depth texture.
// This is needed for some water shaders that use depth-based effects such as edge intersection.

[ExecuteInEditMode, RequireComponent(typeof(Camera))]
public class TCP2_CameraDepth : MonoBehaviour
{
	public bool RenderDepth = true;

	void OnEnable()
	{
		SetCameraDepth();
	}

	void OnValidate()
	{
		SetCameraDepth();
	}

	void SetCameraDepth()
	{
		var cam = this.GetComponent<Camera>();
		if (RenderDepth)
			cam.depthTextureMode |= DepthTextureMode.Depth;
		else
			cam.depthTextureMode &= ~DepthTextureMode.Depth;
	}
}

Thanks!

\$\endgroup\$
  • \$\begingroup\$ This looks like it could be a precision issue — to render the depth, you need to draw a gradient of values between your near and far distances. Depending on how far apart those are, the intermediate values can hit jumps or clusters along the way (like banding you might see when drawing a long gradient in a paint program, or a long landing partway up a staircase). Does changing the gap between your closest and furthest depth in your camera or script change where these artifacts show up, or their shape/intensity? Showing us the shaders and how the artifacts change could also help narrow it down. \$\endgroup\$ – DMGregory Jan 24 at 12:48
  • \$\begingroup\$ Yes, when we pinch zoom in/out the banding increases. It looks like it's being tiled more. I'll share the shader graph in a moment. I built it in Amplify Shader Editor. \$\endgroup\$ – AllanMac Jan 24 at 12:53
  • \$\begingroup\$ Are you handling the pinch/zoom behavior in your script? Or is it applied in an external layer, like a containing app or the OS itself? Walk us through the steps to recreate a simple version of this problem, what we call a Minimal Complete Verifiable Example — that way we can reproduce it on our own devices and test potential solutions. \$\endgroup\$ – DMGregory Jan 24 at 13:00
  • \$\begingroup\$ @DMGregory I've added some more info and have some better ideas now how to solve it. What do you make of it? \$\endgroup\$ – AllanMac Jan 26 at 16:50
  • \$\begingroup\$ did you test with a simple depth shader? using node base tools are good but you should optimize it \$\endgroup\$ – Seyed Morteza Kamali Feb 5 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.