]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_poly.c
lighting improvement in rgba mode, may crash some windows drivers
[xonotic/darkplaces.git] / gl_poly.c
index 9dad35b38306d7e40d7517a7a2331d2a6092ff69..0905f0c003506ee102d56ea6c7397813fde93915 100644 (file)
--- a/gl_poly.c
+++ b/gl_poly.c
@@ -85,6 +85,9 @@ void transpolyend()
 }
 
 int transpolyindices;
+extern qboolean isG200;
+
+/*
 void transpolyrenderminmax()
 {
        int i, j, k, lastvert;
@@ -111,6 +114,7 @@ void transpolyrenderminmax()
                if (max < 4) // free to check here, so skip polys behind the view
                        continue;
                transpoly[i].distance = average;
+*/
                /*
                transpoly[i].mindistance = min;
                transpoly[i].maxdistance = max;
@@ -164,6 +168,7 @@ skip:
                        ;
                }
                */
+/*
                // sorted insert
                for (j = 0;j < transpolyindices;j++)
                        if (transpoly[transpolyindex[j]].distance < average)
@@ -174,9 +179,9 @@ skip:
                transpolyindex[j] = i;
        }
 }
-
-// LordHavoc: qsort compare function
+*/
 /*
+// LordHavoc: qsort compare function
 int transpolyqsort(const void *ia, const void *ib)
 {
        transpoly_t *a, *b;
@@ -206,16 +211,46 @@ int transpolyqsort(const void *ia, const void *ib)
                return -1; // (-1) a is behind b
        return j == b->verts; // (1) a is infront of b    (0) a and b intersect
 //     return (transpoly[*((unsigned short *)ib)].mindistance + transpoly[*((unsigned short *)ib)].maxdistance) - (transpoly[*((unsigned short *)ia)].mindistance + transpoly[*((unsigned short *)ia)].maxdistance);
+       */
+/*
+       return ((transpoly_t*)ia)->distance - ((transpoly_t*)ib)->distance;
 }
 */
 
-extern qboolean isG200;
+int transpolyqsort(const void *ia, const void *ib)
+{
+       return (transpoly[*((unsigned short *)ib)].distance - transpoly[*((unsigned short *)ia)].distance);
+}
 
-/*
-void transpolysort()
+void transpolyrenderminmax()
 {
+       int i, j, lastvert;
+       vec_t d, max, viewdist, average;
+       transpolyindices = 0;
+       viewdist = DotProduct(r_refdef.vieworg, vpn);
+       for (i = 0;i < currenttranspoly;i++)
+       {
+               if (transpoly[i].verts < 3) // only process valid polygons
+                       continue;
+               max = -1000000;
+               lastvert = transpoly[i].firstvert + transpoly[i].verts;
+               average = 0;
+               for (j = transpoly[i].firstvert;j < lastvert;j++)
+               {
+                       d = DotProduct(transvert[j].v, vpn)-viewdist;
+                       average += d;
+                       if (d > max)
+                               max = d;
+               }
+               if (max < 4) // free to check here, so skip polys behind the view
+                       continue;
+               transpoly[i].distance = average / transpoly[i].verts;
+               transpolyindex[transpolyindices++] = i;
+       }
+       qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort);
+}
+/*
        int i, j, a;
-//     qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort);
        a = true;
        while(a)
        {
@@ -466,6 +501,7 @@ void wallpolyrender()
        wallvert_t *vert;
        if (currentwallpoly < 1)
                return;
+       c_brush_polys += currentwallpoly;
        // testing
        //Con_DPrintf("wallpolyrender: %i polys %i vertices\n", currentwallpoly, currentwallvert);
        if (!gl_mtexable)
@@ -639,31 +675,94 @@ void skypolyclear()
 }
 
 extern qboolean isATI;
+
+extern char skyname[];
+extern int solidskytexture, alphaskytexture;
 void skypolyrender()
 {
        int i, j;
        skypoly_t *p;
        skyvert_t *vert;
+       float length, speedscale;
+       vec3_t dir;
        if (currentskypoly < 1)
                return;
        // testing
 //     Con_DPrintf("skypolyrender: %i polys %i vertices\n", currentskypoly, currentskyvert);
-       glDisable(GL_TEXTURE_2D);
-       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_BLEND);
        // make sure zbuffer is enabled
        glEnable(GL_DEPTH_TEST);
        glDepthMask(1);
-       glColor3fv(fogcolor); // note: gets rendered over by sky if fog is not enabled
-       for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
+       if (!fogenabled && !skyname[0]) // normal quake sky
        {
-               vert = &skyvert[p->firstvert];
-               glBegin(GL_POLYGON);
-               for (j=0 ; j<p->verts ; j++, vert++)
-                       glVertex3fv (vert->v);
-               glEnd ();
+               glColor3f(0.5f, 0.5f, 0.5f);
+               glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+               glEnable(GL_TEXTURE_2D);
+               glDisable(GL_BLEND);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               glBindTexture(GL_TEXTURE_2D, solidskytexture); // upper clouds
+               speedscale = realtime*8;
+               speedscale -= (int)speedscale & ~127 ;
+               for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
+               {
+                       vert = &skyvert[p->firstvert];
+                       glBegin(GL_POLYGON);
+                       for (j=0 ; j<p->verts ; j++, vert++)
+                       {
+                               VectorSubtract (vert->v, r_origin, dir);
+                               dir[2] *= 3;    // flatten the sphere
+
+                               length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
+                               length = sqrt (length);
+                               length = 6*63/length;
+
+                               glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
+                               glVertex3fv (vert->v);
+                       }
+                       glEnd ();
+               }
+               glEnable(GL_BLEND);
+               glDepthMask(0);
+               glBindTexture(GL_TEXTURE_2D, alphaskytexture); // lower clouds
+               speedscale = realtime*16;
+               speedscale -= (int)speedscale & ~127 ;
+               for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
+               {
+                       vert = &skyvert[p->firstvert];
+                       glBegin(GL_POLYGON);
+                       for (j=0 ; j<p->verts ; j++, vert++)
+                       {
+                               VectorSubtract (vert->v, r_origin, dir);
+                               dir[2] *= 3;    // flatten the sphere
+
+                               length = dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2];
+                               length = sqrt (length);
+                               length = 6*63/length;
+
+                               glTexCoord2f ((speedscale + dir[0] * length) * (1.0/128), (speedscale + dir[1] * length) * (1.0/128));
+                               glVertex3fv (vert->v);
+                       }
+                       glEnd ();
+               }
+               glDisable(GL_BLEND);
+               glColor3f(1,1,1);
+               glDepthMask(1);
+       }
+       else
+       {
+               glDisable(GL_TEXTURE_2D);
+               glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+               glColor3fv(fogcolor); // note: gets rendered over by skybox if fog is not enabled
+               for (i = 0,p = &skypoly[0];i < currentskypoly;i++, p++)
+               {
+                       vert = &skyvert[p->firstvert];
+                       glBegin(GL_POLYGON);
+                       for (j=0 ; j<p->verts ; j++, vert++)
+                               glVertex3fv (vert->v);
+                       glEnd ();
+               }
+               glColor3f(1,1,1);
+               glEnable(GL_TEXTURE_2D);
        }
-       glColor3f(1,1,1);
-       glEnable(GL_TEXTURE_2D);
 }