- Add support for linearly desaturating images via r_greyscale

- Use correct luminance values for rendering textures
Patch submitted by Forrest Voight.
This commit is contained in:
Thilo Schulz 2011-02-04 16:04:37 +00:00
parent 13836e5f4a
commit e66abb3237
6 changed files with 61 additions and 8 deletions

3
README
View file

@ -181,7 +181,8 @@ New cvars
r_ext_texture_filter_anisotropic - anisotropic texture filtering r_ext_texture_filter_anisotropic - anisotropic texture filtering
r_zProj - distance of observer camera to projection r_zProj - distance of observer camera to projection
plane in quake3 standard units 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 r_stereoEnabled - enable stereo rendering for techniques
like shutter glasses (untested) like shutter glasses (untested)
r_anaglyphMode - Enable rendering of anaglyph images r_anaglyphMode - Enable rendering of anaglyph images

View file

@ -1307,4 +1307,7 @@ typedef enum _flag_status {
#define CDCHKSUM_LEN 2 #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 #endif // __Q_SHARED_H

View file

@ -560,6 +560,27 @@ static void Upload32( unsigned *data,
scan = ((byte *)data); scan = ((byte *)data);
samples = 3; 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(lightMap)
{ {
if(r_greyscale->integer) if(r_greyscale->integer)

View file

@ -920,6 +920,7 @@ void R_Register( void )
r_stereoEnabled = ri.Cvar_Get( "r_stereoEnabled", "0", CVAR_ARCHIVE | CVAR_LATCH); 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_ignoreFastPath = ri.Cvar_Get( "r_ignoreFastPath", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_greyscale = ri.Cvar_Get("r_greyscale", "0", 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 // temporary latched variables that can only change over a restart

View file

@ -31,8 +31,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
static float s_noise_table[NOISE_SIZE]; static float s_noise_table[NOISE_SIZE];
static int s_noise_perm[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 ) static float GetNoiseValue( int x, int y, int z, int t )
{ {
int index = INDEX( ( int ) x, ( int ) y, ( int ) z, ( int ) t ); int index = INDEX( ( int ) x, ( int ) y, ( int ) z, ( int ) t );

View file

@ -459,9 +459,18 @@ static void ProjectDlightTexture_altivec( void ) {
{ {
float luminance; 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; 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 else
{ {
floatColor[0] = dl->color[0] * 255.0f; floatColor[0] = dl->color[0] * 255.0f;
@ -612,10 +621,19 @@ static void ProjectDlightTexture_scalar( void ) {
if(r_greyscale->integer) if(r_greyscale->integer)
{ {
float luminance; 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; 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 else
{ {
floatColor[0] = dl->color[0] * 255.0f; floatColor[0] = dl->color[0] * 255.0f;
@ -964,11 +982,22 @@ static void ComputeColors( shaderStage_t *pStage )
if(r_greyscale->integer) if(r_greyscale->integer)
{ {
int scale; 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++) for(i = 0; i < tess.numVertexes; i++)
{ {
scale = (tess.svars.colors[i][0] + tess.svars.colors[i][1] + tess.svars.colors[i][2]) / 3; 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; 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);
} }
} }
} }