2D Toolkit Forum
2D Toolkit => Support => Topic started by: Demonocrat on September 24, 2013, 11:06:43 am
-
Hi!
Currently i'm trying to make my sprites cast shadows from directional light, but i can't seem to find the right settings for it to happen. I searched forums, but never found any specific answer.
My first goal is to make at least some kind of shadows, and after that i need to make it count alpha channel so i get correctly shaped ones.
Can anyone give me some advices or directions where to look for an answer?
-
Transparent shaders can't cast shadows in Unity - switch to a Unity Cutout/Diffuse shader and it should cast shadows.
-
Hmm... I've found cutout/Diffuse shader only under "Transparrent" in shader lisrt and it give me no shadow :(
Check out this screenshot, is this the right one?
http://take.ms/HCVmYZ
-
Transparent/Cutout/Diffuse should definitely cast shadows.
If it doesn't, it means your scene isn't set up properly - make sure your light is actually casting 3d shadows first (test with 2 boxes).
-
I managed to cast shadows in scene view (was suposed to be using directional light), but now i have another problem.
I can see shadows in scene view: http://take.ms/SSO6RZ
But they still don't show up in game view: http://take.ms/v0LGbc
I tried to move and rotate light around, but had no luck (only managed to get really long messed up shadow at extreme angles and really high intensity)
Looks like tk2d camera wouln't render them unless i switch it to perspective
-
What version of Unity are you using?
-
It's 4.2.1f4
-
There was a bug in unity 4.0 and 4.1 that broke this - coulda sworn it was fixed in 4.2... I'll take another look to confirm and get back to you.
-
This looks like a combination of things that is breaking the shadow casting with the tk2dCamera. If you select the camera, get it to show the Unity camera by clicking the little settings icon next to the tk2dCamera and click "Toggle unity camera". Changing the unity "orthographic size" setting seems to change the shadowing when it shouldn't - its using a custom projection matrix at that point, but the shadowing isn't respecting it. I'll have to investigate this properly - its definitely a bug in the Unity camera that isn't using the projection matrix, but I think from my initial experiments that it is possible to somehow convince it to use the correct settings.
-
I toogled unity camera as you said, but i can't seem to be able to change it from orthographic to perspective (if that's what you were offering to do). No matter what i change at setting of unity camera it jumps back to be equal to settings of tk 2d Camera (Script).
Or maybe i understood you wrong? Is there a temperory fix for this situation at all?
-
No I meant to change the orthographic size (size under the projection box) on the Unity camera. Reduce it from 480 or whatever its at right now, to 10 or something. You should see the shadow creep in but see no change to the viewport otherwise. If you want something to work with now, use a normal Unity camera without the tk2dCamera script attached.
-
Thanks that helped! :)
-
Argh!
Celebrated too soon =(
Now I have a new problem - camera shows only shadows in the middle but completely ignores shadows of the objects on the sides.
Check it out:
First there is no shadows for bar chairs - http://take.ms/OkBVPj
And now there is no shadow for a chair that previously had it, but now on the edge of the camera - http://take.ms/YgB9uZ
-
So what did you actually try here?
-
Well, i want shadows to be shown for all objects on the screen ))
I use single directional light for this purpose, but for some reason camera shows only shadows for the objects in the middle. If you move camera around you could see that shadow disappears from one objects and appear on others.
As i understand this shouldn't happen on orthographic camera, or am i wrong?
-
It should work fine on a normal orthographic camera. Unless there's another bug in Unity 4.2 which I'm unaware of?
But seeing what you're doing, couldn't you just duplicate the sprite, tint it black & semitransparent - that should give you convincing enough shadows shouldn't it?
-
Yeah, i guess it should =)
I'm just not sure yet how to technically auto attach all fake shadows to objects, so i wanted to avoid that ))
-
It will be way way more efficient doing it like that than using shadows. As soon as you turn on lighting & shadows, your draw calls increase massively.
-
Gotcha, ok guess I'll go this way then.
Thanks for all the help! :D