projection test for gallery space w/ chair using squeezed & gnomic projection.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
5.5 KiB

11 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.Recorder;
using UnityEditor.Recorder.Input;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;
using UnityEngine.Windows.WebCam;
11 months ago
public class ShaderManiuplation : MonoBehaviour
{
9 months ago
public GameObject parent;
11 months ago
public enum EquilateralDirection
{
Forward,
Left,
Backwards,
Right
}
public enum ProjectionType
{
Squeeze,
Gnomic
}
List<Shader> m_ShaderList = new List<Shader>();
Material mat;
public EquilateralDirection m_Direction = EquilateralDirection.Backwards;
public ProjectionType m_ProjectionType = ProjectionType.Gnomic;
GameObject m_CubeMapPrefab = null;
public float m_GnomicCameraHeight;
public float m_SqueezedCameraHeight;
public int m_SqueezedResolutionIndex = 0;
public int m_GnomiocResolutionIndexLarge = 0;
public int m_GnomiocResolutionIndexSmall = 0;
11 months ago
// Game View Parameters
Type gameView;
PropertyInfo selectedSizeIndex;
EditorWindow window;
private void OnEnable()
{
SetupEditorSettings();
SetupMatShaders();
}
void UpdateProjectionType()
{
if(m_ShaderList != null && m_ShaderList.Count > 0)
{
if (m_ProjectionType == ProjectionType.Squeeze)
{
9 months ago
//SetShaderSqueezed(m_SqueezedResolutionIndex, 0.85f, 2.5f, 3.5f, 4f, m_SqueezedCameraHeight);
11 months ago
}
else if (m_ProjectionType == ProjectionType.Gnomic)
{
9 months ago
//SetShaderGnomic(m_GnomiocResolutionIndexLarge, 1.5f, 0.2f, 5.13f, 0.125f, m_GnomicCameraHeight);
11 months ago
}
}
}
private void SetShaderSqueezed(int resolutionPreset, float yRotation, float xRotation, float yDivide, float xDivide, float cameraHeight)
{
mat.shader = m_ShaderList[0];
mat.SetFloat("_EquiRotation", xRotation + SetDirection());
mat.SetFloat("_EquiRotationY", yRotation);
mat.SetFloat("_DivideY", yDivide);
mat.SetFloat("_DivideX", xDivide);
ChangeGameViewResolution(resolutionPreset);
m_CubeMapPrefab.transform.localPosition = new Vector3(m_CubeMapPrefab.transform.localPosition.x, cameraHeight, m_CubeMapPrefab.transform.localPosition.z);
11 months ago
}
private void SetShaderGnomic(int resolutionPreset, float xFOV, float yFOV, float yRotation, float xRotation, float cameraHeight)
{
mat.shader = m_ShaderList[1];
if (m_Direction == EquilateralDirection.Left || m_Direction == EquilateralDirection.Right)
{
ChangeGameViewResolution(m_GnomiocResolutionIndexLarge);
11 months ago
xFOV = 0.9f;
yFOV = 0.3f;
yRotation = 5.23f;
}
else
{
ChangeGameViewResolution(m_GnomiocResolutionIndexSmall);
11 months ago
}
mat.SetFloat("_EquiRotation", xRotation + SetDirection());
mat.SetFloat("_EquiRotationY", yRotation);
mat.SetFloat("_FOVScale_X", xFOV);
mat.SetFloat("_FOVScale_Y", yFOV);
m_CubeMapPrefab.transform.localPosition = new Vector3(m_CubeMapPrefab.transform.localPosition.x, cameraHeight, m_CubeMapPrefab.transform.localPosition.z);
11 months ago
}
private float SetDirection()
{
float directionOffset = 0f;
if (m_ProjectionType == ProjectionType.Gnomic)
{
switch(m_Direction)
{
case EquilateralDirection.Left:
directionOffset = 0.25f;
break;
case EquilateralDirection.Right:
directionOffset = 0.75f;
break;
case EquilateralDirection.Forward:
directionOffset = 0;
break;
case EquilateralDirection.Backwards:
directionOffset = 0.5f;
break;
}
}
if (m_ProjectionType == ProjectionType.Squeeze)
{
switch (m_Direction)
{
case EquilateralDirection.Left:
directionOffset = 1;
break;
case EquilateralDirection.Right:
directionOffset = 3;
break;
case EquilateralDirection.Forward:
directionOffset = 0;
break;
case EquilateralDirection.Backwards:
directionOffset = 2;
break;
}
}
return directionOffset;
}
private void OnValidate()
{
UpdateProjectionType();
}
void ChangeGameViewResolution(int index)
{
selectedSizeIndex.SetValue(window, index, null);
}
private void SetupEditorSettings()
{
gameView = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
selectedSizeIndex = gameView.GetProperty("selectedSizeIndex", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
window = EditorWindow.GetWindow(gameView);
}
private void SetupMatShaders()
{
mat = this.GetComponent<RawImage>().material;
m_ShaderList.Add(Shader.Find("Conversion/CubemapToEquirectangularSqueeze"));
m_ShaderList.Add(Shader.Find("Conversion/CubemapToEquirectangularGnomic"));
mat.shader = m_ShaderList[1];
9 months ago
m_CubeMapPrefab = parent;
11 months ago
}
}