Z Fighting Problem

Here is a video about unity depth shader workarounds:

http://www.burgzergarcade.com/tutorials/game-engines/unity3d/unity-ios-shaderlab-tutorial-10-1-z-fighting

also his tutorial 6.2 and 6.3 are all about depth...

and this unity resource: http://unity3d.com/support/documentation/Components/SL-CullAndDepth.html

Here is a Ton of info about it with 3 solutions:

http://software.intel.com/en-us/articles/alternatives-to-using-z-bias-to-fix-z-fighting-issues/

I have ended with a custom-non-optimal-solution that at least works for me. I add a"ZFighter" component to any GameObject which I want to get a little bit distanced from a back object/wall. This separation is calculated according to Camera distance.

  1. using UnityEngine;
  2. using System.Collections;
  3. public class ZFighter : MonoBehaviour {
  4. // Use this for initialization
  5. private Vector3 lastLocalPosition;
  6. private Vector3 lastCamPos;
  7. private Vector3 lastPos;
  8. void Start () {
  9. lastLocalPosition = transform.localPosition;
  10. lastPos = transform.position;
  11. lastCamPos = Camera.main.transform.position - Vector3.up; // just to force update on first frame
  12. }
  13. void Update () {
  14. Vector3 camPos = Camera.main.transform.position;
  15. if (camPos != lastCamPos || transform.position != lastPos) {
  16. lastCamPos = camPos;
  17. transform.localPosition = lastLocalPosition + (camPos - transform.position) * 0.01f;
  18. lastPos = transform.position;
  19. }
  20. }
  21. }
上一篇:nginx 之 负载均衡


下一篇:论文翻译:2021_AEC IN A NETSHELL: ON TARGET AND TOPOLOGY CHOICES FOR FCRN ACOUSTIC ECHO CANCELLATION