Sky Colors Gamma Correction

General discussion for players of Oolite.

Moderators: winston, another_commander

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

Re: Sky Colors Gamma Correction

Post by another_commander »

Nite Owl wrote: Mon May 16, 2022 6:00 pm
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.
The reason the exposure setting cannot be found is that I have not posted the code changes for this experiment. That is because I have made the realization that the way this is going is not really the way it should go. Instead of adding a bunch of new settings inside .GNUstepDefaults, these new properties should probably be parts of planetinfo.plist. And still, even in this way, it would be messy. It would mean that we would have exposure settings in two shaders (planets and ships) and also one more exposure setting for stars and nebulae in the game code. Hmmm... not very efficient, is it?

I am thinking that the best way to do all this would probably be to implement that holy grail of rendering to texture and be done with the ancient direct rendering to the OpenGL pipeline. This would enable rendering of the entire scene to a floating point framebuffer, and then application of gamma correction, tone mapping and probably some post-processing effects (like bloom for example) on that final scene texture, like 99% of games out there do. Instead of having to worry about tone mapping and exposure in three different places, we would have just one setting at the end of the render pass in a final shader. Performance benefits would also be expected as a nice side effect, I guess.

Having said that, modernizing the renderer is probably more work than I can afford to put in at this time, so for now I'll just post the code changes needed for an exposure setting for sky elements. I don't think I'll check this in to master just yet though. Feel free to play with the code, but I think we're staying with what is there for the time being.

Here is the patch against github revision 64960c5a:

Code: Select all

diff --git a/src/Core/OOSkyDrawable.m b/src/Core/OOSkyDrawable.m
index dabe9d70..c1eb9bc2 100644
--- a/src/Core/OOSkyDrawable.m
+++ b/src/Core/OOSkyDrawable.m
@@ -554,12 +554,15 @@ static OOColor *DebugColor(Vector orientation)
 	GLfloat					r, g, b, x;
 	size_t					posSize, tcSize, colSize;
 	unsigned				count = 0;
-	int					skyColorCorrection = [[NSUserDefaults standardUserDefaults] oo_integerForKey:@"sky-color-correction" defaultValue:0];
+	NSUserDefaults		*defaults = [NSUserDefaults standardUserDefaults];
+	int					skyColorCorrection = [defaults oo_integerForKey:@"sky-color-correction" defaultValue:0];
+	GLfloat				exposure = [defaults oo_floatForKey:@"sky-color-exposure" defaultValue:1.0f];
 	
 // Hejl / Burgess-Dawson filmic tone mapping
 // this algorithm has gamma correction already embedded	
 #define SKYCOLOR_TONEMAP_COMPONENT(skyColorComponent) \
 do { \
+	skyColorComponent *= exposure; \
 	x = max(0.0, skyColorComponent - 0.004); \
 	*col++ = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); \
 } while (0) 
@@ -623,9 +626,9 @@ do { \
 					}
 					else if (skyColorCorrection == 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);
+						*col++ = pow(r * exposure, 1.0/2.2);
+						*col++ = pow(g * exposure, 1.0/2.2);
+						*col++ = pow(b * exposure, 1.0/2.2);
 					}
 					else					// gamma correction + filmic tone mapping
 					{

The way to use the exposure is to set its value in .GNUstepDefaults using the key "sky-color-exposure". A float value is expected and the default is 1.0.

Edit: And here is the related Windows test executable.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

<grins> I was kinda hoping that edit would appear.
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
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

I'm probably doing something wrong, as I seem to have lost star colours again.

Image

Using the latest .exe and:

Code: Select all

"sky-color-correction" = 2;
"sky-color-exposure" = 2.3;
Do I need to tinker with my star colours, perhaps?
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
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2687
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

Re: Sky Colors Gamma Correction

Post by Redspear »

Cody wrote: Mon May 16, 2022 9:00 pm

Image
Shiny pebble dropped in a starry pond...
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Re: Sky Colors Gamma Correction

Post by another_commander »

The loss of star color is expected, because exposure is basically a color multiplier. If you are multiplying each color component by 2.3, then a color triplet of e.g. (0..45, 0.45, 1.0) which is a somewhat mid-range blue becomes (1.035, 1.035, 2.3), which is then tone mapped to something that fits inside the 0.0 - 1.0 range for display ((0.85, 0.85, 0.92) using our Hejl/Burgess-Dawson formula to be exact), but is dangerously close to white. The 2.3 value you are using is very high in my opinion; something like 1.5 should be more than enough for brightening up nebulae without destroying color. You can think of it as if it were a photo - 2.3 is the equivalent of overexposure, which essentially "burns" the film.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

O-kay, I understand it better now - I think! <grins>
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: 556
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Sky Colors Gamma Correction

Post by Nite Owl »

As another bit of input. The Exposure in my Ooniverse has been lowered to 0.75. This was done to facilitate both the Cargo Spotter and Trails OXZs which were getting somewhat washed out, and difficult for my ancient eyes to easily see, when viewed against the brighter parts of the newly color enhanced Nebular.

Interstellar Space also got a few changes as the standard Nebular look was just too bright in some areas making Thargoid spotting rather tricky. The Nebular count was lowered along with a few other Blur settings. Have only been in Interstellar Space once since the testing began so this may change again as things progress.

Definitely enjoying the enhancements. Thank You another_commander.
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: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

I nixed the nebulae in IS long ago!
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
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Sky Colors Gamma Correction

Post by Cholmondely »

Cody wrote: Tue May 17, 2022 6:15 pm
I nixed the nebulae in IS long ago!
Ahah! More proof that the so-called IS is really ghostly greenish glowing witchspace!
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Sky Colors Gamma Correction

Post by Cody »

After much tinkering, I've nixed filmic tonemapping, and like Nite Owl, I've dropped exposure to 0.75 - I like my star colours!
More tinkering to come though, methinks - somewhere out there lies the perfect combination.

As for Cholly's assertion, I refer the commander to my previous response: check F5
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!
Post Reply