Running out of lights

billw2015

King
Joined
Jun 22, 2015
Messages
837
Problem: Civ 4 will only support a max of 1024 DirectX lights active at the same time. We exhaust this limit quite easily when not using graphics paging. We hit this limit way before we run out of actual memory in some games.

But it confuses me because we should only need ONE light because there is only the sun (sometimes some effects from mine flares).

This lead me to start investigating what specific models are causing D3D light allocations (some esoteric techniques were required here!).

I started narrowing this down, and found the first offender. Who would have suspected the humble lobster?
Spoiler :

upload_2019-10-8_22-45-44.png



Here is what it looks like in game WITH those two lights:
Spoiler :

upload_2019-10-8_22-46-23.png



And here is what it looks like without:
Spoiler :

upload_2019-10-8_22-53-2.png



Better looking if anything. It is now being only lit by the sun instead of two random extra lights.
I also just found the sneaky shrimp has the same problem.

My plan now is to use the Python NIF tools and scan our entire model library for extra lights. Hopefully I can resolve the running out of lights crash just with model fixes and not more hacky things I was contemplating!
 
Yeah looks like looooad of units and buildings have extra MAX_Default_Light instances, so I will need to write a script to remove them all. Might improve the aesthetics somewhat as well.
 
Here is the full list as far as I can determine:
Spoiler :

art\effects\boomerang_throw\boomerang.nif
art\interface\screens\civilopedia\ancientbattlefield\ancientbattlefield.nif
art\interface\screens\civilopedia\civlopediaenvironmentwidget.nif
art\interface\screens\civilopedia\waterenvironment\waterenvironment.nif
art\structures\buildings\academy\anglo_academy\nypl.nif
art\structures\buildings\alhambra\alhambra.nif
art\structures\buildings\apiary\beehive3x.nif
art\structures\buildings\aqueduct\well.nif
art\structures\buildings\archimedes\siegeworkshop.nif
art\structures\buildings\bach\stephansdom.nif
art\structures\buildings\bahai_cathedral\zorocathedral.nif
art\structures\buildings\bahai_monastery\zoro_kloster.nif
art\structures\buildings\bahai_temple\ftemple.nif
art\structures\buildings\bank\europe_bank\tavern.nif
art\structures\buildings\bank\inca_bank\temple.nif
art\structures\buildings\bath_afrika\bath_afrika.nif
art\structures\buildings\bath_europe\bath_europe.nif
art\structures\buildings\bath_orient\bath_middle_east.nif
art\structures\buildings\bath_south_amerika\bath_southamerika.nif
art\structures\buildings\caravanpost\tradingpost.nif
art\structures\buildings\christianity\dp.nif
art\structures\buildings\divinemonument\virtue4_glory.nif
art\structures\buildings\fighting_pit\cell.nif
art\structures\buildings\flavianamphitheatre\colosseum_new.nif
art\structures\buildings\forbiddenpalace\africa_greatpalace\greatpalace.nif
art\structures\buildings\globetheater\greco_roman_globetheatre\la_scala.nif
art\structures\buildings\globetheater\middle_east_globetheatre\bath_middle_east.nif
art\structures\buildings\great_bath\bath_middle_east_water.nif
art\structures\buildings\great_bath\bath_middle_east.nif
art\structures\buildings\hermitage\meso_hermitage\chapultepec.nif
art\structures\buildings\heroicepic\afro_heroicepic\melentarma.nif
art\structures\buildings\hut\hut.nif
art\structures\buildings\jail\pacific_jail\orcpit.nif
art\structures\buildings\kingstournament\joust.nif
art\structures\buildings\library\asia_library\onsen.nif
art\structures\buildings\library\crescent_library\gondeshapur.nif
art\structures\buildings\library\europe_library\library_renaissance.nif
art\structures\buildings\library\native_library\chislev2.nif
art\structures\buildings\maginotline\bunker.nif
art\structures\buildings\military_academy\afro_militaryacademy\militaryacademy.nif
art\structures\buildings\military_academy\meso_militaryacademy\militaryacademy.nif
art\structures\buildings\nationalepic\meso_nationalepic\olmec.nif
art\structures\buildings\palace\an_african_palace.nif
art\structures\buildings\pergamonaltar\pergamonaltar.nif
art\structures\buildings\poacher_camp\tradingpost.nif
art\structures\buildings\pottery_hut\potteryshop.nif
art\structures\buildings\scotlandyard\barad.nif
art\structures\buildings\smac_caretakers\caretakers_city2.nif
art\structures\buildings\stable\stable_renaissance.nif
art\structures\buildings\tavern\tavern.nif
art\structures\buildings\tengri_song\an_orc.nif
art\structures\buildings\tengri_yurta\an_orc.nif
art\structures\buildings\theatre\cinema.nif
art\structures\buildings\theatre\india_theatre\theatre.nif
art\structures\buildings\university\asia_university\tokyo_national_museum.nif
art\structures\buildings\walls\post01_afro.nif
art\structures\buildings\walls\wall01_afro.nif
art\structures\buildings\walls\wall02_afro.nif
art\structures\buildings\walls\wall04_afro.nif
art\structures\buildings\wtc\wtc.nif
art\structures\cities\palmtrees.nif
art\structures\improvements\fort\palisades.nif
art\structures\improvements\machupicchu\machupicchu.nif
art\structures\improvements\solar\soltown.nif
art\structures\improvements\tidal harness\tidal.nif
art\terrain\resources\co2_ice\rice_freeze0000.nif
art\terrain\resources\co2_ice\rice_freeze0001.nif
art\terrain\resources\co2_ice\rice_freeze0002.nif
art\terrain\resources\co2_ice\rice_freeze0003.nif
art\terrain\resources\lobster\lobster.nif
art\unique\bavarian\marhathegnoz\lightcavalry.nif
art\unique\breton\paladin\frenchyheavyknight.nif
art\unique\catalonian\ballester\crossbowman.nif
art\unique\flemish\brabant_mercenaries\heavyswordsman.nif
art\unique\helvetii\tigurini_scouts\scout_fx_2.nif
art\unique\longobardi\dugundiz\heavyspearman.nif
art\unique\mohawk\mohawk_tracker\infantry.nif
art\unique\nok\nok_merchants\settler_2.nif
art\unique\ophir\treasure_guard\heavyswordsman.nif
art\unique\slovenian\carantanian_mercenary\pikeman.nif
art\unique\tlaxcaltec\yaotlalli_warrior\priest warrior.nif
art\units\african_sparth\ballista_elephant\khmer_elephantballista_fx.nif
art\units\african_sparth\cuirassier\cuirassier_african_fx.nif
art\units\african_sparth\heavy_cavalry\knight.nif
art\units\african_sparth\lancer\knight.nif
art\units\african_sparth\marine\marines2.nif
art\units\african_sparth\special_agent\spy_african_fx.nif
art\units\african_sparth\stonethrower\stone_bullet.nif
art\units\african_sparth\supply_train\supplytrain_fx.nif
art\units\african_sparth\worker_medieval\worker.nif
art\units\america_sparth\axeman\axeman.nif
art\units\america_sparth\crossbowman\crossbowman.nif
art\units\america_sparth\early_jet_fighter\f86.nif
art\units\america_sparth\heavy swordsman\maceman.nif
art\units\america_sparth\heavy_maceman\maceman.nif
art\units\america_sparth\heavy_pikeman\pikeman.nif
art\units\america_sparth\longbowman\longbowman.nif
art\units\america_sparth\mounted_infantry\horseman.nif
art\units\america_sparth\pikeman\heavyspearman_fx.nif
art\units\america_sparth\swordsman\lightswordsman.nif
art\units\androidinfantry\marines_fx.nif
art\units\animals\cobra\cobra.nif
art\units\animals\cow\cow_fx.nif
art\units\animals\dog_1\doggy_2.nif
art\units\animals\dog_1\doggy.nif
art\units\animals\horse\roaminghorse_fx.nif
art\units\animals\horse\roaminghorse.nif
art\units\asian_sparth\adventurer\horseman.nif
art\units\asian_sparth\ballista_elephant\khmer_elephantballista_fx.nif
art\units\asian_sparth\carabanier\cuirassier_fx.nif
art\units\asian_sparth\chaser\anim_effects\stone_bullet.nif
art\units\asian_sparth\cuirassier\cuirassier_fx.nif
art\units\asian_sparth\explorer\explorer_fx.nif
art\units\asian_sparth\heavy_cavalry\lightcavalry_fx.nif
art\units\asian_sparth\highwayman\cuirassier_fx.nif
art\units\asian_sparth\marine\marines2.nif
art\units\asian_sparth\mounted_infantry\horseman.nif
art\units\asian_sparth\outlaw\newnihoncuirassier.nif
art\units\asian_sparth\pioneer\modernworker_fx.nif
art\units\asian_sparth\stonethrower\anim_effects\stone_bullet.nif
art\units\asian_sparth\supply_train\supplytrain_fx.nif
art\units\asian_sparth\trench_machinegun\machinegunner.nif
art\units\asian_sparth\worker_modern\modernworker_fx.nif
art\units\babylon_sparth\guard\swordsman_fx.nif
art\units\babylon_sparth\lancer\heavy_cavalry_fx.nif
art\units\babylon_sparth\obsidian_spearman\sumerspearman_fx.nif
art\units\babylon_sparth\town_watchman\spearman_fx.nif
art\units\byzantium_sparth\archer\archer.nif
art\units\byzantium_sparth\axeman\axeman.nif
art\units\byzantium_sparth\chariot\chariot.nif
art\units\byzantium_sparth\heavy_swordsman\heavyswordsman_fx.nif
art\units\byzantium_sparth\mounted_infantry\horseman.nif
art\units\byzantium_sparth\pikeman\heavyspearman_fx.nif
art\units\byzantium_sparth\swordsman\lightswordsman_fx.nif
art\units\carabinier\cuirassier_fx.nif
art\units\carthage_sparth\currassier\cuirassier_fx.nif
art\units\carthage_sparth\town_watchman\germanicspearman.nif
art\units\celtic_sparth\pikeman\renaissancepikeman3.nif
art\units\confederate_sparth\chariot\chariot.nif
art\units\confederate_sparth\heavy_swordsman\maceman.nif
art\units\confederate_sparth\longbowman\longbowman.nif
art\units\confederate_sparth\mounted_infantry\horseman.nif
art\units\confederate_sparth\pikeman\pikeman.nif
art\units\confederate_sparth\swordsman\swordsman.nif
art\units\denmark_sparth\bomber\fokkertv.nif
art\units\denmark_sparth\chariot\chariot.nif
art\units\denmark_sparth\fighter\fokkerdxxi.nif
art\units\denmark_sparth\longbowman\longbowman.nif
art\units\denmark_sparth\pikeman\papalspearman.nif
art\units\dieselpunk\doublebiplane\anatravkh.nif
art\units\dieselpunk\superheavy_tank\p1000g5.nif
art\units\droidinfantry\marines_fx.nif
art\units\dutch_sparth\knight\knight.nif
art\units\dutch_sparth\light_cavalry\lightcavalry_fx.nif
art\units\dutch_sparth\spearman\heavyspearman_fx.nif
art\units\dutch_sparth\swordsman\lightswordsman_fx.nif
art\units\egyptian_sparth\ballista_elephant\khmer_elephantballista_fx.nif
art\units\egyptian_sparth\mailed_knight\heavy_cavalry_fx.nif
art\units\egyptian_sparth\stone_thrower\anim_effects\stone_bullet.nif
art\units\european_sparth\early_imperial_guard\heavyswordsman_fx.nif
art\units\european_sparth\heavy_axeman\maceman.nif
art\units\european_sparth\militia_medieval\peasant.nif
art\units\german_sparth\composite_bowman\germanyarcher2.nif
art\units\german_sparth\crossbowman\crossbowman2.nif
art\units\german_sparth\heavy_cavalry\heavycavalry_fx.nif
art\units\german_sparth\heavy_pikeman\pikeman.nif
art\units\german_sparth\lancer\lightcavalry.nif
art\units\german_sparth\longbowman\germanylongbowman.nif
art\units\german_sparth\machinegunner\machinegunner_fx.nif
art\units\indian_sparth\machinegunner\machinegunner.nif
art\units\indian_sparth\marine\marines.nif
art\units\japan_sparth\carabinier\cuirassier.nif
art\units\japan_sparth\cuirassier\cuirassier_fx.nif
art\units\japan_sparth\early_jet_fighter\jetfighter.nif
art\units\japan_sparth\machinegun\machinegunner.nif
art\units\japan_sparth\marine\marines2.nif
art\units\japan_sparth\modern_imperial_guard\infantry2.nif
art\units\japan_sparth\trench_infantry\infantry2.nif
art\units\korea_sparth\carabinier\cuirassier_fx.nif
art\units\mali_sparth\marine\malinewmarine.nif
art\units\megafauna\asian_ballista_mammoth\khmer_elephantballista_fx.nif
art\units\megafauna\egyptian_ballista_mammoth\khmer_elephantballista_fx.nif
art\units\megafauna\meast_ballista_mammoth\khmer_elephantballista_fx.nif
art\units\megafauna\sa_ballista_mammoth\khmer_elephantballista_fx.nif
art\units\megafauna\zebra_knight\knight.nif
art\units\megafauna\zebra\asian_zebra_cuirassier\cuirassier_fx.nif
art\units\megafauna\zebra\asian_zebra_knight\lightcavalry_fx.nif
art\units\megafauna\zebra\european_zebra_cuirassier\cuirassier_fx.nif
art\units\megafauna\zebra\european_zebra_knight\heavycavalry_fx.nif
art\units\megafauna\zebra\greek_zebra_cuirassier\cuirassier_fx.nif
art\units\megafauna\zebra\meso_zebra_cuirassier\cuirassier2_fx.nif
art\units\megafauna\zebra\mongol_zebra_cuirassier\cuirassier_fx.nif
art\units\meso_american_sparth\carabinier\cuirassier2.nif
art\units\meso_american_sparth\cuirassier\cuirassier_fx.nif
art\units\middle_eastern_sparth\early_imperial_guard\heavyswordsman_fx.nif
art\units\middle_eastern_sparth\heavy_cavalry\knight.nif
art\units\middle_eastern_sparth\heavy_swordsman\heavyswordsman_fx.nif
art\units\middle_eastern_sparth\machinegun\memachinegunner.nif
art\units\middle_eastern_sparth\supply_train\supplytrain_fx.nif
art\units\mongol_sparth\cuirassier\cuirassier_fx.nif
art\units\mongol_sparth\javalineer\mongolian_javelin.nif
art\units\mongol_sparth\machine_gunner\machinegunner.nif
art\units\native_american_sparth\guard\aztec_jaguar_fx.nif
art\units\native_american_sparth\machinegun\machinegunner2.nif
art\units\native_american_sparth\mailed_knight\unique_byzantine_cataphract_fx.nif
art\units\native_american_sparth\supply_train\supplytrain_fx.nif
art\units\nubia_sparth\carabinier\cuirassier_fx.nif
art\units\planes\jet_interceptor\f104.nif
art\units\polynesia_sparth\infantry\polyinfantry.nif
art\units\polynesia_sparth\machine_gun\polymachinegunner.nif
art\units\polynesia_sparth\marine\marines2.nif
art\units\rome_sparth\war_elephant\romanelephantfinal_fx.nif
art\units\russian_sparth\early_jet_fighter\mig15.nif
art\units\russian_sparth\explorer\worker_fx.nif
art\units\russian_sparth\modern_fighter\mig21.nif
art\units\russian_sparth\modern_interceptor\mig25.nif
art\units\ships\early_carrier\langley.nif
art\units\south_american_sparth\adventurer\knight.nif
art\units\south_american_sparth\ballista_elephant_sa\khmer_elephantballista_fx.nif
art\units\south_american_sparth\great_hunter_sa\rifleman.nif
art\units\south_american_sparth\infantry\marines.nif
art\units\south_american_sparth\light_cavalry_sa\heavy_cavalry_fx.nif
art\units\south_american_sparth\mailed_knight\unique_byzantine_cataphract_fx.nif
art\units\south_american_sparth\mounted_infantry_sa\mountedinfantry_fx.nif
art\units\south_american_sparth\trench_infantry\infantry_fx.nif
art\units\south_american_sparth\trench_machinegun\machinegunner.nif
art\units\spanish_sparth\early_imperial_guard\spainmaceman2.nif
art\units\spanish_sparth\heavy_cavalry\heavycavalry_fx.nif
art\units\spanish_sparth\infantry\infantry_fx.nif
art\units\spanish_sparth\machine_gun\machinegunner.nif
art\units\spanish_sparth\marine\marines.nif
art\units\spanish_sparth\swordsman\lightswordsman.nif
art\units\stone_thrower\anim_effects\stone_bullet.nif
art\units\stonethrower\anim_effects\stone_bullet.nif
art\units\unique\carib\blowgunner\rifleman.nif
art\units\unique\india\urumi\heavyswordsman.nif
art\units\unique\iroquois\tomahawk_thrower\anim_effects\stone_bullet.nif
art\units\unique\italy\elmeti\heavycavalry.nif
art\units\unique\khmer\phak'ak\spearman.nif
art\units\unique\papuan\cannibal\aztec_jaguar_fx.nif
art\units\unique\polish\wingedcavalry\cuirassier_fx.nif
art\units\unique\saxon\raider\swordsman.nif
art\units\unique\spartan\warrior\spearman_fx.nif
art\units\viking_sparth\chariot\chariot_celtic.nif
art\units\viking_sparth\crossbowman\crossbowman.nif
art\units\viking_sparth\heavy_axeman\axeman.nif
art\units\viking_sparth\heavy_pikeman\halberdier.nif
art\units\viking_sparth\infantry\infantry.nif
art\units\viking_sparth\knight\horseman.nif
art\units\viking_sparth\longbowman\longbowman.nif
art\units\viking_sparth\machine_gun\machinegunner_fx.nif
art\units\viking_sparth\marine\marines_fx.nif
art\units\viking_sparth\pikeman\spearman.nif
 
I was curious about what the issue could be, not all that surprised that there's a lot of unnecessary light sources in some of our models actually.
Many of our models are jury rigged mixtures of different models put together and I know there's a lot of leftover junk data in many of them.

Lobster... lol... Get rid of those light sources where it makes little sense, I (we) can modify the object material and textures if we don't like how it looks as a result of the light removal. No problem.

Edit: {
These probably have no reason to have light sources:
art\units\animals\cobra\cobra.nif
art\units\animals\cow\cow_fx.nif
art\units\animals\dog_1\doggy_2.nif
art\units\animals\dog_1\doggy.nif
art\units\animals\horse\roaminghorse_fx.nif
art\units\animals\horse\roaminghorse.nif

If units hold torches or some modern mechanized units have actual lights like a cars front light we should imo let those be to begin with, same with other models I guess.
Yeah looks like looooad of units and buildings have extra MAX_Default_Light instances, so I will need to write a script to remove them all. Might improve the aesthetics somewhat as well.
Probably an ok solution, just don't let the script remove the light sources in:

art\interface\screens\civilopedia\ancientbattlefield\ancientbattlefield.nif
art\interface\screens\civilopedia\civlopediaenvironmentwidget.nif
art\interface\screens\civilopedia\waterenvironment\waterenvironment.nif

These models are showed in the pedia and consist of entire scenes, I don't think the map sunlight reach these scenes.
}
 
Last edited:
Probably an ok solution
It should be correct, MAX_Default_Light is ones added by the MAX exporter accidentally (I'm going to assume unless someone knows different). The list above includes every model with a light, I didn't filter for only ones with MAX_Default_Lights.
The lights in ancientbattlefield.nif for instance aren't MAX default ones:
Spoiler :

upload_2019-10-9_1-12-55.png

 
It should be correct, MAX_Default_Light is ones added by the MAX exporter accidentally (I'm going to assume unless someone knows different). The list above includes every model with a light, I didn't filter for only ones with MAX_Default_Lights.
The lights in ancientbattlefield.nif for instance aren't MAX default ones:
Ah ok, cool.

I've only used blender to make models for C2C, as it is free, it doesn't add any light sources by default.
 
Looks like our old friend and former modder Sparth like to use them a lot. lol
 
Looks like our old friend and former modder Sparth like to use them a lot. lol
It might have been, but it could also have just been the entire modding community having no idea there was a limit. Sparth did a lot of reskinning, or rather, repainting the texture layer, but I'm not sure this is a part of anything he actually worked on directly.
 
It might have been, but it could also have just been the entire modding community having no idea there was a limit. Sparth did a lot of reskinning, or rather, repainting the texture layer, but I'm not sure this is a part of anything he actually worked on directly.
I agree. There is a lot to graphics and most just start by copying what is available and then learning a bit about one bit so that they can improve things. Sparth also got rid of a lot of duplication.
 
in any case, it's always very nice Simple solutions can be found to critical problems, especially when it's basically a compounded thing that was done unknowingly, makes one wonder how much room there actually is in comparison to what is being used,
 
in any case, it's always very nice Simple solutions can be found to critical problems, especially when it's basically a compounded thing that was done unknowingly, makes one wonder how much room there actually is in comparison to what is being used,
Could easily be responsible for some late game crashes I've been assuming were MAFs.
 
Okay these fixes are in now, I hit max 20-30 lights now while panning around the map, instead of >1000.
If you notice any buildings that look too dark then make sure to report them, I removed *all* lights, and that included non-default ones in 30 or so buildings. The tavern building had 4 lights on its own, and was also moon-lighting as a bank, meaning 8 potential extra lights per city if they are paged in. You can see how this can easily escalate to a crash and its only one building.

We can't control how many instances exist on the map (and thus if it will crash or not), so there needs to be a strong argument for having *any* lights in units or buildings I think, and only if a good effect can't be achieved using texturing, materials and emissivity (which doesn't use a light index).

I can now run stably at about 2500MB memory usage (any higher and I get actual out of memory crashes on EOT in the test save I am using). This allows paging in of most of the map, so I relaxed paging settings to improve how things look.
 
Okay these fixes are in now, I hit max 20-30 lights now while panning around the map, instead of >1000.
If you notice any buildings that look too dark then make sure to report them, I removed *all* lights, and that included non-default ones in 30 or so buildings. The tavern building had 4 lights on its own, and was also moon-lighting as a bank, meaning 8 potential extra lights per city if they are paged in. You can see how this can easily escalate to a crash and its only one building.

We can't control how many instances exist on the map (and thus if it will crash or not), so there needs to be a strong argument for having *any* lights in units or buildings I think, and only if a good effect can't be achieved using texturing, materials and emissivity (which doesn't use a light index).

I can now run stably at about 2500MB memory usage (any higher and I get actual out of memory crashes on EOT in the test save I am using). This allows paging in of most of the map, so I relaxed paging settings to improve how things look.
Awesome stuff, hopefully we are now mostly rid of the mysterious CTD that occurs when simply panning the camera around the map of a somewhat advanced game.
 
Yeah I'm keeping it on the dl though :cooool:
Didn't need to take out those guns to fix this problem in the end, so I just put them away for later.
That Yudisitra save (Nanotech era with 19 AIs, Gigantic map (by area), Deity, Eons) takes around 1500 MB after it loaded.
Even with whole map revealed and with constant panning it climbed to only 1900 MB.

I disabled popups - it goes instantly to next city screen, when filling building queue.
 
You have MemSaver on if I remember correctly, I have it off and that save will crash OOM on EOT without paging enabled. The settings I used for default paging are based on making that save not crash!
 
You have MemSaver on if I remember correctly, I have it off and that save will crash OOM on EOT without paging enabled. The settings I used for default paging are based on making that save not crash!
So even old Gigantic (24 000 tiles - now is around 13 000 tiles - original C2C_World Huge) and Pits map (bit bigger than Gigantic) should be be playable in Nanotech and later eras :D
Transhuman era has few units, and galactic and later have effectively no units unlocked - there are few of them but they all are space ones.
 
Back
Top Bottom