From b8afb5df712a78c030919080696d84e517c610de Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:12:00 -0700 Subject: [PATCH 01/13] fix slide reel inverting (do gamma-to-linear before invert instead of linear-to-gamma after convert) --- NewHorizons/Utility/Files/ImageUtilities.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 1ed96114..4c5ad808 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -136,13 +136,16 @@ namespace NewHorizons.Utility.Files } else { - pixels[i].r = 1f - pixels[i].r; - pixels[i].g = 1f - pixels[i].g; - pixels[i].b = 1f - pixels[i].b; + // convert gamma to linear, then invert + // outer wilds will invert, then convert linear to gamma + // reversing the process + pixels[i].r = 1f - Mathf.Pow(pixels[i].r, 2.2f); + pixels[i].g = 1f - Mathf.Pow(pixels[i].g, 2.2f); + pixels[i].b = 1f - Mathf.Pow(pixels[i].b, 2.2f); } } - var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, true); + var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1); newTexture.name = key; newTexture.SetPixels(pixels); newTexture.Apply(); From ea668ae28cf824c1dfc1f52a6e055cca02758bcc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:12:31 -0700 Subject: [PATCH 02/13] do it simpler --- NewHorizons/Utility/Files/ImageUtilities.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 4c5ad808..0adfe547 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -129,19 +129,14 @@ namespace NewHorizons.Utility.Files // Needs a black border if (x == 0 || y == 0 || x == texture.width - 1 || y == texture.height - 1) { - pixels[i].r = 1; - pixels[i].g = 1; - pixels[i].b = 1; - pixels[i].a = 1; + pixels[i] = Color.white; } else { // convert gamma to linear, then invert // outer wilds will invert, then convert linear to gamma // reversing the process - pixels[i].r = 1f - Mathf.Pow(pixels[i].r, 2.2f); - pixels[i].g = 1f - Mathf.Pow(pixels[i].g, 2.2f); - pixels[i].b = 1f - Mathf.Pow(pixels[i].b, 2.2f); + pixels[i] = Color.white - pixels[i].linear; } } From 90b421314b37f0462021a4b7ca1297db2668ae18 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:18:58 -0700 Subject: [PATCH 03/13] remove doc comment since name is obvious --- NewHorizons/Utility/Files/ImageUtilities.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 0adfe547..a8466ffc 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -101,10 +101,6 @@ namespace NewHorizons.Utility.Files _textureCache.Clear(); } - /// - /// used specifically for projected slides. - /// also adds a border (to prevent weird visual bug) and makes the texture linear (otherwise the projected image is too bright). - /// public static Texture2D InvertSlideReel(IModBehaviour mod, Texture2D texture, string originalPath) { var key = $"{texture.name} > invert"; @@ -134,8 +130,7 @@ namespace NewHorizons.Utility.Files else { // convert gamma to linear, then invert - // outer wilds will invert, then convert linear to gamma - // reversing the process + // outer wilds will invert, then convert linear to gamma (reversing the process) pixels[i] = Color.white - pixels[i].linear; } } From 2b25c6b9f2ec58603c3a84d8758f2a29084f72d3 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:34:00 -0700 Subject: [PATCH 04/13] keep it linear --- NewHorizons/Utility/Files/ImageUtilities.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index a8466ffc..adcf6e48 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -135,7 +135,8 @@ namespace NewHorizons.Utility.Files } } - var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1); + // keep this linear. we do our own gamma to linear conversion + var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, true); newTexture.name = key; newTexture.SetPixels(pixels); newTexture.Apply(); From cf263a6609fa04d4a56cd4a721d4cd644a185868 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:56:28 -0700 Subject: [PATCH 05/13] dont invert alpha --- NewHorizons/Utility/Files/ImageUtilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index adcf6e48..b4712c7d 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -133,6 +133,7 @@ namespace NewHorizons.Utility.Files // outer wilds will invert, then convert linear to gamma (reversing the process) pixels[i] = Color.white - pixels[i].linear; } + pixels[i].a = 1; // dont invert alpha } // keep this linear. we do our own gamma to linear conversion From 41ec0e8ecbe883991e44c5afd76f6d878da54f53 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:59:09 -0700 Subject: [PATCH 06/13] do it on individual channels --- NewHorizons/Utility/Files/ImageUtilities.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index b4712c7d..e8f58b7e 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -125,15 +125,19 @@ namespace NewHorizons.Utility.Files // Needs a black border if (x == 0 || y == 0 || x == texture.width - 1 || y == texture.height - 1) { - pixels[i] = Color.white; + pixels[i].r = 1; + pixels[i].g = 1; + pixels[i].b = 1; + pixels[i].a = 1; } else { // convert gamma to linear, then invert // outer wilds will invert, then convert linear to gamma (reversing the process) - pixels[i] = Color.white - pixels[i].linear; + pixels[i].r = 1f - Mathf.LinearToGammaSpace(pixels[i].r); + pixels[i].g = 1f - Mathf.LinearToGammaSpace(pixels[i].g); + pixels[i].b = 1f - Mathf.LinearToGammaSpace(pixels[i].b); } - pixels[i].a = 1; // dont invert alpha } // keep this linear. we do our own gamma to linear conversion From 2ff4d909e6d1ac2f5d1616f86e2c3ae52b956706 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 00:59:56 -0700 Subject: [PATCH 07/13] i am stupid --- NewHorizons/Utility/Files/ImageUtilities.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index e8f58b7e..1a497dfb 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -134,9 +134,9 @@ namespace NewHorizons.Utility.Files { // convert gamma to linear, then invert // outer wilds will invert, then convert linear to gamma (reversing the process) - pixels[i].r = 1f - Mathf.LinearToGammaSpace(pixels[i].r); - pixels[i].g = 1f - Mathf.LinearToGammaSpace(pixels[i].g); - pixels[i].b = 1f - Mathf.LinearToGammaSpace(pixels[i].b); + pixels[i].r = 1f - Mathf.GammaToLinearSpace(pixels[i].r); + pixels[i].g = 1f - Mathf.GammaToLinearSpace(pixels[i].g); + pixels[i].b = 1f - Mathf.GammaToLinearSpace(pixels[i].b); } } From 14ad72eef73c96d57d83cdc5ddb9fbb61793670e Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 01:28:23 -0700 Subject: [PATCH 08/13] DONT keep it linear --- NewHorizons/Utility/Files/ImageUtilities.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 1a497dfb..98e2be74 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -140,8 +140,10 @@ namespace NewHorizons.Utility.Files } } - // keep this linear. we do our own gamma to linear conversion - var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, true); + // normally, you would want to keep this linear because we do our own gamma to linear conversion. + // however, not doing linear makes it match more closely to the source image, which is more desireable + // change this back to true if someone complains + var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, linear: false); newTexture.name = key; newTexture.SetPixels(pixels); newTexture.Apply(); From 0583b227885021fe6b5710f3e6396f72d46a590b Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 01:30:29 -0700 Subject: [PATCH 09/13] comment --- NewHorizons/Utility/Files/ImageUtilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 98e2be74..9a4ebd10 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -141,6 +141,7 @@ namespace NewHorizons.Utility.Files } // normally, you would want to keep this linear because we do our own gamma to linear conversion. + // (it also makes vanilla reel atlas match vanilla reels) // however, not doing linear makes it match more closely to the source image, which is more desireable // change this back to true if someone complains var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, linear: false); From 732e981a8b49a8feea0ed16b9b88cab73f12b7d4 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 01:32:40 -0700 Subject: [PATCH 10/13] comment --- NewHorizons/Utility/Files/ImageUtilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 9a4ebd10..c3804cdf 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -144,6 +144,7 @@ namespace NewHorizons.Utility.Files // (it also makes vanilla reel atlas match vanilla reels) // however, not doing linear makes it match more closely to the source image, which is more desireable // change this back to true if someone complains + // see https://github.com/Outer-Wilds-New-Horizons/new-horizons/pull/986#issuecomment-2449223761 for comparisons var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, linear: false); newTexture.name = key; newTexture.SetPixels(pixels); From 5ea7b82a6cf1e604760506a71be54e96cd3e78f9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 01:33:39 -0700 Subject: [PATCH 11/13] comment --- NewHorizons/Utility/Files/ImageUtilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index c3804cdf..1d2844ff 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -143,9 +143,9 @@ namespace NewHorizons.Utility.Files // normally, you would want to keep this linear because we do our own gamma to linear conversion. // (it also makes vanilla reel atlas match vanilla reels) // however, not doing linear makes it match more closely to the source image, which is more desireable - // change this back to true if someone complains + // change linear to true if someone complains // see https://github.com/Outer-Wilds-New-Horizons/new-horizons/pull/986#issuecomment-2449223761 for comparisons - var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1, linear: false); + var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1); newTexture.name = key; newTexture.SetPixels(pixels); newTexture.Apply(); From 4e4d69c41a4701411e397fd6342301593e93a539 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 12:54:08 -0700 Subject: [PATCH 12/13] update comments --- NewHorizons/Utility/Files/ImageUtilities.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 1d2844ff..8eb7a2d5 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -101,6 +101,10 @@ namespace NewHorizons.Utility.Files _textureCache.Clear(); } + /// + /// used to fix projection slides + /// add a border (to prevent weird visual bug) and does some magic with gamma correction and inverting + /// public static Texture2D InvertSlideReel(IModBehaviour mod, Texture2D texture, string originalPath) { var key = $"{texture.name} > invert"; @@ -140,10 +144,10 @@ namespace NewHorizons.Utility.Files } } - // normally, you would want to keep this linear because we do our own gamma to linear conversion. - // (it also makes vanilla reel atlas match vanilla reels) - // however, not doing linear makes it match more closely to the source image, which is more desireable - // change linear to true if someone complains + // making this linear makes vanilla reel atlas match vanilla reels + // however, it also makes it darker than the source image + // especially for custom slides this is unintuitive + // people will be like "wtf why is it darker than my image" // see https://github.com/Outer-Wilds-New-Horizons/new-horizons/pull/986#issuecomment-2449223761 for comparisons var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1); newTexture.name = key; From c560715f9deb28428dae5e729d7f3669a565a7ea Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 31 Oct 2024 12:55:47 -0700 Subject: [PATCH 13/13] bad grammar --- NewHorizons/Utility/Files/ImageUtilities.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 8eb7a2d5..2e660d17 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -103,7 +103,7 @@ namespace NewHorizons.Utility.Files /// /// used to fix projection slides - /// add a border (to prevent weird visual bug) and does some magic with gamma correction and inverting + /// adds a border (to prevent weird visual bug) and does some magic with gamma correction and inverting /// public static Texture2D InvertSlideReel(IModBehaviour mod, Texture2D texture, string originalPath) { @@ -144,10 +144,10 @@ namespace NewHorizons.Utility.Files } } - // making this linear makes vanilla reel atlas match vanilla reels - // however, it also makes it darker than the source image - // especially for custom slides this is unintuitive - // people will be like "wtf why is it darker than my image" + // making this linear makes vanilla reel atlas match vanilla reels. + // however, it also makes it darker than the source image. + // for custom slides this is unintuitive. + // people will be like "wtf why is it darker than my image?" // see https://github.com/Outer-Wilds-New-Horizons/new-horizons/pull/986#issuecomment-2449223761 for comparisons var newTexture = new Texture2D(texture.width, texture.height, texture.format, texture.mipmapCount != 1); newTexture.name = key;