So, I played a bit more with the sky colors and I present you with a brand new test executable which not only gamma corrects, but it also performs filming tonemapping on the sky colors. Filmic tonemapping is what we use for ships and planets in 1.90 and generates vivid colors, at the same time providing as good detail as possible both in dark and brightly lit areas. The tonemapping algorithm we use is the same one used in our shaders and was originally implemented by Jim Hejl and Richard Burgess-Dawson.
Comparison between gamma correction only (top) with gamma correction + tonemapping (bottom) follows for a few examples. The differences are subtle but believe me, they are there and you will notice immediately in-game.
The test executable can do both simple gamma correction and gamma correction + tonemapping. Use the same .GNUstepDefaults key as before, but this time instead of a YES / NO value set it as follows:
- 0 for no gamma correction (i.e. what we have in 1.90)
- 1 for gamma correction only
- Any other value for gamma correction + filmic tonemapping
So using for example
"skycolor-gamma-correct" = 2;
will fully activate the new feature.
Download the new test exe from
here.
For Linux and Mac users building from source, this is the patch against revision f162e9c:
Code: Select all
diff --git a/src/Core/OOSkyDrawable.m b/src/Core/OOSkyDrawable.m
index 03f66a6a..b17dd668 100644
--- a/src/Core/OOSkyDrawable.m
+++ b/src/Core/OOSkyDrawable.m
@@ -35,12 +35,19 @@ SOFTWARE.
#import "Universe.h"
#import "OOMacroOpenGL.h"
#import "NSObjectOOExtensions.h"
+#import "OOCollectionExtractors.h"
#define SKY_ELEMENT_SCALE_FACTOR (BILLBOARD_DEPTH / 500.0f)
#define NEBULA_SHUFFLE_FACTOR 0.005f
#define DEBUG_COLORS 0 // If set, rgb = xyz (offset to range from 0.1 to 1.0).
+#define SKYCOLOR_TONEMAP(skyColorComponent) \
+do { \
+ x = max(0.0, skyColorComponent - 0.004); \
+ *col++ = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); \
+} while (0)
+
/* Min and max coords are 0 and 1 normally, but the default
sky-render-inset-coords can be used to modify them slightly as an attempted
@@ -550,10 +557,10 @@ static OOColor *DebugColor(Vector orientation)
GLfloat *pos;
GLfloat *tc;
GLfloat *col;
- GLfloat r, g, b;
+ GLfloat r, g, b, x;
size_t posSize, tcSize, colSize;
unsigned count = 0;
- BOOL skyColorGammaCorrect = [[NSUserDefaults standardUserDefaults] boolForKey:@"skycolor-gamma-correct"];
+ int skyColorGammaCorrect = [[NSUserDefaults standardUserDefaults] oo_integerForKey:@"skycolor-gamma-correct" defaultValue:0];
self = [super init];
if (self == nil) OK = NO;
@@ -606,18 +613,24 @@ static OOColor *DebugColor(Vector orientation)
*pos++ = array[i].corners[j].z;
// Colour is the same for each vertex
- if (!skyColorGammaCorrect)
+ if (skyColorGammaCorrect == 0) // no gamma correction
{
*col++ = r;
*col++ = g;
*col++ = b;
}
- else
+ else if (skyColorGammaCorrect == 1) // gamma correction only
{
*col++ = pow(r, 1.0/2.2);
*col++ = pow(g, 1.0/2.2);
*col++ = pow(b, 1.0/2.2);
}
+ else // gamma correctioin + filmic tonemapping
+ {
+ SKYCOLOR_TONEMAP(r);
+ SKYCOLOR_TONEMAP(g);
+ SKYCOLOR_TONEMAP(b);
+ }
*col++ = 1.0f; // Alpha is unused but needs to be there
}