OpenGL modes: factor out shade factor calculation.

This also means that the "r_shadescale_unbounded 0" option will work
in Polymer (except on models).

git-svn-id: https://svn.eduke32.com/eduke32@3286 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-12-14 19:28:01 +00:00
parent 13bff37caa
commit 884302bea1
3 changed files with 12 additions and 10 deletions

View file

@ -93,6 +93,13 @@ extern float alphahackarray[MAXTILES];
extern int32_t r_usenewshading; extern int32_t r_usenewshading;
static inline float getshadefactor(int32_t shade)
{
int32_t shadebound = (shadescale_unbounded || shade>=numshades) ? numshades : numshades-1;
float clamped_shade = min(max(shade*shadescale, 0), shadebound);
return ((float)(numshades-clamped_shade))/(float)numshades;
}
typedef struct pthtyp_t typedef struct pthtyp_t
{ {
struct pthtyp_t *next; struct pthtyp_t *next;

View file

@ -3781,8 +3781,7 @@ static void polymer_drawartsky(int16_t tilenum, char palnum, int8_t shad
pth = gltexcache(picnum, palnum, 0); pth = gltexcache(picnum, palnum, 0);
glpics[i] = pth ? pth->glpic : 0; glpics[i] = pth ? pth->glpic : 0;
glcolors[i][0] = glcolors[i][1] = glcolors[i][2] = glcolors[i][0] = glcolors[i][1] = glcolors[i][2] = getshadefactor(shade);
((float)(numshades-min(max(shade*shadescale,0),numshades)))/((float)numshades);
if (pth && (pth->flags & 2)) if (pth && (pth->flags & 2))
{ {
@ -3871,8 +3870,7 @@ static void polymer_drawskybox(int16_t tilenum, char palnum, int8_t shad
drawingskybox = i + 1; drawingskybox = i + 1;
pth = gltexcache(tilenum, palnum, 4); pth = gltexcache(tilenum, palnum, 4);
color[0] = color[1] = color[2] = color[0] = color[1] = color[2] = getshadefactor(shade);
((float)(numshades-min(max(shade*shadescale,0),numshades)))/((float)numshades);
if (pth && (pth->flags & 2)) if (pth && (pth->flags & 2))
{ {
@ -4495,7 +4493,7 @@ static void polymer_getbuildmaterial(_prmaterial* material, int16_t tile
material->diffusemodulation[0] = material->diffusemodulation[0] =
material->diffusemodulation[1] = material->diffusemodulation[1] =
material->diffusemodulation[2] = material->diffusemodulation[2] =
(GLubyte)(((float)(numshades-min(max((shade * shadescale),0),numshades)))/((float)numshades) * 0xFF); (GLubyte)(getshadefactor(shade) * 0xFF);
if (pth->flags & 2) if (pth->flags & 2)
{ {

View file

@ -2289,9 +2289,7 @@ void drawpoly(double *dpx, double *dpy, int32_t n, int32_t method)
{ {
float pc[4]; float pc[4];
int32_t shadebound = (shadescale_unbounded || globalshade>=numshades) ? numshades : numshades-1; pc[0] = pc[1] = pc[2] = getshadefactor(globalshade);
f = ((float)(numshades-min(max((globalshade * shadescale),0),shadebound)))/((float)numshades);
pc[0] = pc[1] = pc[2] = f;
switch (method&3) switch (method&3)
{ {
default: default:
@ -5948,7 +5946,6 @@ void polymost_fillpolygon(int32_t npoints)
pthtyp *pth; pthtyp *pth;
float f,a=0.0; float f,a=0.0;
int32_t i; int32_t i;
int32_t shadebound = (shadescale_unbounded || globalshade>=numshades) ? numshades : numshades-1;
globalx1 = mulscale16(globalx1,xyaspect); globalx1 = mulscale16(globalx1,xyaspect);
globaly2 = mulscale16(globaly2,xyaspect); globaly2 = mulscale16(globaly2,xyaspect);
@ -5972,7 +5969,7 @@ void polymost_fillpolygon(int32_t npoints)
pth = gltexcache(globalpicnum,globalpal,0); pth = gltexcache(globalpicnum,globalpal,0);
bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0); bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0);
f = ((float)(numshades-min(max((globalshade * shadescale),0),shadebound)))/((float)numshades); f = getshadefactor(globalshade);
switch ((globalorientation>>7)&3) switch ((globalorientation>>7)&3)
{ {
case 0: case 0: