r361 - trunk/code/renderer

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Nov 15 18:30:36 EST 2005


Author: tma
Date: 2005-11-15 18:30:35 -0500 (Tue, 15 Nov 2005)
New Revision: 361

Modified:
   trunk/code/renderer/tr_shade.c
Log:
* Implementation of r_dlightBacks from Shane Isley


Modified: trunk/code/renderer/tr_shade.c
===================================================================
--- trunk/code/renderer/tr_shade.c	2005-11-15 22:22:45 UTC (rev 360)
+++ trunk/code/renderer/tr_shade.c	2005-11-15 23:30:35 UTC (rev 361)
@@ -473,54 +473,73 @@
 		floatColorVec0 = vec_perm(floatColorVec0,floatColorVec0,floatColorVecPerm);
 #endif
 		for ( i = 0 ; i < tess.numVertexes ; i++, texCoords += 2, colors += 4 ) {
+			int		clip = 0;
 #if idppc_altivec
+#define DIST0 dist0
+#define DIST1 dist1
+#define DIST2 dist2
+#define TEXCOORDS0 texCoords0
+#define TEXCOORDS1 texCoords1
 			vec_t dist0, dist1, dist2;
+			
+			dist0 = origin0 - tess.xyz[i][0];
+			dist1 = origin1 - tess.xyz[i][1];
+			dist2 = origin2 - tess.xyz[i][2];
 #else
+#define DIST0 dist[0]
+#define DIST1 dist[1]
+#define DIST2 dist[2]
+#define TEXCOORDS0 texCoords[0]
+#define TEXCOORDS1 texCoords[1]
 			vec3_t	dist;
+			
+			VectorSubtract( origin, tess.xyz[i], dist );
 #endif
-			int		clip;
 
 			backEnd.pc.c_dlightVertexes++;
 
-#if idppc_altivec
-			//VectorSubtract( origin, tess.xyz[i], dist );
-			dist0 = origin0 - tess.xyz[i][0];
-			dist1 = origin1 - tess.xyz[i][1];
-			dist2 = origin2 - tess.xyz[i][2];
-			texCoords0 = 0.5f + dist0 * scale;
-			texCoords1 = 0.5f + dist1 * scale;
+			TEXCOORDS0 = 0.5f + DIST0 * scale;
+			TEXCOORDS1 = 0.5f + DIST1 * scale;
 
-			clip = 0;
-			if ( texCoords0 < 0.0f ) {
-				clip |= 1;
-			} else if ( texCoords0 > 1.0f ) {
-				clip |= 2;
-			}
-			if ( texCoords1 < 0.0f ) {
-				clip |= 4;
-			} else if ( texCoords1 > 1.0f ) {
-				clip |= 8;
-			}
-			texCoords[0] = texCoords0;
-			texCoords[1] = texCoords1;
-			
-			// modulate the strength based on the height and color
-			if ( dist2 > radius ) {
-				clip |= 16;
-				modulate = 0.0f;
-			} else if ( dist2 < -radius ) {
-				clip |= 32;
-				modulate = 0.0f;
+			if( !r_dlightBacks->integer &&
+					// dist . tess.normal[i]
+					( DIST0 * tess.normal[i][0] +
+					DIST1 * tess.normal[i][1] +
+					DIST2 * tess.normal[i][2] ) < 0.0f ) {
+				clip = 63;
 			} else {
-				dist2 = Q_fabs(dist2);
-				if ( dist2 < radius * 0.5f ) {
-					modulate = 1.0f;
+				if ( TEXCOORDS0 < 0.0f ) {
+					clip |= 1;
+				} else if ( TEXCOORDS0 > 1.0f ) {
+					clip |= 2;
+				}
+				if ( TEXCOORDS1 < 0.0f ) {
+					clip |= 4;
+				} else if ( TEXCOORDS1 > 1.0f ) {
+					clip |= 8;
+				}
+				texCoords[0] = TEXCOORDS0;
+				texCoords[1] = TEXCOORDS1;
+
+				// modulate the strength based on the height and color
+				if ( DIST2 > radius ) {
+					clip |= 16;
+					modulate = 0.0f;
+				} else if ( DIST2 < -radius ) {
+					clip |= 32;
+					modulate = 0.0f;
 				} else {
-					modulate = 2.0f * (radius - dist2) * scale;
+					DIST2 = Q_fabs(DIST2);
+					if ( DIST2 < radius * 0.5f ) {
+						modulate = 1.0f;
+					} else {
+						modulate = 2.0f * (radius - DIST2) * scale;
+					}
 				}
 			}
 			clipBits[i] = clip;
 
+#if idppc_altivec
 			modulateVec = vec_ld(0,(float *)&modulate);
 			modulateVec = vec_perm(modulateVec,modulateVec,modulatePerm);
 			colorVec = vec_madd(floatColorVec0,modulateVec,zero);
@@ -530,44 +549,17 @@
 			colorChar = vec_sel(colorChar,vSel,vSel);		// RGBARGBARGBARGBA replace alpha with 255
 			vec_ste((vector unsigned int)colorChar,0,(unsigned int *)colors);	// store color
 #else
-			VectorSubtract( origin, tess.xyz[i], dist );
-			texCoords[0] = 0.5f + dist[0] * scale;
-			texCoords[1] = 0.5f + dist[1] * scale;
-
-			clip = 0;
-			if ( texCoords[0] < 0.0f ) {
-				clip |= 1;
-			} else if ( texCoords[0] > 1.0f ) {
-				clip |= 2;
-			}
-			if ( texCoords[1] < 0.0f ) {
-				clip |= 4;
-			} else if ( texCoords[1] > 1.0f ) {
-				clip |= 8;
-			}
-			// modulate the strength based on the height and color
-			if ( dist[2] > radius ) {
-				clip |= 16;
-				modulate = 0.0f;
-			} else if ( dist[2] < -radius ) {
-				clip |= 32;
-				modulate = 0.0f;
-			} else {
-				dist[2] = Q_fabs(dist[2]);
-				if ( dist[2] < radius * 0.5f ) {
-					modulate = 1.0f;
-				} else {
-					modulate = 2.0f * (radius - dist[2]) * scale;
-				}
-			}
-			clipBits[i] = clip;
-
 			colors[0] = myftol(floatColor[0] * modulate);
 			colors[1] = myftol(floatColor[1] * modulate);
 			colors[2] = myftol(floatColor[2] * modulate);
 			colors[3] = 255;
 #endif
 		}
+#undef DIST0
+#undef DIST1
+#undef DIST2
+#undef TEXCOORDS0
+#undef TEXCOORDS1
 
 		// build a list of triangles that need light
 		numIndexes = 0;




More information about the quake3-commits mailing list