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.
238 lines
7.3 KiB
238 lines
7.3 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.UI;
|
||
|
using UnityEngine.Windows.WebCam;
|
||
|
|
||
|
public class ShaderManiuplation : MonoBehaviour
|
||
|
{
|
||
|
public enum EquilateralDirection
|
||
|
{
|
||
|
Forward,
|
||
|
Backwards,
|
||
|
Left,
|
||
|
Right
|
||
|
}
|
||
|
|
||
|
public enum ProjectionType
|
||
|
{
|
||
|
Cropped,
|
||
|
CroppedFOV,
|
||
|
Squeeze,
|
||
|
Gnomic
|
||
|
}
|
||
|
|
||
|
List<Shader> m_ShaderList = new List<Shader>();
|
||
|
Material mat;
|
||
|
public EquilateralDirection m_Direction = EquilateralDirection.Backwards;
|
||
|
public ProjectionType m_ProjectionType;
|
||
|
bool m_Squeeze = false;
|
||
|
bool m_Gnomic = true;
|
||
|
bool m_Cropped = false;
|
||
|
bool m_CroppedFOV = false;
|
||
|
public bool m_SideViewToggle = true;
|
||
|
GameObject m_CubeMapPrefab = null;
|
||
|
|
||
|
// Game View Parameters
|
||
|
Type gameView;
|
||
|
PropertyInfo selectedSizeIndex;
|
||
|
EditorWindow window;
|
||
|
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
SetupEditorSettings();
|
||
|
SetupMatShaders();
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
UpdateRotation(m_Direction);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void UpdateRotation(EquilateralDirection direction)
|
||
|
{
|
||
|
if(m_Squeeze)
|
||
|
{
|
||
|
// Change Resolution & Set Y
|
||
|
ChangeGameViewResolution(21);
|
||
|
mat.SetFloat("_EquiRotationY", 0.5f);
|
||
|
//m_CubeMapPrefab.transform.position = new Vector3(m_CubeMapPrefab.transform.position.x, 0.5f, m_CubeMapPrefab.transform.position.z);
|
||
|
switch (direction)
|
||
|
{
|
||
|
case EquilateralDirection.Forward:
|
||
|
mat.SetFloat("_EquiRotation", 1f);
|
||
|
break;
|
||
|
case EquilateralDirection.Left:
|
||
|
mat.SetFloat("_EquiRotation", 2f);
|
||
|
break;
|
||
|
case EquilateralDirection.Backwards:
|
||
|
mat.SetFloat("_EquiRotation", 3f);
|
||
|
break;
|
||
|
case EquilateralDirection.Right:
|
||
|
mat.SetFloat("_EquiRotation", 4f);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else if(m_Cropped)
|
||
|
{
|
||
|
ChangeGameViewResolution(21);
|
||
|
//mat.SetFloat("_EquiRotationY", 3.5f);
|
||
|
////m_CubeMapPrefab.transform.position = new Vector3(m_CubeMapPrefab.transform.position.x, 0.5f, m_CubeMapPrefab.transform.position.z);
|
||
|
//switch (direction)
|
||
|
//{
|
||
|
// case EquilateralDirection.Forward:
|
||
|
// mat.SetFloat("_EquiRotation", 0.5f);
|
||
|
// break;
|
||
|
// case EquilateralDirection.Left:
|
||
|
// mat.SetFloat("_EquiRotation", 1f);
|
||
|
// break;
|
||
|
// case EquilateralDirection.Backwards:
|
||
|
// mat.SetFloat("_EquiRotation", 1.5f);
|
||
|
// break;
|
||
|
// case EquilateralDirection.Right:
|
||
|
// mat.SetFloat("_EquiRotation", 2f);
|
||
|
// break;
|
||
|
//}
|
||
|
}
|
||
|
else if(m_Gnomic)
|
||
|
{
|
||
|
switch (direction)
|
||
|
{
|
||
|
case EquilateralDirection.Forward:
|
||
|
mat.SetFloat("_EquiRotation", 0f);
|
||
|
break;
|
||
|
case EquilateralDirection.Left:
|
||
|
mat.SetFloat("_EquiRotation", 0.25f);
|
||
|
break;
|
||
|
case EquilateralDirection.Backwards:
|
||
|
mat.SetFloat("_EquiRotation", 0.5f);
|
||
|
break;
|
||
|
case EquilateralDirection.Right:
|
||
|
mat.SetFloat("_EquiRotation", 0.75f);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
if (m_SideViewToggle)
|
||
|
{
|
||
|
// Set short wall FOV settings (height = 0.5, fovx = 0.9, fovy = 0.3)
|
||
|
mat.SetFloat("_FOVScale_X", 0.9f);
|
||
|
mat.SetFloat("_FOVScale_Y", 0.3f);
|
||
|
mat.SetFloat("_EquiRotationY", 5.23f);
|
||
|
//m_CubeMapPrefab.transform.position = new Vector3(m_CubeMapPrefab.transform.position.x, 0.5f, m_CubeMapPrefab.transform.position.z);
|
||
|
ChangeGameViewResolution(29);
|
||
|
}
|
||
|
else if (!m_SideViewToggle)
|
||
|
{
|
||
|
// Set long wall FOV settings (height = 0.75, fovx = 1.5, fovy = 0.2)
|
||
|
mat.SetFloat("_FOVScale_X", 1.5f);
|
||
|
mat.SetFloat("_FOVScale_Y", 0.2f);
|
||
|
mat.SetFloat("_EquiRotationY", 5.13f);
|
||
|
//m_CubeMapPrefab.transform.position = new Vector3(m_CubeMapPrefab.transform.position.x, 0.8f, m_CubeMapPrefab.transform.position.z);
|
||
|
ChangeGameViewResolution(28);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void UpdateProjectionType()
|
||
|
{
|
||
|
if(m_ShaderList != null && m_ShaderList.Count > 0)
|
||
|
{
|
||
|
if (m_ProjectionType == ProjectionType.Squeeze)
|
||
|
{
|
||
|
mat.shader = m_ShaderList[1];
|
||
|
m_Squeeze = true;
|
||
|
m_Gnomic = false;
|
||
|
m_Cropped = false;
|
||
|
}
|
||
|
else if(m_ProjectionType == ProjectionType.Cropped)
|
||
|
{
|
||
|
mat.shader = m_ShaderList[0];
|
||
|
m_Squeeze = false;
|
||
|
m_Gnomic = false;
|
||
|
m_Cropped = true;
|
||
|
}
|
||
|
else if (m_ProjectionType == ProjectionType.Gnomic)
|
||
|
{
|
||
|
mat.shader = m_ShaderList[2];
|
||
|
m_Squeeze = false;
|
||
|
m_Cropped = false;
|
||
|
m_Gnomic = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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];
|
||
|
m_CubeMapPrefab = GameObject.Find("CubemapCamera");
|
||
|
}
|
||
|
|
||
|
public void SetProjection(string projection)
|
||
|
{
|
||
|
|
||
|
switch(projection)
|
||
|
{
|
||
|
case "Gnomic":
|
||
|
m_Gnomic = true;
|
||
|
m_Squeeze = false;
|
||
|
m_Cropped = false;
|
||
|
m_CroppedFOV = false;
|
||
|
break;
|
||
|
case "Squeeze":
|
||
|
m_Squeeze = true;
|
||
|
m_Cropped = false;
|
||
|
m_Gnomic = false;
|
||
|
m_CroppedFOV = false;
|
||
|
break;
|
||
|
case "Cropped":
|
||
|
m_Cropped = true;
|
||
|
m_Squeeze = false;
|
||
|
m_Gnomic = false;
|
||
|
m_CroppedFOV = false;
|
||
|
break;
|
||
|
case "CroppedFOV":
|
||
|
m_Cropped = false;
|
||
|
m_Squeeze = false;
|
||
|
m_Gnomic = false;
|
||
|
m_CroppedFOV = true;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
UpdateRotation(m_Direction);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|