Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Vibarating Mesh in Unity 3 (Filckering)

Discussion in 'Editor & General Support' started by TriplePAF, Nov 19, 2010.

  1. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    Hello,

    I'm trying to implement in Unity 3.1 pro a healthbar made of cubes like in this thread: http://forum.unity3d.com/threads/13947-Unit-selection-overlay. The mesh starts extremely to flicker if the camera is moving. The problem didn't exist in my Unity 2.6 or Unity iPhone 1.7 projects. I included a simple demo scene that is made of only Unity primitives. The healthbar has a defuse shader applied without any textures.


    What I'm doing here wrong?

    Peter.
     

    Attached Files:

  2. sagron6015

    sagron6015

    Joined:
    Apr 19, 2010
    Posts:
    32
    Not sure what kind of flicker you're seeing - I'm on the latest build of unity and all I see are the edges redrawing slightly pixellated, the mesh itself looks fine. Also, I'd probably use a self-illuminated shader so it isn't dependent on light sources.
     
  3. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    I also think that it is some combination of the edges, shadows and directional light. The camera is standing positioned as a third person Overview cam and automatically scrolls 2 units a second in the Z direction. Everything looks fine if the camera is standing still. Please try the unity package that comes with this main thread.



    Peter.
     
  4. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    i have the same problem .

    Any Solution ?
     
  5. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    I contacted support. There seems no direct solution for that kind of flickering problems with Android or iPhone devices. It seems to be the lack of anti aliasing. Even GUI textures give the same bad result with this type of scrolling camera. In the above post I mentioned that the problem didn't exist with older versions of Unity. I was wrong!

    Should it be possible to mask it with some smart shader?



    Peter.
     
  6. sagron6015

    sagron6015

    Joined:
    Apr 19, 2010
    Posts:
    32
    I've seen people using the fur shader to make edges of objects softer (works as a sort of antialiasing), otherwise you could combine the edge detect with a blur I'd imagine.
     
  7. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    yes this problem was in unity iphone 1.7 too !!!

    i post a bug report and we will see is they ignore or not this !!!
     
  8. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    I already got a few replies from support. Nothing wrong with that. :)

    One suggestion was to use a GUI Texture for getting rid of the depth artifacts. I gave that a try but it still shakes with every WorldToScreenPoint translation. A other suggestion was to Round the numbers, Try Fixed Update (Here is a extra pice of code thats not included with the Unity package).

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class keep3Dposition : MonoBehaviour {
    5.    
    6.    
    7.     public Transform target;
    8.    
    9.     void FixedUpdate ()
    10.     {
    11.        
    12.         Vector3 new3DPosition = new Vector3 (target.position.x, target.position.y + 20f, target.position.z);
    13.        
    14.         Vector2 new2Dposition = Camera.main.WorldToScreenPoint (new3DPosition);
    15.        
    16.         new2Dposition.x /= Screen.width;
    17.         new2Dposition.y /= Screen.height;
    18.        
    19.         new2Dposition.x = (float)System.Math.Truncate ((double)new2Dposition.x * 100f) / 100f;
    20.         new2Dposition.y = (float)System.Math.Truncate ((double)new2Dposition.y * 100f) / 100f;
    21.        
    22.        
    23.         transform.position = new2Dposition;
    24.         //transform.position = Vector3.Lerp (transform.position, new2Dposition, 10f * Time.deltaTime);     
    25.     }
    26. }

    I also tried it with a second orthographic camera that only displayed the healthbars. It gave the same shaking result. I also tried the FUR shader. It doesn't seems to work with the latest production build of Unity 3.1.0f4.

    At the moment I'm out of ideas. :(


    Peter.
     

    Attached Files:

  9. scinfu

    scinfu

    Joined:
    Oct 23, 2008
    Posts:
    404
    thank you .

    i soled using this on AppController.mm
     
  10. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    I tried that setting too with the above unity packages but got the same result as inside the editor. I tested it with an iPhone 3Gs and an iPod 4G.


    Peter.
     
    Last edited: Dec 13, 2010
  11. TriplePAF

    TriplePAF

    Joined:
    Aug 19, 2009
    Posts:
    246
    I solved the problem with a simple 2D plane that lives inside 3D space just above the unit, a greenish blurred photoshop healthbar texture, this shader (Thanks to Jessy):

    Code (csharp):
    1. Shader "2D Art for iPhone" {
    2.    
    3. Properties {_MainTex ("Texture  (A = Transparency)", 2D) = ""}
    4.  
    5.     SubShader
    6.     {  
    7.         Tags {Queue = Transparent}
    8.         Zwrite Off
    9.         Blend SrcAlpha OneMinusSrcAlpha
    10.         Pass {SetTexture[_MainTex]}
    11.     }
    12.  
    13. }
    And the MSAA AppController.mm file found on this forum. The drawback of anti aliasing is that old devices like first and second gen iPhones are not supported but the healthbar looks sweet and stutter free on the newer devices (3Gs or newer).

    Peter.
     

    Attached Files:

    Last edited: Dec 16, 2010