From 2fd091667bc08874d2cc2aca65bb7ead59bfb361 Mon Sep 17 00:00:00 2001 From: tverona1 Date: Sat, 23 Nov 2019 14:31:31 -0800 Subject: [PATCH] Fix cubemap sky map rendering Fix an issue with cubemap sky map rendering --- Assets/Resources/OVRBuildConfig.asset | 2 +- Assets/Scripts/AppProcessor.cs | 24 +++++++++++++++--------- Assets/Scripts/SkyboxHandler.cs | 4 +--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Assets/Resources/OVRBuildConfig.asset b/Assets/Resources/OVRBuildConfig.asset index f2d36f8..cf5cd6c 100644 --- a/Assets/Resources/OVRBuildConfig.asset +++ b/Assets/Resources/OVRBuildConfig.asset @@ -12,6 +12,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 20553fac56ec59645857c0732b787431, type: 3} m_Name: OVRBuildConfig m_EditorClassIdentifier: - androidSDKPath: C:\Users\tvero\AppData\Local\Android\Sdk + androidSDKPath: gradlePath: jdkPath: diff --git a/Assets/Scripts/AppProcessor.cs b/Assets/Scripts/AppProcessor.cs index 71d83e3..f43ac2c 100644 --- a/Assets/Scripts/AppProcessor.cs +++ b/Assets/Scripts/AppProcessor.cs @@ -487,8 +487,9 @@ namespace QuestAppLauncher /// /// Image path /// Max pixels + /// If true, adjusts for cubemap by skipping invert if loading cube map /// Image and dimensions - public static async Task<(byte[], int, int)> LoadRawImageAsync(string path, int maxPixels) + public static async Task<(byte[], int, int)> LoadRawImageAsync(string path, int maxPixels, bool adjustForCubemap = false) { int imageHeight = 0; int imageWidth = 0; @@ -500,7 +501,7 @@ namespace QuestAppLauncher try { - LoadRawImage(path, maxPixels, out image, out imageWidth, out imageHeight); + LoadRawImage(path, maxPixels, adjustForCubemap, out image, out imageWidth, out imageHeight); } finally { @@ -516,10 +517,11 @@ namespace QuestAppLauncher /// /// Image path /// Max pixels + /// If true, adjusts for cubemap by skipping invert if loading cube map /// Output raw image byte array /// Output width /// Output height - public static void LoadRawImage(string path, int maxPixels, out byte[] image, out int imageWidth, out int imageHeight) + public static void LoadRawImage(string path, int maxPixels, bool adjustForCubemap, out byte[] image, out int imageWidth, out int imageHeight) { image = null; imageWidth = 0; @@ -555,13 +557,17 @@ namespace QuestAppLauncher rawImage[i * 4] = tmp; } - // Swap rows - var row = new byte[imageWidth * 4]; - for (var i = 0; i < imageHeight / 2; i++) + // Swap rows if needed + if (!adjustForCubemap || + (4 * imageHeight != 3 * imageWidth && 6 * imageHeight != imageWidth)) { - Buffer.BlockCopy(rawImage, i * imageWidth * 4, row, 0, imageWidth * 4); - Buffer.BlockCopy(rawImage, (imageHeight - i - 1) * imageWidth * 4, rawImage, i * imageWidth * 4, imageWidth * 4); - Buffer.BlockCopy(row, 0, rawImage, (imageHeight - i - 1) * imageWidth * 4, imageWidth * 4); + var row = new byte[imageWidth * 4]; + for (var i = 0; i < imageHeight / 2; i++) + { + Buffer.BlockCopy(rawImage, i * imageWidth * 4, row, 0, imageWidth * 4); + Buffer.BlockCopy(rawImage, (imageHeight - i - 1) * imageWidth * 4, rawImage, i * imageWidth * 4, imageWidth * 4); + Buffer.BlockCopy(row, 0, rawImage, (imageHeight - i - 1) * imageWidth * 4, imageWidth * 4); + } } image = rawImage; diff --git a/Assets/Scripts/SkyboxHandler.cs b/Assets/Scripts/SkyboxHandler.cs index f7daa46..31cab48 100644 --- a/Assets/Scripts/SkyboxHandler.cs +++ b/Assets/Scripts/SkyboxHandler.cs @@ -157,7 +157,7 @@ namespace QuestAppLauncher } // Read the image - var result = await AppProcessor.LoadRawImageAsync(MakeAbsoluteSkymapPath(skyboxPath), MaxPixels); + var result = await AppProcessor.LoadRawImageAsync(MakeAbsoluteSkymapPath(skyboxPath), MaxPixels, true); var image = result.Item1; var imageWidth = result.Item2; var imageHeight = result.Item3; @@ -191,7 +191,6 @@ namespace QuestAppLauncher Debug.LogFormat("Setting horizontal-cross cubemap skybox"); destroyTexture = true; material = new Material(Shader.Find("skybox/cube")); - material.SetFloat("_RotationX", 180); material.SetTexture("_Tex", CubemapFromHorizCrossTexture2D(texture)); } else if (6 * texture.height == texture.width) @@ -202,7 +201,6 @@ namespace QuestAppLauncher Debug.LogFormat("Setting horizontal cubemap skybox"); destroyTexture = true; material = new Material(Shader.Find("skybox/cube")); - material.SetFloat("_RotationX", 180); material.SetTexture("_Tex", CubemapFromHorizTexture2D(texture)); } else