wowserhq / wowser

World of Warcraft in the browser using JavaScript and WebGL
MIT License
243 stars 63 forks source link

Implement distance culling #162

Open fallenoak opened 8 years ago

fallenoak commented 8 years ago

After watching a few videos of people playing WotLK-era World of Warcraft, I'm almost certain that the client implements distance culling of some sort. In particular, it seems like small-ish map doodads are culled much earlier than large map doodads and WMOs.

Ideas

Some client constants (from MoP):

Potentially interesting client functions (from MoP):

Other interesting code bits (from MoP):

int CWorldView::Update(*args)
{

  ...

  if (World::GetTerrainLod()) {
    if (World::GetTerrainLodDist() < s_fadeDistScale * CWorldView::s_fadeDistDefault) {
      CWorldView::s_fadeDistMax = LODWORD(World::GetTerrainLodDist());
    } else {
      CWorldView::s_fadeDistMax = s_fadeDistScale * CWorldView::s_fadeDistDefault;
    }
  }

  CWorldView::s_fadeDistMin = CWorldView::s_fadeDistMax - CWorldView::s_fadeRangeDefault;
  CWorldView::s_fadeDistMaxSqr = CWorldView::s_fadeDistMax * CWorldView::s_fadeDistMax;
  CWorldView::s_fadeDistMinSqr = CWorldView::s_fadeDistMin * CWorldView::s_fadeDistMin;

  ...

}
int World::GetTerrainLod()
{
  if (World::s_terrainLodDist >= 0.01) {
    return World::s_terrainLodDist <= fmaxf(World::s_farClip, World::s_minFarClip) * 0.6;
  } else {
    return 0;
  }
}
int World::GetWmoLod()
{
  if (World::s_wmoLodDist >= 0.01) {
    return World::s_wmoLodDist <= fmaxf(World::s_farClip, World::s_minFarClip) * 0.6;
  } else {
    return 0;
  }
}
long double World::GetHorizonFarClip()
{
  return (fmaxf(World::s_farClip, World::s_minFarClip) * World::s_horizonFarClipScale);
}
void World::SetMinFarClip(float minFarClip)
{
  if (minFarClip < 200.0) {
    World::s_minFarClip = 200.0;
  } else if (minFarClip > 2600.0) {
    World::s_minFarClip = 2600.0;
  } else {
    World::s_minFarClip = minFarClip;
  }

  return World::s_minFarClip;
}
fallenoak commented 8 years ago

According to schlumpf on #modcraft:

[10:28:48] [fallenoak] i seem to recall seeing doodads fading in as the camera approaches... but perhaps that's just from the files having to load? [10:29:44] [schlumpf] should be based on their bounding box + distance, yes [10:29:57] [fallenoak] right, so bigger objects would stay visible longer? [10:30:11] [schlumpf] yes

As part of this issue, it might be worth spending some time hunting around IDA to see if there's anything to be gleaned about exactly how the official client handles the relationship between doodad bounding boxes and distance.