Fix cubemap sky map rendering
Fix an issue with cubemap sky map rendering
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -487,8 +487,9 @@ namespace QuestAppLauncher
|
||||
/// </summary>
|
||||
/// <param name="path">Image path</param>
|
||||
/// <param name="maxPixels">Max pixels</param>
|
||||
/// <param name="adjustForCubemap">If true, adjusts for cubemap by skipping invert if loading cube map</param>
|
||||
/// <returns>Image and dimensions</returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="path">Image path</param>
|
||||
/// <param name="maxPixels">Max pixels</param>
|
||||
/// <param name="adjustForCubemap">If true, adjusts for cubemap by skipping invert if loading cube map</param>
|
||||
/// <param name="image">Output raw image byte array</param>
|
||||
/// <param name="imageWidth">Output width</param>
|
||||
/// <param name="imageHeight">Output height</param>
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user