Skip to content

Commit

Permalink
Merge pull request #716 from qw-ctf/lit-water
Browse files Browse the repository at this point in the history
BSP, MODERN: Add support for lit water.
  • Loading branch information
tcsabina authored Dec 16, 2022
2 parents 4010a7d + 4b9c1fc commit 4d4ec00
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions gl_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct texture_s {
qbool loaded; //help speed up vid_restart, actual only for brush models
int isLumaTexture; //fb is luma texture, rather than normal fb
qbool isAlphaTested; //texture is flagged for alpha-testing
qbool isLitTurb; //turb texture has lightmap
int turbType;

int gl_width;
Expand Down
1 change: 1 addition & 0 deletions glm_rsurf.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ static qbool GLM_AssignTexture(int texture_num, texture_t* texture)
drawcall->mappings[index].flags = R_TextureReferenceIsValid(texture->fb_texturenum) && texture->isLumaTexture ? EZQ_SURFACE_HAS_LUMA : 0;
drawcall->mappings[index].flags |= R_TextureReferenceIsValid(texture->fb_texturenum) && !texture->isLumaTexture ? EZQ_SURFACE_HAS_FB : 0;
drawcall->mappings[index].flags |= R_TextureReferenceIsValid(texture->fb_texturenum) && texture->isAlphaTested ? EZQ_SURFACE_ALPHATEST : 0;
drawcall->mappings[index].flags |= texture->isLitTurb ? EZQ_SURFACE_LIT_TURB : 0;
return true;
}

Expand Down
1 change: 1 addition & 0 deletions glsl/constants.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define EZQ_SURFACE_WORLD 64 // world-surface (should have detail textures applied, r_drawflat applied)
#define EZQ_SURFACE_ALPHATEST 128 // alpha-testing should take place when rendering
#define EZQ_SURFACE_HAS_FB 256 // surface has fb texture in next array index
#define EZQ_SURFACE_LIT_TURB 512 // turb surface has lightmap

#define MAX_SAMPLER_MAPPINGS 256

Expand Down
3 changes: 3 additions & 0 deletions glsl/draw_world.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ void main()
}
else {
frag_colour = texColor * waterAlpha;
if ((Flags & EZQ_SURFACE_LIT_TURB) > 0) {
frag_colour = vec4(lmColor.rgb, 1) * frag_colour;
}
#ifdef DRAW_FOG
frag_colour = applyFog(frag_colour, gl_FragCoord.z / gl_FragCoord.w);
#endif
Expand Down
4 changes: 3 additions & 1 deletion r_brushmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ static int R_BrushModelPopulateVBO(model_t* m, void* vbo_buffer, int vbo_pos)
has_luma = has_fb & m->textures[i]->isLumaTexture;
for (j = 0; j < m->nummodelsurfaces; ++j) {
msurface_t* surf = m->surfaces + m->firstmodelsurface + j;
int lightmap = surf->flags & (SURF_DRAWTURB | SURF_DRAWSKY) ? -1 : surf->lightmaptexturenum;
qbool isTurbOrSky = surf->flags & (SURF_DRAWTURB | SURF_DRAWSKY);
qbool isLitTurb = surf->texinfo->texture->isLitTurb;
int lightmap = isTurbOrSky && !isLitTurb ? -1 : surf->lightmaptexturenum;
glpoly_t* poly;

if (surf->texinfo->miptex != i) {
Expand Down
12 changes: 6 additions & 6 deletions r_brushmodel_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ model_t* Mod_FindName(const char *name);

static void SetTextureFlags(model_t* mod, msurface_t* out, int surfnum)
{
int i;

out->texinfo->surfaces++;

// set the drawing flags flag
Expand All @@ -68,12 +66,14 @@ static void SetTextureFlags(model_t* mod, msurface_t* out, int surfnum)
}

if (Mod_IsTurbTextureName(mod, out->texinfo->texture->name)) { // turbulent
out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
out->flags |= SURF_DRAWTURB;
out->texinfo->skippable = false;

for (i = 0; i < 2; i++) {
out->extents[i] = 16384;
out->texturemins[i] = -8192;
// check if texture should receive no lighting.
if (out->texinfo->flags & TEX_SPECIAL) {
out->flags |= SURF_DRAWTILED;
} else {
out->texinfo->texture->isLitTurb = true;
}
R_TurbSurfacesSubdivide(out); // cut up polygon for warps
return;
Expand Down
6 changes: 2 additions & 4 deletions r_lightmaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static void R_BuildSurfaceDisplayList(model_t* currentmodel, msurface_t *fa)
poly->verts[i][4] = t;

// lightmap texture coordinates
if (isTurb) {
if (isTurb && !fa->texinfo->texture->isLitTurb) {
poly->verts[i][5] = poly->verts[i][6] = 0;
poly->verts[i][7] = poly->verts[i][8] = 0;
}
Expand Down Expand Up @@ -880,9 +880,7 @@ void R_BuildLightmaps(void)
continue;
}

if (!isTurb) {
R_LightmapCreateForSurface(m->surfaces + i, m->isworldmodel ? m->surfaces[i].surfacenum : -1);
}
R_LightmapCreateForSurface(m->surfaces + i, m->isworldmodel ? m->surfaces[i].surfacenum : -1);
R_BuildSurfaceDisplayList(m, m->surfaces + i);
}
}
Expand Down

0 comments on commit 4d4ec00

Please sign in to comment.