Search Unity

The performance of shadow mapping in Mobile platform

Discussion in 'Editor & General Support' started by sui0528, Oct 22, 2014.

  1. sui0528

    sui0528

    Joined:
    Sep 15, 2014
    Posts:
    52
    Hi guys,

    I want to integrate the real-time shadow mapping in our game, only one directional light shadow, only only players are shadow casters.
    The shadow mapping algorithm of Unity is cascaded shadow mapping, as the document said, if I use it in mobile, there will be only 1 cascade, so it is no longer CSM ( am I right ? ), and only one directional light cast shadow. Cascades is not important for us, one is enough, but I wonder whether the shadow rendering pipeline will change on mobile ( eg, just projective shadow mapping, with no cascaded specific implementation in C++ code or in shader code ) , or it still goes with the CSM pipeline ( eg, process specific cascade in shader code or other stuff ).

    In our game, only players are shadow casters and other stuff shadow recievers. I wonder there are some benefits if I implement my own shadow mapping, use depth texture and one shadow camera goes with the main character.

    But if I do it, there are more things or problems to consider than using the Unity shadow system. For example, which objects in the scene should recieve shadow, if they are in the shadow area, they should recieve, but if they not, they shouldn't. So there are two problems I should solve :

    1. I should figure out which objects recieve shadow, if I do the culling via script, how should I do? Loop through all objects in the scene ? Check if these objects are in the shadow camera frustum? I don't know how to implement it exept that I had Unity source code.

    2. Even if I figured out which objects are shadow recievers, I will keep two shaders for all objects that are candidate shadow recievers, one with no shadow map, another with shadow map, if I use one version ( with shadow map ), the shader code is more complicated and not efficient.

    And there are some other problems, eg, cos only characters can cast shadows, if there is a floating rock behind a character, it will recieve the shadow of the character, the ground part behind the rock should not recieve shadow of the character because the shadow is blocked by the rock, but cos the depth information of the rock is not rendered into the shadow depth map, the ground part will have wrong shadowing effect.

    Maybe there are some more issues to consider, now I want to know :

    1. Is the real-time shadow mapping efficient in mobile platform? Only one directional light, only one cascade, short shadow distance, low shadow map resolution.
    2. Should I implement my own shadow mapping? If I can't use some efficient algorithm to collect the shadow recievers of whole scene, I must make a custom shader with shadow for all the material of all the scene object, and the shader is longer and complicated.

    Thanks for any advice!
     
  2. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    You can get away with limited use of shadows on mobile, so long as you limit it to fairly modern devices (iPhone5+, maybe). But yes, you'll want to keep the settings fairly low (one cascade, limited shadow distance), and there's certainly a few issues to be aware of.

    As well as limiting the shadow casters, you can carefully limit the shadow *receivers* to improve performance - either by splitting up meshes, or having two versions of your shaders - one which receives shadows and another which doesn't. For example, just casting shadows on 'ground' meshes, not walls or other objects.

    If you're using lightmaps for the environment, and writing your own shaders, you can also control how the real-time shadows are combined with lightmaps - instead of 'lightmap*shadow*texture' - which gives double-shadowing, you can do something along the lines of 'min(lightmap, shadow)*texture'. This can help a bit with the problem cases of shadows projecting through objects onto other (shadowed) surfaces.
     
  3. sui0528

    sui0528

    Joined:
    Sep 15, 2014
    Posts:
    52
    Thanks for your advices, it is valuable for me.
    Yes, now our solution is using UNITY shadows with very limited settings. The quality is not good, but maybe is enough, as you said, I filtered some objects as shadow recievers, this can make draw call count lower, we use lightmap, and now has no problem with it.
    for high end device gpu, shadowmap maybe not the performance killer, but for the low or medium, it maybe a disaster, but I test it on andreno 220 GPU and others, it is not a main issue.