Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for stereoscopic cubemaps #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Skybox-PanoramicBeta.shader
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ SubShader {
half4 _Tint;
half _Exposure;
float _Rotation;
int _Layout;
#ifndef _MAPPING_6_FRAMES_LAYOUT
bool _MirrorOnBack;
int _ImageType;
int _Layout;
#endif

#ifndef _MAPPING_6_FRAMES_LAYOUT
Expand Down Expand Up @@ -86,6 +86,7 @@ SubShader {
struct v2f {
float4 vertex : SV_POSITION;
float3 texcoord : TEXCOORD0;
float4 layout3DScaleAndOffset : TEXCOORD6;
#ifdef _MAPPING_6_FRAMES_LAYOUT
float3 layout : TEXCOORD1;
float4 edgeSize : TEXCOORD2;
Expand All @@ -94,7 +95,6 @@ SubShader {
float4 faceZCoordLayouts : TEXCOORD5;
#else
float2 image180ScaleAndCutoff : TEXCOORD1;
float4 layout3DScaleAndOffset : TEXCOORD2;
#endif
UNITY_VERTEX_OUTPUT_STEREO
};
Expand Down Expand Up @@ -167,21 +167,24 @@ SubShader {
o.image180ScaleAndCutoff = float2(1.0, 1.0);
else // 180 degree
o.image180ScaleAndCutoff = float2(2.0, _MirrorOnBack ? 1.0 : 0.5);
#endif

// Calculate constant scale and offset for 3D layouts
if (_Layout == 0) // No 3D layout
o.layout3DScaleAndOffset = float4(0,0,1,1);
else if (_Layout == 1) // Side-by-Side 3D layout
o.layout3DScaleAndOffset = float4(unity_StereoEyeIndex,0,0.5,1);
else // Over-Under 3D layout
o.layout3DScaleAndOffset = float4(0, 1-unity_StereoEyeIndex,1,0.5);
#endif

return o;
}

fixed4 frag (v2f i) : SV_Target
{
#ifdef _MAPPING_6_FRAMES_LAYOUT
float2 tc = ToCubeCoords(i.texcoord, i.layout, i.edgeSize, i.faceXCoordLayouts, i.faceYCoordLayouts, i.faceZCoordLayouts);
tc = (tc + i.layout3DScaleAndOffset.xy) * i.layout3DScaleAndOffset.zw;
#else
float2 tc = ToRadialCoords(i.texcoord);
if (tc.x > i.image180ScaleAndCutoff[1])
Expand Down
128 changes: 64 additions & 64 deletions SkyboxPanoramicBetaShaderGUI.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;

namespace UnityEditor
{
internal class SkyboxPanoramicBetaShaderGUI : ShaderGUI
{
readonly AnimBool m_ShowLatLongLayout = new AnimBool();
readonly AnimBool m_ShowMirrorOnBack = new AnimBool();
readonly AnimBool m_Show3DControl = new AnimBool();

bool m_Initialized = false;

public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
if (!m_Initialized)
{
m_ShowLatLongLayout.valueChanged.AddListener(materialEditor.Repaint);
m_ShowMirrorOnBack.valueChanged.AddListener(materialEditor.Repaint);
m_Show3DControl.valueChanged.AddListener(materialEditor.Repaint);
m_Initialized = true;
}

// Allow the default implementation to set widths for consistency for common properties.
float lw = EditorGUIUtility.labelWidth;
materialEditor.SetDefaultGUIWidths();
ShowProp(materialEditor, FindProperty("_Tint", props));
ShowProp(materialEditor, FindProperty("_Exposure", props));
ShowProp(materialEditor, FindProperty("_Rotation", props));
ShowProp(materialEditor, FindProperty("_Tex", props));
EditorGUIUtility.labelWidth = lw;

m_ShowLatLongLayout.target = ShowProp(materialEditor, FindProperty("_Mapping", props)) == 1;
if (EditorGUILayout.BeginFadeGroup(m_ShowLatLongLayout.faded))
{
m_ShowMirrorOnBack.target = ShowProp(materialEditor, FindProperty("_ImageType", props)) == 1;
if (EditorGUILayout.BeginFadeGroup(m_ShowMirrorOnBack.faded))
{
EditorGUI.indentLevel++;
ShowProp(materialEditor, FindProperty("_MirrorOnBack", props));
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();

// No 3D settings unless PlayerSettings have VR support.
m_Show3DControl.value = PlayerSettings.virtualRealitySupported;
if (EditorGUILayout.BeginFadeGroup(m_Show3DControl.faded))
ShowProp(materialEditor, FindProperty("_Layout", props));
EditorGUILayout.EndFadeGroup();
}
EditorGUILayout.EndFadeGroup();

// Let the default implementation add the extra shader properties at the bottom.
materialEditor.PropertiesDefaultGUI(new MaterialProperty[0]);
}

private float ShowProp(MaterialEditor materialEditor, MaterialProperty prop)
{
materialEditor.ShaderProperty(prop, prop.displayName);
return prop.floatValue;
}
}
}
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
namespace UnityEditor
{
internal class SkyboxPanoramicBetaShaderGUI : ShaderGUI
{
readonly AnimBool m_ShowLatLongLayout = new AnimBool();
readonly AnimBool m_ShowMirrorOnBack = new AnimBool();
readonly AnimBool m_Show3DControl = new AnimBool();
bool m_Initialized = false;
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
if (!m_Initialized)
{
m_ShowLatLongLayout.valueChanged.AddListener(materialEditor.Repaint);
m_ShowMirrorOnBack.valueChanged.AddListener(materialEditor.Repaint);
m_Show3DControl.valueChanged.AddListener(materialEditor.Repaint);
m_Initialized = true;
}
// Allow the default implementation to set widths for consistency for common properties.
float lw = EditorGUIUtility.labelWidth;
materialEditor.SetDefaultGUIWidths();
ShowProp(materialEditor, FindProperty("_Tint", props));
ShowProp(materialEditor, FindProperty("_Exposure", props));
ShowProp(materialEditor, FindProperty("_Rotation", props));
ShowProp(materialEditor, FindProperty("_Tex", props));
EditorGUIUtility.labelWidth = lw;
m_ShowLatLongLayout.target = ShowProp(materialEditor, FindProperty("_Mapping", props)) == 1;
if (EditorGUILayout.BeginFadeGroup(m_ShowLatLongLayout.faded))
{
m_ShowMirrorOnBack.target = ShowProp(materialEditor, FindProperty("_ImageType", props)) == 1;
if (EditorGUILayout.BeginFadeGroup(m_ShowMirrorOnBack.faded))
{
EditorGUI.indentLevel++;
ShowProp(materialEditor, FindProperty("_MirrorOnBack", props));
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();
}
EditorGUILayout.EndFadeGroup();
// No 3D settings unless PlayerSettings have VR support.
m_Show3DControl.value = PlayerSettings.virtualRealitySupported;
if (EditorGUILayout.BeginFadeGroup(m_Show3DControl.faded))
ShowProp(materialEditor, FindProperty("_Layout", props));
EditorGUILayout.EndFadeGroup();
// Let the default implementation add the extra shader properties at the bottom.
materialEditor.PropertiesDefaultGUI(new MaterialProperty[0]);
}
private float ShowProp(MaterialEditor materialEditor, MaterialProperty prop)
{
materialEditor.ShaderProperty(prop, prop.displayName);
return prop.floatValue;
}
}
}