From 93551117b1b74e738de899b8cb9111a645b0e9d2 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 28 Jan 2023 00:14:16 +0100 Subject: [PATCH] Added surface flags, allowing for rendering of water surfaces --- bsp.h | 7 +++++++ main.cpp | 17 +++++++++++++++-- ps1bsp.h | 18 ++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/bsp.h b/bsp.h index fe8089d..138191b 100644 --- a/bsp.h +++ b/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 diff --git a/main.cpp b/main.cpp index 1fd45dc..3e57c3a 100644 --- a/main.cpp +++ b/main.cpp @@ -149,10 +149,23 @@ int process_faces(const world_t* world, const std::vector& 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 }; diff --git a/ps1bsp.h b/ps1bsp.h index 0d1d57e..8c16883 100644 --- a/ps1bsp.h +++ b/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