15
2012
Fake Realtime Shadows With Surface Shader
Yes! After several hours of shader errors, finally got this working, fake realtime shadows using shader (2D)
Its using obstacle map texture (see image#2), so thats the 1st downside of it,
but still better than nothing..
More info later..
Ideas to try:
– Blur the wall map texture, Soft shadows?
– Add 2nd pass for: combining the shadow, instead of 1st pass? or use 2nd pass for blurring?
– Would this work as camera shader, using depthmap as an automatic obstacle map? (*problem: how to get neighbour pixel colors from vertex color..?)
– Fake directional light shadows should be even easier?
– Use light attenuation for shadow / light strength?
Current progress:
– Can use screenshot as an automatic wall mask texture, no need to create it manually
– But that creates another problem, the view should be same size as plane/texture?
– Using depthmap as wall mask would give realtime shadows, with moving objects also,
but no idea how to use depth pass like a texture+uv with Tex2D..
Webplayer:
http://unitycoder.com/upload/demos/mFakeShadowShader2/
Download source:
fakeShadowShader.unityPackage
—
*image#2: obstacle texture map

Related Posts
8 Comments + Add Comment
Leave a comment to PinkPanter
Recent posts
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
- Convert LAS/LAZ/PLY pointclouds to GLTF (GLB) Point Meshes (standalone converter)
Recent Comments
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
- on UI Scroll View automatic Content height
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by













Hi, are there any plans of releasing the source? or can you explain in short how this shader works?
Basically: in shader, inside a for loop (maybe it was 10-20 steps), from every pixel, towards the light, it checks if there is white mask area between them.. If yes, then that pixel color is black/darker.
I’ll post the example scene sometime later.. it didnt really work so well..
Thank you!
I was thinking about a shader based solution for this:
http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/walls-and-shadows-in-2d-r2711
Then I rembered seeing something similar on your blog 🙂
That looks good, too bad the source code is not complete..
Hi, can you releasing the source code?
Sorry for the obsession, but it’s perfect for my project, but haven’r experience in writing shaders…
I’ll try add it soon (by next week at least)
one note, you need to create that obstacle mask image.. (so if objects are moving, they wont cast shadows, unless they are updated on the obstacle mask texture..)
source added
Thank you so much 🙂