Graphics Map Asset (Ghosts)

From COD Engine Research
Jump to: navigation, search

The graphics map (or gfx_map) has existed on every Call of Duty so far and is part of the D3DBSP system produced by Radiant. Where the collision map is used for collision data in the map, the graphics map holds visual systems such as lights and particularly the dPVS system. The Dynamic Potentially Visible Sets (dPVS) were developed by Umbra Software to compute visibility databases in real time, and power the Call of Duty engine to this day.

struct GfxPortal;
 
struct __declspec(align(8)) GfxSky
{
  int skySurfCount;
  int *skyStartSurfs;
  GfxImage *skyImage;
  char skySamplerState;
};
 
struct GfxWorldDpvsPlanes
{
  int cellCount;
  cplane_s *planes;
  unsigned __int16 *nodes;
  unsigned int *sceneEntCellBits;
};
 
struct GfxCellTreeCount
{
  int aabbTreeCount;
};
 
struct __declspec(align(8)) GfxAabbTree
{
  Bounds bounds;
  unsigned __int16 childCount;
  unsigned __int16 surfaceCount;
  unsigned int startSurfIndex;
  unsigned __int16 smodelIndexCount;
  unsigned __int16 *smodelIndexes;
  int childrenOffset;
};
 
struct GfxCellTree
{
  GfxAabbTree *aabbTree;
};
 
struct GfxPortalWritable
{
  bool isQueued;
  bool isAncestor;
  char recursionDepth;
  char hullPointCount;
  float (*hullPoints)[2];
  GfxPortal *queuedParent;
};
 
struct DpvsPlane
{
  float coeffs[4];
};
 
struct GfxPortal
{
  GfxPortalWritable writable;
  DpvsPlane plane;
  float (*vertices)[3];
  unsigned __int16 cellIndex;
  unsigned __int16 closeDistance;
  char vertexCount;
  float hullAxis[2][3];
};
 
struct GfxCell
{
  Bounds bounds;
  int portalCount;
  GfxPortal *portals;
  char reflectionProbeCount;
  char *reflectionProbes;
  char reflectionProbeReferenceCount;
  char *reflectionProbeReferences;
};
 
struct GfxReflectionProbeVolumeData
{
  float volumePlanes[6][4];
};
 
struct __declspec(align(8)) GfxReflectionProbe
{
  float origin[3];
  GfxReflectionProbeVolumeData *probeVolumes;
  unsigned int probeVolumeCount;
};
 
struct GfxReflectionProbeReferenceOrigin
{
  float origin[3];
};
 
struct GfxReflectionProbeReference
{
  char index;
};
 
struct GfxLightmapArray
{
  GfxImage *primary;
  GfxImage *secondary;
};
 
struct GfxWorldVertex
{
  float xyz[3];
  float binormalSign;
  GfxColor color;
#if defined(_XBOX) || defined(PS3)
  PackedTexCoords texCoord;
  PackedTexCoords lmapCoord;
#else
  float texCoord[2];
  float lmapCoord[2];
#endif
  PackedUnitVec normal;
  PackedUnitVec tangent;
};
 
struct GfxWorldVertexData
{
  GfxWorldVertex *vertices;
#ifdef _XBOX
  GfxWorldVertex *vertices2;
#endif
  D3DVertexBuffer worldVb;
};
 
struct GfxWorldVertexLayerData
{
  char *data;
  D3DVertexBuffer layerVb;
};
 
struct GfxWorldDraw
{
  unsigned int reflectionProbeCount;
  GfxImage **reflectionProbes;
  GfxReflectionProbe *reflectionProbeOrigins;
  GfxTexture *reflectionProbeTextures;
  unsigned int reflectionProbeReferenceCount;
  GfxReflectionProbeReferenceOrigin *reflectionProbeReferenceOrigins;
  GfxReflectionProbeReference *reflectionProbeReferences;
  int lightmapCount;
  GfxLightmapArray *lightmaps;
  GfxTexture *lightmapPrimaryTextures;
  GfxTexture *lightmapSecondaryTextures;
  GfxImage *lightmapOverridePrimary;
  GfxImage *lightmapOverrideSecondary;
  unsigned int trisType;
  unsigned int vertexCount;
  GfxWorldVertexData vd;
  unsigned int vertexLayerDataSize;
  GfxWorldVertexLayerData vld;
  unsigned int indexCount;
  unsigned __int16 *indices;
  D3DIndexBuffer indexBuffer;
};
 
struct GfxLightGridEntry
{
  unsigned int colorsIndex;
  unsigned __int16 primaryLightEnvIndex;
  char unused;
  char needsTrace;
};
 
struct GfxLightGridColors
{
  char rgb[56][3];
};
 
struct GfxLightGridColorsHDR
{
  float colorVec3[56][3];
};
 
struct GfxLightGridTree
{
  char maxDepth;
  int nodeCount;
  int leafCount;
  int coordMinGridSpace[3];
  int coordMaxGridSpace[3];
  int coordHalfSizeGridSpace[3];
  int defaultColorIndexBitCount;
  int defaultLightIndexBitCount;
  unsigned int *p_nodeTable;
  int leafTableSize;
  char *p_leafTable;
};
 
struct GfxLightGrid
{
  bool hasLightRegions;
  bool useSkyForLowZ;
  unsigned int lastSunPrimaryLightIndex;
  unsigned __int16 mins[3];
  unsigned __int16 maxs[3];
  unsigned int rowAxis;
  unsigned int colAxis;
  unsigned __int16 *rowDataStart;
  unsigned int rawRowDataSize;
  char *rawRowData;
  unsigned int entryCount;
  GfxLightGridEntry *entries;
  unsigned int colorCount;
  GfxLightGridColors *colors;
  unsigned int missingGridColorIndex;
  int tableVersion;
  int paletteVersion;
  char rangeExponent8BitsEncoding;
  char rangeExponent12BitsEncoding;
  char rangeExponent16BitsEncoding;
  char stageCount;
  float *stageLightingContrastGain;
  unsigned int paletteEntryCount;
  int *paletteEntryAddress;
  unsigned int paletteBitstreamSize;
  char *paletteBitstream;
  GfxLightGridColorsHDR skyLightGridColors;
  GfxLightGridColorsHDR defaultLightGridColors;
  GfxLightGridTree tree;
};
 
struct GfxBrushModelWritable
{
  float mins[3];
  float maxs[3];
};
 
struct GfxBrushModel
{
  GfxBrushModelWritable writable;
  float bounds[2][3];
  unsigned int surfaceCount;
  unsigned int startSurfIndex;
};
 
struct MaterialMemory
{
  Material *material;
  int memory;
};
 
struct __declspec(align(8)) sunflare_t
{
  bool hasValidData;
  Material *spriteMaterial;
  Material *flareMaterial;
  float spriteSize;
  float flareMinSize;
  float flareMinDot;
  float flareMaxSize;
  float flareMaxDot;
  float flareMaxAlpha;
  int flareFadeInTime;
  int flareFadeOutTime;
  float blindMinDot;
  float blindMaxDot;
  float blindMaxDarken;
  int blindFadeInTime;
  int blindFadeOutTime;
  float glareMinDot;
  float glareMaxDot;
  float glareMaxLighten;
  int glareFadeInTime;
  int glareFadeOutTime;
  float sunFxPosition[3];
};
 
struct XModelDrawInfo
{
  unsigned __int16 lod;
  unsigned __int16 surfId;
};
 
struct GfxSceneDynModel
{
  XModelDrawInfo info;
  unsigned __int16 dynEntId;
};
 
struct BModelDrawInfo
{
  unsigned __int16 surfId;
};
 
struct GfxSceneDynBrush
{
  BModelDrawInfo info;
  unsigned __int16 dynEntId;
};
 
struct GfxShadowGeometry
{
  unsigned __int16 surfaceCount;
  unsigned __int16 smodelCount;
  unsigned __int16 *sortedSurfIndex;
  unsigned __int16 *smodelIndex;
};
 
struct GfxLightRegionAxis
{
  float dir[3];
  float midPoint;
  float halfSize;
};
 
struct GfxLightRegionHull
{
  float kdopMidPoint[9];
  float kdopHalfSize[9];
  unsigned int axisCount;
  GfxLightRegionAxis *axis;
};
 
struct GfxLightRegion
{
  unsigned int hullCount;
  GfxLightRegionHull *hulls;
};
 
struct GfxStaticModelInst
{
  Bounds bounds;
  float lightingOrigin[3];
};
 
struct srfTriangles_t
{
  unsigned int vertexLayerData;
  unsigned int firstVertex;
#ifdef PC
  float maxEdgeLength;
#endif
  unsigned __int16 vertexCount;
  unsigned __int16 triCount;
  unsigned int baseIndex;
};
 
struct GfxSurfaceLightingAndFlagsFields
{
  char lightmapIndex;
  char reflectionProbeIndex;
#ifdef PC
  unsigned __int16 primaryLightEnvIndex;
#else
  char primaryLightEnvIndex;
#endif
  char flags;
};
 
union GfxSurfaceLightingAndFlags
{
  GfxSurfaceLightingAndFlagsFields fields;
#ifdef PC
  unsigned __int64 packed;
#else
  unsigned int packed;
#endif
};
 
struct GfxSurface
{
  srfTriangles_t tris;
  Material *material;
  GfxSurfaceLightingAndFlags laf;
};
 
struct __declspec(align(4)) GfxSurfaceBounds
{
  Bounds bounds;
  char flags;
#ifdef _XBOX
  float maxEdgeLength; //Not sure if this goes here, but the srfTriangles_t is missing 4 bytes and I need 4 here, and it'd make sense that this would go here, as it isn't in the Xbox 360 CoD4 srfTriangles_t.
#endif
};
 
struct GfxPackedPlacement
{
  float origin[3];
#if defined(_XBOX) || defined(PS3)
  PackedUnitVec axis[3];
#else
  float axis[3][3];
#endif
  float scale;
};
 
struct GfxStaticModelVertexLighting
{
  char visibility[4];
  unsigned __int16 ambientColorFloat16[4];
#ifdef PC
  unsigned __int16 highlightColorFloat16[4];
#endif
};
 
struct __declspec(align(8)) GfxStaticModelVertexLightingInfo
{
  GfxStaticModelVertexLighting *lightingValues;
  D3DVertexBuffer lightingValuesVb;
  unsigned int numLightingValues;
};
 
struct __declspec(align(8)) GfxStaticModelDrawInst
{
  GfxPackedPlacement placement;
  XModel *model;
 
#ifdef PC
  float groundLighting[4];
#else
  float groundLighting[1];//Again, this makes sense... Either this, or a packed vertex.
#endif
 
  GfxStaticModelVertexLightingInfo vertexLightingInfo;
 
#ifdef PC
  GfxStaticModelLightmapInfo modelLightmapInfo;
#endif
 
  unsigned __int16 lightingHandle;
  unsigned __int16 cullDist;
 
#ifdef PC
  unsigned __int16 flags;
  unsigned __int16 staticModelId;
  unsigned __int16 primaryLightEnvIndex;
#else
  char flags;
  char staticModelId;
  char primaryLightEnvIndex;
#endif
 
  char reflectionProbeIndex;
  char firstMtlSkinIndex;
  char sunShadowFlags;
};
 
struct GfxDrawSurfFields
{
  unsigned __int64 objectId : 16;
  unsigned __int64 reflectionProbeIndex : 8;
  unsigned __int64 hasGfxEntIndex : 1;
  unsigned __int64 customIndex : 5;
  unsigned __int64 materialSortedIndex : 13;
  unsigned __int64 tessellation : 3;//This is probably PC only, but that would mean this structure would only need 4 bytes, and it needs 8
  unsigned __int64 prepass : 2;
  unsigned __int64 useHeroLighting : 1;
  unsigned __int64 sceneLightEnvIndex : 16;
  unsigned __int64 viewModelRender : 1;
  unsigned __int64 surfType : 4;
  unsigned __int64 primarySortKey : 6;
  unsigned __int64 unused : 30;
};
 
union GfxDrawSurf
{
  GfxDrawSurfFields fields;
  Packed128 packed;
};
 
struct __declspec(align(8)) GfxWorldDpvsStatic
{
  unsigned int smodelCount;
  unsigned int staticSurfaceCount;
  unsigned int litOpaqueSurfsBegin;
  unsigned int litOpaqueSurfsEnd;
#ifdef PC
  unsigned int litDecalSurfsBegin;
  unsigned int litDecalSurfsEnd;
#endif
  unsigned int litTransSurfsBegin;
  unsigned int litTransSurfsEnd;
  unsigned int shadowCasterSurfsBegin;
  unsigned int shadowCasterSurfsEnd;
  unsigned int emissiveSurfsBegin;
  unsigned int emissiveSurfsEnd;
  unsigned int smodelVisDataCount;
  unsigned int surfaceVisDataCount;
  unsigned int *smodelVisData[3];
  unsigned int *surfaceVisData[3];
#ifdef PC
  unsigned int *tessellationCutoffVisData[3];
#endif
  unsigned int *sortedSurfIndex;
  GfxStaticModelInst *smodelInsts;
  GfxSurface *surfaces;
  GfxSurfaceBounds *surfacesBounds;
  GfxStaticModelDrawInst *smodelDrawInsts;
  GfxDrawSurf *surfaceMaterials;
  unsigned int *surfaceCastsSunShadow;
  unsigned int sunShadowOptCount;
  unsigned int sunSurfVisDataCount;
  unsigned int *surfaceCastsSunShadowOpt;
#ifdef PC
  void **constantBuffersLit;
  void **constantBuffersAmbient;
#endif
  volatile int usageCount;
};
 
struct GfxWorldDpvsDynamic
{
  unsigned int dynEntClientWordCount[2];
  unsigned int dynEntClientCount[2];
  unsigned int *dynEntCellBits[2];
  char *dynEntVisData[2][3];
};
 
struct GfxHeroOnlyLight
{
  char type;
  char unused[3];
  float color[3];
  float dir[3];
  float up[3];
  float origin[3];
  float radius;
  float cosHalfFovOuter;
  float cosHalfFovInner;
  int exponent;
};
 
struct __declspec(align(8)) GfxWorld
{
  const char *name;
  const char *baseName;
  unsigned int bspVersion;
  int planeCount;
  int nodeCount;
  unsigned int surfaceCount;
  int skyCount;
  GfxSky *skies;
  unsigned int primaryLightCount;
  unsigned int primaryLightEnvCount;
#ifdef PC
  unsigned int lastSunPrimaryLightIndex;
  //One of these sortKey unsigned ints has to go on 360
  //Given that GfxWorldDpvsStatic is missing 8 bytes in the first 0x30+8 bytes,
  //I attribute that to the litDecal settings, which means this would also have to go
  unsigned int sortKeyLitDecal;
#endif
  unsigned int sortKeyEffectDecal;
  unsigned int sortKeyTopDecal;
  unsigned int sortKeyEffectAuto;
  unsigned int sortKeyDistortion;
  GfxWorldDpvsPlanes dpvsPlanes;
  GfxCellTreeCount *aabbTreeCounts;
  GfxCellTree *aabbTrees;
  GfxCell *cells;
  GfxWorldDraw draw;
  GfxLightGrid lightGrid;
  int modelCount;
  GfxBrushModel *models;
  float mins[3];
  float maxs[3];
  unsigned int checksum;
  int materialMemoryCount;
  MaterialMemory *materialMemory;
  sunflare_t sun;
  float outdoorLookupMatrix[4][4];
  GfxImage *outdoorImage;
  unsigned int *cellCasterBits;
  unsigned int *cellHasSunLitSurfsBits;
  GfxSceneDynModel *sceneDynModel;
  GfxSceneDynBrush *sceneDynBrush;
  unsigned int *primaryLightEntityShadowVis;
  unsigned int *primaryLightDynEntShadowVis[2];
  char *primaryLightForModelDynEnt;
  GfxShadowGeometry *shadowGeom;
#ifdef _XBOX
  GfxShadowGeometry *shadowGeom1;
#endif
  GfxLightRegion *lightRegion;
  GfxWorldDpvsStatic dpvs;
  GfxWorldDpvsDynamic dpvsDyn;
  unsigned int mapVtxChecksum;
  unsigned int heroOnlyLightCount;
  GfxHeroOnlyLight *heroOnlyLights;
  char fogTypesAllowed;
};

Keep in mind that the checksum is checked on other clients using the mapcrc dvar.