]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
-Increased MAX_LIGHTSTYLES to 256.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 18 Aug 2005 13:45:16 +0000 (13:45 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 18 Aug 2005 13:45:16 +0000 (13:45 +0000)
-Changed BuildNormals to use area-weighting/averaging instead of normal averaging.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5590 d7cf8633-e32d-0410-b094-e92efae38249

mathlib.h
model_shared.c
quakedef.h
svvm_cmds.c

index d5f6ee070da70d43541add0c8e6ad3528989e79e..678f4e220c0d14434b97a2f1489f8c2686d15d8f 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -88,7 +88,11 @@ extern vec3_t vec3_origin;
 #define VectorReflect(a,r,b,c) do{double d;d = DotProduct((a), (b)) * -(1.0 + (r));VectorMA((a), (d), (b), (c));}while(0)
 #define BoxesOverlap(a,b,c,d) ((a)[0] <= (d)[0] && (b)[0] >= (c)[0] && (a)[1] <= (d)[1] && (b)[1] >= (c)[1] && (a)[2] <= (d)[2] && (b)[2] >= (c)[2])
 
-#define TriangleNormal(a,b,c,n) ((n)[0] = ((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1]), (n)[1] = ((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2]), (n)[2] = ((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0]))
+#define TriangleNormal(a,b,c,n) ( \
+       (n)[0] = ((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1]), \
+       (n)[1] = ((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2]), \
+       (n)[2] = ((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0]) \
+       )
 
 // fast PointInfrontOfTriangle
 // subtracts v1 from v0 and v2, combined into a crossproduct, combined with a
index 18f5ae07a6e8091191c6f46de61d2ec636d27a93..fe81e7ffcb13760cfe4219975acda2955294ba60 100644 (file)
@@ -488,33 +488,51 @@ void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, c
 // warning: this is an expensive function!
 void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f)
 {
-       int i, tnum;
-       float normal[3], *v;
-       const int *e;
+       int i;
+       const int *element;
+       float *vectorNormal;
        // clear the vectors
        memset(normal3f + 3 * firstvertex, 0, numvertices * sizeof(float[3]));
        // process each vertex of each triangle and accumulate the results
-       for (tnum = 0, e = elements;tnum < numtriangles;tnum++, e += 3)
+       // use area-averaging, to make triangles with a big area have a bigger
+       // weighting on the vertex normal than triangles with a small area
+       // to do so, just add the 'normals' together (the bigger the area
+       // the greater the length of the normal is 
+       element = elements;
+       for (i = 0; i < numtriangles; i++)
        {
-               TriangleNormal(vertex3f + e[0] * 3, vertex3f + e[1] * 3, vertex3f + e[2] * 3, normal);
-               VectorNormalize(normal);
-               v = normal3f + e[0] * 3;
-               v[0] += normal[0];
-               v[1] += normal[1];
-               v[2] += normal[2];
-               v = normal3f + e[1] * 3;
-               v[0] += normal[0];
-               v[1] += normal[1];
-               v[2] += normal[2];
-               v = normal3f + e[2] * 3;
-               v[0] += normal[0];
-               v[1] += normal[1];
-               v[2] += normal[2];
+               float areaNormal[3];
+
+               TriangleNormal(
+                       vertex3f + element[0] * 3, 
+                       vertex3f + element[1] * 3, 
+                       vertex3f + element[2] * 3, 
+                       areaNormal
+                       );
+       
+               vectorNormal = normal3f + element[0] * 3;
+               vectorNormal[0] += areaNormal[0];
+               vectorNormal[1] += areaNormal[1];
+               vectorNormal[2] += areaNormal[2];
+
+               vectorNormal = normal3f + element[1] * 3;
+               vectorNormal[0] += areaNormal[0];
+               vectorNormal[1] += areaNormal[1];
+               vectorNormal[2] += areaNormal[2];
+
+               vectorNormal = normal3f + element[2] * 3;
+               vectorNormal[0] += areaNormal[0];
+               vectorNormal[1] += areaNormal[1];
+               vectorNormal[2] += areaNormal[2];
+
+               element += 3;
+       }
+       // and just normalize the accumulated vertex normal in the end
+       vectorNormal = normal3f + 3 * firstvertex;
+       for (i = 0; i < numvertices; i++) {
+               VectorNormalize(vectorNormal);
+               vectorNormal += 3;
        }
-       // now we could divide the vectors by the number of averaged values on
-       // each vertex...  but instead normalize them
-       for (i = 0, v = normal3f + 3 * firstvertex;i < numvertices;i++, v += 3)
-               VectorNormalize(v);
 }
 
 void Mod_BuildBumpVectors(const float *v0, const float *v1, const float *v2, const float *tc0, const float *tc1, const float *tc2, float *svector3f, float *tvector3f, float *normal3f)
index 1c3dadd0d7e9dd8873a2a7c80502d4f1c26c0b67..45aad902c55215f83544fec95eb7573331466e0c 100644 (file)
@@ -56,7 +56,7 @@ extern char *buildstring;
 //
 // LordHavoc: increased entity limit to 2048 from 600
 #define        MAX_EDICTS              32768           // FIXME: ouch! ouch! ouch!
-#define        MAX_LIGHTSTYLES 64
+#define        MAX_LIGHTSTYLES 256
 // LordHavoc: increased model and sound limits from 256 and 256 to 4096 and 4096 (and added protocol extensions accordingly to break the 256 barrier)
 #define        MAX_MODELS              4096
 #define        MAX_SOUNDS              4096
index d77c1f0057d0a4e1b95e1cd7423662590b2ff078..9b1492d1899d979dd420ce0eae8ac58dbd3a54c4 100644 (file)
@@ -862,7 +862,7 @@ void PF_lightstyle (void)
        style = PRVM_G_FLOAT(OFS_PARM0);
        val = PRVM_G_STRING(OFS_PARM1);
 
-       if( (unsigned) style >= 64 ) {
+       if( (unsigned) style >= MAX_LIGHTSTYLES ) {
                PRVM_ERROR( "PF_lightstyle: style: %i >= 64", style );
        }