Fix ambient light cubemap (#535)

It was unintentionally flipped before.
This commit is contained in:
Nick 2023-03-04 17:27:34 -05:00 committed by GitHub
commit 5fc8c842b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 21 deletions

View File

@ -1,9 +1,9 @@
ManifestFileVersion: 0
CRC: 192875128
CRC: 3537427957
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: bd3accfa8245e7e8c1fe0bf8cfa04eb1
Hash: c4d8f41970054074bb375ac5cbe82855
TypeTreeHash:
serializedVersion: 2
Hash: de71b9c55befb829b1640ea21774b932
@ -171,7 +171,7 @@ ClassTypes:
Script: {instanceID: 0}
SerializeReferenceClassIdentifiers: []
Assets:
- Assets/AmbientLight_QM.png
- Assets/BrambleCollision.prefab
- Assets/Vessel_Body.prefab
- Assets/AmbientLight_QM.png
Dependencies: []

View File

@ -1,6 +1,8 @@
using UnityEngine;
using NewHorizons.Utility;
using NewHorizons.External.Modules;
using System;
namespace NewHorizons.Builder.General
{
public static class AmbientLightBuilder
@ -32,30 +34,25 @@ namespace NewHorizons.Builder.General
if (config.tint != null)
{
var tint = config.tint.ToColor();
var cubemap = Main.NHPrivateAssetBundle.LoadAsset<Cubemap>("AmbientLight_QM");
var cubemapFace = CubemapFace.Unknown;
var baseCubemap = Main.NHPrivateAssetBundle.LoadAsset<Cubemap>("AmbientLight_QM");
var cubemap = new Cubemap(baseCubemap.width, baseCubemap.format, baseCubemap.mipmapCount != 1);
cubemap.name = baseCubemap.name + "Tinted";
cubemap.wrapMode = baseCubemap.wrapMode;
for (int i = 0; i < 6; i++)
{
switch (i)
{
case 0: cubemapFace = CubemapFace.PositiveX; break;
case 1: cubemapFace = CubemapFace.NegativeX; break;
case 2: cubemapFace = CubemapFace.PositiveY; break;
case 3: cubemapFace = CubemapFace.NegativeY; break;
case 4: cubemapFace = CubemapFace.PositiveZ; break;
case 5: cubemapFace = CubemapFace.NegativeZ; break;
default: break;
}
var sourceColors = cubemap.GetPixels(cubemapFace, 0);
var cubemapFace = (CubemapFace)i;
var sourceColors = baseCubemap.GetPixels(cubemapFace);
var newColors = new Color[sourceColors.Length];
for (int j = 0; j < sourceColors.Length; j++)
{
var grey = sourceColors[j].grayscale * 2;
newColors[j] = tint * new Color(grey, grey, grey);
var grey = sourceColors[j].grayscale * 2; // looks nicer with multiplier
newColors[j] = new Color(grey, grey, grey) * tint;
}
cubemap.SetPixels(newColors, cubemapFace);
}
cubemap.Apply();
ImageUtilities.TrackGeneratedTexture(cubemap);
light.cookie = cubemap;
}

View File

@ -7,14 +7,19 @@ using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
namespace NewHorizons.Utility
{
public static class ImageUtilities
{
private static Dictionary<string, Texture2D> _loadedTextures = new Dictionary<string, Texture2D>();
private static List<Texture2D> _generatedTextures = new List<Texture2D>();
private static readonly Dictionary<string, Texture2D> _loadedTextures = new();
private static readonly List<Texture> _generatedTextures = new();
/// <summary>
/// Track textures generated outside of this file so they can be cleaned up on scene unload
/// </summary>
/// <param name="texture"></param>
public static void TrackGeneratedTexture(Texture texture) => _generatedTextures.Add(texture);
public static bool IsTextureLoaded(IModBehaviour mod, string filename)
{