Hi, i've been looking into how to create colored shadows. Tried to search around for quite a while but haven't really found anything. I know that shadows don't have colors in a real world, but i am aiming for a somewhat different style. Here is an example of what i want to achieve: So i am wondering if there is a way of having an object cast a colored shadow or receive a colored shadow? I do need the ambient light to change through different colors while keeping the shadow the same color. Sadly i don't know anything about writing shaders, so i am a bit lost. Any type of hint/tip would help me a lot. Thanks!
Have you tried just colouring your scene's ambient light? "Shadow colour" is whatever other light manages to reach a shadowed area, and ambient light reaches everything.
You can also render unity's shadows to a texture then render this back over the scene. Seems wholly really stupid to do when its probably one line of code on unity's part. Whoever at unity decided we were not allowed to unlock shadow colour - please reconsider. This is one change I feel unity need to allow flexibility on. Stylised graphics are very welcome.
I played around with it for a while but still haven't come up with the results i want. The closest i got is that every shadow BEHIND my model became purple... Maybe i can use this somehow, not sure. I'll keep testing. Thanks! I made the tree myself. The house is from the Human RTS pack from bitgem (http://bitgem3d.com/) and i just modified the colors and the mesh a bit. I did, and the results aren't too bad. It may work but i'm not happy that it re-colors every texture as well. I also wanted to add a Day/Night cycle and change ambient light over time (but this may have to affect the shadow anyway, which would be okay). With ambient light it looks like this: While the original colors are more like this: So i'm getting very close, but i'm not 100% happy with the overall colored look through ambient light. Maybe i can find a shader for the terrain that does not account ambient light, but i assume this would also eliminate the colored shadow again? This is an interesting approach, i will check this out and see if i can get it to work! Thanks. And yeah, i've used other 3d engines before and shadow color has always been a feature in the ones i used, so i am a bit surprised that Unity doesn't offer this as an option. I understand that it's not realistic, but not everyone is aiming for realistic styles heh. Thanks so far!
You should decrease your directional light by subtracting the ambient colour. That way it will sum with the ambient light to white.
I have been asking for shadow color option for years and have been ignored for years. Maybe if a few more people cry out loud the gods up there may hear us.
Curious...could you be more specific please? Maybe an example of how to get the light.a or something..
Gossip on the grapevine from Unity tech says they're on this issue, and while there can be no promises, it's something they're aware of and want to improve
Hey, thanks for the tip. Not knowing that much about colors, i tried to literally substract the ambient color from the directional light color but that didn't quite work heh (unless i did something wrong). However, i just tried to manually change the directional light color so it sort of balances back to white and it seems to work. I ended up with this:
You could easily write a shadow color into the shader, but at best you'd only be able to specify a color per type of light rather than per light (at least easily).
http://forum.unity3d.com/threads/227276-Colored-Shadows-Released Using this you can set the color of the shadows.
Hey Farfarer, Would you be able to link to any documentation or articles on changing shadow passes in shaders? I don't believe I've seen much on the subject.
No documentation to hand, but it's possible to do it with the defines you can lift from AutoLight.cginc. I've not tested this, but it should show the principle... Code (csharp): // Inside a cginc which you include in your shader. // Uniform shadow colour for all lights. uniform fixed3 _ShadowColor = fixed3(0.0, 0.0, 0.0); // Or if you want a different shadow colour per light type, use this instead. #ifdef POINT uniform fixed3 _ShadowColor = fixed3(1.0, 0.0, 0.0); #endif #ifdef SPOT uniform fixed3 _ShadowColor = fixed3(0.0, 1.0, 0.0); #endif #ifdef DIRECTIONAL uniform fixed3 _ShadowColor = fixed3(0.0, 0.0, 1.0); #endif #ifdef POINT_COOKIE uniform fixed3 _ShadowColor = fixed3(1.0, 1.0, 0.0); #endif #ifdef DIRECTIONAL_COOKIE uniform fixed3 _ShadowColor = fixed3(0.0, 1.0, 1.0); #endif // Then inside your fragment shader. // If custom vert/frag rather than surface shader. // This gets the shadow * attenuation value. fixed atten = LIGHT_ATTENUATION (i); // Or this gets just the shadow value (without attenuation multiplied into it). fixed atten = SHADOW_ATTENUATION(a); // If you are using surface shader, then the variable atten is already defined for you as shadow * attenuation. // Get the shadow value and apply it. fixed4 c = tex2D(_MainTex, i.uv); c.rgb *= _ShadowColor * (1-atten); return c;