Search Unity

Are Blob Shadows CPU intensive on iPhone?

Discussion in 'iOS and tvOS' started by Bububear, Oct 30, 2010.

  1. Bububear

    Bububear

    Joined:
    Mar 1, 2009
    Posts:
    106
    In my current game, I have my main character using a blob shadow projection. It is running smooth on the iPhone 4.
    Adding the shadow did not seem to have any impact on the CPU with just one instance, so I'm just wondering how many of these I can afford to attach to other objects in the scene?

    Any insight is appreciated. :confused:
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Blob shadows are intense because they create a massive amount of drawcalls (each model touched by a blob shadow is redrawn)
    As such it will striker rather heavily if you don't have the environment etc setup for it.
     
  3. Bububear

    Bububear

    Joined:
    Mar 1, 2009
    Posts:
    106

    Thanks for your response Dreamora.. But do you see that as the only drawback?.., ( an extra draw call, considering that the shadow is only projected on 1 terrain object). If that's the case, I think I can probably afford 5 blob shadows per stage?

    Also., if i'm specifically only targetting iPhone 3GS and 4, what would you suggest is a good max limit to cap at on the # of draw calls?
     
  4. marjan

    marjan

    Joined:
    Jun 6, 2009
    Posts:
    563
    Actually Blobshadows slow down things a lot, depending how everything is set up.

    Lets say you have one big model for the ground that fills the entire screen and a blob is casting its shadow on that... Veeerrryy slow on devices with a large screen, as iPad.
    Now try the same without a blob shadow and use a plane with a transparent shadowimage instead that is hovering slightly over the ground.
    You should see a dramatic speed increase on these devices (unless you zoom in so much, that the shadow itself fills a large part of the screen.)

    I don´t know about the technical reason for that, other that its supposed to stress the fillrate of the device and the larger the screen is, the worse. Unfortunatly the described technique does only work good on flat grounds.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the technical reason marjan, as I mentioned above, is that every mesh hit by a blob projector is redrawn again which kills your fillrate completely (ipad can draw the screen 3 times per frame to remain fluent. waste 2 with the ground mesh due to the projector and you are dead normally FPS wise)

    The blob projector is something you can only afford if you split the world into tiny enough models to reduce the redraw and especially have only diffuse or simple objects being affected, otherwise you won't be too happy.

    but you can always test it and use them if they are fine, no reason to say no from start. but don't expect too much
     
  6. impla007

    impla007

    Joined:
    Jan 30, 2010
    Posts:
    57
    Thanks dreamora and marjan

    On the iPad and one big model filling the entire screen, removing the only blob shadow I had, give me a bonus of 10 Frames/sec. I am now at 30/Fps and it is smooth as never.

    Question : Where can I found an hoover script to attach to a plane ?
     
  7. marjan

    marjan

    Joined:
    Jun 6, 2009
    Posts:
    563
    i guess you can script that yourself. It also depends whether your shadowcasting carracter is jumping or faling, thus changing its distance to the ground.

    1. if not:
    You can just put the shadowplane inside your gameobject, making it a child of your shadowcasting charakter/object. done.

    2. juse this if you need to jump:

    (This is a script i wrote for lucky cats 3d which updates the shadows for the cats. Put this on your shadow casting gameobject and connect your shadowplane to myBlob. Dont get confused by the name myBlob, it does not expect a real blobshadow. what it does is set the position of the shadow to the characters position and in case the cahracter is jumping/flying/falling scale and fade out the shadow, so it looks just like a blobshadow. You might need to tweak some numbers in the update function, to get a good result in your scene)

    Code (csharp):
    1. var myBlob: GameObject;
    2.     private var myT : Transform;
    3.     private var blobT : Transform;
    4.     private var myColor: Color;
    5.     private var smat: Material;
    6.  
    7.     function Awake() {
    8.         blobT = myBlob.transform;
    9.         myT = transform;
    10.         smat = myBlob.renderer.material;
    11.         myColor = smat.color;
    12.     }
    13.    
    14.     function Update() {
    15.         blobT.position  = myT.position;
    16.         blobT.position.y = 0.005;
    17.         if (myT.position.y > 0.01) {
    18.             blobT.localScale.x = blobT.localScale.z = 1 + myT.position.y/2;
    19.    
    20.             myColor.a = Mathf.Clamp((5 -myT.position.y)/5, 0.2, 1.0);
    21.             smat.color = myColor;
    22.         }
    23.     }
     
  8. fuzzy3d

    fuzzy3d

    Joined:
    Jun 17, 2009
    Posts:
    228
    Hello,
    I make some changes in original blob shader and this is faster now. Can anybody smarter than me take look at code and make this even better/simpler? :D Thanks.

    Code (csharp):
    1. Shader "Projector/Multiply-simple" {
    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. //         Fog { Color (1, 1, 1) }
    12.          AlphaTest Greater 0
    13.          ColorMask RGB
    14.          Blend DstColor Zero
    15.          Offset -1, -1
    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. }