Browse Source

ref_soft: Partial world luxels support

pull/2/head
mittorn 5 years ago
parent
commit
1c0262a8c4
  1. 8
      r_bsp.c
  2. 29
      r_edge.c
  3. 126
      r_surf.c

8
r_bsp.c

@ -35,8 +35,8 @@ int r_currentbkey; @@ -35,8 +35,8 @@ int r_currentbkey;
typedef enum {touchessolid, drawnode, nodrawnode} solidstate_t;
#define MAX_BMODEL_VERTS 500 // 6K
#define MAX_BMODEL_EDGES 1000 // 12K
#define MAX_BMODEL_VERTS 1000 // 12K
#define MAX_BMODEL_EDGES 2000 // 24K
static mvertex_t *pbverts;
static bedge_t *pbedges;
@ -421,7 +421,7 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf) @@ -421,7 +421,7 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
// FIXME: share the clip edge by having a winding direction flag?
if (numbedges >= (MAX_BMODEL_EDGES - 1))
{
gEngfuncs.Con_Printf ("Out of edges for bmodel\n");
//gEngfuncs.Con_Printf ("Out of edges for bmodel\n");
return;
}
@ -465,7 +465,7 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf) @@ -465,7 +465,7 @@ void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf)
{
if (numbedges >= (MAX_BMODEL_EDGES - 2))
{
gEngfuncs.Con_Printf ("Out of edges for bmodel\n");
//gEngfuncs.Con_Printf ("Out of edges for bmodel\n");
return;
}

29
r_edge.c

@ -821,8 +821,17 @@ void D_CalcGradients (msurface_t *pface) @@ -821,8 +821,17 @@ void D_CalcGradients (msurface_t *pface)
mipscale = 1.0 / (float)(1 << miplevel);
if( pface->texinfo->flags & TEX_WORLD_LUXELS )
{
TransformVector (pface->texinfo->vecs[0], p_saxis);
TransformVector (pface->texinfo->vecs[1], p_taxis);
}
else
{
TransformVector (pface->info->lmvecs[0], p_saxis);
TransformVector (pface->info->lmvecs[1], p_taxis);
}
t = xscaleinv * mipscale;
d_sdivzstepu = p_saxis[0] * t;
@ -840,12 +849,24 @@ void D_CalcGradients (msurface_t *pface) @@ -840,12 +849,24 @@ void D_CalcGradients (msurface_t *pface)
VectorScale (transformed_modelorg, mipscale, p_temp1);
t = 0x10000*mipscale;
if( pface->texinfo->flags & TEX_WORLD_LUXELS )
{
sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
((pface->texturemins[0] << 16) >> miplevel)
+ pface->texinfo->vecs[0][3]*t;
tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
((pface->texturemins[1] << 16) >> miplevel)
+ pface->texinfo->vecs[1][3]*t;
}
else
{
sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
((pface->info->lightmapmins[0] << 16) >> miplevel)
+ pface->info->lmvecs[0][3]*t;
tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
((pface->info->lightmapmins[1] << 16) >> miplevel)
+ pface->info->lmvecs[1][3]*t;
}
// PGM - changing flow speed for non-warping textures.
if (pface->flags & SURF_CONVEYOR)
{
@ -859,6 +880,12 @@ void D_CalcGradients (msurface_t *pface) @@ -859,6 +880,12 @@ void D_CalcGradients (msurface_t *pface)
else
bbextents = ((pface->info->lightextents[0] << 16) >> miplevel) - 1;
bbextentt = ((pface->info->lightextents[1] << 16) >> miplevel) - 1;
if( pface->texinfo->flags & TEX_WORLD_LUXELS )
{
bbextents = ((pface->extents[0] << 16) >> miplevel) - 1;
bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
}
}
@ -1139,8 +1166,6 @@ void D_SolidSurf (surf_t *s) @@ -1139,8 +1166,6 @@ void D_SolidSurf (surf_t *s)
if( !pface )
return;
#if 1
if( pface->flags & SURF_CONVEYOR )
miplevel = 1;
else

126
r_surf.c

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// r_surf.c: surface-related refresh code
#include "r_local.h"
#include "mod_local.h"
drawsurf_t r_drawsurf;
@ -41,6 +42,9 @@ void R_DrawSurfaceBlock8_mip1 (void); @@ -41,6 +42,9 @@ void R_DrawSurfaceBlock8_mip1 (void);
void R_DrawSurfaceBlock8_mip2 (void);
void R_DrawSurfaceBlock8_mip3 (void);
void R_DrawSurfaceBlock8_Generic (void);
void R_DrawSurfaceBlock8_World (void);
static float worldlux_s, worldlux_t;
static void (*surfmiptable[4])(void) = {
R_DrawSurfaceBlock8_mip0,
@ -93,8 +97,8 @@ void R_AddDynamicLights( msurface_t *surf ) @@ -93,8 +97,8 @@ void R_AddDynamicLights( msurface_t *surf )
{
if( surf->texinfo->faceinfo )
sample_frac = surf->texinfo->faceinfo->texture_step;
//else if( FBitSet( surf->texinfo->flags, TEX_EXTRA_LIGHTMAP ))
// sample_frac = LM_SAMPLE_EXTRASIZE;
else if( FBitSet( surf->texinfo->flags, TEX_EXTRA_LIGHTMAP ))
sample_frac = LM_SAMPLE_EXTRASIZE;
else sample_frac = LM_SAMPLE_SIZE;
}
@ -504,7 +508,6 @@ void R_DrawSurface (void) @@ -504,7 +508,6 @@ void R_DrawSurface (void)
else
sample_pot = 1 << sample_bits;
}
mt = r_drawsurf.image;
r_source = mt->pixels[r_drawsurf.surfmip];
@ -526,6 +529,7 @@ void R_DrawSurface (void) @@ -526,6 +529,7 @@ void R_DrawSurface (void)
r_numhblocks = r_drawsurf.surfwidth >> blockdivshift;
r_numvblocks = r_drawsurf.surfheight >> blockdivshift;
//==============================
if( sample_size == 16 )
@ -544,8 +548,46 @@ void R_DrawSurface (void) @@ -544,8 +548,46 @@ void R_DrawSurface (void)
r_sourcemax = r_source + (tmax * smax);
//soffset = r_drawsurf.surf->texturemins[0];
//basetoffset = r_drawsurf.surf->texturemins[1];
// glitchy and slow way to draw some lightmap
if( r_drawsurf.surf->texinfo->flags & TEX_WORLD_LUXELS )
{
worldlux_s = r_drawsurf.surf->extents[0] / r_drawsurf.surf->info->lightextents[0];
worldlux_t = r_drawsurf.surf->extents[1] / r_drawsurf.surf->info->lightextents[1];
if( worldlux_s == 0 )
worldlux_s = 1;
if( worldlux_t == 0 )
worldlux_t = 1;
soffset = r_drawsurf.surf->texturemins[0];
basetoffset = r_drawsurf.surf->texturemins[1];
//soffset = r_drawsurf.surf->info->lightmapmins[0] * worldlux_s;
//basetoffset = r_drawsurf.surf->info->lightmapmins[1] * worldlux_t;
// << 16 components are to guarantee positive values for %
soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax;
basetptr = &r_source[((((basetoffset >> r_drawsurf.surfmip)
+ (tmax << 16)) % tmax) * twidth)];
pcolumndest = r_drawsurf.surfdat;
for (u=0 ; u<r_numhblocks; u++)
{
r_lightptr = blocklights + (int)(u/ (worldlux_s+0.5));
prowdestbase = pcolumndest;
pbasesource = basetptr + soffset;
R_DrawSurfaceBlock8_World();
soffset = soffset + horzblockstep;
if (soffset >= smax)
soffset = 0;
pcolumndest += horzblockstep;
}
return;
}
soffset = r_drawsurf.surf->info->lightmapmins[0];
basetoffset = r_drawsurf.surf->info->lightmapmins[1];
@ -566,7 +608,7 @@ void R_DrawSurface (void) @@ -566,7 +608,7 @@ void R_DrawSurface (void)
(*pblockdrawer)();
soffset = soffset + blocksize;
soffset = soffset + horzblockstep;
if (soffset >= smax)
soffset = 0;
@ -582,6 +624,63 @@ void R_DrawSurface (void) @@ -582,6 +624,63 @@ void R_DrawSurface (void)
#if !id386
#define BLEND_LM(pix, light) vid.colormap[(pix >> 3) | ((light & 0x1f00) << 5)] | pix & 7;
/*
================
R_DrawSurfaceBlock8_World
Does not draw lightmap correclty, but scale it correctly. Better than nothing
================
*/
void R_DrawSurfaceBlock8_World (void)
{
int v, i, b;
uint lightstep, lighttemp, light;
pixel_t pix, *psource, *prowdest;
int lightpos = 0;
psource = pbasesource;
prowdest = prowdestbase;
for (v=0 ; v<r_numvblocks ; v++)
{
// FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[(lightpos/r_lightwidth) * r_lightwidth];
lightright = r_lightptr[(lightpos/r_lightwidth) * r_lightwidth+1];
lightpos += r_lightwidth / worldlux_s;
lightleftstep = (r_lightptr[(lightpos/r_lightwidth) * r_lightwidth] - lightleft) >> (4-r_drawsurf.surfmip);
lightrightstep =(r_lightptr[(lightpos/r_lightwidth) * r_lightwidth+1] - lightright) >> (4-r_drawsurf.surfmip);
for (i=0 ; i<blocksize ; i++)
{
lighttemp = lightleft - lightright;
lightstep = lighttemp >> (4-r_drawsurf.surfmip);
light = lightright;
for (b=blocksize-1; b>=0; b--)
{
//pix = psource[(uint)(b * worldlux_s)];
pix = psource[b];
prowdest[b] = BLEND_LM(pix, light);
if( pix == TRANSPARENT_COLOR )
prowdest[b] = TRANSPARENT_COLOR;
//((unsigned char *)vid.colormap)
//[(light & 0xFF00) + pix];
light += lightstep;
}
psource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
prowdest += surfrowbytes;
}
if (psource >= r_sourcemax)
psource -= r_stepback;
}
}
/*
================
@ -1208,7 +1307,11 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) @@ -1208,7 +1307,11 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel)
//
r_drawsurf.image = R_GetTexture(R_TextureAnimation (surface)->gl_texturenum);
if( surface->flags & SURF_CONVEYOR )
// does not support conveyors with world luxels now
if( surface->texinfo->flags & TEX_WORLD_LUXELS )
surface->flags &= ~SURF_CONVEYOR;
if( surface->flags & SURF_CONVEYOR)
{
if( miplevel >= 1)
{
@ -1271,7 +1374,14 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) @@ -1271,7 +1374,14 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel)
r_drawsurf.surfwidth = surface->info->lightextents[0] >> miplevel;
r_drawsurf.rowbytes = r_drawsurf.surfwidth;
r_drawsurf.surfheight = surface->info->lightextents[1] >> miplevel;
//surface->extents[1] >> miplevel;
// use texture space if world luxels used
if( surface->texinfo->flags & TEX_WORLD_LUXELS )
{
r_drawsurf.surfwidth = surface->extents[0] >> miplevel;
r_drawsurf.rowbytes = r_drawsurf.surfwidth;
r_drawsurf.surfheight = surface->extents[1] >> miplevel;
}
//

Loading…
Cancel
Save