header files for material/water

This commit is contained in:
q66 2020-04-29 02:04:26 +02:00
parent c3faff7d4a
commit 768c588322
16 changed files with 215 additions and 177 deletions

View file

@ -245,8 +245,7 @@ static inline cubeext &ext(cube &c)
// renderlights
#define LIGHTTILE_MAXW 16
#define LIGHTTILE_MAXH 16
#include "renderlights.hh"
extern int lighttilealignw, lighttilealignh, lighttilevieww, lighttileviewh, lighttilew, lighttileh;
@ -442,79 +441,12 @@ extern void updatedynlights();
extern int finddynlights();
extern bool getdynlight(int n, vec &o, float &radius, vec &color, vec &dir, int &spot, int &flags);
// material
extern float matliquidsx1, matliquidsy1, matliquidsx2, matliquidsy2;
extern float matsolidsx1, matsolidsy1, matsolidsx2, matsolidsy2;
extern float matrefractsx1, matrefractsy1, matrefractsx2, matrefractsy2;
extern uint matliquidtiles[LIGHTTILE_MAXH], matsolidtiles[LIGHTTILE_MAXH];
extern vector<materialsurface> editsurfs, glasssurfs[4], watersurfs[4], waterfallsurfs[4], lavasurfs[4], lavafallsurfs[4];
extern const vec matnormals[6];
extern int showmat;
extern int findmaterial(const char *name);
extern const char *findmaterialname(int mat);
extern const char *getmaterialdesc(int mat, const char *prefix = "");
extern void genmatsurfs(const cube &c, const ivec &co, int size, vector<materialsurface> &matsurfs);
extern void calcmatbb(vtxarray *va, const ivec &co, int size, vector<materialsurface> &matsurfs);
extern int optimizematsurfs(materialsurface *matbuf, int matsurfs);
extern void setupmaterials(int start = 0, int len = 0);
extern int findmaterials();
extern void rendermaterialmask();
extern void renderliquidmaterials();
extern void rendersolidmaterials();
extern void rendereditmaterials();
extern void renderminimapmaterials();
extern int visiblematerial(const cube &c, int orient, const ivec &co, int size, ushort matmask = MATF_VOLUME);
// water
extern int vertwater, waterreflect, caustics;
extern float watersx1, watersy1, watersx2, watersy2;
#define GETMATIDXVAR(name, var, type) \
type get##name##var(int mat) \
{ \
switch(mat&MATF_INDEX) \
{ \
default: case 0: return name##var; \
case 1: return name##2##var; \
case 2: return name##3##var; \
case 3: return name##4##var; \
} \
}
extern const bvec &getwatercolour(int mat);
extern const bvec &getwaterdeepcolour(int mat);
extern const bvec &getwaterdeepfade(int mat);
extern const bvec &getwaterrefractcolour(int mat);
extern const bvec &getwaterfallcolour(int mat);
extern const bvec &getwaterfallrefractcolour(int mat);
extern int getwaterfog(int mat);
extern int getwaterdeep(int mat);
extern int getwaterspec(int mat);
extern float getwaterrefract(int mat);
extern int getwaterfallspec(int mat);
extern float getwaterfallrefract(int mat);
extern const bvec &getlavacolour(int mat);
extern int getlavafog(int mat);
extern float getlavaglowmin(int mat);
extern float getlavaglowmax(int mat);
extern int getlavaspec(int mat);
extern const bvec &getglasscolour(int mat);
extern float getglassrefract(int mat);
extern int getglassspec(int mat);
extern void renderwater();
extern void renderwaterfalls();
extern void renderlava();
extern void renderlava(const materialsurface &m, Texture *tex, float scale);
extern void loadcaustics(bool force = false);
extern void renderwaterfog(int mat, float blend);
extern void preloadwatershaders(bool force = false);
// client
extern void localdisconnect(bool cleanup = true);
extern void clientkeepalive();

View file

@ -1,5 +1,10 @@
#include "material.hh"
#include "water.hh"
#include "engine.hh"
vector<materialsurface> editsurfs, glasssurfs[4], watersurfs[4], waterfallsurfs[4], lavasurfs[4], lavafallsurfs[4];
struct QuadNode
{
int x, y, size;
@ -142,7 +147,7 @@ const char *getmaterialdesc(int mat, const char *prefix)
return desc;
}
int visiblematerial(const cube &c, int orient, const ivec &co, int size, ushort matmask)
static int visiblematerial(const cube &c, int orient, const ivec &co, int size, ushort matmask = MATF_VOLUME)
{
ushort mat = c.material&matmask;
switch(mat)
@ -343,7 +348,7 @@ int optimizematsurfs(materialsurface *matbuf, int matsurfs)
return matsurfs - (end-matbuf);
}
void preloadglassshaders(bool force = false)
static void preloadglassshaders(bool force = false)
{
static bool needglass = false;
if(force) needglass = true;
@ -460,7 +465,7 @@ static inline bool editmatcmp(const materialsurface &x, const materialsurface &y
return false;
}
void sorteditmaterials()
static void sorteditmaterials()
{
sortorigin = ivec(camera1->o);
vec dir = vec(camdir).abs();
@ -471,7 +476,7 @@ void sorteditmaterials()
editsurfs.sort(editmatcmp);
}
void rendermatgrid()
static void rendermatgrid()
{
enablepolygonoffset(GL_POLYGON_OFFSET_LINE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@ -563,8 +568,6 @@ static void drawglass(const materialsurface &m, float offset, const vec *normal
#define GENFACEVERTZ(o,n, x,y,z, xv,yv,zv) GENFACEVERT(o,n, x,y,z, xv,yv,zv)
}
vector<materialsurface> editsurfs, glasssurfs[4], watersurfs[4], waterfallsurfs[4], lavasurfs[4], lavafallsurfs[4];
float matliquidsx1 = -1, matliquidsy1 = -1, matliquidsx2 = 1, matliquidsy2 = 1;
float matsolidsx1 = -1, matsolidsy1 = -1, matsolidsx2 = 1, matsolidsy2 = 1;
float matrefractsx1 = -1, matrefractsy1 = -1, matrefractsx2 = 1, matrefractsy2 = 1;
@ -693,7 +696,7 @@ GETMATIDXVAR(glass, spec, int)
VARFP(glassenv, 0, 1, 1, preloadglassshaders());
void renderglass()
static void renderglass()
{
loopk(4)
{

43
src/engine/material.hh Normal file
View file

@ -0,0 +1,43 @@
#ifndef ENGINE_MATERIAL_HH
#define ENGINE_MATERIAL_HH
#include "renderlights.hh"
#include "octa.hh"
extern uint matliquidtiles[LIGHTTILE_MAXH], matsolidtiles[LIGHTTILE_MAXH];
extern float matliquidsx1, matliquidsy1, matliquidsx2, matliquidsy2;
extern float matsolidsx1, matsolidsy1, matsolidsx2, matsolidsy2;
extern float matrefractsx1, matrefractsy1, matrefractsx2, matrefractsy2;
extern int showmat;
int findmaterial(const char *name);
const char *findmaterialname(int mat);
const char *getmaterialdesc(int mat, const char *prefix = "");
void genmatsurfs(const cube &c, const ivec &co, int size, vector<materialsurface> &matsurfs);
void calcmatbb(vtxarray *va, const ivec &co, int size, vector<materialsurface> &matsurfs);
int optimizematsurfs(materialsurface *matbuf, int matsurfs);
void setupmaterials(int start = 0, int len = 0);
int findmaterials();
void rendermaterialmask();
void renderliquidmaterials();
void rendersolidmaterials();
void rendereditmaterials();
void renderminimapmaterials();
#define GETMATIDXVAR(name, var, type) \
type get##name##var(int mat) \
{ \
switch(mat&MATF_INDEX) \
{ \
default: case 0: return name##var; \
case 1: return name##2##var; \
case 2: return name##3##var; \
case 3: return name##4##var; \
} \
}
#endif

View file

@ -1,6 +1,36 @@
#ifndef ENGINE_OCTA_HH
#define ENGINE_OCTA_HH
#include <shared/geom.hh>
#include <shared/ents.hh>
struct vertex { vec pos; bvec4 norm; vec tc; bvec4 tangent; };
struct selinfo
{
int corner;
int cx, cxs, cy, cys;
ivec o, s;
int grid, orient;
selinfo() : corner(0), cx(0), cxs(0), cy(0), cys(0), o(0, 0, 0), s(0, 0, 0), grid(8), orient(0) {}
int size() const { return s.x*s.y*s.z; }
int us(int d) const { return s[d]*grid; }
bool operator==(const selinfo &sel) const { return o==sel.o && s==sel.s && grid==sel.grid && orient==sel.orient; }
bool validate()
{
extern int worldsize;
if(grid <= 0 || grid >= worldsize) return false;
if(o.x >= worldsize || o.y >= worldsize || o.z >= worldsize) return false;
if(o.x < 0) { s.x -= (grid - 1 - o.x)/grid; o.x = 0; }
if(o.y < 0) { s.y -= (grid - 1 - o.y)/grid; o.y = 0; }
if(o.z < 0) { s.z -= (grid - 1 - o.z)/grid; o.z = 0; }
s.x = clamp(s.x, 0, (worldsize - o.x)/grid);
s.y = clamp(s.y, 0, (worldsize - o.y)/grid);
s.z = clamp(s.z, 0, (worldsize - o.z)/grid);
return s.x > 0 && s.y > 0 && s.z > 0;
}
};
// 6-directional octree heightfield map format
struct elementset

View file

@ -1,4 +1,5 @@
#include "blend.hh"
#include "material.hh"
#include "world.hh"
#include "engine.hh"

View file

@ -1,6 +1,7 @@
// octarender.cpp: fill vertex arrays with different cube surfaces.
#include "blend.hh"
#include "material.hh"
#include "world.hh"
#include "engine.hh"

View file

@ -2,6 +2,8 @@
#include "aa.hh"
#include "blend.hh"
#include "material.hh"
#include "water.hh"
#include "engine.hh"

View file

@ -1,4 +1,7 @@
#include "renderlights.hh"
#include "aa.hh"
#include "material.hh"
#include "world.hh"
#include "engine.hh"

View file

@ -0,0 +1,7 @@
#ifndef ENGINE_RENDERLIGHTS_HH
#define ENGINE_RENDERLIGHTS_HH
#define LIGHTTILE_MAXW 16
#define LIGHTTILE_MAXH 16
#endif

View file

@ -1,5 +1,6 @@
// renderparticles.cpp
#include "water.hh"
#include "world.hh"
#include "engine.hh"

View file

@ -1,3 +1,5 @@
#include "material.hh"
#include "engine.hh"
struct stainvert

View file

@ -1,5 +1,7 @@
// texture.cpp: texture slot management
#include "material.hh"
#include "engine.hh"
#ifdef __APPLE__

View file

@ -1,7 +1,77 @@
#include "material.hh"
#include "water.hh"
#include "engine.hh"
extern const vec matnormals[6];
extern vector<materialsurface> watersurfs[4], waterfallsurfs[4], lavasurfs[4], lavafallsurfs[4];
#define NUMCAUSTICS 32
VARFR(causticscale, 0, 50, 10000, preloadwatershaders());
VARFR(causticmillis, 0, 75, 1000, preloadwatershaders());
FVARR(causticcontrast, 0, 0.6f, 2);
FVARR(causticoffset, 0, 0.7f, 1);
VARFP(caustics, 0, 1, 1, { loadcaustics(); preloadwatershaders(); });
#define WATERVARS(name) \
CVAR0R(name##colour, 0x01212C); \
CVAR0R(name##deepcolour, 0x010A10); \
CVAR0R(name##deepfade, 0x60BFFF); \
CVAR0R(name##refractcolour, 0xFFFFFF); \
VARR(name##fog, 0, 30, 10000); \
VARR(name##deep, 0, 50, 10000); \
VARR(name##spec, 0, 150, 200); \
FVARR(name##refract, 0, 0.1f, 1e3f); \
CVARR(name##fallcolour, 0); \
CVARR(name##fallrefractcolour, 0); \
VARR(name##fallspec, 0, 150, 200); \
FVARR(name##fallrefract, 0, 0.1f, 1e3f);
WATERVARS(water)
WATERVARS(water2)
WATERVARS(water3)
WATERVARS(water4)
GETMATIDXVAR(water, colour, const bvec &)
GETMATIDXVAR(water, deepcolour, const bvec &)
GETMATIDXVAR(water, deepfade, const bvec &)
GETMATIDXVAR(water, refractcolour, const bvec &)
GETMATIDXVAR(water, fallcolour, const bvec &)
GETMATIDXVAR(water, fallrefractcolour, const bvec &)
GETMATIDXVAR(water, fog, int)
GETMATIDXVAR(water, deep, int)
GETMATIDXVAR(water, spec, int)
GETMATIDXVAR(water, refract, float)
GETMATIDXVAR(water, fallspec, int)
GETMATIDXVAR(water, fallrefract, float)
#define LAVAVARS(name) \
CVAR0R(name##colour, 0xFF4000); \
VARR(name##fog, 0, 50, 10000); \
FVARR(name##glowmin, 0, 0.25f, 2); \
FVARR(name##glowmax, 0, 1.0f, 2); \
VARR(name##spec, 0, 25, 200);
LAVAVARS(lava)
LAVAVARS(lava2)
LAVAVARS(lava3)
LAVAVARS(lava4)
GETMATIDXVAR(lava, colour, const bvec &)
GETMATIDXVAR(lava, fog, int)
GETMATIDXVAR(lava, glowmin, float)
GETMATIDXVAR(lava, glowmax, float)
GETMATIDXVAR(lava, spec, int)
VARFP(waterreflect, 0, 1, 1, { preloadwatershaders(); });
VARR(waterreflectstep, 1, 32, 10000);
VARFP(waterenvmap, 0, 1, 1, { preloadwatershaders(); });
VARFP(waterfallenv, 0, 1, 1, preloadwatershaders());
VARFP(vertwater, 0, 1, 1, allchanged());
static Texture *caustictex[NUMCAUSTICS] = { NULL };
void loadcaustics(bool force)
@ -18,18 +88,14 @@ void loadcaustics(bool force)
}
}
void cleanupcaustics()
#if 0
static void cleanupcaustics()
{
loopi(NUMCAUSTICS) caustictex[i] = NULL;
}
#endif
VARFR(causticscale, 0, 50, 10000, preloadwatershaders());
VARFR(causticmillis, 0, 75, 1000, preloadwatershaders());
FVARR(causticcontrast, 0, 0.6f, 2);
FVARR(causticoffset, 0, 0.7f, 1);
VARFP(caustics, 0, 1, 1, { loadcaustics(); preloadwatershaders(); });
void setupcaustics(int tmu, float surface = -1e16f)
static void setupcaustics(int tmu, float surface = -1e16f)
{
if(!caustictex[0]) loadcaustics(true);
@ -63,7 +129,7 @@ void setupcaustics(int tmu, float surface = -1e16f)
GLOBALPARAMF(causticsblend, blendscale*(1-frac), blendscale*frac, blendoffset - causticoffset*blendscale);
}
void rendercaustics(float surface, float syl, float syr)
static void rendercaustics(float surface, float syl, float syr)
{
if(!caustics || !causticscale || !causticmillis) return;
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
@ -225,7 +291,7 @@ VERTWN(vertln, {
xtraverts += gle::end(); \
}
void rendervertwater(int subdiv, int xo, int yo, int z, int size, int mat)
static void rendervertwater(int subdiv, int xo, int yo, int z, int size, int mat)
{
wx1 = xo;
wy1 = yo;
@ -255,7 +321,7 @@ void rendervertwater(int subdiv, int xo, int yo, int z, int size, int mat)
}
}
int calcwatersubdiv(int x, int y, int z, int size)
static int calcwatersubdiv(int x, int y, int z, int size)
{
float dist;
if(camera1->o.x >= x && camera1->o.x < x + size &&
@ -267,7 +333,7 @@ int calcwatersubdiv(int x, int y, int z, int size)
return subdiv >= 31 ? INT_MAX : 1<<subdiv;
}
int renderwaterlod(int x, int y, int z, int size, int mat)
static int renderwaterlod(int x, int y, int z, int size, int mat)
{
if(size <= (32 << waterlod))
{
@ -317,7 +383,7 @@ int renderwaterlod(int x, int y, int z, int size, int mat)
xtraverts += 4; \
}
void renderflatwater(int x, int y, int z, int rsize, int csize, int mat)
static void renderflatwater(int x, int y, int z, int rsize, int csize, int mat)
{
switch(mat)
{
@ -331,8 +397,6 @@ void renderflatwater(int x, int y, int z, int rsize, int csize, int mat)
}
}
VARFP(vertwater, 0, 1, 1, allchanged());
static inline void renderwater(const materialsurface &m, int mat = MAT_WATER)
{
if(!vertwater || drawtex == DRAWTEX_MINIMAP) renderflatwater(m.o.x, m.o.y, m.o.z, m.rsize, m.csize, mat);
@ -340,61 +404,6 @@ static inline void renderwater(const materialsurface &m, int mat = MAT_WATER)
rendervertwater(m.csize, m.o.x, m.o.y, m.o.z, m.csize, mat);
}
#define WATERVARS(name) \
CVAR0R(name##colour, 0x01212C); \
CVAR0R(name##deepcolour, 0x010A10); \
CVAR0R(name##deepfade, 0x60BFFF); \
CVAR0R(name##refractcolour, 0xFFFFFF); \
VARR(name##fog, 0, 30, 10000); \
VARR(name##deep, 0, 50, 10000); \
VARR(name##spec, 0, 150, 200); \
FVARR(name##refract, 0, 0.1f, 1e3f); \
CVARR(name##fallcolour, 0); \
CVARR(name##fallrefractcolour, 0); \
VARR(name##fallspec, 0, 150, 200); \
FVARR(name##fallrefract, 0, 0.1f, 1e3f);
WATERVARS(water)
WATERVARS(water2)
WATERVARS(water3)
WATERVARS(water4)
GETMATIDXVAR(water, colour, const bvec &)
GETMATIDXVAR(water, deepcolour, const bvec &)
GETMATIDXVAR(water, deepfade, const bvec &)
GETMATIDXVAR(water, refractcolour, const bvec &)
GETMATIDXVAR(water, fallcolour, const bvec &)
GETMATIDXVAR(water, fallrefractcolour, const bvec &)
GETMATIDXVAR(water, fog, int)
GETMATIDXVAR(water, deep, int)
GETMATIDXVAR(water, spec, int)
GETMATIDXVAR(water, refract, float)
GETMATIDXVAR(water, fallspec, int)
GETMATIDXVAR(water, fallrefract, float)
#define LAVAVARS(name) \
CVAR0R(name##colour, 0xFF4000); \
VARR(name##fog, 0, 50, 10000); \
FVARR(name##glowmin, 0, 0.25f, 2); \
FVARR(name##glowmax, 0, 1.0f, 2); \
VARR(name##spec, 0, 25, 200);
LAVAVARS(lava)
LAVAVARS(lava2)
LAVAVARS(lava3)
LAVAVARS(lava4)
GETMATIDXVAR(lava, colour, const bvec &)
GETMATIDXVAR(lava, fog, int)
GETMATIDXVAR(lava, glowmin, float)
GETMATIDXVAR(lava, glowmax, float)
GETMATIDXVAR(lava, spec, int)
VARFP(waterreflect, 0, 1, 1, { preloadwatershaders(); });
VARR(waterreflectstep, 1, 32, 10000);
VARFP(waterenvmap, 0, 1, 1, { preloadwatershaders(); });
VARFP(waterfallenv, 0, 1, 1, preloadwatershaders());
void preloadwatershaders(bool force)
{
static bool needwater = false;

30
src/engine/water.hh Normal file
View file

@ -0,0 +1,30 @@
#ifndef ENGINE_WATER_HH
#define ENGINE_WATER_HH
#include <shared/geom.hh>
#define WATER_AMPLITUDE 0.4f
#define WATER_OFFSET 1.1f
extern int vertwater;
void loadcaustics(bool force = false);
void renderwaterfog(int mat, float blend);
void preloadwatershaders(bool force = false);
void renderlava();
void renderwater();
void renderwaterfalls();
const bvec &getwatercolour(int mat);
const bvec &getwaterdeepcolour(int mat);
const bvec &getwaterfallcolour(int mat);
int getwaterfog(int mat);
int getwaterdeep(int mat);
float getwaterrefract(int mat);
const bvec &getlavacolour(int mat);
int getlavafog(int mat);
#endif

View file

@ -2,7 +2,6 @@
#define ENGINE_WORLD_HH
#include <shared/geom.hh>
#include <shared/ents.hh>
/* FIXME: move these defines/enums */
@ -14,9 +13,6 @@ enum // hardcoded texture numbers
NUMDEFAULTSLOTS
};
#define WATER_AMPLITUDE 0.4f
#define WATER_OFFSET 1.1f
enum
{
MATSURF_NOT_VISIBLE = 0,
@ -26,33 +22,6 @@ enum
#define TEX_SCALE 16.0f
struct vertex { vec pos; bvec4 norm; vec tc; bvec4 tangent; };
struct selinfo
{
int corner;
int cx, cxs, cy, cys;
ivec o, s;
int grid, orient;
selinfo() : corner(0), cx(0), cxs(0), cy(0), cys(0), o(0, 0, 0), s(0, 0, 0), grid(8), orient(0) {}
int size() const { return s.x*s.y*s.z; }
int us(int d) const { return s[d]*grid; }
bool operator==(const selinfo &sel) const { return o==sel.o && s==sel.s && grid==sel.grid && orient==sel.orient; }
bool validate()
{
extern int worldsize;
if(grid <= 0 || grid >= worldsize) return false;
if(o.x >= worldsize || o.y >= worldsize || o.z >= worldsize) return false;
if(o.x < 0) { s.x -= (grid - 1 - o.x)/grid; o.x = 0; }
if(o.y < 0) { s.y -= (grid - 1 - o.y)/grid; o.y = 0; }
if(o.z < 0) { s.z -= (grid - 1 - o.z)/grid; o.z = 0; }
s.x = clamp(s.x, 0, (worldsize - o.x)/grid);
s.y = clamp(s.y, 0, (worldsize - o.y)/grid);
s.z = clamp(s.z, 0, (worldsize - o.z)/grid);
return s.x > 0 && s.y > 0 && s.z > 0;
}
};
#include "octa.hh"
extern vector<int> outsideents;

View file

@ -1,6 +1,9 @@
#ifndef SHARED_ENTS_HH
#define SHARED_ENTS_HH
#include "tools.hh"
#include "geom.hh"
// this file defines static map entities ("entity") and dynamic entities (players/monsters, "dynent")
// the gamecode extends these types to add game specific functionality