CSM - Dynamic shadows for turrets and gun barrels

Lots of cool and useful tips to mod either serverside or clientside

CSM - Dynamic shadows for turrets and gun barrels

Postby Apache Thunder » Tue Oct 20, 2009 6:07 pm

The following is a repost of what is at SSM forums. Should be ok to post it here too. :D

The following should apply to both BF1942 and BFVietnam respectively. And of coarse this isn't server side. :P

I discovered a way to get moving shadows for child objects like gun barrels. The trick is that shadows will only appear for a child object if that object is addTemplated to the main PCO and NOT to anything else. It can't be addTemplated to a complex bundle that's attached to a lodObject or addTemplated to a rotation bundle which in turn is on the firearm addTemplated to that, or addTemplated to anywhere else for that matter. It must be on the main PCO. I am NOT talking about soldiers! The game engine treats those differently! This is for vehicles!

Example:

Code: Select all
ObjectTemplate.create PlayerControlObject M1A1
.
.
.
ObjectTemplate.addTemplate lodM1A1
rem *** Make sure to position it so it is mostly close to where the real barrel should be! ***
ObjectTemplate.addTemplate M1A1TurretShadow
ObjectTemplate.setPosition 0/1.5/1.5

.
.
.
ObjectTemplate.create RotationalBundle M1A1Turretshadow
ObjectTemplate.geometry M1A1TurretShadow
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.hasCollisionPhysics 0
ObjectTemplate.createInvisible 1
.
.
.


You should get the idea here. You make a dummy rotation bundle that has the same movement as the turret and give it a gunbarrel mesh that has a shadow mesh, (it could use the same geometry for the visible gun barrel as long as it actually has a shadow mesh in the SM file and such) then make it invisible with the invisible command and voila! Shadowmeshes for child objects!

So if you want your tank gunbarrels (and maybe turrets too if you want to take it that far), then this is the way to do it. This could also be used on things like planes.

Take the v22 hover plane hybrid as an example. If you want to give shadow meshes to the big prop rotation bundles. You do something similar above. Just position them so they match up with the real bundles and it should work great. This doesn't appear to produce any extra overhead in performance from that of a normal setup. So this shouldn't lag or anything. Dynamic Shadows shouldn't really be a problem even with some slower machines. (plus I think something like this can be turned off in the menu anyway if your machine is too crappy to even handle dynamic shadows).

BF2 and beyond has featured working shadow meshes for turret, gun barrels and all sorts of other things. So this brings a bit more enhancement to the visual side of the mod your working on. :D

Here's the result as shown in the BF242 mod I'm currently working on: (click to view)

Image

In that video I made the turret shadow mesh and barrel shadow mesh as one SM file. This made it easier to position. :D

So it is recommended that you make the gun barrel (and all it's pieces) and turret one mesh and use that as the shadow mesh. Since it will be invisible, what the LOD mesh looks like isn't important. You can get way with just making a tiny plane object or box and put it at 0/0/0 and use that as the lod. The new shadow objects will be invisible. But despite this, they MUST have a lod mesh or the game will crash. So just put anything in as a lod as long as it's something simple like a box or plane mesh. ;)

You can try and make the gun barrel a separate shadow object. But you can't addTemplate it to the turret shadow object. It must be separate. So this means you would have to add the pivot position code and play around with the settings till it rotates correctly which by the way I could never get working right. I tried this on a mobile SA-3 tank. I made the turret and missile rails separate rotation bundles.

But the rail (the part that the missiles go on) won't rotate on the vertical axis correctly despite all I have tried with the setPivotPosition code. So it's best just to make any gun barrels and such part of the same mesh as the turret shadow mesh.

Post your results! If you need help doing this for your vehicles. Post here and I'll try my best to help you.

EDIT:

Also you can even do this on other things like helo props for example: (click to view video)

Image

You can't make the new object a engine. It has to be a rotational bundle since engines won't rotate the geometry tied directly to them. Only stuff addTemplated to them will rotate. But we can't do this here since there is a one child object limit to dynamic shadows as already mentioned above.

Happy coding!
ImageImageImage

I have cameras in your head!
User avatar
Apache Thunder
 
Posts: 1199
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby fo0k » Tue Oct 20, 2009 7:11 pm

These are great! thx.. gonna try and fill this thing up with just about anything I know this week
User avatar
fo0k
 
Posts: 1423
Joined: Fri Oct 16, 2009 4:21 pm
Location: UK

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Senshi » Fri Dec 11, 2009 8:32 pm

Could you give the code for the helo as an example? I'm not quite sure how I to set up the rotational bundle so it only starts moving when the prop is moving, too... :?

I'll show what I have done now:
I created a shadow mesh containing only a shadow mesh for the prop (it's a Henschel B1) and saved it nice and tidy.

In geometries.con I created
Code: Select all
GeometryTemplate.create StandardMesh Henschel_prop_shadow
GeometryTemplate.file Hen_prop_shadow


In Objects.con I put them on very basic rot. bundles (just copied the ones from the radarbun), two, to be precise (as the Henschel has two props ;) ) .
Code: Select all
rem *** HenschelPropshadowleft ***
ObjectTemplate.create RotationalBundle HenschelPropshadowleft
ObjectTemplate.geometry Henschel_prop_shadow
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.setMinRotation 0/0/0
ObjectTemplate.setMaxRotation 0/0/0
ObjectTemplate.setMaxSpeed 110/0/0
ObjectTemplate.setAcceleration 10/0/0
ObjectTemplate.setContinousRotationSpeed 100/0/

rem *** HenschelPropshadowright ***
ObjectTemplate.create RotationalBundle HenschelPropshadowright
ObjectTemplate.geometry Henschel_prop_shadow
ObjectTemplate.hasDynamicShadow 1
ObjectTemplate.setMinRotation 0/0/0
ObjectTemplate.setMaxRotation 0/0/0
ObjectTemplate.setMaxSpeed 110/0/0
ObjectTemplate.setAcceleration 10/0/0
ObjectTemplate.setContinousRotationSpeed 100/0/


I then added these two to the main object:
Code: Select all
rem *** lodHenschel ***
ObjectTemplate.create LodObject lodHenschel
ObjectTemplate.hasMobilePhysics 1
ObjectTemplate.hasCollisionPhysics 1
ObjectTemplate.hasResponsePhysics 1
ObjectTemplate.lodselector HenschelLodSelector
ObjectTemplate.addTemplate HenschelComplex
ObjectTemplate.addTemplate HenschelSimple
ObjectTemplate.addTemplate HenschelWreck
ObjectTemplate.addTemplate HenschelPropshadowright
ObjectTemplate.addTemplate HenschelPropshadowleft
ObjectTemplate.setPosition 2.5471/0.6412/3.2984


and for test purposes alligned the shadowleft thingie (using 3dsmax vehicle tool, that's why I also left the Lod01 ;) ) . But sadly, this doesn't show up ingame at all :cry: No shadow, no LOD01, nothing
User avatar
Senshi
 
Posts: 695
Joined: Sun Oct 18, 2009 1:14 pm
Location: Germany

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Apache Thunder » Sat Dec 12, 2009 2:00 am

Nope that won't work. You have to addTemplate them to the PCO and NOT to any child object beyond that. For example you addTemplate the prop shadows to the Henschel, not the lodHenschel or the HenschelComplex. Must be addTemplated to directly to the PCO. ;)
ImageImageImage

I have cameras in your head!
User avatar
Apache Thunder
 
Posts: 1199
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Senshi » Sat Dec 12, 2009 2:45 am

Did that. Now the lod01 shows up ingame as intended ( i left it in as "marker" for now), but sadly, no shadow visible :( ).

Image

They grey prop is the "marker" Lod01 being visible without problems (imagine it spinning very fast ;) ), the second one currently still is on 0/0/0 and thus protruding from the body.

I'm not sure what could cause that problem. Did I mess up the standardmesh? I have a simple standardmesh with 3 models (.sm is called hen_prop_shadow.sm):
Image

The accompanying .rs files reads this:
Code: Select all
subshader "hen_prop_shadow_Material0" "StandardMesh/Default"
{
   lighting true;
   lightingSpecular false;
   materialDiffuse 0.588 0.588 0.588;
}
Last edited by Senshi on Sat Dec 12, 2009 3:05 am, edited 1 time in total.
User avatar
Senshi
 
Posts: 695
Joined: Sun Oct 18, 2009 1:14 pm
Location: Germany

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Apache Thunder » Sat Dec 12, 2009 3:00 am

Have you made sure the geometryTemplates also have the hasDynamicShadow line? I just noticed your geometry template code doesn't have it. You must specify the line for the geometry template in order for shadows to work at all.

Code: Select all
GeometryTemplate.hasDynamicShadow 1
ImageImageImage

I have cameras in your head!
User avatar
Apache Thunder
 
Posts: 1199
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Senshi » Sat Dec 12, 2009 3:09 am

Huh. And I thought it was enough to use ObjectTemplate.hasDynamicShadow 1 when i create the rot bundle...Then again, I don't often fiddle with these specific lines of code.

And yay, it works! How awesome is that?!?

Now only one question remains: How did you set it up so the shadow movement correlates with the actual prop RPM? At least there should be a difference between off-low-high... 8-) It does somehow react to the inputs (or so it seems), but it appears somehow..."delayed" Pretty weird.
User avatar
Senshi
 
Posts: 695
Joined: Sun Oct 18, 2009 1:14 pm
Location: Germany

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Apache Thunder » Sat Dec 12, 2009 3:14 am

Cool. :D

As for it matching up with engine RPM....not much chance of getting that to work. Rotational bundles unlike engines can't have a continuous rotational speed and yet stop spinning when the vehicle is not in use. Best you can do is add the continuous rotation speed code to it and then have the acceleration and max speed set in a way that matches that of the engine. (yep, you can have continuous rotational speed and have control over it at the same time!)

It might be tricky to get right though as engines speed up and slow down differently then rotational bundles.

(just noticed that your rotational bundle does indeed already use the continuous rotation speed code. :P )

Also if you want it to behave properly in multiplayer, be sure to add network info to it. It will speed 2x or faster in multiplayer if it does not have network info.
ImageImageImage

I have cameras in your head!
User avatar
Apache Thunder
 
Posts: 1199
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Senshi » Sat Dec 12, 2009 3:54 am

Hm, I tried adding an input to rot. bundle and giving it the very same settings as the engine, but oddly, that has different results on the rot. bundle than on the engine...The shadowmarker starts moving as it should (well, almost) simultaneously to the prop and all very fine, but then suddenly stops at once when hitting Max RPM (at least that's what I suspect...if you let go of the throttle, it starts moving again (AutomaticReset 1). This would be the perfect solution, but I'm not sure how to fix that problem...

On fiddling with MaxSpeed and MaxAcceleration...I'm still confused about these settings.

Why do they have 0/0/0 ? Which digit is responsible for what?

Atm the shadows are spinning up way too slow (->"delayed") and spin too long afterwards (when the actual engines are spinning down already...)

And all this is very weird anyway. The lod01 of the shadow mesh spins all the time, as set in the continuosrotation. But the shadow stands still as long as the engines stand still. Only when a pilot actually cranks up the engines, the shadow props start spinning too. I have absolutely no idea where BF42 makes that relation at all.

EDIT: My current guess that the game relates that to the speed the PCO is traveling at...the shadow stops spinning exactly when the PCO stops moving...interesting. Weird, but interesting.
User avatar
Senshi
 
Posts: 695
Joined: Sun Oct 18, 2009 1:14 pm
Location: Germany

Re: CSM - Dynamic shadows for turrets and gun barrels

Postby Apache Thunder » Sat Dec 12, 2009 4:16 am

Yes. That is something I noticed early on. Dynamic Shadows don't update when the PCO is stationary. It's why I can't get moving shadows to work on the stationary SA-3 . :(
ImageImageImage

I have cameras in your head!
User avatar
Apache Thunder
 
Posts: 1199
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA

Next

Return to General Modding Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests