Draw Distance (Done Right) Beta

ChthonChthon Posts: 1,855
edited May 2015 in Mod Showcase
[update 3/1/2015: New version is out. Removed RENDERALWAYS flag because it was causing problems. Same download link.]

This mod started out as what I thought would be a 15-minute side project to incorporate draw distance into my still-not-even-close-to-done Eternity mod. Turns out that doing draw distance "right" is a major pain in the ****, and no one's really done it before, as far as I know. Changing draw distance has side effects, cleaning up the side effects creates more side effects, and so on. I believe this is the first mod to attempt to sort out all the side effects. To give credit where credit is due, a great deal of the critical information here came from posts by Denton that no one properly appreciated at the time.

This mod is in beta. I think I've got everything sorted out, but I may have missed stuff. So please test it out and post your findings to this thread.
DOWNLOAD LINK

The rest of this post is dedicated to explaining what goes into doing draw distance correctly. This is useful for (1) people making their own draw distance mod, (2) people merging draw distance with other mods, and (3) people who want to know what to look for by way of potential errors to report.

I. Camera Distance
Camera distance is how far the camera is zoomed out from the ground. It's not "draw distance," but it's often part of the draw distance mods. Originally I had not intended on messing with camera distance, but balance issues with aggro forced me to.
Camera distance is set per map, and controlled by the CAMERAMULT value in the .TEMPLATE files found in MEDIA\LAYOUTS\.
The default for most outdoor levels is 1.2. The default for most indoor levels is 1.0.
Increasing indoor levels higher than 1.1 causes 2 problems: (1) sometimes the ceiling gets between the camera and the battlefield, and (2) sometimes you encounter "end of the word" bugs where you can see the boundary between the map and the undefined space beyond. These happen noticeably, but rarely, at 1.2, and more frequently as you increase camera distance.

For this mod, camera distance for indoor levels has been increased to 1.1.

II. Draw Distance
Draw distance is the distance away from the player at which monsters are rendered to the scene. Many people dislike the default draw distance because the monsters fade in too close for comfort, often in places that you thought were safe territory until the monster appeared.
Draw distance is controlled by some values in GLOBALS.DAT.
UNIT_NEAR_RANGE is the distance at which the game instantiates monsters as you move towards them. If you move away from an existing monster, at this distance it will instantly disappear into suspended state until you get near it again.
TRIGGER_NEAR_RANGE performs the same function as UNIT_NEAR_RANGE for the stash, shared stash, practice dummy, and landmarks.
OUTDOOR_UNIT_ACTIVE_RANGE is the distance at which a monster in an overworld map starts to fade in or out, and starts to do things like idle and wander.
INDOOR_UNIT_ACTIVE_RANGE is the same thing for dungeon maps.
Obviously, you want UNIT_NEAR_RANGE at least slightly bigger than both OUTDOOR_UNIT_ACTIVE_RANGE and INDOOR_UNIT_ACTIVE_RANGE.

Now, what are sane values for OUTDOOR_UNIT_ACTIVE_RANGE and INDOOR_UNIT_ACTIVE_RANGE? I did some testing using a modified elemental attunement and the damage shapes console command. Here are the results:

For a 1.2 camera zoom (i.e. most outdoors stuff):
12 - brushes bottom of the screen
18 - almost reaches bottom corners
20 - default
32 - all but a really, really tiny bit in the top corners
33 - full coverage

For a 1.0 camera zoom (i.e. most indoors stuff):
10 - brushes bottom of the screen
15 - almost reaches bottom corners
16 - default
26 - all but a tiny bit in top corners
27 - full coverage

For this mod, I set OUTDOOR_UNIT_ACTIVE_RANGE to 32 and INDOOR_UNIT_ACTIVE_RANGE to 29 (29 gets all but a tiny bit in the top corners at 1.1 zoom), and UNIT_NEAR_RANGE to 34.

Now, adjusting the draw distance has two major side effects:
1. Making the game keep track of and draw these extra monsters makes the program more resource-intensive, and less powerful computers can't handle it and will lag. This is an unavoidable cost of draw distance mods.
2. It causes all sorts of problems with the AI aggro model. In a minute, we're going to come back to this and look at what it takes to get the aggro working right.

III. Render Always Flag
When monsters come out from behind an obstruction, such as a UI menu, they fade in. This causes the same sort of "oh surprise, there's a monster there!" problem as a short draw distance. The solution is to set the RENDERALWAYS:true in the base monster so that all the monsters inherit it.


Unfortunately, this has a side effect. Some monsters don't display properly with RENDERALWAYS:true, so you need to go back through and set RENDERALWAYS:false for some units. This seems to happen mostly with breakables and other units that switch between two visible states. I think I've found them all, but maybe missed some. Please keep an eye out for these while testing.


Here's the list of units I changed back to RENDERALWAYS:false:
VAULT_LIGHTNING_TURRET.DAT
nether_flytrap_lootable_01.dat (ichor pod)
vaultturretmobilespawnertop.dat (mobile spawner top)
eggs flyer_egg_01.dat through 04 + trillbot_egg.dat (skara eggs)
tutaran_trap_01.dat
mine_trap_01
Automaton_Gen2_Rusted
Automaton_Gen2_MuddyEnvi1
Automaton_Gen2_MuddyEnvi2
Gargoyal_Lava ??? (think this one was just my imagination...)
barrel_poison_01
barrel_poison_stack_01
barrel_tnt
barrel_tnt_small

[edit: This breaks some particle effects, so it has to go. :(]

IV. The Horrible Mess That Is Aggro

A. Aggro Generally
This section is basic information about how aggro works in TL2. There are three ways that a monster can notice you. First, it can notice you if you are within its Sight Radius in a direction that falls within its View Angle (i.e., it notices you by looking at you). Second, it can notice you if you are within its Motion Radius, regardless of the direction (i.e., it notices you because it hears you/smells you/sees you from the corner of its eye). Third, it can notice you if you do damage to any monster that is within its DMG React Radius. (That includes the monster itself, except that critical hits reset the monster's "mind" so it won't react to them.) After the monster has noticed you, it decides whether or not to chase you based on its Follow Radius.


B. Problem #1: No Reaction to Long Range Pot Shots
The first major side effect of upping the draw distance is that it creates a situation in which you can hit monsters near the edge of the screen with long-range skills, but they won't react. So you can just sit back and take pot shots until they die. This makes the game braindead easy, and that's not good.

The solution is to increase the monsters' Follow Radii. But how much?

To sort this one out, I wrote a small program that surveys the dat files to make a report of the existing Follow Radii, and then changes them according to a mapping between old and new values that I provide. This enabled me to keep the new Follow Radii in roughly the same proportion to OUTDOOR_UNIT_ACTIVE_RANGE and INDOOR_UNIT_ACTIVE_RANGE as they were before. This means that there are still some monsters that you can take out with cheesy pot shots -- but they are the same monsters that you can do that to in vanilla TL2. Everything else will give chase when you attack it (or its buddies).

If you want to play with it, the program is here: DrawDistanceHelper.7z (I'm not offering support for this, since it was primarily intended for my own use.)

For this mod, I used the following mapping:
10->16; 14->22; 16->26; 17->27; 18->29; 19->30; 20->32; 22->33; 24->34; 25->34; 26->34; 27->35; 28->35; 30->36; 35->36; 36->36; 40->40.

C. Problem #2: Pot Shots Part Duex

In addition to increasing follow distance across the board, some monsters needed additional special tweaks to their aggro-related stats to make them adequately aggressive. Most of these were bosses, who would lose sight of the player and thus stop chasing until the player damaged them. While not as bad as monsters that won't chase at all, bosses that stop chasing and give you free hits are also too easy.

Here's the list of monsters that needed tweaks to increase their aggro-related stats:
C_STURM_MELEE_GUNNBREN_CHAMP.DAT (increase sight to 20 & follow to 32)
C_STURM_MELEE_STENNBRUM_CHAMP.DAT (increase sight to 20 & follow to 32)
C_STURM_MELEECHAMPELEC.DAT (increase sight to 20 & follow to 32)
C_STURM_MELEECHAMPFIRE.DAT (increase sight to 20 & follow to 32)
bandit_ranged (increase sight to 12)
bandit_ranged_tower (increase sight to 12)
boss_goblin_mine (increase sight to 30)
boss_map_troll (increase sight to 30)
boss_faceless_king (increase sight to 30)
boos_bloatfang (increase sight to 32)
boss_fungus (increase sight to 30)
boss_map_ancient_guardian (increase sight to 30)
boss_map_sturm (increase sight to 30)
boss_map_tutara (increase sight to 30)
boss_map_werewolf (increase sight to 30)
boss_map_wraith (increase sight to 30)
boss_netherim_shadow (increase sight to 30)
boss_pider_cave (increase sight to 30)
boss_werewwolf (increase sight to 30)
boss_wraith (increase sight to 30)
boss_yakutaur (increase sight to 30, motion to 25)

Also, some scripted events with bosses got broken, so I have to edit the map layouts for these two events:
increase sphere trigger range around winter widow to 29 (without this it's possible to hit the boss without ever triggering her active state)
increase bandit kings box trigger width from 6 to 12 (without this you won't get close enough to trigger the boss banner and music before aggroing the bosses)

Please keep an eye out for insufficiently aggressive monsters (especially bosses) when testing this mod out. I think I got them all, but I may have missed some.

D. Problem #3: Off-Screen Aggro
The second major side effect of increasing draw distance is that you get a lot of aggro coming from off-screen. The heart of this problem is the isometric view angle. Getting the draw distance circle (really an oval form the player's point of view) big enough to cover the top corners of the screen requires extending the circle way, way, way past the bottom of the screen. (Remember that the bottom of the screen is 12 units away at 1.2 zoom, but it takes a 32 unit circle to (almost) reach the top corners.) So there are quite a few monsters with sufficient sight and follow distances that they will aggro from pretty far beyond the bottom of the screen (and the sides to a lesser degree). (Especially since we just increased follow distances across the board...) Why doesn't this happen in vanilla TL2? Because the monsters don't exist yet when you enter the range at which they'd see and attack you. The low draw distance in vanilla TL2 is effectively clamping monster aggro range, and the draw distance increase removes that limit. (By the way, this is the problem that forced me to up the camera distance for indoors areas.)

I tweaked my little program to generate a report of monsters that end up with unusually large increases in the size of the area from which they'd aggro from off-screen. The math is as follows:
Distance_at_which_monster_will_attack = D = Min{sight_radius, draw_distance};
Size_of_area_from_which_monster_will_aggro_from_off-screen = S = Max{0, (D - distance_to_bottom_of_screen)};
so, S = Max{0, Min{sight_radius, draw_distance} - distance_to_bottom_of_screen};
DeltaS = New_S - Old_S;
If DeltaS is unusually big, then the monster may be a problem. (Ideally, DeltaS would have a baseline of zero, but that's not possible. I think I ended up with a baseline around 2-3.)
Using the auto-generated list of potential troublemakers, combined with some playtesting, I came up with the following list of monsters that needed some tweaks to their aggro-related stats:
FUNGUS_SPORE.DAT (set fdist back to 18)
FUNGUS_SPORE_PET.DAT (set fdist back to 18)
skill_skeletonwarrior_Agressive (versions 1-6) (set fdist back to 18)
skill_bloodskeleton (set fdist back to 18)
SKELETALANCIENT_MAGE.DAT (sight -3)
SKELETALANCIENT_MAGECHAMPION.DAT (sight -3, motion -1)
SKELETALANCIENT_MAGECHAMPIONNOMINION.DAT (sight -3; motion -1)
TROG_BRUTE.DAT (sight -2)
TROG_BRUTE_BOSS.DAT (sight -2)
TROG_BRUTE_POLEARM_BOSS.DAT (sight -2)
VARKOLYN_BRUTE.DAT (sight -3)
VARKOLYN_BRUTE_CHAMP.DAT (sight -3)
ARKOLYN_BRUTE_SPAWNER.DAT (sight -3)
VARKOLYN_CASTER.DAT (sight -2)
VARKOLYN_CASTER_CHAMP.DAT (sight -2)
VARKOLYN_CASTER_QUEST_DOOR.DAT (sight -2)
VARKOLYN_CASTER_SPAWNER.DAT (sight -2)
VARKOLYN_MELEE_CHAMP.DAT (sight -3)
VARKOLYN_RANGED.DAT (sight -3)
BOSS_MAP_WEREWOLF.DAT (sight -3)
BOSS_WEREWOLF.DAT (sight -3)
WEREWOLF.DAT (sight -3)
WEREWOLF2.DAT (sight -3)
WEREWOLF3.DAT (sight -3)
WEREWOLF_CELLAR_CHAMPION.DAT (sight -3)
WEREWOLF_CHAMPION.DAT (sight -3)
ZOMBIE_ANCIENT_CHAMP.DAT (sight, motion, & damage react -5)
ZOMBIE_SWAMP_WITCH.DAT (sight, motion, & damage react -5)

Also, it turns out that monsters using teleport+attack skills from off-screen is just no fair, so these two skills got their ranges cut down:
Gargoyal_Jump skill (range -5 (down to 15))
NetherimTeleportToPlayer skill (range -14 (down to 16))

Once again, I think I caught everything that needed fixing, but I may have missed some. So, please test the mod out, and post what you find.

(But please note that some amount of increased off-screen aggro is unavoidable. So don't expect to see it reduced back down to the levels in vanilla TL2 -- because it's not possible. Also, it wouldn't be fair. Increased draw distance gives the player a pretty big advantage in terms of hitting first and having a lot of time to keep on hitting while the monster closes the gap, so I don't feel too bad about letting the monsters sometimes get the drop on the player.)


E. Problem #4: Friendly Minions... Oh ****!

So.... it turns out that friendly summonable minions get a hidden bonus to some of their aggro-related stats. And this makes a complete and utter mess of their aggro behavior with increased draw distance. Surprise!

I'm not sure which stats get the hidden bonus, and I'm not sure how to design an experiment to isolate them properly. I suspect that Sight Radius, Motion Radius, and Follow Radius all get the bonus. Probably DMG React Radius, too. I'm also not 100% sure how big the bonus is. I suspect that it's equal to OUTDOOR_UNIT_ACTIVE_RANGE or INDOOR_UNIT_ACTIVE_RANGE depending on the current map. The one thing I am proud of figuring out is how to counteract the damned bonus to make minions sane again -- apply a passive sight bonus with a negative value. After messing around, I settled on a value of -23.5 for all friendly minions, plus special tweaks to individual minions:
spider-mine (negative sight bonus + revert follow back to 18)
hammerbot (no special tweaks, just the negative sight bonus)
machine_gun_bot (negative sight bonus + revert follow back to 18)
eng_copterbot (no special tweaks, just the negative sight bonus)
embermageavatar (no special tweaks, just the negative sight bonus)
wolfshade (negative sight bonus + adjust follow radius down to 10)
shadowling brute (no special tweaks, just the negative sight bonus)
shadowlingbat (negative sight bonus + adjust sight and motion down from 20 to 8, react up from 10 to 20)
zombiedustfiend (negative sight bonus + adjust sight and motion down from 20 to 8, react up from 10 to 20)
zombie pet (negative sight bonus + revert follow back to 18)
zombie item summon (negative sight bonus + revert follow back to 18)
zombie pet blood (negative sight bonus + revert follow back to 18)
skeleton warrior skill (negative sight bonus + follow from 18 down to 13, react 2 up to 7)
skeleton blood skill (negative sight bonus + follow from 18 down to 13, react 2 up to 7)
nether imp summon (negative sight bonus + follow from 18 down to 13, react 2 up to 7) (also fixed abnormally high follow on rank 1)
(Non-moving minions don't need adjustments)
(Did not adjust flaming sword since the spell isn't in vanilla TL2, and the skill is a complete mess that needs work in order to be usable.)
(Did not adjust aloe gel since the unit itself doesn't exist in vanilla TL2.)

This is something that could use a lot of play testing. It was quite difficult to get the minions to (mostly) stay on the screen without making them too unaggressive. There's also an unfixable problem with minions "island hopping" off the screen by taking out a nearby monster, then a second monster near the first monster and closer to the edge of the screen, then a third monster near the second monster and even closer to the edge of the screen, etc., until the damned minion's gone and run off the damned screen. (Wolf Shade is particularly bad about this because he's so darned fast.) In any event, I think the balance with the minions is definitely 1000x better than with a naive draw distance mod, even if it isn't perfect.

[edit: hey, I totally forgot to make notes for one more set of changes -- OOPS!]

V. The SPAWN_INVISIBLE Flag
The SPAWN_INVISIBLE flag causes monsters to not get rendered for their very first frame. This prevents monsters that are supposed to "pop up" from somewhere from flickering for a moment before popping up. (This problem is most notable with the Varkolyn in the dragon-theme dungeons.) To give credit where credit is due, I totally borrowed this list of monsters that need SPAWN_INVISIBLE set to true from Deezire's Unearthed Arcana mod:
ezro_crawler.dat
TUTARA_BRUTE.DAT
TUTARA_BRUTE_CHAMP.DAT
TUTARA_CASTER.DAT
TUTARA_CASTER_CHAMP.DAT
TUTARA_MELEE.DAT
TUTARA_MELEE_CHAMP.DAT
tutara_melee_heavy.dat
tutara_melee_shield.dat
TUTARA_RANGED.DAT
TUTARA_SPEAR.DAT
VARKOLYN_BRUTE_CHAMP.DAT
VARKOLYN_BRUTE_SPAWNER.DAT
VARKOLYN_CASTER.DAT
VARKOLYN_CASTER_CHAMP.DAT
VARKOLYN_CASTER_QUEST_DOOR.DAT
VARKOLYN_CASTER_SPAWNER.DAT
VARKOLYN_MELEE.DAT
VARKOLYN_MELEE_CHAMP.DAT
VARKOLYN_MELEE_SPAWNER.DAT
VARKOLYN_POPCORN_BOMBERS.DAT
VARKOLYN_POPCORN_SPAWNER.DAT
VARKOLYN_RANGED.DAT
VARK_BRUTE.DAT
VARK_POPCORN.DAT
Torchlight 2 Rapid Respec - Putting the "hack" in "hack-n-slash"
StashNinja - INFINITE Stash for Torchlight 2
NullMod - Play together in the same multiplayer game with different mods!

Comments

  • gytfunkegytfunke Posts: 571
    Well, this is relevant to my interests.
  • Kva3imodaKva3imoda Posts: 984 ✭✭
    Chthon, it sounds cool. I should try it. :)
    4ByzPdz.png 88pn2UZ.pngtrCrfep.png
  • ZiddersZidders Posts: 14,345 ✭✭✭
    I don't know how good I am at beta testing but I'll definitely give this a try. Thanks for all the effort you put into the stuff you do.
    ItfooQF.png
  • ChthonChthon Posts: 1,855
    I forgot to include in the notes: I also stole borrowed Deezire's fix for the flickering varkolyn pop-ups from Unearthed Arcana. Edited OP to include it.
    Torchlight 2 Rapid Respec - Putting the "hack" in "hack-n-slash"
    StashNinja - INFINITE Stash for Torchlight 2
    NullMod - Play together in the same multiplayer game with different mods!
  • One odd thing I ran into:

    Installed the mod and started a new character. In the intro area (Echo Pass), the Deathflingers were consistently not loading in until I was right on top of them. All the other mobs were loading correctly. Got to the Temple Steppes and the Deathflingers there were loading correctly. Started two more new characters and the Deathflingers in Echo Pass are now loading correctly, also. I did exit the game several times between the first character and the other two, and I'm guessing that's what fixed it.

    Beyond that single instance of odd behavior, everything seemed to work like a charm. Will post again if I run into anything else or figure out how to recreate that late-loading thing.
  • ChthonChthon Posts: 1,855
    One odd thing I ran into:

    Installed the mod and started a new character. In the intro area (Echo Pass), the Deathflingers were consistently not loading in until I was right on top of them. All the other mobs were loading correctly. Got to the Temple Steppes and the Deathflingers there were loading correctly. Started two more new characters and the Deathflingers in Echo Pass are now loading correctly, also. I did exit the game several times between the first character and the other two, and I'm guessing that's what fixed it.

    Beyond that single instance of odd behavior, everything seemed to work like a charm. Will post again if I run into anything else or figure out how to recreate that late-loading thing.

    I can't reproduce this. I suspect that it's a vanilla TL2 issue for two reasons: (1) I didn't touch this unit's file, and the only change it should be inheriting from base is RENDERALWAYS:true, which shouldn't cause this. Second, I have encountered this bug once before -- in Unearthed Arcana, and Deezire told me the same thing -- "I didn't touch that file." So, I guess let me know if you figure out how to make it happen again. I can't do anything to fix it until I can make it happen consistently.
    Torchlight 2 Rapid Respec - Putting the "hack" in "hack-n-slash"
    StashNinja - INFINITE Stash for Torchlight 2
    NullMod - Play together in the same multiplayer game with different mods!
  • ChthonChthon Posts: 1,855
    Update: For some unknown reason, renderalways breaks particle effects that connect from point to point, like stormclaw's lightning. So, I think it needs to go. I'll post a new version with it removed when I get time.
    Torchlight 2 Rapid Respec - Putting the "hack" in "hack-n-slash"
    StashNinja - INFINITE Stash for Torchlight 2
    NullMod - Play together in the same multiplayer game with different mods!
  • zeddicouszeddicous Posts: 9
    I use Zoomy Light(Steam) , but exterior/interior/monster draw distance is to far(and reduce FPS), I want suitable one :D
  • zeddicouszeddicous Posts: 9
    Hello, I found DESTROY DEAD CORPSE(local_settings) is invalid when use this mode, can you fix it?
  • ChthonChthon Posts: 1,855
    New version is out. I got rid of the RENDERALWAYS flag because it was causing problems. The download link is the same.
    zeddicous wrote:
    Hello, I found DESTROY DEAD CORPSE(local_settings) is invalid when use this mode, can you fix it?

    Try the new version. If that doesn't fix it for you, then I don't have the faintest idea what is causing your problem.
    Torchlight 2 Rapid Respec - Putting the "hack" in "hack-n-slash"
    StashNinja - INFINITE Stash for Torchlight 2
    NullMod - Play together in the same multiplayer game with different mods!
  • zeddicouszeddicous Posts: 9
    Chthon wrote:
    New version is out. I got rid of the RENDERALWAYS flag because it was causing problems. The download link is the same.
    Try the new version. If that doesn't fix it for you, then I don't have the faintest idea what is causing your problem.
    It's work!
    Now dead corpse will fade out , thank you!
  • FhaarkasFhaarkas Posts: 690
    I'm just waking up from my slumber to say - I hope this Eternity project carries on to the finish line. Just reading the OP of this thread gave me a nerdgasm that lit my desire to pick up TL2 again. /dramatic
    Remember, remember, the 20th of September.
    Random quote:
    I just stand back and try to manage the chaos. - Erich Schaefer
    Caution: Autistic thinker.
    Mods: Torchlight | Diablo Font | Foggy Town
Sign In or Register to comment.