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
Recent posts
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
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 🙂