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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Realtime Lights and Shadows on Mobile

Discussion in 'General Graphics' started by RdArrogantKnight, Dec 11, 2015.

  1. RdArrogantKnight

    RdArrogantKnight

    Joined:
    Jun 24, 2013
    Posts:
    13
    Hi, I was wondering if there is any way to approach realtime shadows on mobile that could give me anywhere near 30 fps.

    It seems like if I have any realtime lights that are capable of casting a shadow, the fps drops to 22 or lower. Immediately. No matter how much I try to cut down on the objects that are capable of casting or receiving these shadows, the framerate barely changes.

    I realize my Android phone isn't the greatest, and expecting strong performance from it might be unreasonable, but it's frustrating to keep throwing effort at this and hoping I can work my way up to 30 fps. In reality, a plane with a stationary cube throwing a realtime shadow is a large framerate hit right away, and just having two characters onscreen pushes down to 20fps.

    Is this just how things are, or is there a solution? It seems I ought to just give up on any sort of mobile game with realtime shadows.
     
    Last edited: Dec 11, 2015
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
    What is your phone?

    What shaders are you using?
     
  3. RdArrogantKnight

    RdArrogantKnight

    Joined:
    Jun 24, 2013
    Posts:
    13
    My phone is a Moto G, the shaders are the unity standard shader on everything.
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
    Don't use the standard shader.
     
    astracat111 likes this.
  5. Potaski

    Potaski

    Joined:
    Aug 21, 2013
    Posts:
    52
    I have the same issue. Even when only one object drops shadow, the drawcall of the entire scene is doubled. It seems screen space shadow is turned on by default. As I can remember things didn't work like that several versions ago.
     
  6. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    I have one directional light and about 50 shadow casters in my mobile game as the video below shows - skip to about 25 seconds when the game has actually started:



    I never get less the 45fps - which is the target fps.

    So how does this work?

    • Do not use the standard shader. Use the mobile shaders.
    • Turn off all GI
    • Have a very small shadow distance. If you look you will see the shadows pop up a bit in the video
    • You can have soft shadows but no shadow cascades.
    • One directional light only
     
    theANMATOR2b likes this.
  7. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,453
    I would add that keeping screen space shadows should actually help performance, as it greatly reduces the cost to lookup a shadow value for all the geometry. Basically a tex2D lookup with uv versus having to sample the directional cascaded shadowmap which requires a lot of matrix multiplications.

    Unless I am missing something... someone correct me if I am wrong
     
  8. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    What are "screen space shadows"? Thanks.
     
  9. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,453
    Directional light shadows are usually computed by rendering the scene depth to what is called a cascade map. This can have 1, 2 or 4 quadrants depending on quality settings. A shadow value for any world space position and distance from the camera can then be computed, but this requires some matrix math to get the world position turned into a "shadow" position. With screen space shadows, the cascade shadow map can be transformed into a full screen texture with a lot of softening and other filtering applied, and finally any shader that needs shadows can simply do a texture lookup using the full screen uv coordinate to do shadow light computation.
     
  10. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks for this info!
     
  11. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Is this an asset I would purchase or something within Unity? Thanks.
     
  12. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
    No look in your quality settings and down there will be shadow Cascades