Dynamic Shadows for child objects.

Ask questions, discuss ideas, get answers
Post Reply
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Dynamic Shadows for child objects.

Post by Apache Thunder »

I've recently discovered a trick to getting dynamic shadows working for child objects on a vehicle without having to place them on the main PCO object.

All vanilla vehicles and just about every vehicle I've encountered in any mod never has the dynamic shadow code present on the lodObject. Perhaps some have it on the complex bundle, but not having it on the lodObject brakes the chain and thus the reason why no vehicles I know of have working shadows on child objects. The requirement to get child objects to have working shadows is simple. All the objects nested on the main PCO all have to have the "hasDynamicShadow" property enabled. If one is missing, then the chain is broken and thus no shadows.


To get dynamic shadows working on a turret and gun barrel for example all you have to do is add the dynamic shadow command to all host objects in the chain the leads to the target child object(s). So for example: (of coarse make sure the geometries involved here actually have shadow meshes. ;) )

Code: Select all


ObjectTemplate.create PlayerControlObject ExampleTank
.
rem [unneeded code for example omitted]
.
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.addTemplate ExampleLod

ObjectTemplate.create lodObject ExampleLod
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.addTemplate ExampleComplex
ObjectTemplate.addTemplate ExampleSimple
ObjectTemplate.lodSelector ExampleSelector

ObjectTemplate.create Bundle ExampleComplex
ObjectTemplate.geometry ExampleGeometry_m1
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.addTemplate ExampleTurret

ObjectTemplate.create RotationalBundle ExampleTurret
ObjectTemplate.geometry ExampleTurret_m1
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.addTemplate ExampleGunBarrel

ObjectTemplate.create RotationalBundle ExampleGunBarrel
ObjectTemplate.geometry ExampleGunBarrel_m1
ObjectTemplate.hasDynamicShadow 1

That is one example on how to do it. If a single object in this chain does not have shadows turned on, it brakes the chain and thus your turret and gun barrels for example won't have shadows! The main place this stops in any mod and in vanilla BF1942 is at the lod object. The dynamic shadow code is sometimes added to turrets and other things in many mods and perhaps in vanilla Bf1942, but in most cases the lack of the code on the lod object and in most cases the complex bundle as well cause them to never work.

This is not something I noticed little while back when I was recoding the LCVPs in my BFH'42 mod. I had finally ported the official mesh used in the real game. I then rebuilt the coding. I without thinking about it, added the dynamic shadow code to the lod object and the complex bundle. After some testing I discovered an odd parachute shadow bug. I noticed the bug didn't occur on passenger positions. Thus I examined the code and noticed that I had enabled shadows on the lod object and the complex bundle which is outside the norm for vehicles in BF1942.

So logically I thought the only way this can ever happen is if in fact the child object limitation doesn't exist. (unfortunately the game doesn't turn on shadows for the main soldier mesh on vehicle seats...it only does this with the parachute which is not something we would have wanted. So for now no shadows for soldiers in jeep seats. :( )

So I repeated what I did to one of my helicopters as a test. I added the shadow code to all child objects leading to engine prop for the main rotor. That means adding the shadow code to the lodObject, the complex bundle, the engine, the lod object tied to that engine, and then finally the prop itself. Then shadows worked!

However it doesn't quite work correctly on plane/helicopter props due to the lod system they use. The shadows for the "non blur" version of the prop work fine but become invisible after the blur lod is activated. I tried adding a shadow mesh to the blur version of the prop, but curiously, it didn't rotate or move at all. This behavior is confirmed to occur with it's collision mesh (if it has one in your case) as well. I stuck a sticky projectile to a prop on a helicopter and flew it up before it detonated, it always went off in the same place. (though the projectile it self becomes invisible since it was "stickied" to the static prop and not the blur prop). So the collison mesh and shadow mesh of the blur prop in the lod system never rotates resulting in shadows not updating correctly.

So rotational bundles placed on the main PCO (or anywhere else so long as all the child objects in the chain have the shadow setting turned on) would still be needed for those. :(


There is only one bug I know of that you might encounter while doing this. If you enable shadows on the lod object and the main complex bundle on a vehicle that has a seat with a visible soldier on the driver position, the driver's parachute shadow becomes activated even though the parachute has not been activated. Even if dynamic shadows are turned off for the parachute geometry and object!

There are two ways to fix this. One, you can use a "StandardMesh" geometry template on the parachute mesh to have it behave as a non animated mesh. Since the game is hardcoded to only load shadow properties from the lod of AnimatedMeshes but have all others use a separate shadowmesh. This effectively prevents shadows from working on the parachute in any circumstance.

But this would mean your parachute would no longer animate. So this is the better way to fix it: (note this method will result in the parachute becoming visible in 1p view, which can be good thing in my opinion. ;) )

Code: Select all

ObjectTemplate.create Bundle Parachute
ObjectTemplate.name Parachute
rem ----------------------------------
ObjectTemplate.addTemplate ParachuteAnimated


ObjectTemplate.create AnimatedBundle ParachuteAnimated
ObjectTemplate.setGeometry Parachute
ObjectTemplate.createSkeleton animations/Parachute_m1.ske
ObjectTemplate.setAnimationState OpenParachute
Then go to the CommonSoldierData.inc file and add/edit this line of code that is found directly below the "ObjectTemplate.addTemplate Parachute" line:

Code: Select all

ObjectTemplate.setIsFirstPersonPart 0
Then you can keep the parachute as an Animated Mesh and then have dynamic shadows enabled on child objects of vehicles with a visible driver seat. You also have the neat side effect of having the parachute visible in 1p view like with BF2 and newer games.
ImageImageImage
I have cameras in your head!
User avatar
fo0k
Posts: 1433
Joined: Fri Oct 16, 2009 4:21 pm
Location: UK

Re: Dynamic Shadows for child objects.

Post by fo0k »

Awesome info dude.
Django
Posts: 29
Joined: Mon Dec 10, 2012 2:58 pm

Re: Dynamic Shadows for child objects.

Post by Django »

that is great!
the missing shadows on vehicles like the ATAT and ATST in GC were always a manko.
thx a lot
Post Reply