Search Unity

Super Fast Soft Shadows - 2D soft shadows released!

Discussion in 'Assets and Asset Store' started by Andy-Korth, Jul 15, 2015.

  1. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Super Fast Soft Shadows is live on the asset store!
    https://www.assetstore.unity3d.com/en/#!/content/38682





    We're the authors of Chipmunk2D physics engine and Cocos2D-SpriteBuilder maintainers. We recently rewrote the Cocos2D renderer and added lighting effects, and now we're back to writing Unity plugins!

    Super Fast Soft Shadows uses a unique shader based algorithm: Shadow projection occurs inside the vertex shader, not on the CPU. This allows us to achieve:
    * Speed on mobile platforms
    * High number of colored lights and shadowed objects
    * Flexibility in light size and softness of shadows

    Shadow mask generation occurs in a single pass - it doesn't use expensive image filters or pixel shaders to soften the shadows. This means it runs great on mobile!


    Physically realistic penumbra, umbra, and antumbra rendering is based on configurable light sizes. This produces accurate rendering when the light source is larger than the objects casting the shadows.

    Great for atmospheric effects:

    For more screenshots, check out the in-progress thread: http://forum.unity3d.com/threads/super-fast-soft-shadow-system-in-progress.331154/
    And the store page: https://www.assetstore.unity3d.com/en/#!/content/38682
     
    Last edited: Dec 21, 2016
    EliasMasche likes this.
  2. JonathanCzeck

    JonathanCzeck

    Joined:
    Mar 21, 2013
    Posts:
    12
    Really awesome... nice work. We're going to give it a try for our next game! Clean code and highly performant. It seems superior to any other thing out there in multiple ways.
     
  3. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Thanks a lot! Let me know if you have any questions or suggestions for improvement!


    I also wanted to share this screenshot here- you can create some really cool artistic effects by cranking the global dynamic range way up. You can get a bloom/oversaturated look this way.​
     
  4. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    We made sure that editing the lights and outlines was as smooth as possible. The editor components can preview everything in real time so you know exactly what your scene will look like.

     
  5. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
  6. Mr-Stein

    Mr-Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    @Andy.Korth look awesome!, there is no promotional price?
     
  7. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    We'd love to do one of the Unity asset store feature sales - I know there's a process for signing up for them, but I haven't had a chance to look into it yet.
     
  8. JonathanCzeck

    JonathanCzeck

    Joined:
    Mar 21, 2013
    Posts:
    12
    I'm having trouble with it and Image Effects. When I apply any image effect the game view turns into garble. Any ideas, or is it not compatible with them?
     
  9. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    @JonathanCzeck I got your followup email also- thanks a lot for your help with this!

    The fix for using Image Effects is to save and then restore the active RenderBuffers when drawing the shadows. Edit SFRender.cs and find the OnPreRender function (about line 239). Wrap the code in there with this:


    Code (CSharp):
    1.  
    2.    private void OnPreRender(){
    3.         RenderBuffer savedColorBuffer = Graphics.activeColorBuffer;
    4.         RenderBuffer savedDepthBuffer = Graphics.activeDepthBuffer;
    5.  
    6.     // Keep the rest of the code OnPreRender code here...
    7.  
    8.         Graphics.SetRenderTarget (savedColorBuffer, savedDepthBuffer);
    9. }
    10.  
    We'll look to include this in the next version!


    Image Effects! A vortex!​
     
  10. JonathanCzeck

    JonathanCzeck

    Joined:
    Mar 21, 2013
    Posts:
    12
    Thanks, it works perfectly now.
     
  11. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144

    By adjusting the fog and scatter colors, you can easily do a great job re-theming different levels and giving them a unique feel based on the color of the lights and the fog in the scene. I've got a yellow light in the corner here, and a red fog, which is applied over all objects, both shadowed and lit. Adjusting fog and scatter allow you to control which colors are absorbed and reflected in the atmosphere of your scene.
     
  12. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    A new version has been submitted to the store featuring some fixes to full screen shader effects- thanks JonathanCzeck for your help with that! There are also some Unity 5 specific fixes.

    Next up, we're considering what we can do to get some light-probe sorts of effects to shade your foreground sprites.
     
  13. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Important fix for DirectX platforms!

    To fix DirectX rendering of Super Fast Soft Shadows, please apply the following fix:

    In SFRender.cs, at the end of the RenderLightMapMethod (around line 230), replace the code with this code:

    Code (CSharp):
    1.  
    2.             var textureMatrix = (clippedProjection*modelView).inverse;
    3.              
    4. #if !UNITY_EDITOR_OSX && ( UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_XBOX360 || UNITY_XBOXONE || UNITY_WP8 || UNITY_WSA || UNITY_WINRT )
    5.             // Viewport and texture coordinats are flipped on DirectX.
    6.             // Need to flip the projection going in, then flip the texture coordinates coming out.
    7.             var flip = Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f));
    8.             textureMatrix = flip*textureMatrix*flip;
    9. #endif
    10.  
    11.             // Composite the light.
    12.             // Draw a fullscreen quad with the light's texture on it.
    13.             // The vertex shader doesn't use any transforms at all.
    14.             // Abuse the projection matrix since there isn't really a better way to pass the texture's transform.
    15.             GL.LoadProjectionMatrix(textureMatrix);
    16.             Graphics.DrawTexture(LIGHT_RECT, light._cookieTexture, SRC_RECT, 0, 0, 0, 0, color, this.lightMaterial);
    17.         }
    18.  
    19.         if(shadows) _culledPolygons.Clear();
    The extra #ifdef will ensure viewport and texture coordinates get flipped properly to account for the reversed Y axis on DirectX platforms.

    Thanks to everyone in the community for your support and help finding and fixing this issue! This fix has been submitted for version 1.2 in the asset store, but it will be a few days before it goes out- it's currently in review.
     
  14. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Version 1.2 has been posted in the asset store! thanks for all your support!
     
  15. arkhament

    arkhament

    Joined:
    Jan 24, 2015
    Posts:
    114
    Hi @Andy.Korth, with SFSS I can made or reproduce Scenes/Levels shiny like this?:


    Regards,
     
  16. AndyKorth

    AndyKorth

    Joined:
    Oct 19, 2009
    Posts:
    41
    It looks like that's a different and simpler technique. They're not casting shadows off of their sprites, they are just drawing their sprites twice. In addition to the main sprite, they are also offsetting the sprite into the background and drawing it again, with just the alpha and a grey scale. It also looks like their shadow is exactly the same size as the sprite itself, so it's never projected at an angle. It's a different technique for a different goal.

    The lights don't really seem to cast any shadows at all, they are just drawn on top of the scene. They also seem to make good use of bloom effects. Our solution focuses on light sources that cast shadows created by geometry.

    There's probably stuff on the asset store that does this, but I haven't looked around.
     
  17. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    On request, we've been adding sampled lighting so that you can light a sprite using the amount of light at it's base. You can set it up to sample the light at a specific point or along a line. Stay tuned!

    For example:
     
  18. Mr-Stein

    Mr-Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    Hi @Andy.Korth and @slembcke2 I'm looking for a solution like looking @arkhament.
    It is possible to make that kind of effect as the lights in the Guacamelee! game?
     
  19. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    So Pablo is the name of the user that requested the extra light sampling features. He sent me a work in progress shot and said I could share it. Looks awesome so far!
     
  20. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @Mr.Stein I guess you could use SFSoftShadows to generate the light effects in the game, though as @AndyKorth mentioned, all you need to do to get their shadow effect is to render the foreground sprites with a separate camera into a render texture. Then use the render texture's alpha channel to draw the shadows as a layer in your main camera. No projections or difficult shaders required.
     
  21. AndyKorth

    AndyKorth

    Joined:
    Oct 19, 2009
    Posts:
    41
  22. Mr-Stein

    Mr-Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    @AndyKorth, this asset work with layers? I mean to do something like spot light in the background
     
  23. AndyKorth

    AndyKorth

    Joined:
    Oct 19, 2009
    Posts:
    41
    @Mr.Stein Yes! Lights and geometry have configurable layers, so you can make certain lights have shadows cast only by certain geometry. You can also control what receives lights (like your background) by using the shadowed shader on those materials, but not others. Good question, thanks!
     
    Mr-Stein likes this.
  24. arkhament

    arkhament

    Joined:
    Jan 24, 2015
    Posts:
    114
    @AndyKorth @slembcke2 this will work if I want to just generate light? I mean only bloom, shine or illuminate a part of the scene(torch, fire) without generating shadows.
    I ask this because Im looking buy a package that can do everything(Light + Shadow, only Light, work with Layermask, change color in runtime, sprite illumination)

    Regards,
     
    Last edited: Oct 6, 2015
  25. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
  26. AndyKorth

    AndyKorth

    Joined:
    Oct 19, 2009
    Posts:
    41
    We've submitted version 1.4, which fixes some DirectX y-axis flipping issues It also includes improvements for users who might be using a perspective camera.

    There was a bit of confusion about a missing version in the asset store. I think I must have messed something up when trying to submit version 1.3. It was submit while version 1.2 was still in review, and I guess it never went through. 1.4 will be up as soon as the review process is done!

    Also a question for our users: How many of you are still using Unity 4? Is support for Unity 4 still a priority? I've so far been doing testing and submission in 4, just to make sure it'll work for people who are on that version.
     
  27. Mr-Stein

    Mr-Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    Hi @AndyKorth and @slembcke2
    I bought SFSS last week and I have 2 questions now:
    1) if I have in a scene 4 lights.. there is some way to change the intensity of only one of those lights?

    2) There is a way that the light affect the sprites by layers? the only way that I find was changing the material: SFUnshadowed and shader: Sprites/SFSoftShadow.

    Regards
     
    Last edited: Nov 6, 2015
  28. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Hi @Mr.Stein,
    1)
    The best way to change the intensity (or brightness) of an individual light is to ramp up the color - multiply each RGB in your color by a "intensity" factor to increase or decrease it. You can see an example of us doing this in the CaveScene example that comes with the project. Take a look at the flicker light script and try adjusting the light strength and you'll see what we mean.

    2) The asset does work with layers (like backgrounds, etc), you are correct that you can change which objects receive shadows by changing the material. There's also a layer field on the lights- that controls which objects actually cast shadows. But I think you're talking about changing what receives shadows? Could you explain exactly what you are trying to do? Do you want certain lights to only cast on certain objects?

    If you're doing parallax effects, you probably don't want your background layers to receive foreground lights, in that case you should use a normal shader on them.
     
  29. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    You can also use SFSS to create a directional light sort of effect. I was helping a customer earlier today with their setup so they could create something like this:



    If you want something like this in your game, we recommend you set up your scene with a single light that follows your camera. Remember, you can set the source of your light to be outside of the bounds of the light's cookie. In this case, it's way off screen to the upper left.

    Also, try a solid white cookie, or a subtle gradient. Here's how the scene is set up for this example:
     
    Manny Calavera likes this.
  30. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    SFSS 2.0 is now submitted for review!

    Version 2.0 includes a bunch of new features, such as:
    • New sampling shaders- shade an object by sampling the shadow map at a point or across a horizontal line.
    • New ambient light blending options
    • Four new example scenes, including a directional light example
    • Built and uploaded in Unity 5
    • Full Undo support
    Thanks for all your patience and support!


     
    Manny Calavera likes this.
  31. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270


    I've been reviving an idea that allows light to bleed into a surface by a bit. This can greatly enhance atmospheric effects. It also helps hide aliasing artifacts caused by subsampling, allowing the shadow map resolution to be reduced, and performance increased.

    The implementation adds only a little extra logic to the fragment shader, so it shouldn't affect fill rate performance by much.
     
  32. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270

    SFSS has been fairly focused on working as well as possible on mobile, but I'm also adding a couple of changes to enable HDR rendering on platforms that support it. Now you can use linear light blending without worrying about overexposure. You just need to enable HDR rendering on your camera, and optionally add the tone mapping image effect. \o/
     
  33. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    One of the local Global Game Jam teams used SFSS for their game, Neon Ritual. It turned out pretty nice for a game made in 48 hrs. I think the shadows helped give it a lot of flair, but I might be biased. ; )



     
  34. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
  35. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    SFSS version 3.0 has been submitted for review to the asset store!

    We've got some cool new features like:
    * Light penetration: Light can now softly bleed into a surface.
    * Can be used to make the lit edges of an object glow, or for a self shadowing effect.
    * Helps hide resolution shadow resolution artifacts.
    * HDR support:
    * Lightmap rendering is automatically performed in HDR when attached to an HDR camera.
    * Lights now have an additional intensity property when using linear light blending.
    * Editor scene preview of lighting effects.

    And a few important fixes and other improvements, especially for the latest versions of Unity:
    * Now works with Metal rendering on iOS with the latest Unity versions. (Earlier versions had shader compiler bugs)
    * Disable DirectX workarounds on Windows when using the OpenGL renderer.
    * Better support for batching of lit sprites.
    * Improved tooltips.

    Additionally, we improved the documentation- we've got a separate pdf for performance tips. We've also added to the examples. Including this new HDR linear color space demo:


    You can also see the light penetration on the surfaces of the asteroids in that scene.
     
  36. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    Version 3.1 has been submitted to the asset store, and is waiting for review. Changes include:
    • Memory usage improvements.
      • No dynamic memory allocation. (Very GC friendly)
      • Reducing memory usage by sharing meshes and vertex arrays.
    • Correctly render lights and SFPolygons with flipped transforms.
    • Copy from collider now respects the "offset" property.
    • Fix "cracks" that would appear in shadows for a 0 radius light.
    • Always show light intensity. (It would disappear with certain colorspace settings.)
    • Editor mode shadow culling fixes.
     
    Manny Calavera likes this.
  37. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
  38. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    3.1.1 has been submitted to the Asset Store.
    Notable changes include:
    • Fix Shadow Layers being ignored
    • New Shadow Layer example
    • Metaball particle example
     
  39. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Working on version 3.1.2, which will include improved support for tinting and transparent sprites:
     
  40. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
  41. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    I've been loving using SFSS since the release. Would definitely purchase addon/new asset for fog of war system using SFSS. Just an idea and nice demo!
     
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    As my mini-game needs a mosaic effect (things get more blocky during a transition like old snes games), I wondered if there's an easier way to modify the source for this? basically it's just rendering as it is now but with offset final uv and a smaller part of the render texture (gives the impression everything gets more blocky) - sorry if I didn't make much sense!

    Figured it would save an extra blit to modify this instead.
     
  43. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Also it appears broken in 5.6. I looked at the shaders, and it seems that Unity now flip them in shader. In addition to this, scene view is a bit overbright, just a heads up as I don't expect you to fix anything for beta :)

    My hack to add flipping appears to skew rotated sprites in game view too :/

    Maybe drop some hints where we can fix I guess if not too much trouble!
     
    Last edited: Dec 28, 2016
  44. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Arrrrrrrrg, something breaks every version. We'll probably download the beta and test it next week. The flipping behavior is a big pain to test and deal with. We probably should have a windows machine side-by-side, but SFSS doesn't quite make enough money to justify a windows machine just for testing DX flipping behavior in Unity...

    As for the mosaic effect, SFSS should work with full screen effects, even though there is that extra blit. If you're doing it as a transition, do you want to do the entire screen? If you want to make just the lightmap blocky, you could animate a change to the lightmap and shadow map resolutions. For that blocky look, you'll probably want to change them to a nearest neighbor sampling too. Hopefully those ideas are helpful, I'm not 100% sure if that's what you're looking for.
     
  45. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    There doesn't seem to be anything in the beta changelog ( https://unity3d.com/unity/beta ) about changes to the flipping behavior in shaders, so perhaps it's unintended. We'll file a bug after getting 5.6b installed.
     
  46. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah I thought it was odd but looking at the sprite shader source in the builtin shaders seems to verify flipping is now something expected on the shader side of things. I think the reason for this may be with instancing or something. Regardless, it's not much problem...

    Very impressive asset btw.
     
  47. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    I have a scene with many flowers that grow in dark. SFLight component is attached to each flower. The radius for each light is very small and they don't cast shadows but they still use 3 drawcalls per light. Is there a better way to lit (very) small areas of screen?

    It's not really related but I just wanted to share a vid I made today. It has improved a lot and it wouldn't be possible without SFSS.

     
    Last edited: Dec 30, 2016
  48. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sorry to report some other issues (Understand it's beta Unity, but leaving notes so you get to them):

    - Unity's new 9 slice feature doesn't work well at all (sprites) with no tinting or flipping.

    - not sure why GUI drawing is used to composite the image. This is possibly slow (has been historically slower, not sure about now)

    - GC allocations per frame

    - Can't make my own version of your shader work well in all circumstances, does it need a particular name? Might just be me!
     
  49. HowlingMoonSoftware

    HowlingMoonSoftware

    Joined:
    Sep 29, 2016
    Posts:
    5
    @hippocoder Argh. I think there have been breaking renderer changes in every single minor release of Unity 5. I think maybe 1/3 of the total development time has been working around new Unity bugs. We'll have to take a closer look on Monday I guess when I'm back at home.

    GUI drawing? Not sure what you mean?

    Bah. I checked for that shortly before release since I had rewritten so much of it to work with perspective. It might be a regression I added at the last moment before submitting or something. :-\ Or it might be a change due to 5.6?

    Shouldn't need any special names or anything. All the sprite shader does is to read from the screen space light maps and blend it with the sprite color. A screenshot might be helpful?

    For each light there is 1 draw call for the unshadowed light, 1 for the shadowed light, and 1 for the shadow mask. If a light has it's layer mask set to "None" then it will skip the shadow mask draw call. If you disable shadow rendering on the SFRenderer, then it will only make one draw call per light since it entirely skip the shadowed lightmap pass.
     
  50. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Thank you for the answer. So I guess performance-wise I should be using some particle shader for very small lights and SFLight for big lights.