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

How they do it? Angry Birds 2 Shadows

Discussion in '2D' started by resetme, Aug 2, 2015.

  1. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Hi guys, so i was playing angry birds 2 and i realise that stages have shadows. The shadow of the clouds moving slow in the stage, but that cloud affect only the "game layer" not the background or items. Mostly of 2d games that use shadows have a different approach. the shadow affect everything, plus the background, looks like they just put the shadow up everything and animate it.

    So, how the guys from Angry birds 2 achieve that nice shadows?? Its kinda moving inside the UV maps. i have no idea....

    angryBirds2.jpg
     
  2. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    They are probably rendering everything to different layers and on the foreground layer they are moving some shadows across the screen? The shadows are probably blended using some blending mode like in Photoshop.

    To stop it from affecting the background layers they could use different cameras or render textures or some other trickery I guess.
     
    theANMATOR2b likes this.
  3. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    i was thinking that maybe they use projectors. but projectors don't work with sprites.. but that would be the easier way to make it, projectors and sprite shade with shadows.
     
  4. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I'm thinking you're thinking about this way too naively. Just because the game is made with Unity doesn't mean it's just made with the things Unity ships with. Most likely you wouldn't recognize it as a Unity game at all if you opened their project. They've probably made custom tools, shaders, scripts for every facet of the game, shadows included.

    But as a simple proof of concept you can try with 2 cameras. Put your background sprite on its own layer and use 1 camera to render just that. Then create another camera which renders the foreground sprite. Create a bunch of clouds on a transparent background in Photoshop or whatever, assign that to a sprite and move that across the screen horizontally. Assign the shadow sprite to the foreground as well.

    Then you can expand on that with blending modes etc. as your technical skills improve.
     
    Last edited: Aug 3, 2015
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    It could just be a modified sprite shader with an extra texture layer that moves across in screen space.
     
  6. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    thank you guyz, gonna try some of those ideas!
     
  7. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    I'm making a Terraria style game for awhile now, and this problem was becoming a bit infuriating. I couldn't find any clear examples anywhere. Lots of vague ideas.

    I finally created a solution involving 3 cameras (background, foreground, light), and I have the foreground camera write into a stencil buffer with a shader into a render texture, and the lighting camera read the stencil buffer with a shader through a render texture. In order to stencil the alpha values away on the foreground, it has discard pixels, so It's probably not the fastest solution, if someone has a better one, I'd appreciate it. And if Unity would like to create a native masking solution it would likely be more efficient.

    Here is an example project: https://app.box.com/s/1vcephth1y3lcxea0kztbev7c28wgbck

    Everything is commented there. And you can see in the project that the shadowing is foreground layer, using a multiply/stencil shader. I also included a regular version of the stencil buffer shader if you wanted to render decals to only the foreground.

    Pass it around, and teach people how to do this. If I solve anymore irritating problems, I'm going to keep posting solutions and explanations. We need to learn how to use Unity if we want the quality of our games and options to increase. It's not easy to do that alone.
     
  8. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    @kuchaku, would it be possible to provide a screenshot of your solution? Thanks!
     
  9. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    This would probably be the clearest way to see it in action:



    You see how the cloud texture is drawn in the editor scene, but is overlay over the foreground stuff in the game. There is a scene of this in the project itself, but it has another cloud in the background so it might be less clear what is going on. Anyway, it's pretty much set it and forget it. Draw anything you want on the foreground camrea, draw your shadows on light layer. If I grabbed a different shader you could put additive lighting somewhere likely as well.
     
    Last edited: Aug 6, 2015
  10. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
  11. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
    This.
     
  12. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
    We just update 2DxFX with a Sky Cloud Shadow FX ( including auto move on/off, speed, direction and intensity ), very easy to use