Search Unity

[SOLVED!] Blob Shadows Flickering on iPhone

Discussion in 'iOS and tvOS' started by arzi, Feb 1, 2010.

  1. arzi

    arzi

    Joined:
    Apr 6, 2009
    Posts:
    154
    I've been trying to get blob shadows working on iPhone, using the shader, material and textures from the iPhone Standard Assets. They work fine in the editor, but on the device the shadows flicker. If I have only one active projector in the scene, they flicker only when moving, but with more projectors they flicker constantly.

    Any ideas what could be causing this? I've been trying both normal and orthogonal projecting, tampered with the shader code and tried out different settings but to no avail.
     

    Attached Files:

  2. jbury

    jbury

    Joined:
    Nov 7, 2008
    Posts:
    87
    Mmmmm it's not really a similar problem but I found I had a lot of framerate issues using the blob projectors and it was causing a large amount of drawcalls

    In the end I just made a plane with shadow texture on it and found it just ran a lot better
     
  3. b-joe

    b-joe

    Joined:
    Sep 7, 2009
    Posts:
    48
    I'm having the exact same problem. I tried all the tips from this post: http://forum.unity3d.com/viewtopic.php?t=17132&highlight=blobshadow
    but nothing seems to work for me.

    I filed a bugreport about a week ago, but I haven't heard from UT yet. Maybe you should file a bugreport too, so they could see that this is a quite common problem.
     
  4. BogdanDude

    BogdanDude

    Joined:
    Jun 18, 2009
    Posts:
    89
    We used a plane with a blob texture set to multiply, and moved it a bit higher above the ground, and it works just fine.
     
  5. GhostDog

    GhostDog

    Joined:
    Nov 11, 2009
    Posts:
    103
    Looks like it's Z-fighting. I think the only way to affect the Z bias is through a custom shader. Maybe you can bin up the drop shadows and render them last or raise the offset level if a custom shader is not an option.
     
  6. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    I'm having the same z-fighting problem in my game on iPhone. I've followed all of the suggestions on all of the threads but nothing has fixed it. bug?

     
  7. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    I refuse to use the blob shadow stuff because it performs horribly and adds a bagillion vertices. Instead, use a plane with your own shadow it in and assign a shader to it using an appropriately ordered transparent queue.

    But if you have uneven terrain, then this simpler solution is useless too.
     
  8. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    Yeah I have uneven terrain. So I'm still looking for a solution to the blob shadow / projector issue.
     
  9. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    I found the solution. Add the following line under Pass {} in the ProjectorMultiply.shader:

    Code (csharp):
    1. Offset -1, -1
    Here's the complete shader with the line added.

    Code (csharp):
    1. Shader "Projector/Multiply" {
    2.    Properties {
    3.       _ShadowTex ("Cookie", 2D) = "gray" { TexGen ObjectLinear }
    4.       _FalloffTex ("FallOff", 2D) = "white" { TexGen ObjectLinear   }
    5.    }
    6.  
    7.    Subshader {
    8.       Tags { "RenderType"="Transparent-1" }
    9.       Pass {
    10.          ZWrite Off
    11.          Offset -1, -1
    12.          //Fog { Color (1, 1, 1) }
    13.          AlphaTest Greater 0
    14.          ColorMask RGB
    15.          Blend DstColor Zero
    16.          SetTexture [_ShadowTex] {
    17.             combine texture, ONE - texture
    18.             Matrix [_Projector]
    19.          }
    20.          SetTexture [_FalloffTex] {
    21.             constantColor (1,1,1,0)
    22.             combine previous lerp (texture) constant
    23.             Matrix [_ProjectorClip]
    24.          }
    25.       }
    26.    }
    27. }
    Offset is described in the Culling Depth Testing doc: "For example Offset 0, -1 pulls the polygon closer to the camera ignoring the polygon's slope, whereas Offset -1, -1 will pull the polygon even closer when looking at a grazing angle."
     
    skullthug likes this.
  10. arzi

    arzi

    Joined:
    Apr 6, 2009
    Posts:
    154
    Hey, that worked for me too!

    Thanks!

    Now, I just hope they're not way too heavy for pre-3GS models..
     
  11. AbhishekS

    AbhishekS

    Joined:
    Dec 15, 2008
    Posts:
    157
    Im trying to generate shadow using projector for iphone but im not able to make it can anyone guide me out there by providing some tips on how to get it done.
     
  12. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    No work.... :cry:

    Offset -1, -1

    :evil: :evil: :evil: :evil: :evil:

    It fly~~~
     
  13. tiz777

    tiz777

    Joined:
    Jan 20, 2010
    Posts:
    93
    Thank you meanstreak!

    That worked for me too :D

    When I get a little more time, I will take a deeper look on what your correction means :oops:
     
  14. peterson79

    peterson79

    Joined:
    Sep 25, 2010
    Posts:
    5
    @meanstreak
    Code (csharp):
    1. Offset -1, -1
    Worked for me!

    Thanks,
     
  15. nawash

    nawash

    Joined:
    Jan 29, 2010
    Posts:
    166
    Works GREAT for me.
    Does unity team confirm it is same than :

    Bias = m * D3DRS_ZSLOPESCALE + D3DRS_ZBIAS
    where, m is the max depth slope of triangle ******m = max(abs(∂z / ∂x), abs(∂z / ∂y))
    ?
     
  16. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Yes, it's pretty much the same. The actual numbers do not map 1:1 between OpenGL Direct3D, but one of them is slope-dependent bias, and another is constant bias.
     
  17. nawash

    nawash

    Joined:
    Jan 29, 2010
    Posts:
    166
    Thank you for this feedback.

    Works like a charm on PC and MacOSX .. but ... not on iPad.

    Does somebody have an hint ?

    If implemented using "glPolygonOffset" it seems (googling) the PowerVR SGX does not support this renderstate on iPad...

    http://www.imgtec.com/forum/forum_posts.asp?TID=954&PID=3366

    Can someone from Unity tell me if "glDepthRange" (workaround) is available via a "pass" renderstate ?

    I have placed a "Offset -1, -1" in every "pass" section of the "diffuse" shader.
    Using a 24 bits depth buffer does not solve the issue.

    I am quite stuck here....

    Any comment/help is welcome...
     
    Last edited: Oct 18, 2010
  18. korimako

    korimako

    Joined:
    Aug 10, 2013
    Posts:
    40
    Here I am in 2020, and this post with "Offset -1, -1", just fixed my bug. Thank you, people of the past.
     
    Andrey2Akimov likes this.