Voxel fixes from Nuke

git-svn-id: https://svn.eduke32.com/eduke32@7788 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-07-13 03:20:17 +00:00 committed by Christoph Oelckers
parent 4e04e4a096
commit f46db45970
2 changed files with 33 additions and 17 deletions

View file

@ -4761,11 +4761,10 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int
dayscale = scale(dayscale, mulscale16(xdimenscale,viewingrangerecip), xdimen<<8); dayscale = scale(dayscale, mulscale16(xdimenscale,viewingrangerecip), xdimen<<8);
const int32_t daxscalerecip = divideu32_noinline(1<<30, daxscale); const int32_t daxscalerecip = divideu32_noinline(1<<30, daxscale);
const int32_t dayscalerecip = divideu32_noinline(1<<30, dayscale);
int32_t *longptr = (int32_t *)davoxptr; int32_t *longptr = (int32_t *)davoxptr;
const int32_t daxsiz = B_LITTLE32(longptr[0]), daysiz = B_LITTLE32(longptr[1]), dazsiz = B_LITTLE32(longptr[2]); const int32_t daxsiz = B_LITTLE32(longptr[0]), daysiz = B_LITTLE32(longptr[1]), dazsiz = B_LITTLE32(longptr[2]);
int32_t daxpivot = B_LITTLE32(longptr[3]), daypivot = B_LITTLE32(longptr[4]);// dazpivot = B_LITTLE32(longptr[5]); int32_t daxpivot = B_LITTLE32(longptr[3]), daypivot = B_LITTLE32(longptr[4]), dazpivot = B_LITTLE32(longptr[5]);
if (cstat & 4) daxpivot = (daxsiz<<8)-daxpivot; if (cstat & 4) daxpivot = (daxsiz<<8)-daxpivot;
davoxptr += (6<<2); davoxptr += (6<<2);
@ -4782,8 +4781,8 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int
x = (dasprx-globalposx) - dmulscale18(daxpivot,sprcosang, daypivot,-sprsinang); x = (dasprx-globalposx) - dmulscale18(daxpivot,sprcosang, daypivot,-sprsinang);
y = (daspry-globalposy) - dmulscale18(daypivot,sprcosang, daxpivot,sprsinang); y = (daspry-globalposy) - dmulscale18(daypivot,sprcosang, daxpivot,sprsinang);
cosang = mulscale16(cosang, dayscalerecip); cosang <<= 2;
sinang = mulscale16(sinang, dayscalerecip); sinang <<= 2;
const voxint_t gxstart = (voxint_t)y*cosang - (voxint_t)x*sinang; const voxint_t gxstart = (voxint_t)y*cosang - (voxint_t)x*sinang;
const voxint_t gystart = (voxint_t)x*cosang + (voxint_t)y*sinang; const voxint_t gystart = (voxint_t)x*cosang + (voxint_t)y*sinang;
@ -4800,9 +4799,18 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int
if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale)) if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale))
return; return;
const int32_t syoff = divscale21(globalposz-dasprz,odayscale) + (dazsiz<<14); int32_t zoff = dazsiz<<14;
floorz = min(floorz, dasprz+mulscale7(dazsiz,odayscale)); if (!(cstat & 128))
ceilingz = max(ceilingz, dasprz-mulscale7(dazsiz, odayscale)); zoff += dazpivot<<7;
else if ((cstat&48) != 48)
{
zoff += dazpivot<<7;
zoff -= dazsiz<<14;
}
const int32_t syoff = divscale21(globalposz-dasprz,odayscale)+zoff;
floorz = min(floorz, dasprz+mulscale21(-zoff+(dazsiz<<15),odayscale));
ceilingz = max(ceilingz, dasprz+mulscale21(-zoff, odayscale));
const int32_t flooroff = divscale21(floorz-globalposz,odayscale); const int32_t flooroff = divscale21(floorz-globalposz,odayscale);
const int32_t ceilingoff = divscale21(ceilingz-globalposz,odayscale); const int32_t ceilingoff = divscale21(ceilingz-globalposz,odayscale);
int32_t yoff = (klabs(gxinc)+klabs(gyinc))>>1; int32_t yoff = (klabs(gxinc)+klabs(gyinc))>>1;
@ -4951,10 +4959,10 @@ static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int
rx -= lx; rx -= lx;
const int32_t l1 = distrecip[clamp((ny-yoff)>>14, 1, DISTRECIPSIZ-1)]; const int32_t l1 = mulscale12(distrecip[clamp((ny-yoff)>>14, 1, DISTRECIPSIZ-1)], dayscale);
// FIXME! AMCTC RC2/beta shotgun voxel // FIXME! AMCTC RC2/beta shotgun voxel
// (e.g. training map right after M16 shooting): // (e.g. training map right after M16 shooting):
const int32_t l2 = distrecip[clamp((ny+yoff)>>14, 1, DISTRECIPSIZ-1)]; const int32_t l2 = mulscale12(distrecip[clamp((ny+yoff)>>14, 1, DISTRECIPSIZ-1)], dayscale);
int32_t cz1 = 0, cz2 = INT32_MAX; int32_t cz1 = 0, cz2 = INT32_MAX;
if (clipcf) if (clipcf)
@ -6116,8 +6124,6 @@ draw_as_face_sprite:
nyrepeat = ((int32_t)tspr->yrepeat)*voxscale[vtilenum]; nyrepeat = ((int32_t)tspr->yrepeat)*voxscale[vtilenum];
} }
if (!(cstat&128))
tspr->z -= mulscale22(B_LITTLE32(longptr[5]),nyrepeat);
off.x = tspr->xoffset; off.x = tspr->xoffset;
off.y = /*picanm[sprite[tspr->owner].picnum].yofs +*/ tspr->yoffset; off.y = /*picanm[sprite[tspr->owner].picnum].yofs +*/ tspr->yoffset;
if (cstat & 4) off.x = -off.x; if (cstat & 4) off.x = -off.x;
@ -6158,6 +6164,9 @@ draw_as_face_sprite:
if ((cstat&4) == 0) x1 -= i; else x1 += i; if ((cstat&4) == 0) x1 -= i; else x1 += i;
y1 = mulscale16(tspr->z-globalposz,xdsiz); y1 = mulscale16(tspr->z-globalposz,xdsiz);
if (!(cstat & 128))
y1 -= mulscale16(mulscale22(B_LITTLE32(longptr[5]), nyrepeat), xdsiz);
//y1 -= mulscale30(xdsiz,nyrepeat*yoff); //y1 -= mulscale30(xdsiz,nyrepeat*yoff);
y1 += (globalhoriz<<8)-siz.y; y1 += (globalhoriz<<8)-siz.y;
//if (cstat&128) //Already fixed up above //if (cstat&128) //Already fixed up above
@ -6196,7 +6205,7 @@ draw_as_face_sprite:
const int32_t floorz = (sec->floorstat&3) == 0 ? sec->floorz : INT32_MAX; const int32_t floorz = (sec->floorstat&3) == 0 ? sec->floorz : INT32_MAX;
classicDrawVoxel(tspr->x,tspr->y,tspr->z,i,daxrepeat,(int32_t)tspr->yrepeat,vtilenum, classicDrawVoxel(tspr->x,tspr->y,tspr->z,i,daxrepeat,(int32_t)tspr->yrepeat,vtilenum,
tspr->shade,tspr->pal,lwall,swall,cstat,(tspr->cstat&48)!=48,floorz,ceilingz); tspr->shade,tspr->pal,lwall,swall,tspr->cstat,(tspr->cstat&48)!=48,floorz,ceilingz);
} }
} }

View file

@ -1013,7 +1013,7 @@ voxmodel_t *loadkvxfrombuf(const char *kvxbuffer, int32_t length)
int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
{ {
// float clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98}; // float clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98};
float f, g, k0; float f, g, k0, zoff;
if ((intptr_t)m == (intptr_t)(-1)) // hackhackhack if ((intptr_t)m == (intptr_t)(-1)) // hackhackhack
return 0; return 0;
@ -1048,7 +1048,14 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
k0 = (float) tspr->z; k0 = (float) tspr->z;
f = ((globalorientation&8) && (sprite[tspr->owner].cstat&48)!=0) ? -4.f : 4.f; f = ((globalorientation&8) && (sprite[tspr->owner].cstat&48)!=0) ? -4.f : 4.f;
k0 -= (tspr->yoffset*tspr->yrepeat)*f*m->bscale; k0 -= (tspr->yoffset*tspr->yrepeat)*f*m->bscale;
if (!(tspr->cstat&128)) k0 -= (m->piv.z*tspr->yrepeat)*4.f*m->scale; zoff = m->siz.z*.5f;
if (!(tspr->cstat&128))
zoff += m->piv.z;
else if ((tspr->cstat&48) != 48)
{
zoff += m->piv.z;
zoff -= m->siz.z*.5f;
}
f = (65536.f*512.f) / ((float)xdimen*viewingrange); f = (65536.f*512.f) / ((float)xdimen*viewingrange);
g = 32.f / ((float)xdimen*gxyaspect); g = 32.f / ((float)xdimen*gxyaspect);
@ -1114,9 +1121,9 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
g = m0.y*f; mat[4] = omat[8]*g; mat[5] = omat[9]*g; mat[6] = omat[10]*g; g = m0.y*f; mat[4] = omat[8]*g; mat[5] = omat[9]*g; mat[6] = omat[10]*g;
g =-m0.z*f; mat[8] = omat[4]*g; mat[9] = omat[5]*g; mat[10] = omat[6]*g; g =-m0.z*f; mat[8] = omat[4]*g; mat[9] = omat[5]*g; mat[10] = omat[6]*g;
// //
mat[12] -= (m->piv.x*mat[0] + m->piv.y*mat[4] + m->siz.z*.5f*mat[8]); mat[12] -= (m->piv.x*mat[0] + m->piv.y*mat[4] + zoff*mat[8]);
mat[13] -= (m->piv.x*mat[1] + m->piv.y*mat[5] + m->siz.z*.5f*mat[9]); mat[13] -= (m->piv.x*mat[1] + m->piv.y*mat[5] + zoff*mat[9]);
mat[14] -= (m->piv.x*mat[2] + m->piv.y*mat[6] + m->siz.z*.5f*mat[10]); mat[14] -= (m->piv.x*mat[2] + m->piv.y*mat[6] + zoff*mat[10]);
// //
glMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation glMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation
mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f;