mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-27 11:40:52 +00:00
OpenGL sprite billboarding
Should work on both normal and precipitation sprites. Papersprites should be unaffected. Sprites that are split by lighting should work correctly.
This commit is contained in:
parent
db18492836
commit
7c661f0537
1 changed files with 114 additions and 25 deletions
|
@ -4259,10 +4259,44 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is expecting a pointer to an array containing 4 wallVerts for a sprite
|
||||||
|
static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts)
|
||||||
|
{
|
||||||
|
if (spr && spr->mobj && !(spr->mobj->frame & FF_PAPERSPRITE) &&
|
||||||
|
wallVerts)
|
||||||
|
{ // This will eventually become an if statement
|
||||||
|
float basey = FIXED_TO_FLOAT(spr->mobj->z);
|
||||||
|
float lowy = wallVerts[0].y;
|
||||||
|
if (P_MobjFlip(spr->mobj) == -1)
|
||||||
|
{
|
||||||
|
basey = FIXED_TO_FLOAT(spr->mobj->z + spr->mobj->height);
|
||||||
|
}
|
||||||
|
// Rotate sprites to fully billboard with the camera
|
||||||
|
// X, Y, AND Z need to be manipulated for the polys to rotate around the
|
||||||
|
// origin, because of how the origin setting works I believe that should
|
||||||
|
// be mobj->z or mobj->z + mobj->height
|
||||||
|
wallVerts[2].y = wallVerts[3].y = (spr->ty - basey) * gr_viewludsin + basey;
|
||||||
|
wallVerts[0].y = wallVerts[1].y = (lowy - basey) * gr_viewludsin + basey;
|
||||||
|
// translate back to be around 0 before translating back
|
||||||
|
wallVerts[3].x += ((spr->ty - basey) * gr_viewludcos) * gr_viewcos;
|
||||||
|
wallVerts[2].x += ((spr->ty - basey) * gr_viewludcos) * gr_viewcos;
|
||||||
|
|
||||||
|
wallVerts[0].x += ((lowy - basey) * gr_viewludcos) * gr_viewcos;
|
||||||
|
wallVerts[1].x += ((lowy - basey) * gr_viewludcos) * gr_viewcos;
|
||||||
|
|
||||||
|
wallVerts[3].z += ((spr->ty - basey) * gr_viewludcos) * gr_viewsin;
|
||||||
|
wallVerts[2].z += ((spr->ty - basey) * gr_viewludcos) * gr_viewsin;
|
||||||
|
|
||||||
|
wallVerts[0].z += ((lowy - basey) * gr_viewludcos) * gr_viewsin;
|
||||||
|
wallVerts[1].z += ((lowy - basey) * gr_viewludcos) * gr_viewsin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void HWR_SplitSprite(gr_vissprite_t *spr)
|
static void HWR_SplitSprite(gr_vissprite_t *spr)
|
||||||
{
|
{
|
||||||
float this_scale = 1.0f;
|
float this_scale = 1.0f;
|
||||||
FOutVector wallVerts[4];
|
FOutVector wallVerts[4];
|
||||||
|
FOutVector baseWallVerts[4]; // This is what the verts should end up as
|
||||||
GLPatch_t *gpatch;
|
GLPatch_t *gpatch;
|
||||||
FSurfaceInfo Surf;
|
FSurfaceInfo Surf;
|
||||||
const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)spr->mobj->skin)->flags & SF_HIRES);
|
const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)spr->mobj->skin)->flags & SF_HIRES);
|
||||||
|
@ -4275,11 +4309,13 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
|
||||||
float realtop, realbot, top, bot;
|
float realtop, realbot, top, bot;
|
||||||
float towtop, towbot, towmult;
|
float towtop, towbot, towmult;
|
||||||
float bheight;
|
float bheight;
|
||||||
|
float realheight, heightmult;
|
||||||
const sector_t *sector = spr->mobj->subsector->sector;
|
const sector_t *sector = spr->mobj->subsector->sector;
|
||||||
const lightlist_t *list = sector->lightlist;
|
const lightlist_t *list = sector->lightlist;
|
||||||
#ifdef ESLOPE
|
#ifdef ESLOPE
|
||||||
float endrealtop, endrealbot, endtop, endbot;
|
float endrealtop, endrealbot, endtop, endbot;
|
||||||
float endbheight;
|
float endbheight;
|
||||||
|
float endrealheight;
|
||||||
fixed_t temp;
|
fixed_t temp;
|
||||||
fixed_t v1x, v1y, v2x, v2y;
|
fixed_t v1x, v1y, v2x, v2y;
|
||||||
#endif
|
#endif
|
||||||
|
@ -4312,16 +4348,16 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
|
||||||
HWR_DrawSpriteShadow(spr, gpatch, this_scale);
|
HWR_DrawSpriteShadow(spr, gpatch, this_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
wallVerts[0].x = wallVerts[3].x = spr->x1;
|
baseWallVerts[0].x = baseWallVerts[3].x = spr->x1;
|
||||||
wallVerts[2].x = wallVerts[1].x = spr->x2;
|
baseWallVerts[2].x = baseWallVerts[1].x = spr->x2;
|
||||||
wallVerts[0].z = wallVerts[3].z = spr->z1;
|
baseWallVerts[0].z = baseWallVerts[3].z = spr->z1;
|
||||||
wallVerts[1].z = wallVerts[2].z = spr->z2;
|
baseWallVerts[1].z = baseWallVerts[2].z = spr->z2;
|
||||||
|
|
||||||
wallVerts[2].y = wallVerts[3].y = spr->ty;
|
baseWallVerts[2].y = baseWallVerts[3].y = spr->ty;
|
||||||
if (spr->mobj && fabsf(this_scale - 1.0f) > 1.0E-36f)
|
if (spr->mobj && fabsf(this_scale - 1.0f) > 1.0E-36f)
|
||||||
wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height * this_scale;
|
baseWallVerts[0].y = baseWallVerts[1].y = spr->ty - gpatch->height * this_scale;
|
||||||
else
|
else
|
||||||
wallVerts[0].y = wallVerts[1].y = spr->ty - gpatch->height;
|
baseWallVerts[0].y = baseWallVerts[1].y = spr->ty - gpatch->height;
|
||||||
|
|
||||||
v1x = FLOAT_TO_FIXED(spr->x1);
|
v1x = FLOAT_TO_FIXED(spr->x1);
|
||||||
v1y = FLOAT_TO_FIXED(spr->z1);
|
v1y = FLOAT_TO_FIXED(spr->z1);
|
||||||
|
@ -4330,44 +4366,52 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
|
||||||
|
|
||||||
if (spr->flip)
|
if (spr->flip)
|
||||||
{
|
{
|
||||||
wallVerts[0].sow = wallVerts[3].sow = gpatch->max_s;
|
baseWallVerts[0].sow = baseWallVerts[3].sow = gpatch->max_s;
|
||||||
wallVerts[2].sow = wallVerts[1].sow = 0;
|
baseWallVerts[2].sow = baseWallVerts[1].sow = 0;
|
||||||
}else{
|
}else{
|
||||||
wallVerts[0].sow = wallVerts[3].sow = 0;
|
baseWallVerts[0].sow = baseWallVerts[3].sow = 0;
|
||||||
wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s;
|
baseWallVerts[2].sow = baseWallVerts[1].sow = gpatch->max_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// flip the texture coords (look familiar?)
|
// flip the texture coords (look familiar?)
|
||||||
if (spr->vflip)
|
if (spr->vflip)
|
||||||
{
|
{
|
||||||
wallVerts[3].tow = wallVerts[2].tow = gpatch->max_t;
|
baseWallVerts[3].tow = baseWallVerts[2].tow = gpatch->max_t;
|
||||||
wallVerts[0].tow = wallVerts[1].tow = 0;
|
baseWallVerts[0].tow = baseWallVerts[1].tow = 0;
|
||||||
}else{
|
}else{
|
||||||
wallVerts[3].tow = wallVerts[2].tow = 0;
|
baseWallVerts[3].tow = baseWallVerts[2].tow = 0;
|
||||||
wallVerts[0].tow = wallVerts[1].tow = gpatch->max_t;
|
baseWallVerts[0].tow = baseWallVerts[1].tow = gpatch->max_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it has a dispoffset, push it a little towards the camera
|
// if it has a dispoffset, push it a little towards the camera
|
||||||
if (spr->dispoffset) {
|
if (spr->dispoffset) {
|
||||||
float co = -gr_viewcos*(0.05f*spr->dispoffset);
|
float co = -gr_viewcos*(0.05f*spr->dispoffset);
|
||||||
float si = -gr_viewsin*(0.05f*spr->dispoffset);
|
float si = -gr_viewsin*(0.05f*spr->dispoffset);
|
||||||
wallVerts[0].z = wallVerts[3].z = wallVerts[0].z+si;
|
baseWallVerts[0].z = baseWallVerts[3].z = baseWallVerts[0].z+si;
|
||||||
wallVerts[1].z = wallVerts[2].z = wallVerts[1].z+si;
|
baseWallVerts[1].z = baseWallVerts[2].z = baseWallVerts[1].z+si;
|
||||||
wallVerts[0].x = wallVerts[3].x = wallVerts[0].x+co;
|
baseWallVerts[0].x = baseWallVerts[3].x = baseWallVerts[0].x+co;
|
||||||
wallVerts[1].x = wallVerts[2].x = wallVerts[1].x+co;
|
baseWallVerts[1].x = baseWallVerts[2].x = baseWallVerts[1].x+co;
|
||||||
}
|
}
|
||||||
|
|
||||||
realtop = top = wallVerts[3].y;
|
// Let dispoffset work first since this adjust each vertex
|
||||||
realbot = bot = wallVerts[0].y;
|
HWR_RotateSpritePolyToAim(spr, baseWallVerts);
|
||||||
towtop = wallVerts[3].tow;
|
|
||||||
towbot = wallVerts[0].tow;
|
realtop = top = baseWallVerts[3].y;
|
||||||
|
realbot = bot = baseWallVerts[0].y;
|
||||||
|
towtop = baseWallVerts[3].tow;
|
||||||
|
towbot = baseWallVerts[0].tow;
|
||||||
towmult = (towbot - towtop) / (top - bot);
|
towmult = (towbot - towtop) / (top - bot);
|
||||||
|
|
||||||
#ifdef ESLOPE
|
#ifdef ESLOPE
|
||||||
endrealtop = endtop = wallVerts[2].y;
|
endrealtop = endtop = baseWallVerts[2].y;
|
||||||
endrealbot = endbot = wallVerts[1].y;
|
endrealbot = endbot = baseWallVerts[1].y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// copy the contents of baseWallVerts into the drawn wallVerts array
|
||||||
|
// baseWallVerts is used to know the final shape to easily get the vertex
|
||||||
|
// co-ordinates
|
||||||
|
memcpy(wallVerts, baseWallVerts, sizeof(baseWallVerts));
|
||||||
|
|
||||||
if (!cv_translucency.value) // translucency disabled
|
if (!cv_translucency.value) // translucency disabled
|
||||||
{
|
{
|
||||||
Surf.FlatColor.s.alpha = 0xFF;
|
Surf.FlatColor.s.alpha = 0xFF;
|
||||||
|
@ -4494,12 +4538,51 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
|
||||||
wallVerts[2].y = endtop;
|
wallVerts[2].y = endtop;
|
||||||
wallVerts[0].y = bot;
|
wallVerts[0].y = bot;
|
||||||
wallVerts[1].y = endbot;
|
wallVerts[1].y = endbot;
|
||||||
|
|
||||||
|
// The x and y only need to be adjusted in the case that it's not a papersprite
|
||||||
|
if (spr->mobj && !(spr->mobj->frame & FF_PAPERSPRITE)) {
|
||||||
|
// Get the x and z of the vertices so billboarding draws correctly
|
||||||
|
realheight = realbot - realtop;
|
||||||
|
endrealheight = endrealbot - endrealtop;
|
||||||
|
heightmult = (realtop - top) / realheight;
|
||||||
|
wallVerts[3].x = baseWallVerts[3].x + (baseWallVerts[3].x - baseWallVerts[0].x) * heightmult;
|
||||||
|
wallVerts[3].z = baseWallVerts[3].z + (baseWallVerts[3].z - baseWallVerts[0].z) * heightmult;
|
||||||
|
|
||||||
|
heightmult = (endrealtop - endtop) / endrealheight;
|
||||||
|
wallVerts[2].x = baseWallVerts[2].x + (baseWallVerts[2].x - baseWallVerts[1].x) * heightmult;
|
||||||
|
wallVerts[2].z = baseWallVerts[2].z + (baseWallVerts[2].z - baseWallVerts[1].z) * heightmult;
|
||||||
|
|
||||||
|
heightmult = (realtop - bot) / realheight;
|
||||||
|
wallVerts[0].x = baseWallVerts[3].x + (baseWallVerts[3].x - baseWallVerts[0].x) * heightmult;
|
||||||
|
wallVerts[0].z = baseWallVerts[3].z + (baseWallVerts[3].z - baseWallVerts[0].z) * heightmult;
|
||||||
|
|
||||||
|
heightmult = (endrealtop - endbot) / endrealheight;
|
||||||
|
wallVerts[1].x = baseWallVerts[2].x + (baseWallVerts[2].x - baseWallVerts[1].x) * heightmult;
|
||||||
|
wallVerts[1].z = baseWallVerts[2].z + (baseWallVerts[2].z - baseWallVerts[1].z) * heightmult;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
wallVerts[3].tow = wallVerts[2].tow = towtop + ((realtop - top) * towmult);
|
wallVerts[3].tow = wallVerts[2].tow = towtop + ((realtop - top) * towmult);
|
||||||
wallVerts[0].tow = wallVerts[1].tow = towtop + ((realtop - bot) * towmult);
|
wallVerts[0].tow = wallVerts[1].tow = towtop + ((realtop - bot) * towmult);
|
||||||
|
|
||||||
wallVerts[2].y = wallVerts[3].y = top;
|
wallVerts[2].y = wallVerts[3].y = top;
|
||||||
wallVerts[0].y = wallVerts[1].y = bot;
|
wallVerts[0].y = wallVerts[1].y = bot;
|
||||||
|
|
||||||
|
// The x and y only need to be adjusted in the case that it's not a papersprite
|
||||||
|
if (spr->mobj && !(spr->mobj->frame & FF_PAPERSPRITE)) {
|
||||||
|
// Get the x and z of the vertices so billboarding draws correctly
|
||||||
|
realheight = realbot - realtop;
|
||||||
|
heightmult = (realtop - top) / realheight;
|
||||||
|
wallVerts[3].x = baseWallVerts[3].x + (baseWallVerts[3].x - baseWallVerts[0].x) * heightmult;
|
||||||
|
wallVerts[3].z = baseWallVerts[3].z + (baseWallVerts[3].z - baseWallVerts[0].z) * heightmult;
|
||||||
|
wallVerts[2].x = baseWallVerts[2].x + (baseWallVerts[2].x - baseWallVerts[1].x) * heightmult;
|
||||||
|
wallVerts[2].z = baseWallVerts[2].z + (baseWallVerts[2].z - baseWallVerts[1].z) * heightmult;
|
||||||
|
|
||||||
|
heightmult = (realtop - bot) / realheight;
|
||||||
|
wallVerts[0].x = baseWallVerts[3].x + (baseWallVerts[3].x - baseWallVerts[0].x) * heightmult;
|
||||||
|
wallVerts[0].z = baseWallVerts[3].z + (baseWallVerts[3].z - baseWallVerts[0].z) * heightmult;
|
||||||
|
wallVerts[1].x = baseWallVerts[2].x + (baseWallVerts[2].x - baseWallVerts[1].x) * heightmult;
|
||||||
|
wallVerts[1].z = baseWallVerts[2].z + (baseWallVerts[2].z - baseWallVerts[1].z) * heightmult;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (colormap)
|
if (colormap)
|
||||||
|
@ -4669,6 +4752,9 @@ static void HWR_DrawSprite(gr_vissprite_t *spr)
|
||||||
wallVerts[1].x = wallVerts[2].x = wallVerts[1].x+co;
|
wallVerts[1].x = wallVerts[2].x = wallVerts[1].x+co;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let dispoffset work first since this adjust each vertex
|
||||||
|
HWR_RotateSpritePolyToAim(spr, wallVerts);
|
||||||
|
|
||||||
// This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black.
|
// This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black.
|
||||||
// sprite lighting by modulating the RGB components
|
// sprite lighting by modulating the RGB components
|
||||||
/// \todo coloured
|
/// \todo coloured
|
||||||
|
@ -4750,6 +4836,9 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr)
|
||||||
wallVerts[0].z = wallVerts[3].z = spr->z1;
|
wallVerts[0].z = wallVerts[3].z = spr->z1;
|
||||||
wallVerts[1].z = wallVerts[2].z = spr->z2;
|
wallVerts[1].z = wallVerts[2].z = spr->z2;
|
||||||
|
|
||||||
|
// Let dispoffset work first since this adjust each vertex
|
||||||
|
HWR_RotateSpritePolyToAim(spr, wallVerts);
|
||||||
|
|
||||||
wallVerts[0].sow = wallVerts[3].sow = 0;
|
wallVerts[0].sow = wallVerts[3].sow = 0;
|
||||||
wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s;
|
wallVerts[2].sow = wallVerts[1].sow = gpatch->max_s;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue