]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
merged matrix4x4 and matrix3x4 into matrixlib, updated makefiles and dsp, some cleanu...
[xonotic/darkplaces.git] / gl_rsurf.c
index d9b63381c489e924dcf1a706f53fc55c0648a72a..e3429922df8fb731dd812cb674838c570c620009 100644 (file)
@@ -99,9 +99,17 @@ static int R_AddDynamicLights (msurface_t *surf)
                if (dist2 >= maxdist)
                        continue;
 
-               impact[0] = local[0] - surf->plane->normal[0] * dist;
-               impact[1] = local[1] - surf->plane->normal[1] * dist;
-               impact[2] = local[2] - surf->plane->normal[2] * dist;
+               if (surf->plane->type < 3)
+               {
+                       VectorCopy(local, impact);
+                       impact[surf->plane->type] -= dist;
+               }
+               else
+               {
+                       impact[0] = local[0] - surf->plane->normal[0] * dist;
+                       impact[1] = local[1] - surf->plane->normal[1] * dist;
+                       impact[2] = local[2] - surf->plane->normal[2] * dist;
+               }
 
                impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
                impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
@@ -203,9 +211,17 @@ loc0:
        {
                maxdist3 = maxdist - dist2;
 
-               impact[0] = origin[0] - node->plane->normal[0] * ndist;
-               impact[1] = origin[1] - node->plane->normal[1] * ndist;
-               impact[2] = origin[2] - node->plane->normal[2] * ndist;
+               if (node->plane->type < 3)
+               {
+                       VectorCopy(origin, impact);
+                       impact[node->plane->type] -= ndist;
+               }
+               else
+               {
+                       impact[0] = origin[0] - node->plane->normal[0] * ndist;
+                       impact[1] = origin[1] - node->plane->normal[1] * ndist;
+                       impact[2] = origin[2] - node->plane->normal[2] * ndist;
+               }
 
                for (surf = model->surfaces + node->firstsurface, endsurf = surf + node->numsurfaces;surf < endsurf;surf++)
                {
@@ -365,12 +381,8 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
        if ((currentrenderentity->effects & EF_FULLBRIGHT) || !cl.worldmodel->lightdata)
        {
                bl = blocklights;
-               for (i = 0;i < size;i++)
-               {
-                       *bl++ = 255*256;
-                       *bl++ = 255*256;
-                       *bl++ = 255*256;
-               }
+               for (i = 0;i < size3;i++)
+                       bl[i] = 255*256;
        }
        else
        {
@@ -396,21 +408,19 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
 
 // add all the lightmaps
                if (lightmap)
-                       for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
-                               for (scale = d_lightstylevalue[surf->styles[maps]], bl = blocklights, i = 0;i < size3;i++)
-                                       *bl++ += *lightmap++ * scale;
+               {
+                       bl = blocklights;
+                       for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3)
+                               for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++)
+                                       bl[i] += lightmap[i] * scale;
+               }
        }
 
        stain = surf->stainsamples;
-       if (stain)
-               for (bl = blocklights, i = 0;i < size3;i++)
-                       if (stain[i] < 255)
-                               bl[i] = (bl[i] * stain[i]) >> 8;
-
        bl = blocklights;
        out = templight;
        // deal with lightmap brightness scale
-       shift = 7 + lightscalebit;
+       shift = 15 + lightscalebit;
        if (currentrenderentity->model->lightmaprgba)
        {
                stride = (surf->lightmaptexturestride - smax) * 4;
@@ -418,9 +428,9 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
                {
                        for (j = 0;j < smax;j++)
                        {
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
                                *out++ = 255;
                        }
                }
@@ -432,9 +442,9 @@ static void R_BuildLightMap (msurface_t *surf, int dlightchanged)
                {
                        for (j = 0;j < smax;j++)
                        {
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
-                               l = *bl++ >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
+                               l = (*bl++ * *stain++) >> shift;*out++ = min(l, 255);
                        }
                }
        }
@@ -1921,7 +1931,7 @@ Cshader_t *Cshaders[5] =
 
 void R_PrepareSurfaces(void)
 {
-       int i;
+       int i, entframe, texframe, framecount;
        texture_t *t;
        model_t *model;
        msurface_t *surf;
@@ -1930,6 +1940,8 @@ void R_PrepareSurfaces(void)
                Cshaders[i]->chain = NULL;
 
        model = currentrenderentity->model;
+       entframe = currentrenderentity->frame;
+       texframe = (int)(cl.time * 5.0f);
 
        for (i = 0;i < model->nummodelsurfaces;i++)
        {
@@ -1941,11 +1953,27 @@ void R_PrepareSurfaces(void)
                                surf->insertframe = r_framecount;
                                c_faces++;
                                t = surf->texinfo->texture;
-                               if (t->alternate_anims != NULL && currentrenderentity->frame)
-                                       t = t->alternate_anims;
-                               if (t->anim_total >= 2)
-                                       t = t->anim_frames[(int)(cl.time * 5.0f) % t->anim_total];
-                               surf->currenttexture = t;
+                               if (t->animated)
+                               {
+                                       if (entframe)
+                                       {
+                                               framecount = t->anim_total[1];
+                                               if (framecount >= 2)
+                                                       surf->currenttexture = t->anim_frames[1][texframe % framecount];
+                                               else
+                                                       surf->currenttexture = t->anim_frames[1][0];
+                                       }
+                                       else
+                                       {
+                                               framecount = t->anim_total[0];
+                                               if (framecount >= 2)
+                                                       surf->currenttexture = t->anim_frames[0][texframe % framecount];
+                                               else
+                                                       surf->currenttexture = t->anim_frames[0][0];
+                                       }
+                               }
+                               else
+                                       surf->currenttexture = t;
                        }
 
                        surf->chain = surf->shader->chain;