Sky Colors Gamma Correction

General discussion for players of Oolite.

Moderators: another_commander, winston

User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Sky Colors Gamma Correction

Post by Nite Owl »

Here is a quick sampling of the kinds of stuff that Mr. Latest Log is being flooded with.

Code: Select all

13:31:13.851 [oxp-standards.error]: OXP ../AddOns/adcks Navy Destroyer V1.0.oxp has no manifest.plist
13:31:20.983 [oxp-standards.deprecated]: Old style sub-entity declarations are deprecated in stealth_base
13:31:35.271 [oxp-standards.deprecated]: The conditions key is deprecated for equipment Hyper-Cargo System Illicit Hack
13:31:35.277 [oxp-standards.deprecated]: Script ../AddOns/LinkG7 v0.1.oxp/Scripts/linkG7_autoJumper.js does not "use strict";
None of this ever appeared in my logs prior to using the patch .exe. Since a lot of older OXP's/OXZ's are in use my guess is that the Developer Version checks for such things while the Release Version does not. Have tried TWEAKING both logcontrol.plist and verifyOXP.plist but have had no luck. Still getting a very large amount of messages similar to the above with the patch .exe. It can be lived with until a patch .exe is created off of the Release Version but any help that can be given to suppress the mess until then would be much appreciated.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16055
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

Nite Owl wrote: Wed May 11, 2022 11:07 pm
... any help that can be given to suppress the mess until then would be much appreciated.
Would this help? It cleared my log out nicely.
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Sky Colors Gamma Correction

Post by Nite Owl »

Thank You Cody, that fixed the problem completely. Much Appreciated.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

For the Linux and Mac users who do not have access to a test binary, here is the source code patch used for the Windows test executable. You can try building from source if you want to give this a go. The patch refers to github revision ca776c1.

Code: Select all

diff --git a/src/Core/OOSkyDrawable.m b/src/Core/OOSkyDrawable.m
index ea3b0c0a..03f66a6a 100644
--- a/src/Core/OOSkyDrawable.m
+++ b/src/Core/OOSkyDrawable.m
@@ -553,6 +553,7 @@ static OOColor *DebugColor(Vector orientation)
 	GLfloat					r, g, b;
 	size_t					posSize, tcSize, colSize;
 	unsigned				count = 0;
+	BOOL					skyColorGammaCorrect = [[NSUserDefaults standardUserDefaults] boolForKey:@"skycolor-gamma-correct"];
 	
 	self = [super init];
 	if (self == nil)  OK = NO;
@@ -605,9 +606,18 @@ static OOColor *DebugColor(Vector orientation)
 					*pos++ = array[i].corners[j].z;
 					
 					// Colour is the same for each vertex
-					*col++ = r;
-					*col++ = g;
-					*col++ = b;
+					if (!skyColorGammaCorrect)
+					{
+						*col++ = r;
+						*col++ = g;
+						*col++ = b;
+					}
+					else
+					{
+						*col++ = pow(r, 1.0/2.2);
+						*col++ = pow(g, 1.0/2.2);
+						*col++ = pow(b, 1.0/2.2);
+					}
 					*col++ = 1.0f;	// Alpha is unused but needs to be there
 				}
 				 
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

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.

Image
Image

Image
Image

Image
Image

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
 				}
 				
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16055
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

Is there any reason why filmic tonemapping might affect star colours?
I'm just back from the opticians, and only had a quick look.
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

@Cody: I wouldn't think so, at least not to the extent that it would be immediately noticeable. If anything, it should probably make star colors slightly more vibrant, like everything else
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16055
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

<nods> I can't do a proper comparison 'til my eyes have adjusted to the new prescription. Tomorrow, after I've slept.
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Sky Colors Gamma Correction

Post by Nite Owl »

Since running these executable tests the following keeps popping up in my .GNUstepDefaults.

Code: Select all

"debug-settings-override" = { };
My guess is that it has something to do with the developer version of the executable but no documentation on what it does or what parameters might be associated with it can be found. Please advise.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

Nite Owl wrote: Sat May 14, 2022 6:12 pm
Since running these executable tests the following keeps popping up in my .GNUstepDefaults.

Code: Select all

"debug-settings-override" = { };
My guess is that it has something to do with the developer version of the executable but no documentation on what it does or what parameters might be associated with it can be found. Please advise.
This is indeed related to the test release executable and it just stores settings for the debug console. Safe to ignore.
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2637
Joined: Thu Jun 20, 2013 10:22 pm

Re: Sky Colors Gamma Correction

Post by Redspear »

Not sure if it's the tonemapping addition or just having had more time to think about it generally, but having been on the fence about this I think I'm moving steadily towards the 'pro' camp now.

Great work a_c 8)
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 271
Joined: Thu Jan 01, 2009 9:45 am

Re: Sky Colors Gamma Correction

Post by DGill »

I like it - very colourful!

Image
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

The feature has hit the master branch on github but is currently dormant. Please refer to the comments of commit 64960c5 for information on how to enable it.

Note that the .GNUstepDefaults key controlling the type of color correction to be applied has now been changed to "sky-color-correction".
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6547
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

For fun: Fooling around with exposure for stars and nebulae:

Exposure 0.6:
Image

Exposure 1.0 (default):
Image

Exposure 1.38:
Image

Exposure 2.38:
Image
User avatar
Nite Owl
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Sky Colors Gamma Correction

Post by Nite Owl »

Where is the Exposure setting found? Checked out the commit and it is not there. The only similar thing to be found was in the oolite-default-planet.fragment shader.

Code: Select all

#define NULTIPLIER_EXPOSURE			1.0  // Misspelling of NULTIPLIER ?? Should it be MULTIPLIER ??
In any case the exact location of the Exposure setting would be most appreciated so the experimentation can continue.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
Post Reply