Iggy's Lighting Misadventures(and attempts at optimization)

"I thought this was going to be easy" I thought to myself. Oh... what a fool I was.

For the past few days I have been poking around the files of the PC version of Saints Row 2. You see, the xenia(Xbox 360) emulator had a recent update that significantly improved performance. One of those games being none other than Saints Row 2. With it rendering nearly everything perfectly, except for light coronas which seems to clip through geometry. I started taking loads of screenshots of Saints Row 2 both of xenia and the PC port. Shortly afterwards I started playing a game of spot-the-difference between the two. That is when I noticed something that caught my eye. Saints Row 2 on PC has more shadow maps than the console counterpart. Not only that but the areas that had additional shadows was where the frame rate dipped. "Hmmmmm... am I on to something?" I thought to myself. I quickly googled various terms to see if anybody else noticed this and from my results the answer was no.

PC screenshot above, xenia screenshot below:
pcshadows.png
consoleshadows.png

This is where I developed a theory, that the shadows were what was responsible for the framerate drops for the interiors in the PC version. I figured that if I could disable the shadows from the light source I could improve the performance in these areas. I thought I could release an "Optimized Stilwater" mod. First, I tried out Möyh Mäyh's experimental map editor, just to test things out I replaced the light you see under the pole dancer with a plant. I thought the light object itself was responsible for casting lights. Nope! Just a pole dancer on a plant with a terrible frame rate. So then I messed around with various "lightset" files. Only to find out that those files are for editing light data in cutscenes, not the map itself. A bit frustrated at my first couple attempts I browsed the forums and learned of Möyh Mäyh's SR2 Chunk Kaitai. It is a tool that lets you view the data of the "chunks" files in the game. It is still very much a work-in-progress so I asked him if I could view and edit lighting data with the tool. Surely enough I could! In fact he added that just hours before I asked.
nopcshadows.png

1665177432993.png


Then things got a little bit funky to say the least. Each light source in the game (seems) to have 36 flags. The thing is we don't know what most of these do, yet. Eager to mess with the lighting I found the light I wanted to edit. "Finally, people could play Saints Row 2 at a consistent(ish) frame rate after all these years!" I was excited. I eagerly booted up the game to see that successfully manged to edit the light to stop casting shadows! Only... um the framerate drop is still there. Welp, there went my theory. Perplexed, I continued fiddling with the other lighting flags. Setting all(except pos) of them to 0, and wouldn't you know it essentially deleted the light and the frame rate improved dramatically! But then another issue occurred, the light in the office was not working. How did that happen? Shortly afterwords I got a crash. Now I was even more perplexed. With no idea what else to do I went through a cycle of setting every "unk" to 0 except 1 which was left at the default setting. I did this in sequential order, until I found the culprit. "Unk10" when messed with seems to be responsible for the the performance issues and the crashes. All of the other "unks" don't seem to have any effect on the performance or stability. As of this date we still don't know exactly what "unk10" does. But I can confirm that Möyh Mäyh will be looking into unk10 soon. The remedy of Saints Row 2's frame drops may soon be within grasp.

I will be sure to post any updates regarding these endeavours. ;)

P.S. A big thanks to Möyh Mäyh for his tools and all his help!
 
A quick glance at random random chunks, unk10 is an uint, with values such as 0, 75, or 100. I don't have the game installed where I work on this, so I guess I have to download it before I can say anything meaningful. Unknown 2 through 4 seem to be rgb.

View attachment 33787
Yeah, that tracks. A bit curious why some of the values in unk10 vary so much. Here is unk10's value for the pole dancer light mentioned earlier.
1665937221813.png
 
This is just a random suggestion of mine but why not just copy the lighting&shadows of the console port to the pc port (i don't know anything about modding).
 
I am afraid it just isn't that simple. For starters the console version appears to have an entirely different file system. We would have to get the chunk files from it, which I'm not really allowed to talk about because the forums don't allow console modding. There could also be many other changes between the ports we are not aware of.
 
Yeah, that tracks. A bit curious why some of the values in unk10 vary so much. Here is unk10's value for the pole dancer light mentioned earlier. View attachment 33788
3 bytes of FF? It's signed integer then. I wonder what it does. Anyway, this one isn't shadows. Unk0 is bit flags and I found shadows from there.

1666367224991.png

Setting those 2 bits controls shadows.

Edit: I did a dumb.
 

Attachments

  • 20221021181447_1.jpg
    20221021181447_1.jpg
    160.5 KB · Views: 153
Last edited:
Good to know! I have also done some more poking around and I noticed something. If you disable all the shadows in the options, replay a cutscene and then visit an area that had the performance issues. You will get the frame rate drops as if the shadows were enabled even though they aren't! Something bizarre is going on, I have no idea what is causing it.
 
Barrio district and some areas has issues this lagging will just getting worst it means the game wants you quickly visit the store and make it crashed i dont know what cause it+ no wonder modders giving advice always skipping the cutscenes because it will affect the mission ingame laters..
 
Alright after doing chatting with Möyh in discord I can confirm that disabling shadows does actually improve performance. Also thanks to Möyh's new chunk editor update I can now change lighting data without having to fiddle with a hex editor. I plan on releasing version 0.1 of the "Optimized Stilwater" mod within the next 24 hours. Version 0.1 will only effect Saints Row HQ, as this version will exist more as a proof-of-concept than an actual mod. I still need to find every single chunk that needs optimizing. "Optimized Stilwater" will come in 2 editions, the first will disable all of the shadows in unoptimized chunks, the second will only disable some of the shadows and will leave some of the more "notable" shadows untouched. Like the light emitting from the Saints HQ statue for example, or chandaliers.

In addition I am planning on releasing files that documents all of the chunk files that tells you what is what. Because the file names aren't exactly great identifiers.
 
Last edited:
Alright after doing chatting with Möyh in discord I can confirm that disabling shadows does actually improve performance. Also thanks to Möyh's new chunk editor update I can now change lighting data without having to fiddle with a hex editor. I plan on releasing version 0.1 of the "Optimized Stilwater" mod within the next 24 hours. Version 0.1 will only effect Saints Row HQ, as this version will exist more as a proof-of-concept than an actual mod. I still need to find every single chunk that needs optimizing. "Optimized Stilwater" will come in 2 editions, the first will disable all of the shadows in unoptimized chunks, the second will only disable some of the shadows and will leave some of the more "notable" shadows untouched. Like the light emitting from the Saints HQ statue for example, or chandaliers.

In addition I am planning on releasing files that documents all of the chunk files that tells you what is what. Because the file names aren't exactly great identifiers.
Greattttt cant wait to see it!!
 
Back
Top