[quake3-commits] r1849 - in trunk: . code/qcommon code/renderer

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Feb 4 11:04:37 EST 2011


Author: thilo
Date: 2011-02-04 11:04:37 -0500 (Fri, 04 Feb 2011)
New Revision: 1849

Modified:
   trunk/README
   trunk/code/qcommon/q_shared.h
   trunk/code/renderer/tr_image.c
   trunk/code/renderer/tr_init.c
   trunk/code/renderer/tr_noise.c
   trunk/code/renderer/tr_shade.c
Log:
- Add support for linearly desaturating images via r_greyscale
- Use correct luminance values for rendering textures
Patch submitted by Forrest Voight.


Modified: trunk/README
===================================================================
--- trunk/README	2011-02-04 15:21:15 UTC (rev 1848)
+++ trunk/README	2011-02-04 16:04:37 UTC (rev 1849)
@@ -181,7 +181,8 @@
   r_ext_texture_filter_anisotropic  - anisotropic texture filtering
   r_zProj                           - distance of observer camera to projection
                                       plane in quake3 standard units
-  r_greyscale                       - render black and white images
+  r_greyscale                       - desaturate textures, useful for anaglyph,
+                                      supports values in the range of 0 to 1
   r_stereoEnabled                   - enable stereo rendering for techniques
                                       like shutter glasses (untested)
   r_anaglyphMode                    - Enable rendering of anaglyph images

Modified: trunk/code/qcommon/q_shared.h
===================================================================
--- trunk/code/qcommon/q_shared.h	2011-02-04 15:21:15 UTC (rev 1848)
+++ trunk/code/qcommon/q_shared.h	2011-02-04 16:04:37 UTC (rev 1849)
@@ -1307,4 +1307,7 @@
 #define CDCHKSUM_LEN 2
 
 
+#define LERP( a, b, w ) ( ( a ) * ( 1.0f - ( w ) ) + ( b ) * ( w ) )
+#define LUMA( red, green, blue ) ( 0.2126f * ( red ) + 0.7152f * ( green ) + 0.0722f * ( blue ) )
+
 #endif	// __Q_SHARED_H

Modified: trunk/code/renderer/tr_image.c
===================================================================
--- trunk/code/renderer/tr_image.c	2011-02-04 15:21:15 UTC (rev 1848)
+++ trunk/code/renderer/tr_image.c	2011-02-04 16:04:37 UTC (rev 1849)
@@ -560,6 +560,27 @@
 	scan = ((byte *)data);
 	samples = 3;
 
+	if( r_greyscale->integer )
+	{
+		for ( i = 0; i < c; i++ )
+		{
+			byte luma = LUMA(scan[i*4], scan[i*4 + 1], scan[i*4 + 2]);
+			scan[i*4] = luma;
+			scan[i*4 + 1] = luma;
+			scan[i*4 + 2] = luma;
+		}
+	}
+	else if( r_greyscale->value )
+	{
+		for ( i = 0; i < c; i++ )
+		{
+			float luma = LUMA(scan[i*4], scan[i*4 + 1], scan[i*4 + 2]);
+			scan[i*4] = LERP(scan[i*4], luma, r_greyscale->value);
+			scan[i*4 + 1] = LERP(scan[i*4 + 1], luma, r_greyscale->value);
+			scan[i*4 + 2] = LERP(scan[i*4 + 2], luma, r_greyscale->value);
+		}
+	}
+
 	if(lightMap)
 	{
 		if(r_greyscale->integer)

Modified: trunk/code/renderer/tr_init.c
===================================================================
--- trunk/code/renderer/tr_init.c	2011-02-04 15:21:15 UTC (rev 1848)
+++ trunk/code/renderer/tr_init.c	2011-02-04 16:04:37 UTC (rev 1849)
@@ -920,6 +920,7 @@
 	r_stereoEnabled = ri.Cvar_Get( "r_stereoEnabled", "0", CVAR_ARCHIVE | CVAR_LATCH);
 	r_ignoreFastPath = ri.Cvar_Get( "r_ignoreFastPath", "1", CVAR_ARCHIVE | CVAR_LATCH );
 	r_greyscale = ri.Cvar_Get("r_greyscale", "0", CVAR_ARCHIVE | CVAR_LATCH);
+	ri.Cvar_CheckRange(r_greyscale, 0, 1, qfalse);
 
 	//
 	// temporary latched variables that can only change over a restart

Modified: trunk/code/renderer/tr_noise.c
===================================================================
--- trunk/code/renderer/tr_noise.c	2011-02-04 15:21:15 UTC (rev 1848)
+++ trunk/code/renderer/tr_noise.c	2011-02-04 16:04:37 UTC (rev 1849)
@@ -31,8 +31,6 @@
 static float s_noise_table[NOISE_SIZE];
 static int s_noise_perm[NOISE_SIZE];
 
-#define LERP( a, b, w ) ( a * ( 1.0f - w ) + b * w )
-
 static float GetNoiseValue( int x, int y, int z, int t )
 {
 	int index = INDEX( ( int ) x, ( int ) y, ( int ) z, ( int ) t );

Modified: trunk/code/renderer/tr_shade.c
===================================================================
--- trunk/code/renderer/tr_shade.c	2011-02-04 15:21:15 UTC (rev 1848)
+++ trunk/code/renderer/tr_shade.c	2011-02-04 16:04:37 UTC (rev 1849)
@@ -459,9 +459,18 @@
 		{
 			float luminance;
 			
-			luminance = (dl->color[0] * 255.0f + dl->color[1] * 255.0f + dl->color[2] * 255.0f) / 3;
+			luminance = LUMA(dl->color[0], dl->color[1], dl->color[2]) * 255.0f;
 			floatColor[0] = floatColor[1] = floatColor[2] = luminance;
 		}
+		else if(r_greyscale->value)
+		{
+			float luminance;
+			
+			luminance = LUMA(dl->color[0], dl->color[1], dl->color[2]) * 255.0f;
+			floatColor[0] = LERP(dl->color[0] * 255.0f, luminance, r_greyscale->value);
+			floatColor[1] = LERP(dl->color[1] * 255.0f, luminance, r_greyscale->value);
+			floatColor[2] = LERP(dl->color[2] * 255.0f, luminance, r_greyscale->value);
+		}
 		else
 		{
 			floatColor[0] = dl->color[0] * 255.0f;
@@ -612,10 +621,19 @@
 		if(r_greyscale->integer)
 		{
 			float luminance;
-			
-			luminance = (dl->color[0] * 255.0f + dl->color[1] * 255.0f + dl->color[2] * 255.0f) / 3;
+
+			luminance = LUMA(dl->color[0], dl->color[1], dl->color[2]) * 255.0f;
 			floatColor[0] = floatColor[1] = floatColor[2] = luminance;
 		}
+		else if(r_greyscale->value)
+		{
+			float luminance;
+			
+			luminance = LUMA(dl->color[0], dl->color[1], dl->color[2]) * 255.0f;
+			floatColor[0] = LERP(dl->color[0] * 255.0f, luminance, r_greyscale->value);
+			floatColor[1] = LERP(dl->color[1] * 255.0f, luminance, r_greyscale->value);
+			floatColor[2] = LERP(dl->color[2] * 255.0f, luminance, r_greyscale->value);
+		}
 		else
 		{
 			floatColor[0] = dl->color[0] * 255.0f;
@@ -964,11 +982,22 @@
 	if(r_greyscale->integer)
 	{
 		int scale;
+		for(i = 0; i < tess.numVertexes; i++)
+		{
+			scale = LUMA(tess.svars.colors[i][0], tess.svars.colors[i][1], tess.svars.colors[i][2]);
+ 			tess.svars.colors[i][0] = tess.svars.colors[i][1] = tess.svars.colors[i][2] = scale;
+		}
+	}
+	else if(r_greyscale->value)
+	{
+		float scale;
 		
 		for(i = 0; i < tess.numVertexes; i++)
 		{
-			scale = (tess.svars.colors[i][0] + tess.svars.colors[i][1] + tess.svars.colors[i][2]) / 3;
-			tess.svars.colors[i][0] = tess.svars.colors[i][1] = tess.svars.colors[i][2] = scale;
+			scale = LUMA(tess.svars.colors[i][0], tess.svars.colors[i][1], tess.svars.colors[i][2]);
+			tess.svars.colors[i][0] = LERP(tess.svars.colors[i][0], scale, r_greyscale->value);
+			tess.svars.colors[i][1] = LERP(tess.svars.colors[i][1], scale, r_greyscale->value);
+			tess.svars.colors[i][2] = LERP(tess.svars.colors[i][2], scale, r_greyscale->value);
 		}
 	}
 }



More information about the quake3-commits mailing list