No announcement yet.

How do I make the player cast a shadow?

  • Filter
  • Time
  • Show
Clear All
new posts

    How do I make the player cast a shadow?

    Two questions really...

    I've read on the forums that a spotlight can cast a player shadow, but I'd prefer if my directional light would. Can't seem to get it to go though, even though it casts shadows for everything else. (I also placed a spotlight in my level and it didn't cast a player shadow either.) In my IDtech 4 days I recall the r_playercastshadow command, is there something similar that I have to set?

    What is the difference between a "Directional" and a "Dominant Directional"? Is one preferred for certain uses over the other?

    Yeah, compared to idTech the lighting is completely different in UDK. You get both static and dynamic lights as different entities and you can also force static lights to behave dynamically to some degree.

    Then you also get the dominant lights which function as the name implies a light source that is dominant over others, the major light source of an area. It can be the sun or indoors you can have a major area lit by one of these. They can only be used one at a time in any given area, meaning they can not overlap each other, if they do, you would get shadow popping. Compared to other lights they cast the best looking static shadows and by default would cast proper dynamic shadows. They will also cast dynamic shadow from static objects on to the player.

    So, for player shadows, to get the proper looking shadow, you can use a dominant light. In areas where you can't use dominant lights and still want player shadows you will need to kind of force the shadow to work. For that use a togglable light, which is a dynamic light and change the shadow mode to normal. Make sure to disable "Cast Composite Shadow". This way you will get a proper shadow from the player. The down side here is that static objects won't shadow the player at all. So if you used this method and have a dark area created by shadows of this light, the player will seem to stick out because it receives light all the time from this specific source.

    Just like in Doom3 though, you can't over use dynamic lights. The same kind of principals apply with regards to overlapping dynamic lights. The biggest difference is that in Doom you need to be careful about overlapping on polygons, which is a lot more forgiving to deal with where as in the UDK you need to be careful about overlapping on objects, with regards to static meshes, basically any models. Meaning that if two lights simply touch the same static mesh it's the same as two lights fully overlapping this mesh. So you can imagine this is much less leeway in dynamic light use in one area. You can't just cut some more polygons to have less impact on overlap, it doesn't work that way with static meshes. With BSP though I think it's pretty much the same as Doom.

    As far as static lights goes, you can't really get a proper player shadow. You can just push the direction of the modulated shadow around as a bit of a trick to sell the idea. The modulated shadow however is basically a shadow that multiplies on top of everything so it will overlap other shadows. It will also go through the whole world so you would be able to see it going through walls depending on the circumstances.

    Ultimately it's kind of your choice to make how much "real" looking shadows you want. All lights can affect the modulated shadow so it's the easiest to deal with that although it's sort of fake method. But then not all lights can give you a real shadow and to get the real shadow all the time is quite expensive and has some limitations in other areas so that takes some trial and error to deal with.

    Sorry, maybe I went overboard about the lights a little bit.. A lot of my UDK time goes into figuring out lights and how to get past the modulated shadows completely. I'm just not a big fan of fake shadows and at this point the UDK really is best suited for the fake shadows. But it's not impossible to get past it I think.


      Thanks for taking the time for such a detailed reply, this helps a great deal.

      In my professional experience I am used to seeing the "lighting shuffle" between forward lights and lightmaps. To be honest I was a little disappointed that the UDK doesn't incorporate a deferred lighting model, which I thought might be the case when looking at the game, with all the emissive/lightmass going on. Even then that wouldn't necessarily make nice shadows so much easier.

      I've taken some time to mess around with the light/shadow settings and see what I can figure. The shadow methods are interesting, especially the use of stencil shadows for static meshes before lighting is built. A lot more parameters than I expected takes a lighting build to take effect, the skylight for example, which I sorta assumed was just an ambient.

      It still doesn't help the fact that the player doesn't cast a shadow while alive. Vehicles cast shadows, (now both a standard and a composite shadow in the right places, respectively) and if the player dies the ragdoll casts a shadow, but while alive the player still doesn't cast a shadow and I can't figure how to change that.

      In the pawn there are settings like armscastshadow=false and such, but setting them to 'true' didn't appear to change anything. I can't find where the player is set, or see what I'd have to alter to set it. (*mimes digging through a drawer of socks)


        Ok, I think I actually misunderstood the first time. The 3rdp models do in fact cast shadows and even your player model would if you used "behindview" to go into 3rdp. But in 1stp you do not cast any shadows. I don't have much experience with the 1stp setup in the UDK but as far as I know, there is no model to cast shadows from in 1stp view. The arms you see are the only model there is. When you go to 3rdp, then only the character model is being used.

        I only have a theory to get the shadow which is to use 3rdp view but to place the camera in such a place where it still seems 1stp view. Not really sure how to place the camera but I can guess it's in the camera script or something, but I really have very small amount of scripting knowledge, VERY little.. . I think doing this should still play the same since in 3rdp view the game still feels the same in the controls and then the character is there and will cast a shadow with all animations.. etc. I'm just not the right person to say how to actually accomplish this. I also know that in Doom you can place the 3rdp camera with console commands though I don't know if this is possible in the UDK.


          Hmm, ok. This helps me clarify what I'm probably looking for. Thank you.

          I'm assuming that the camera is still attached to a player model of some sort, with an origin and a skeleton on it, and that the camera is offset from a bone somewhere. In fact I see in the Camera.uc that there is a simple first person implementation is uses a "GetActorEyesViewPoint". (maybe defined by a bone or maybe something more arbitrary) I'll dig around for a little longer and then ask in the script/programming threads, probably.