Browse Source

Added surface flags, allowing for rendering of water surfaces

master
Nico de Poel 3 years ago
parent
commit
93551117b1
  1. 7
      bsp.h
  2. 17
      main.cpp
  3. 18
      ps1bsp.h

7
bsp.h

@ -1,5 +1,12 @@
#pragma once
#define CONTENTS_EMPTY -1
#define CONTENTS_SOLID -2
#define CONTENTS_WATER -3
#define CONTENTS_SLIME -4
#define CONTENTS_LAVA -5
#define CONTENTS_SKY -6
typedef struct // A Directory entry
{
long offset; // Offset to entry, in bytes, from start of file

17
main.cpp

@ -149,10 +149,23 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
const miptex_t* miptex = &world->miptexes[texinfo->texture_id];
const ps1bsp_texture_t& ps1tex = textures[texinfo->texture_id];
auto polygons = tesselator.tesselateFace(face);
outFace->firstPolygon = (unsigned short)outPolygons.size();
// Skip sky surfaces for now
if (!strncmp(miptex->name, "sky", 3))
{
outFace->flags |= SURF_DRAWSKY;
outFace->numPolygons = 0;
continue;
}
// Draw water as fullbright transparent surfaces
if (miptex->name[0] == '*')
{
outFace->flags |= SURF_DRAWTURB | SURF_DRAWWATER;
}
auto polygons = tesselator.tesselateFace(face);
for (auto polyIter = polygons.begin(); polyIter != polygons.end(); ++polyIter)
{
ps1bsp_polygon_t outPoly = { 0 };

18
ps1bsp.h

@ -57,6 +57,7 @@ typedef struct
} ps1bsp_vertex_t;
// Texture UV and lighting data for a vertex on a particular polygon.
// TODO: break up into poly vertex (index + uv) and surface vertex (index + light) shared between polygons.
typedef struct
{
unsigned short index;
@ -83,6 +84,20 @@ typedef struct
unsigned char b : 5;
} ps1bsp_facevertex_t;
#define SURF_PLANEBACK 0x2
#define SURF_DRAWSKY 0x4
#define SURF_DRAWSPRITE 0x8
#define SURF_DRAWTURB 0x10
#define SURF_DRAWTILED 0x20
#define SURF_DRAWBACKGROUND 0x40
#define SURF_UNDERWATER 0x80
#define SURF_NOTEXTURE 0x100
#define SURF_DRAWFENCE 0x200
#define SURF_DRAWLAVA 0x400
#define SURF_DRAWSLIME 0x800
#define SURF_DRAWTELE 0x1000
#define SURF_DRAWWATER 0x2000
// High quality: Face -> polygons -> polygon vertex indices (index + UV + light) -> vertices
// Low quality: Face -> face vertex indices (index + color) -> vertices
typedef struct
@ -99,14 +114,13 @@ typedef struct
unsigned char numFaceVertices;
unsigned char textureId;
unsigned short flags;
// Used for backface culling
SVECTOR center;
// Which frame was this face last drawn on? Used to check if this face should be drawn.
u_long drawFrame;
u_short pad; // For 32-bit alignment
} ps1bsp_face_t;
typedef struct

Loading…
Cancel
Save