Page 1 of 1

Tutorial: How to Create Cockpit Shadow Maps

Posted: Thu Sep 10, 2020 6:29 am
by blue_max
Shadow maps for cockpits were introduced some time ago, but I never explained in detail how to create them. These are the steps you'll have to follow to create shadow maps for cockpits:

1. Using Jeremy's XwaOptEditor, open the cockpit OPT and export it to OBJ. For this example I'll be using the MissileboatCockpit.OPT.

2. Import the OBJ in Blender (File->Import->OBJ) using the following settings:

OBJ-import-settings-with-split.png

3. We want to make a closed cockpit OBJ and we'll remove things we don't care about, like small details, the hull, wings, etc. This is what the Missileboat Cockpit OPT looks like at the beginning:

Missileboat-1.png

This is what it looks like after removing big things, like the hull, wings and other stuff that we don't care about:

Missileboat-2.png

Re: Tutorial: How to Create Cockpit Shadow Maps

Posted: Thu Sep 10, 2020 6:32 am
by blue_max
4. Cockpits may have some gaps in areas that aren't normally visible, like these:

Missileboat-3.png

These holes need to be closed or they'll also create weird gaps in the projected shadows:

Missileboat-4.png

Re: Tutorial: How to Create Cockpit Shadow Maps

Posted: Thu Sep 10, 2020 6:33 am
by blue_max
5. Remove all the details and close any remaining gaps. This is how the cockpit looks now, notice all the buttons and DC elements:

Missileboat-5.png

This is what it looks like after removing all those small details:

Missileboat-6.png

Re: Tutorial: How to Create Cockpit Shadow Maps

Posted: Thu Sep 10, 2020 6:36 am
by blue_max
6. Export the OBJ using the following settings:

OBJ-export-settings.png

7. Name the OBJ "Ship-Name-Cockpit.OBJ" (in this case that would be MissileboatCockpit.obj) and put it in the ShadowMapping subdirectory.

8. Finally, test the shadow map in the game. If you notice that the map doesn't match the geometry, you may need to flip the axes. You can do that by flipping the OBJ itself, or you can do it in the material file for the cockpit by adding the "shadow_map_mult_x/y/z" setting in the [Default] section. For instance, XwingCockpit.mat has this section to flip the Z-axis of the shadow map:

Code: Select all

[Default]
Metallic   = 0.4
Intensity  = 0.8
Glossiness = 0.08
shadow_map_mult_z = -1

For this example, I checked the yoke and the sticks on both sides, the shadows match, so we're good:

shadow-test-1.jpg
shadow-test-2.jpg

Re: Tutorial: How to Create Cockpit Shadow Maps

Posted: Thu Sep 10, 2020 6:37 am
by blue_max
Notes:

* Don't worry about normals or UVs in the Shadow Map OBJ, we don't need them. In fact, the OBJ should only contain vertices and faces.

* The Shadow Map should only contain triangles. Blender can triangulate everything in the final export step, but if you're using other software you'll have to do that manually.

* Computing shadows does have some (minor) impact in performance. Obviously the more complex your shadow map is, the bigger the penalty. I've found that removing the wings, hull and other stuff doesn't really affect the shadows, and has a barely noticeable impact in performance. You may keep these elements, though.

* The shadow maps don't support S-Foils or other cockpit motion. So if you add the wings to your X-Wing shadow map, the shadow map won't move with the S-Foils, sorry!

Re: Tutorial: How to Create Cockpit Shadow Maps

Posted: Thu Sep 10, 2020 4:00 pm
by JeremyaFr
Thank you for the tutorial :thumbs:

Re: Tutorial: How to Create Cockpit Shadow Maps

Posted: Wed Jun 22, 2022 8:20 am
by Vince T
@blue_max I'll move this tutorial over to the new Guides section :)