Browse Source

ref_soft: Decals support

pull/2/head
mittorn 6 years ago
parent
commit
1871f39b2b
  1. 31
      r_context.c
  2. 1296
      r_decals.c
  3. 10
      r_local.h
  4. 4
      r_main.c
  5. 128
      r_surf.c

31
r_context.c

@ -387,27 +387,6 @@ qboolean VID_CubemapShot(const char *base, uint size, const float *vieworg, qboo @@ -387,27 +387,6 @@ qboolean VID_CubemapShot(const char *base, uint size, const float *vieworg, qboo
// cubemaps? in my softrender???
}
void R_DecalShoot(int textureIndex, int entityIndex, int modelIndex, vec3_t pos, int flags, float scale)
{
}
void R_DecalRemoveAll(int texture)
{
}
int R_CreateDecalList(decallist_t *pList)
{
return 0;
}
void R_ClearAllDecals()
{
}
void R_InitSkyClouds(mip_t *mt, texture_t *tx, qboolean custom_palette)
{
@ -448,16 +427,6 @@ void DrawSingleDecal(decal_t *pDecal, msurface_t *fa) @@ -448,16 +427,6 @@ void DrawSingleDecal(decal_t *pDecal, msurface_t *fa)
}
float *R_DecalSetupVerts(decal_t *pDecal, msurface_t *surf, int texture, int *outCount)
{
return NULL;
}
void R_EntityRemoveDecals(model_t *mod)
{
}
void GL_SelectTexture(int texture)
{

1296
r_decals.c

File diff suppressed because it is too large Load Diff

10
r_local.h

@ -406,18 +406,18 @@ int R_CullModel( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax ); @@ -406,18 +406,18 @@ int R_CullModel( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax );
qboolean R_CullBox( const vec3_t mins, const vec3_t maxs );
qboolean R_CullSphere( const vec3_t centre, const float radius );
//int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags );
#endif
//
// gl_decals.c
//
void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse );
float *R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *outCount );
void DrawSingleDecal( decal_t *pDecal, msurface_t *fa );
//void DrawSingleDecal( decal_t *pDecal, msurface_t *fa );
void R_EntityRemoveDecals( model_t *mod );
void DrawDecalsBatch( void );
//void DrawDecalsBatch( void );
void R_ClearDecals( void );
#if 0
//
// gl_drawhulls.c
@ -1223,6 +1223,8 @@ extern cvar_t *sw_stipplealpha; @@ -1223,6 +1223,8 @@ extern cvar_t *sw_stipplealpha;
extern cvar_t *sw_surfcacheoverride;
extern cvar_t *sw_waterwarp;
extern cvar_t *sw_texfilt;
extern cvar_t *r_decals;
extern vec3_t modelorg;
extern vec3_t r_origin;

4
r_main.c

@ -104,6 +104,8 @@ cvar_t *vid_gamma; @@ -104,6 +104,8 @@ cvar_t *vid_gamma;
cvar_t *sw_lockpvs;
//PGM
cvar_t *r_decals;
mleaf_t *r_viewleaf;
int r_viewcluster, r_oldviewcluster;
@ -1925,7 +1927,7 @@ qboolean R_Init() @@ -1925,7 +1927,7 @@ qboolean R_Init()
sw_texfilt = gEngfuncs.Cvar_Get ("sw_texfilt", "0", 0, "texture dither");
//r_lefthand = ri.Cvar_Get( "hand", "0", FCVAR_USERINFO | FCVAR_ARCHIVE );
// r_speeds = ri.Cvar_Get ("r_speeds", "0", 0);
r_decals = gEngfuncs.pfnGetCvarPointer( "r_decals", 0 );
//r_drawworld = ri.Cvar_Get ("r_drawworld", "1", 0);
//r_dspeeds = ri.Cvar_Get ("r_dspeeds", "0", 0);
// r_lightlevel = ri.Cvar_Get ("r_lightlevel", "0", 0);

128
r_surf.c

@ -147,9 +147,9 @@ void R_AddDynamicLights( msurface_t *surf ) @@ -147,9 +147,9 @@ void R_AddDynamicLights( msurface_t *surf )
if( dist < minlight )
{
printf("dlight %f\n", dist);
//printf("dlight %f\n", dist);
//*(void**)0 = 0;
bl[0] += ((int)((rad - dist) * 256) * 7.5) / 256;
bl[0] += ((int)((rad - dist) * 256) * 7.5);
//bl[1] += ((int)((rad - dist) * 256) * 2.5) / 256;
//bl[2] += ((int)((rad - dist) * 256) * 2.5) / 256;
}
@ -237,7 +237,7 @@ static void R_BuildLightMap( ) @@ -237,7 +237,7 @@ static void R_BuildLightMap( )
t = 0;
if( t > 65535 * 3 )
t = 65535 * 3;
t = t * 31 / 65535 / 3;//(255*256 - t) >> (8 - VID_CBITS);
t = t / 2048 / 3;//(255*256 - t) >> (8 - VID_CBITS);
//if (t < (1 << 6))
//t = (1 << 6);
@ -961,6 +961,127 @@ int D_log2 (int num) @@ -961,6 +961,127 @@ int D_log2 (int num)
}
//=============================================================================
void R_DecalComputeBasis( msurface_t *surf, int flags, vec3_t textureSpaceBasis[3] );
void R_DrawSurfaceDecals()
{
msurface_t *fa = r_drawsurf.surf;
decal_t *p;
for( p = fa->pdecals; p; p = p->pnext)
{
pixel_t *dest, *source;
vec4_t textureU, textureV;
image_t *tex = R_GetTexture( p->texture );
int s1 = 0,t1 = 0, s2 = tex->width, t2 = tex->height;
unsigned int height;
unsigned int f, fstep;
int skip;
pixel_t *buffer;
qboolean transparent;
int x, y, u,v, sv, w, h;
vec3_t basis[3];
Vector4Copy( fa->texinfo->vecs[0], textureU );
Vector4Copy( fa->texinfo->vecs[1], textureV );
R_DecalComputeBasis( fa, 0, basis );
w = fabs( tex->width * DotProduct( textureU, basis[0] )) +
fabs( tex->height * DotProduct( textureU, basis[1] ));
h = fabs( tex->width * DotProduct( textureV, basis[0] )) +
fabs( tex->height * DotProduct( textureV, basis[1] ));
// project decal center into the texture space of the surface
x = DotProduct( p->position, textureU ) + textureU[3] - fa->texturemins[0] - w/2;
y = DotProduct( p->position, textureV ) + textureV[3] - fa->texturemins[1] - h/2;
x = x >> r_drawsurf.surfmip;
y = y >> r_drawsurf.surfmip;
w = w >> r_drawsurf.surfmip;
h = h >> r_drawsurf.surfmip;
if( x < 0 )
{
s1 += (-x)*(s2-s1) / w;
x = 0;
}
if( x + w > r_drawsurf.surfwidth )
{
s2 -= (x + w - r_drawsurf.surfwidth) * (s2 - s1)/ w ;
w = r_drawsurf.surfwidth - x;
}
if( y + h > r_drawsurf.surfheight )
{
t2 -= (y + h - r_drawsurf.surfheight) * (t2 - t1) / h;
h = r_drawsurf.surfheight - y;
}
if( !tex->pixels[0] || s1 >= s2 || t1 >= t2 )
continue;
if( tex->alpha_pixels )
{
buffer = tex->alpha_pixels;
transparent = true;
}
else
buffer = tex->pixels[0];
height = h;
if (y < 0)
{
skip = -y;
height += y;
y = 0;
}
else
skip = 0;
dest = ((pixel_t*)r_drawsurf.surfdat) + y * r_drawsurf.rowbytes + x;
for (v=0 ; v<height ; v++)
{
//int alpha1 = vid.alpha;
sv = (skip + v)*(t2-t1)/h + t1;
source = buffer + sv*tex->width + s1;
{
f = 0;
fstep = s2*0x10000/w;
if( w == s2 - s1 )
fstep = 0x10000;
for (u=0 ; u<w ; u++)
{
pixel_t src = source[f>>16];
int alpha = 7;
f += fstep;
if( transparent )
{
alpha &= src >> 16 - 3;
src = src << 3;
}
if( alpha <= 0 )
continue;
if( alpha < 7) // && (vid.rendermode == kRenderTransAlpha || vid.rendermode == kRenderTransTexture ) )
{
pixel_t screen = dest[u]; // | 0xff & screen & src ;
dest[u] = vid.alphamap[( alpha << 16)|(src & 0xff00)|(screen>>8)] << 8 | (screen & 0xff) | ((src & 0xff) >> 3);
}
else
dest[u] = src;
}
}
dest += r_drawsurf.rowbytes;
}
}
}
/*
================
@ -1054,6 +1175,7 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel) @@ -1054,6 +1175,7 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel)
// rasterize the surface into the cache
R_DrawSurface ();
R_DrawSurfaceDecals();
return cache;
}

Loading…
Cancel
Save