I am trying to replicate the Skyrim shadows, where on candles the shadow will “dance” slightly and the light intensity will fluctuate, I wasn’t sure whether to post this under Graphics or Scripting, but hopefully one of you may have a solution to this, I have a flame particle on my candles and fire on the torches but static lights, it doesn’t look right.
You’ll need to attach a script to the light. The script should make the light’s intensity and range fluctuate randomly.
I have a script that does both of these, these values don’t change the shadow, they just make it more predominant, or less so. I need a way to slightly move the shadow itself, if you have Skyrim (not sure why anyone wouldn’t), go into a house with candles, and look at a shadow cast by that candle for a bit, they slightly move, its a relatively small thing, but all the small things mount up and lead to a more immersive experience.
The best way to “move” shadows in Unity is to move the light source
You could get the shadow framebuffer,but I honestly don’t know why you would want to, moving the shadow texture would be a lot more difficult and would NOT produce the same effect like skyrim.
So, to replicate the effect - you have to use point lights with realtime shadows(only Pro version!), and then attach a script that will “wobble” the light - move it a little bit up/down/left/right…then the shadows will move too! Of course you could use a directional light in the free version of unity, but then it would be like a flashlight,not like a candle.
It’s often sufficient to just have a zone the camera can enter, and the closer to the center of the zone, the more pronounced the micro rotation applied to the directional light. This is sufficient for unity free. For pro, the same can be done with a local light.
so there is no way to move or rotate the shadow independently without moving the light source? this sounds like a very inefficient way to achieve this, I was hoping an offset could be applied to a baked shadow causing it to appear to move, but perhaps not.
you could write a cg/vert/frag shadow pass in 4 and use a vertex shader to perform this. But unity 5 uses screen space shadows afaik so that’s not really viable. What you’re asking for isn’t an incredibly viable thing. It’s also solved completely by having a point light with shadows simply move around and pulse slightly at the candle.
If you’re using the free version of Unity, it’s probably not possible.
Alright, just so you don’t think we are avoiding telling you. Like hippocoder mentioned - you could create a new shader for your materials that you want to be affected by this moving shadow. Create a new shader, and then click on “show generated code”. That will show you the full code of that shader - scroll down to the code managing the lightmaps. There, you can make it sample the lightmap with an offset, that you could set from a script using a shader uniform. That would work - but it will look badly because you will be moving the entire lightmap, not just the shadows, as they are not separate. The lightmap was also calculated from a certain position - so when you move the lightmap the whole perspective will be skewed. But yeah, you can do that.
@hippocoder I am using Unity Pro, I have the U5 preorder, I will be working primarily in U5 when it is finally released for obvious reasons, but from what you have said, this would not be a viable way to do this, I may have to ignore this on my list then, its not that big a thing, it just would have been nice to have
If you have unity5, why on earth wouldn’t you use a point light and jitter it around softly with shadows?
He didn’t say anything of the sort.
@PhobicGunner it’s implied, moving the lights slightly, be it in an animation, or script, is very inefficient, for the light to have to physically recalculate the lighting shadow every frame it moves, I don’t think it would be efficient and definately wouldn’t run well on slower machines.
If the light is not lightmapped, then it already does that regardless of whether you move it or not - that’s how real-time shadows work.
EDIT: And, by the way, that’s exactly how Skyrim does it. Realtime shadow maps, jitter the light source.
If so many lights in Skyrim use real-time shadows and jitter around, how does it run so smoothly, even on basic systems?
I know Unity doesn’t have the best optimisation in the world but the Creation Kit can’t be THAT good.
I don’t even need to look it up to know that Skyrim uses realtime shadow mapping - it’s glaringly obvious.
That said, I think the answer is that most lights in Skyrim probably don’t cast shadows. They probably have one or two main lights in a scene that cast shadows, and the smaller less important lights (such as small candles) probably don’t cast any shadows at all.
Deferred rendering probably. I’ve had literally thousands of lights at the same time, all casting shadows in real time with deferred rendering. Again, in Unity it’s a Pro feature. Also, like PhobicGunner said - it’s very likely that Skyrim doesn’t have that many light sources that produce real time shadows in any of the scenes. Most light sources, will be light mapped, and those that aren’t are probably unlikely to exist in huge numbers(few fireballs cast at the same time + a few candles is not horribly difficult to render even without deferred rendering).
Use shadow cookies. Unity - Manual: Lights
It is a technique very well used by many games. Furthermore it enables you to use very soft shadows, even with unity free and it is not as compute intensive as real time shadows.
Light cookies are only usable on Directional Lights, and not Point Lights, the way I am designing my maps, a directional light would not suit my lighting requirements, only things like Point Lights do so light cookies aren’t an option either, unless someone knows how to use them on a point light
Uh you don’t even need light cookies. In any case it looks like you’re actively fighting our advice without knowing much about Unity so I wish you best of luck.
Just try a point light with shadows on. Runs fine even on rubbish systems. Remember, it’s not like you’ll have 100 candles all with point light shadows in one tiny space…
FYI we had something similar (jiggling) on Vita at 60fps. So I’m sure with some care, a mighty desktop will do it fine.