WMO/PortalCulling

From wowdev
Jump to navigation Jump to search

// This is my implementation for portal culling, probably different than blizzard's Zee (talk)

Find if camera position is inside the WMO bounding box
  If yes, find if the camera is inside the bounding box of one or more wmo groups
    Go through each group that the camera is present in
      Render group
      The next part needs to run recursively so that we can see through multiple portals at once
      Find all the portals in the current group from MOPR
      Check if the camera(player) is facing the front or the back of the portal:
        dist = norm.x * pos.x + norm.y * pos.y + norm.z * pos.z + pDist;
        * norm is the plane normal that comes from MOPT
        * pos is the camera position (player position) relative to the wmo
        if the side value in MOPR is negative then
          if dist > 0 then return true
        else
          if dist < 0 then return true
      If the camera is facing the front of the portal, then we need to calculate if the portal is in the view frustrum
      PortalCulling()
      the view frustrum needs to be passed recursively to the portal culling function, starting with the screen frustrum which is usually going to be between Minimum X/Y = 0 and Maximum X/Y = 1
      the next frustrum that is passed is that of the current portal, which is calculated as so:
        convert the portal vertices into screen space, by multiplying each one with the view and projection matrices of the camera
        go through each vertex and check:
          If the Z coord of the screen point is positive: (ignore negative because it's behind the camera)
            If the X coord of all of the screen points are less than the minimum X value of the input frustrum or is greater than the maximum X value then the in frustrum and portal don't intersect
            If the X value is inbetween these values then repeat the test but with the Y values.
        If the in frustrum and portal do intersect then
          find the group in MOPR that shares the same portal id and draw it
          Run PortalCulling() recursion here, but this time instead of passing screen frustrum, pass the min and max X/Y of the current portal's vertices in screen space