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.
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.
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.
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.
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.
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?
@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:
private void OnPreRender(){
RenderBuffer savedColorBuffer = Graphics.activeColorBuffer;
RenderBuffer savedDepthBuffer = Graphics.activeDepthBuffer;
// Keep the rest of the code OnPreRender code here...
Graphics.SetRenderTarget (savedColorBuffer, savedDepthBuffer);
}
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.
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.
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:
var textureMatrix = (clippedProjection*modelView).inverse;
#if !UNITY_EDITOR_OSX && ( UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_XBOX360 || UNITY_XBOXONE || UNITY_WP8 || UNITY_WSA || UNITY_WINRT )
// Viewport and texture coordinats are flipped on DirectX.
// Need to flip the projection going in, then flip the texture coordinates coming out.
var flip = Matrix4x4.Scale(new Vector3(1.0f, -1.0f, 1.0f));
textureMatrix = flip*textureMatrix*flip;
#endif
// Composite the light.
// Draw a fullscreen quad with the light's texture on it.
// The vertex shader doesn't use any transforms at all.
// Abuse the projection matrix since there isn't really a better way to pass the texture's transform.
GL.LoadProjectionMatrix(textureMatrix);
Graphics.DrawTexture(LIGHT_RECT, light._cookieTexture, SRC_RECT, 0, 0, 0, 0, color, this.lightMaterial);
}
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.
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.
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!
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?
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!
@Mr-Stein I guess you could use SFSoftShadows to generate the light effects in the game, though as @AndyKorth_1 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.