mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 15:21:44 +00:00
GL3: Dynamic Lightmaps (via blending)
well, seems to work, but once the lightmaps are rendered with the normal textured faces, maybe the dynamic part can be done in shader? (Might even look less blocky, because it's not limited to lightmap resolution then)
This commit is contained in:
parent
2932d995fe
commit
13789554ba
3 changed files with 23 additions and 31 deletions
|
@ -46,9 +46,7 @@ GL3_LM_UploadBlock(qboolean dynamic)
|
||||||
|
|
||||||
if (dynamic)
|
if (dynamic)
|
||||||
{
|
{
|
||||||
STUB_ONCE("TODO: dynamic lightmap!");
|
|
||||||
texture = 0;
|
texture = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -273,15 +271,14 @@ GL3_LM_BeginBuildingLightmaps(gl3model_t *m)
|
||||||
|
|
||||||
gl3_lms.current_lightmap_texture = 1;
|
gl3_lms.current_lightmap_texture = 1;
|
||||||
gl3_lms.internal_format = GL_LIGHTMAP_FORMAT;
|
gl3_lms.internal_format = GL_LIGHTMAP_FORMAT;
|
||||||
#if 0
|
|
||||||
/* initialize the dynamic lightmap texture */
|
/* initialize the dynamic lightmap texture */
|
||||||
GL3_Bind(gl3state.lightmap_textureIDs[0]);
|
GL3_Bind(gl3state.lightmap_textureIDs[0]);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, gl3_lms.internal_format,
|
glTexImage2D(GL_TEXTURE_2D, 0, gl3_lms.internal_format,
|
||||||
BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_LIGHTMAP_FORMAT,
|
BLOCK_WIDTH, BLOCK_HEIGHT, 0,
|
||||||
GL_UNSIGNED_BYTE, dummy);
|
GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, dummy);
|
||||||
#endif // 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -314,17 +314,15 @@ BlendLightmaps(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STUB_ONCE("TODO: Implement!");
|
|
||||||
#if 1
|
|
||||||
/* don't bother writing Z */
|
/* don't bother writing Z */
|
||||||
glDepthMask(0);
|
glDepthMask(0);
|
||||||
|
|
||||||
/* set the appropriate blending mode unless
|
/* set the appropriate blending mode unless
|
||||||
we're only looking at the lightmaps. */
|
we're only looking at the lightmaps. */
|
||||||
if ( 1 ) // TODO !gl_lightmap->value)
|
if ( !gl_lightmap->value )
|
||||||
{
|
{
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
#if 0
|
#if 0 // TODO: sth about saturatelighting
|
||||||
if (gl_saturatelighting->value)
|
if (gl_saturatelighting->value)
|
||||||
{
|
{
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
|
@ -380,13 +378,12 @@ BlendLightmaps(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* render dynamic lightmaps */
|
/* render dynamic lightmaps */
|
||||||
if (gl_dynamic->value)
|
if (gl_dynamic->value)
|
||||||
{
|
{
|
||||||
LM_InitBlock();
|
GL3_LM_InitBlock();
|
||||||
|
|
||||||
GL3_Bind(gl_state.lightmap_textures + 0);
|
GL3_Bind(gl3state.lightmap_textureIDs[0]);
|
||||||
|
|
||||||
if (currentmodel == gl3_worldmodel)
|
if (currentmodel == gl3_worldmodel)
|
||||||
{
|
{
|
||||||
|
@ -405,7 +402,7 @@ BlendLightmaps(void)
|
||||||
smax = (surf->extents[0] >> 4) + 1;
|
smax = (surf->extents[0] >> 4) + 1;
|
||||||
tmax = (surf->extents[1] >> 4) + 1;
|
tmax = (surf->extents[1] >> 4) + 1;
|
||||||
|
|
||||||
if (LM_AllocBlock(smax, tmax, &surf->dlight_s, &surf->dlight_t))
|
if (GL3_LM_AllocBlock(smax, tmax, &surf->dlight_s, &surf->dlight_t))
|
||||||
{
|
{
|
||||||
base = gl3_lms.lightmap_buffer;
|
base = gl3_lms.lightmap_buffer;
|
||||||
base += (surf->dlight_t * BLOCK_WIDTH +
|
base += (surf->dlight_t * BLOCK_WIDTH +
|
||||||
|
@ -418,7 +415,7 @@ BlendLightmaps(void)
|
||||||
msurface_t *drawsurf;
|
msurface_t *drawsurf;
|
||||||
|
|
||||||
/* upload what we have so far */
|
/* upload what we have so far */
|
||||||
LM_UploadBlock(true);
|
GL3_LM_UploadBlock(true);
|
||||||
|
|
||||||
/* draw all surfaces that use this lightmap */
|
/* draw all surfaces that use this lightmap */
|
||||||
for (drawsurf = newdrawsurf;
|
for (drawsurf = newdrawsurf;
|
||||||
|
@ -428,11 +425,11 @@ BlendLightmaps(void)
|
||||||
if (drawsurf->polys)
|
if (drawsurf->polys)
|
||||||
{
|
{
|
||||||
// Apply overbright bits to the dynamic lightmaps
|
// Apply overbright bits to the dynamic lightmaps
|
||||||
if (gl_overbrightbits->value)
|
/*if (gl_overbrightbits->value) TODO: overbrightbits stuff
|
||||||
{
|
{
|
||||||
R_TexEnv(GL_COMBINE_EXT);
|
R_TexEnv(GL_COMBINE_EXT);
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, gl_overbrightbits->value);
|
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, gl_overbrightbits->value);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
DrawGLPolyChain(drawsurf->polys,
|
DrawGLPolyChain(drawsurf->polys,
|
||||||
(drawsurf->light_s - drawsurf->dlight_s) * (1.0 / 128.0),
|
(drawsurf->light_s - drawsurf->dlight_s) * (1.0 / 128.0),
|
||||||
|
@ -443,10 +440,10 @@ BlendLightmaps(void)
|
||||||
newdrawsurf = drawsurf;
|
newdrawsurf = drawsurf;
|
||||||
|
|
||||||
/* clear the block */
|
/* clear the block */
|
||||||
LM_InitBlock();
|
GL3_LM_InitBlock();
|
||||||
|
|
||||||
/* try uploading the block now */
|
/* try uploading the block now */
|
||||||
if (!LM_AllocBlock(smax, tmax, &surf->dlight_s, &surf->dlight_t))
|
if (!GL3_LM_AllocBlock(smax, tmax, &surf->dlight_s, &surf->dlight_t))
|
||||||
{
|
{
|
||||||
ri.Sys_Error(ERR_FATAL,
|
ri.Sys_Error(ERR_FATAL,
|
||||||
"Consecutive calls to LM_AllocBlock(%d,%d) failed (dynamic)\n",
|
"Consecutive calls to LM_AllocBlock(%d,%d) failed (dynamic)\n",
|
||||||
|
@ -464,7 +461,7 @@ BlendLightmaps(void)
|
||||||
/* draw remainder of dynamic lightmaps that haven't been uploaded yet */
|
/* draw remainder of dynamic lightmaps that haven't been uploaded yet */
|
||||||
if (newdrawsurf)
|
if (newdrawsurf)
|
||||||
{
|
{
|
||||||
LM_UploadBlock(true);
|
GL3_LM_UploadBlock(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (surf = newdrawsurf; surf != 0; surf = surf->lightmapchain)
|
for (surf = newdrawsurf; surf != 0; surf = surf->lightmapchain)
|
||||||
|
@ -472,11 +469,12 @@ BlendLightmaps(void)
|
||||||
if (surf->polys)
|
if (surf->polys)
|
||||||
{
|
{
|
||||||
// Apply overbright bits to the remainder lightmaps
|
// Apply overbright bits to the remainder lightmaps
|
||||||
|
/* TODO: overbrightbits
|
||||||
if (gl_overbrightbits->value)
|
if (gl_overbrightbits->value)
|
||||||
{
|
{
|
||||||
R_TexEnv(GL_COMBINE_EXT);
|
R_TexEnv(GL_COMBINE_EXT);
|
||||||
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, gl_overbrightbits->value);
|
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, gl_overbrightbits->value);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
DrawGLPolyChain(surf->polys,
|
DrawGLPolyChain(surf->polys,
|
||||||
(surf->light_s - surf->dlight_s) * (1.0 / 128.0),
|
(surf->light_s - surf->dlight_s) * (1.0 / 128.0),
|
||||||
|
@ -484,13 +482,11 @@ BlendLightmaps(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
/* restore state */
|
/* restore state */
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glDepthMask(1);
|
glDepthMask(1);
|
||||||
#endif // 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -533,8 +529,8 @@ RenderBrushPoly(msurface_t *fa)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
R_TexEnv(GL_MODULATE);
|
R_TexEnv(GL_MODULATE);
|
||||||
glColor4f(gl_state.inverse_intensity, gl_state.inverse_intensity,
|
glColor4f(gl3state.inverse_intensity, gl3state.inverse_intensity,
|
||||||
gl_state.inverse_intensity, 1.0f);
|
gl3state.inverse_intensity, 1.0f);
|
||||||
}
|
}
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
|
@ -596,24 +592,24 @@ RenderBrushPoly(msurface_t *fa)
|
||||||
(fa->dlightframe != gl3_framecount))
|
(fa->dlightframe != gl3_framecount))
|
||||||
{
|
{
|
||||||
// undo dynamic light changes, put into non-dynamic lightmap chain?
|
// undo dynamic light changes, put into non-dynamic lightmap chain?
|
||||||
|
// (not totally sure what's happening here)
|
||||||
|
|
||||||
unsigned temp[34 * 34];
|
unsigned temp[34 * 34];
|
||||||
int smax, tmax;
|
int smax, tmax;
|
||||||
|
|
||||||
smax = (fa->extents[0] >> 4) + 1;
|
smax = (fa->extents[0] >> 4) + 1;
|
||||||
tmax = (fa->extents[1] >> 4) + 1;
|
tmax = (fa->extents[1] >> 4) + 1;
|
||||||
#if 0
|
|
||||||
GL3_BuildLightMap(fa, (void *)temp, smax * 4);
|
GL3_BuildLightMap(fa, (void *)temp, smax * 4);
|
||||||
GL3_SetCacheState(fa);
|
GL3_SetCacheState(fa);
|
||||||
|
|
||||||
GL3_Bind(gl3state.lightmap_textures + fa->lightmaptexturenum);
|
GL3_Bind(gl3state.lightmap_textureIDs[fa->lightmaptexturenum]);
|
||||||
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, fa->light_s, fa->light_t,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, fa->light_s, fa->light_t,
|
||||||
smax, tmax, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, temp);
|
smax, tmax, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, temp);
|
||||||
|
|
||||||
fa->lightmapchain = gl3_lms.lightmap_surfaces[fa->lightmaptexturenum];
|
fa->lightmapchain = gl3_lms.lightmap_surfaces[fa->lightmaptexturenum];
|
||||||
gl3_lms.lightmap_surfaces[fa->lightmaptexturenum] = fa;
|
gl3_lms.lightmap_surfaces[fa->lightmaptexturenum] = fa;
|
||||||
#endif // 0
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -627,7 +623,6 @@ RenderBrushPoly(msurface_t *fa)
|
||||||
fa->lightmapchain = gl3_lms.lightmap_surfaces[fa->lightmaptexturenum];
|
fa->lightmapchain = gl3_lms.lightmap_surfaces[fa->lightmaptexturenum];
|
||||||
gl3_lms.lightmap_surfaces[fa->lightmaptexturenum] = fa;
|
gl3_lms.lightmap_surfaces[fa->lightmaptexturenum] = fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -650,7 +645,7 @@ GL3_DrawAlphaSurfaces(void)
|
||||||
|
|
||||||
/* the textures are prescaled up for a better
|
/* the textures are prescaled up for a better
|
||||||
lighting range, so scale it back down */
|
lighting range, so scale it back down */
|
||||||
//intens = gl_state.inverse_intensity;
|
//intens = gl3state.inverse_intensity;
|
||||||
STUB_ONCE("Something about inverse intensity??");
|
STUB_ONCE("Something about inverse intensity??");
|
||||||
|
|
||||||
for (s = gl3_alpha_surfaces; s != NULL; s = s->texturechain)
|
for (s = gl3_alpha_surfaces; s != NULL; s = s->texturechain)
|
||||||
|
|
|
@ -463,7 +463,7 @@ extern cvar_t *gl_lightlevel;
|
||||||
extern cvar_t *gl_overbrightbits;
|
extern cvar_t *gl_overbrightbits;
|
||||||
|
|
||||||
extern cvar_t *gl_modulate;
|
extern cvar_t *gl_modulate;
|
||||||
|
extern cvar_t *gl_lightmap;
|
||||||
extern cvar_t *gl_stencilshadow;
|
extern cvar_t *gl_stencilshadow;
|
||||||
|
|
||||||
extern cvar_t *gl_dynamic;
|
extern cvar_t *gl_dynamic;
|
||||||
|
|
Loading…
Reference in a new issue