Tutorial: How to Create Cockpit Shadow Maps

This forum is dedicated to sharing knowledge via guides, tutorials and any other form of how-to's. It may in time succeed the modding wiki.
Post Reply

Tutorial: How to Create Cockpit Shadow Maps

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Thu Sep 10, 2020 6:29 am

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
You do not have the required permissions to view the files attached to this post.
Last edited by Forceflow on Thu Sep 10, 2020 8:57 am, edited 1 time in total.
Reason: Stickied

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Thu Sep 10, 2020 6:32 am

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
You do not have the required permissions to view the files attached to this post.

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Thu Sep 10, 2020 6:33 am

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
You do not have the required permissions to view the files attached to this post.

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Thu Sep 10, 2020 6:36 am

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
You do not have the required permissions to view the files attached to this post.

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Thu Sep 10, 2020 6:37 am

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!

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Thu Sep 10, 2020 4:00 pm

Thank you for the tutorial :thumbs:

User avatar
Vince T
Fleet Admiral (Administrator)
Posts: 14045
Joined: Fri Apr 27, 2001 11:01 pm
Contact:

Post by Vince T » Wed Jun 22, 2022 8:20 am

@blue_max I'll move this tutorial over to the new Guides section :)
Your ship, Captain. I need a drink. - Vince Trageton
Vince T's X-Wing HQ - where the bad guys get their gear

Post Reply