Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Functions | Variables
water.cpp File Reference
#include <SDL_opengl.h>
#include <boost/algorithm/clamp.hpp>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include "inexor/engine/glare.hpp"
#include "inexor/engine/glemu.hpp"
#include "inexor/engine/glexts.hpp"
#include "inexor/engine/lightmap.hpp"
#include "inexor/engine/material.hpp"
#include "inexor/engine/octaedit.hpp"
#include "inexor/engine/octarender.hpp"
#include "inexor/engine/octree.hpp"
#include "inexor/engine/pvs.hpp"
#include "inexor/engine/rendergl.hpp"
#include "inexor/engine/renderva.hpp"
#include "inexor/engine/shader.hpp"
#include "inexor/engine/water.hpp"
#include "inexor/engine/world.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/network/legacy/buffer_types.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_tools.hpp"
#include "inexor/shared/cube_vector.hpp"
#include "inexor/shared/ents.hpp"
#include "inexor/shared/geom.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/texture/cubemap.hpp"
#include "inexor/texture/slot.hpp"
#include "inexor/texture/texsettings.hpp"
#include "inexor/texture/texture.hpp"
#include "inexor/ui/screen/ScreenManager.hpp"
#include "inexor/util/legacy_time.hpp"

Classes

struct  Reflection
 

Macros

#define VERTW(vertw, defbody, body)
 
#define VERTWN(vertw, defbody, body)
 
#define renderwaterstrips(vertw, z)
 
#define renderwaterquad(vertwn, z)
 
#define MAXREFLECTIONS   16
 
#define WATERVARS(name)
 
#define LAVAVARS(name)
 
#define SETWATERSHADER(which, name)
 
#define GENFACEORIENT(orient, v0, v1, v2, v3)   case orient: v0 v1 v2 v3 break;
 
#define GENFACEVERT(orient, vert, mx, my, mz, sx, sy, sz)   gle::attribf(mx sx, my sy, mz sz);
 

Functions

 VARFP (waterreflect, 0, 1, 1,{cleanreflections();preloadwatershaders();})
 
 VARFP (waterrefract, 0, 1, 1,{cleanreflections();preloadwatershaders();})
 
 VARFP (waterenvmap, 0, 1, 1,{cleanreflections();preloadwatershaders();})
 
 VARFP (waterfallrefract, 0, 0, 1,{cleanreflections();preloadwatershaders();})
 
 VARP (watersubdiv, 0, 2, 3)
 
 VARP (waterlod, 0, 1, 3)
 
 VERTW (vertwt,{gle::deftexcoord0();},{gle::attribf(v1/8.0f, v2/8.0f);}) VERTWN(vertwtn
 
 VERTW (vertl,{gle::deftexcoord0();},{gle::attribf(lavaxk *(v1+lavascroll), lavayk *(v2+lavascroll));}) VERTWN(vertln
 
void rendervertwater (int subdiv, int xo, int yo, int z, int size, int mat)
 
int calcwatersubdiv (int x, int y, int z, int size)
 
int renderwaterlod (int x, int y, int z, int size, int mat)
 
void renderflatwater (int x, int y, int z, int rsize, int csize, int mat)
 
 VARFP (vertwater, 0, 1, 1, allchanged())
 
static void renderwater (const materialsurface &m, int mat=MAT_WATER)
 
void renderlava (const materialsurface &m, Texture *tex, float scale)
 
 VARP (reflectdist, 0, 2000, 10000)
 
void setprojtexmatrix (Reflection &ref)
 
GLuint getwaterfalltex ()
 
 VAR (oqwater, 0, 2, 2)
 
 VARFP (waterfade, 0, 1, 1,{cleanreflections();preloadwatershaders();})
 
void preloadwatershaders (bool force)
 
void renderwater ()
 
void setupwaterfallrefract ()
 
void cleanreflection (Reflection &ref)
 
void cleanreflections ()
 
 VARFP (reflectsize, 6, 8, 10, cleanreflections())
 
void genwatertex (GLuint &tex, GLuint &fb, GLuint &db, bool refract=false)
 
void addwaterfallrefraction (materialsurface &m)
 
void addreflection (materialsurface &m)
 
static void drawmaterialquery (const materialsurface &m, float offset, float border=0, float reflect=-1)
 
void drawreflection (float z, bool refract, int fogdepth=-1, const bvec &col=bvec(0, 0, 0))
 
void queryreflection (Reflection &ref, bool init)
 
void queryreflections ()
 
 VARP (maxreflect, 1, 2, 8)
 
 VAR (maskreflect, 0, 2, 16)
 
void maskreflection (Reflection &ref, float offset, bool reflect, bool clear=false)
 
 VAR (reflectscissor, 0, 1, 1)
 
 VAR (reflectvfc, 0, 1, 1)
 
static bool calcscissorbox (Reflection &ref, int size, vec &clipmin, vec &clipmax, int &sx, int &sy, int &sw, int &sh)
 
 VARR (refractclear, 0, 0, 1)
 
void drawreflections ()
 

Variables

static int wx1
 
static int wy1
 
static int wx2
 
static int wy2
 
static int wsize
 
static float whscale
 
static float whoffset
 
static float lavaxk = 1.0f
 
static float lavayk = 1.0f
 
static float lavascroll = 0.0f
 
Reflection reflections [MAXREFLECTIONS]
 
Reflection waterfallrefraction
 
GLuint reflectionfb = 0
 
GLuint reflectiondb = 0
 
int rplanes = 0
 
int refracting = 0
 
int refractfog = 0
 
bvec refractcolor (0, 0, 0)
 
bool reflecting = false
 
bool fading = false
 
bool fogging = false
 
float reflectz = 1e16f
 

Macro Definition Documentation

#define GENFACEORIENT (   orient,
  v0,
  v1,
  v2,
  v3 
)    case orient: v0 v1 v2 v3 break;
#define GENFACEVERT (   orient,
  vert,
  mx,
  my,
  mz,
  sx,
  sy,
  sz 
)    gle::attribf(mx sx, my sy, mz sz);
#define LAVAVARS (   name)
Value:
bvec name##color(0xFF, 0x40, 0x00); \
HVARFR(name##colour, 0, 0xFF4000, 0xFFFFFF, \
{ \
if(!name##colour) name##colour = 0xFF4000; \
name##color = bvec((name##colour>>16)&0xFF, (name##colour>>8)&0xFF, name##colour&0xFF); \
}); \
VARR(name##fog, 0, 50, 10000);
#define HVARFR(name, min, cur, max, body)
Definition: command.hpp:405
VARR(refractclear, 0, 0, 1)
SharedVar< int > fog
3-dimensional UNSIGNED CHAR vector.
Definition: geom.hpp:1398
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
static void color(const bvec &v, uchar alpha=255)
Definition: glemu.hpp:71
#define MAXREFLECTIONS   16
#define renderwaterquad (   vertwn,
 
)
Value:
{ \
if(gle::attribbuf.empty()) { def##vertwn(); gle::begin(GL_QUADS); } \
vertwn(x, y, z); \
vertwn(x+rsize, y, z); \
vertwn(x+rsize, y+csize, z); \
vertwn(x, y+csize, z); \
xtraverts += 4; \
}
void begin(GLenum mode)
Definition: glemu.cpp:220
ucharbuf attribbuf
Definition: glemu.cpp:35
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
int xtraverts
Definition: rendergl.cpp:1943

Referenced by renderflatwater().

#define renderwaterstrips (   vertw,
 
)
Value:
{ \
def##vertw(); \
gle::begin(GL_TRIANGLE_STRIP, 2*(wy2-wy1 + 1)*(wx2-wx1)/subdiv); \
for(int x = wx1; x<wx2; x += subdiv) \
{ \
vertw(x, wy1, z); \
vertw(x+subdiv, wy1, z); \
for(int y = wy1; y<wy2; y += subdiv) \
{ \
vertw(x, y+subdiv, z); \
vertw(x+subdiv, y+subdiv, z); \
} \
} \
}
void begin(GLenum mode)
Definition: glemu.cpp:220
void multidraw()
Definition: glemu.cpp:245
static int wx2
Definition: water.cpp:52
static int wy2
Definition: water.cpp:52
static int wy1
Definition: water.cpp:52
int end()
Definition: glemu.cpp:256
static int wx1
Definition: water.cpp:52
int xtraverts
Definition: rendergl.cpp:1943

Referenced by rendervertwater().

#define SETWATERSHADER (   which,
  name 
)
Value:
do { \
static Shader *name##shader = NULL; \
if(!name##shader) name##shader = lookupshaderbyname(#name); \
which##shader = name##shader; \
} while(0)
Shader * lookupshaderbyname(const char *name)
Definition: shader.cpp:73
#define NULL
Definition: cube_types.hpp:35
void shader(int *type, char *name, char *vs, char *ps)
Definition: shader.cpp:1060
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
Definition: shader.hpp:142

Referenced by renderwater().

#define VERTW (   vertw,
  defbody,
  body 
)
Value:
static inline void def##vertw() \
{ \
gle::defvertex(); \
defbody; \
} \
static inline void vertw(float v1, float v2, float v3) \
{ \
float angle = (v1-wx1)*(v2-wy1)*(v1-wx2)*(v2-wy2)*whscale+whoffset; \
float s = angle - int(angle) - 0.5f; \
s *= 8 - fabs(s)*16; \
gle::attribf(v1, v2, v3+h); \
body; \
}
static float whoffset
Definition: water.cpp:53
#define WATER_OFFSET
Definition: world.hpp:23
#define WATER_AMPLITUDE
Definition: world.hpp:22
static int wx2
Definition: water.cpp:52
static int wy2
Definition: water.cpp:52
static int wy1
Definition: water.cpp:52
static int wx1
Definition: water.cpp:52
static float whscale
Definition: water.cpp:53
#define VERTWN (   vertw,
  defbody,
  body 
)
Value:
static inline void def##vertw() \
{ \
gle::defvertex(); \
defbody; \
} \
static inline void vertw(float v1, float v2, float v3) \
{ \
float h = -WATER_OFFSET; \
gle::attribf(v1, v2, v3+h); \
body; \
}
#define WATER_OFFSET
Definition: world.hpp:23
#define WATERVARS (   name)
Value:
bvec name##color(0x14, 0x46, 0x50), name##fallcolor(0, 0, 0); \
HVARFR(name##colour, 0, 0x144650, 0xFFFFFF, \
{ \
if(!name##colour) name##colour = 0x144650; \
name##color = bvec((name##colour>>16)&0xFF, (name##colour>>8)&0xFF, name##colour&0xFF); \
}); \
VARR(name##fog, 0, 150, 10000); \
VARR(name##spec, 0, 150, 1000); \
HVARFR(name##fallcolour, 0, 0, 0xFFFFFF, \
{ \
name##fallcolor = bvec((name##fallcolour>>16)&0xFF, (name##fallcolour>>8)&0xFF, name##fallcolour&0xFF); \
});
#define HVARFR(name, min, cur, max, body)
Definition: command.hpp:405
VARR(refractclear, 0, 0, 1)
SharedVar< int > fog
3-dimensional UNSIGNED CHAR vector.
Definition: geom.hpp:1398
if(NOT DEFINED PROJECT_ARCH) message(FATAL_ERROR"You are generating from the wrong folder! \"Where is the Source
Definition: CMakeLists.txt:2
static void color(const bvec &v, uchar alpha=255)
Definition: glemu.hpp:71

Function Documentation

void addreflection ( materialsurface m)
void addwaterfallrefraction ( materialsurface m)
static bool calcscissorbox ( Reflection ref,
int  size,
vec clipmin,
vec clipmax,
int &  sx,
int &  sy,
int &  sw,
int &  sh 
)
static
int calcwatersubdiv ( int  x,
int  y,
int  z,
int  size 
)

References camera1, vec::dist(), and physent::o.

Referenced by renderwaterlod().

void cleanreflection ( Reflection ref)
void cleanreflections ( )
static void drawmaterialquery ( const materialsurface m,
float  offset,
float  border = 0,
float  reflect = -1 
)
static
void drawreflection ( float  z,
bool  refract,
int  fogdepth = -1,
const bvec col = bvec(0, 0, 0) 
)
void drawreflections ( )
void genwatertex ( GLuint tex,
GLuint fb,
GLuint db,
bool  refract = false 
)
GLuint getwaterfalltex ( )
void maskreflection ( Reflection ref,
float  offset,
bool  reflect,
bool  clear = false 
)
void preloadwatershaders ( bool  force)
void queryreflection ( Reflection ref,
bool  init 
)
void queryreflections ( )
void renderflatwater ( int  x,
int  y,
int  z,
int  rsize,
int  csize,
int  mat 
)

References MAT_LAVA, MAT_WATER, and renderwaterquad.

Referenced by renderwater().

void renderlava ( const materialsurface m,
Texture tex,
float  scale 
)
void rendervertwater ( int  subdiv,
int  xo,
int  yo,
int  z,
int  size,
int  mat 
)
static void renderwater ( const materialsurface m,
int  mat = MAT_WATER 
)
inlinestatic
void renderwater ( )
int renderwaterlod ( int  x,
int  y,
int  z,
int  size,
int  mat 
)
void setprojtexmatrix ( Reflection ref)

References camprojmatrix, and LOCALPARAM.

Referenced by renderwater(), and setupwaterfallrefract().

void setupwaterfallrefract ( )
VAR ( oqwater  ,
,
,
 
)
VAR ( maskreflect  ,
,
,
16   
)
VAR ( reflectscissor  ,
,
,
 
)
VAR ( reflectvfc  ,
,
,
 
)
VARFP ( waterreflect  ,
,
,
,
{cleanreflections();preloadwatershaders();}   
)
VARFP ( waterrefract  ,
,
,
,
{cleanreflections();preloadwatershaders();}   
)
VARFP ( waterenvmap  ,
,
,
,
{cleanreflections();preloadwatershaders();}   
)
VARFP ( waterfallrefract  ,
,
,
,
{cleanreflections();preloadwatershaders();}   
)
VARFP ( vertwater  ,
,
,
,
allchanged()   
)
VARFP ( waterfade  ,
,
,
,
{cleanreflections();preloadwatershaders();}   
)
VARFP ( reflectsize  ,
,
,
10  ,
cleanreflections()   
)
VARP ( watersubdiv  ,
,
,
 
)
VARP ( waterlod  ,
,
,
 
)
VARP ( reflectdist  ,
,
2000  ,
10000   
)
VARP ( maxreflect  ,
,
,
 
)
VARR ( refractclear  ,
,
,
 
)
VERTW ( vertwt  ,
{gle::deftexcoord0();}  ,
{gle::attribf(v1/8.0f, v2/8.0f);}   
)
VERTW ( vertl  ,
{gle::deftexcoord0();}  ,
{gle::attribf(lavaxk *(v1+lavascroll), lavayk *(v2+lavascroll));}   
)

Variable Documentation

bool fading = false
bool fogging = false
float lavascroll = 0.0f
static

Referenced by renderlava().

float lavaxk = 1.0f
static

Referenced by renderlava().

float lavayk = 1.0f
static

Referenced by renderlava().

bool reflecting = false
GLuint reflectiondb = 0
GLuint reflectionfb = 0
Reflection reflections[MAXREFLECTIONS]
float reflectz = 1e16f
bvec refractcolor(0, 0, 0)
int refractfog = 0
int refracting = 0
int rplanes = 0
Reflection waterfallrefraction
float whoffset
static

Referenced by rendervertwater().

float whscale
static

Referenced by rendervertwater().

int wsize
static

Referenced by rendervertwater().

int wx1
static

Referenced by rendervertwater().

int wx2
static

Referenced by rendervertwater().

int wy1
static

Referenced by rendervertwater().

int wy2
static

Referenced by rendervertwater().