clean project
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea92cf3962c621b48b7d4d6d51a09d2f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,147 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use
|
||||
the Utilities SDK except in compliance with the License, which is provided at the time of installation
|
||||
or download, or which otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
https://developer.oculus.com/licenses/utilities-1.31
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
[CustomEditor(typeof(OVROverlayCanvas))]
|
||||
public class OVROverlayCanvasEditor : Editor {
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
OVROverlayCanvas canvas = target as OVROverlayCanvas;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
float lastTextureSize = canvas.MaxTextureSize;
|
||||
canvas.MaxTextureSize = EditorGUILayout.IntField(new GUIContent("Max Texture Size", "Limits the maximum size of the texture used for this canvas"), canvas.MaxTextureSize);
|
||||
canvas.MinTextureSize = EditorGUILayout.IntField(new GUIContent("Min Texture Size", "Limits the minimum size this texture will be displayed at"), canvas.MinTextureSize);
|
||||
|
||||
// Automatically adjust pixels per unit when texture size is adjusted to maintain the same density
|
||||
canvas.PixelsPerUnit *= lastTextureSize / (float)canvas.MaxTextureSize;
|
||||
canvas.PixelsPerUnit = EditorGUILayout.FloatField(new GUIContent("Pixels Per Unit", "Controls the density of the texture"), canvas.PixelsPerUnit);
|
||||
|
||||
canvas.DrawRate = EditorGUILayout.IntField(new GUIContent("Draw Rate", "Controls how frequently this canvas updates. A value of 1 means every frame, 2 means every other, etc."), canvas.DrawRate);
|
||||
if (canvas.DrawRate > 1)
|
||||
{
|
||||
canvas.DrawFrameOffset = EditorGUILayout.IntField(new GUIContent("Draw Frame Offset", "Allows you to alternate which frame each canvas will draw on by specifying a frame offset."), canvas.DrawFrameOffset);
|
||||
}
|
||||
|
||||
canvas.Expensive = EditorGUILayout.Toggle(new GUIContent("Expensive", "Improve the visual appearance at the cost of additional GPU time"), canvas.Expensive);
|
||||
canvas.Opacity = (OVROverlayCanvas.DrawMode)EditorGUILayout.EnumPopup(new GUIContent("Opacity", "Treat this canvas as opaque, which is a big performance improvement"), canvas.Opacity);
|
||||
|
||||
if (canvas.Opacity == OVROverlayCanvas.DrawMode.TransparentDefaultAlpha)
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.yellow;
|
||||
EditorGUILayout.LabelField("Transparent Default Alpha is not recommended with overlapping semitransparent graphics.");
|
||||
GUI.contentColor = prevColor;
|
||||
}
|
||||
|
||||
if (canvas.Opacity == OVROverlayCanvas.DrawMode.TransparentCorrectAlpha)
|
||||
{
|
||||
var graphics = canvas.GetComponentsInChildren<UnityEngine.UI.Graphic>();
|
||||
bool usingDefaultMaterial = false;
|
||||
foreach(var graphic in graphics)
|
||||
{
|
||||
if (graphic.material == null || graphic.material == graphic.defaultMaterial)
|
||||
{
|
||||
usingDefaultMaterial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (usingDefaultMaterial)
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.yellow;
|
||||
EditorGUILayout.LabelField("Some graphics in this canvas are using the default UI material.");
|
||||
EditorGUILayout.LabelField("Would you like to replace all of them with the corrected UI Material?");
|
||||
GUI.contentColor = prevColor;
|
||||
|
||||
if (GUILayout.Button("Replace Materials"))
|
||||
{
|
||||
var matList = AssetDatabase.FindAssets("t:Material UI Default Correct");
|
||||
if (matList.Length > 0)
|
||||
{
|
||||
var mat = AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(matList[0]));
|
||||
|
||||
foreach(var graphic in graphics)
|
||||
{
|
||||
if (graphic.material == null || graphic.material == graphic.defaultMaterial)
|
||||
{
|
||||
graphic.material = mat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canvas.Opacity == OVROverlayCanvas.DrawMode.TransparentCorrectAlpha ||
|
||||
canvas.Opacity == OVROverlayCanvas.DrawMode.TransparentDefaultAlpha)
|
||||
{
|
||||
if (PlayerSettings.colorSpace == ColorSpace.Gamma)
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.yellow;
|
||||
EditorGUILayout.LabelField("Alpha blending may not be correct with Gamma Color Space");
|
||||
GUI.contentColor = prevColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
canvas.Layer = EditorGUILayout.LayerField(new GUIContent("Layer", "The layer this overlay should be drawn on"), canvas.Layer);
|
||||
|
||||
if (Camera.main != null)
|
||||
{
|
||||
if ((Camera.main.cullingMask & (1 << canvas.gameObject.layer)) != 0)
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.red;
|
||||
EditorGUILayout.LabelField("Main Camera does not cull " + LayerMask.LayerToName(canvas.gameObject.layer)+". Make sure the layer of this object is not drawn by the main camera");
|
||||
GUI.contentColor = prevColor;
|
||||
}
|
||||
if ((Camera.main.cullingMask & (1 << canvas.Layer)) == 0)
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.red;
|
||||
EditorGUILayout.LabelField("Layer should be assigned to a layer visible to your main camera.");
|
||||
GUI.contentColor = prevColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.yellow;
|
||||
EditorGUILayout.LabelField("No Main Camera found. Make sure you camera does not draw layer "+LayerMask.LayerToName(canvas.gameObject.layer));
|
||||
GUI.contentColor = prevColor;
|
||||
}
|
||||
|
||||
if (canvas.Layer == canvas.gameObject.layer)
|
||||
{
|
||||
var prevColor = GUI.contentColor;
|
||||
GUI.contentColor = Color.red;
|
||||
EditorGUILayout.LabelField("Layer is set to the same layer as this object (" + LayerMask.LayerToName(canvas.gameObject.layer) + ").");
|
||||
GUI.contentColor = prevColor;
|
||||
}
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Editor Debug", EditorStyles.boldLabel);
|
||||
canvas.overlayEnabled = EditorGUILayout.Toggle("Overlay Enabled", canvas.overlayEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98ff563b1c4841849b47889f82138370
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 991fe756c49fc274096dc1fc55c4f784
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_Name: UI Default Correct
|
||||
m_Shader: {fileID: 4800000, guid: e720ef9c6dcfbe4489d043ddf61706f8, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _ColorMask: 15
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UVSec: 0
|
||||
- _UseUIAlphaClip: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c303ccfd63b005d4bbdb8f0bbf9e834b
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6838aca3835e89e4395150f887716a4a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,313 @@
|
||||
/************************************************************************************
|
||||
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
|
||||
|
||||
Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use
|
||||
the Utilities SDK except in compliance with the License, which is provided at the time of installation
|
||||
or download, or which otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
https://developer.oculus.com/licenses/utilities-1.31
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Utilities SDK distributed
|
||||
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
||||
ANY KIND, either express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
************************************************************************************/
|
||||
//#define DEBUG_OVERLAY_CANVAS
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Canvas))]
|
||||
public class OVROverlayCanvas : MonoBehaviour
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
private Shader _transparentShader = null;
|
||||
[SerializeField, HideInInspector]
|
||||
private Shader _opaqueShader = null;
|
||||
|
||||
RectTransform _rectTransform;
|
||||
Canvas _canvas;
|
||||
Camera _camera;
|
||||
OVROverlay _overlay;
|
||||
RenderTexture _renderTexture;
|
||||
MeshRenderer _meshRenderer;
|
||||
|
||||
Mesh _quad;
|
||||
Material _defaultMat;
|
||||
|
||||
public int MaxTextureSize = 1600;
|
||||
public int MinTextureSize = 200;
|
||||
public float PixelsPerUnit = 1f;
|
||||
public int DrawRate = 1;
|
||||
public int DrawFrameOffset = 0;
|
||||
public bool Expensive = false;
|
||||
public int Layer = 0;
|
||||
|
||||
public enum DrawMode
|
||||
{
|
||||
Opaque,
|
||||
OpaqueWithClip,
|
||||
TransparentDefaultAlpha,
|
||||
TransparentCorrectAlpha
|
||||
}
|
||||
|
||||
|
||||
public DrawMode Opacity = DrawMode.OpaqueWithClip;
|
||||
|
||||
private bool ScaleViewport = Application.isMobilePlatform;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_canvas = GetComponent<Canvas>();
|
||||
|
||||
_rectTransform = _canvas.GetComponent<RectTransform>();
|
||||
|
||||
float rectWidth = _rectTransform.rect.width;
|
||||
float rectHeight = _rectTransform.rect.height;
|
||||
|
||||
float aspectX = rectWidth >= rectHeight ? 1 : rectWidth / rectHeight;
|
||||
float aspectY = rectHeight >= rectWidth ? 1 : rectHeight / rectWidth;
|
||||
|
||||
// if we are scaling the viewport we don't need to add a border
|
||||
int pixelBorder = ScaleViewport ? 0 : 8;
|
||||
int innerWidth = Mathf.CeilToInt(aspectX * (MaxTextureSize - pixelBorder * 2));
|
||||
int innerHeight = Mathf.CeilToInt(aspectY * (MaxTextureSize - pixelBorder * 2));
|
||||
int width = innerWidth + pixelBorder * 2;
|
||||
int height = innerHeight + pixelBorder * 2;
|
||||
|
||||
float paddedWidth = rectWidth * (width / (float)innerWidth);
|
||||
float paddedHeight = rectHeight * (height / (float)innerHeight);
|
||||
|
||||
float insetRectWidth = innerWidth / (float)width;
|
||||
float insetRectHeight = innerHeight / (float)height;
|
||||
|
||||
// ever so slightly shrink our opaque mesh to avoid black borders
|
||||
Vector2 opaqueTrim = Opacity == DrawMode.Opaque ? new Vector2(0.005f / _rectTransform.lossyScale.x, 0.005f / _rectTransform.lossyScale.y) : Vector2.zero;
|
||||
|
||||
_renderTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
|
||||
// if we can't scale the viewport, generate mipmaps instead
|
||||
_renderTexture.useMipMap = !ScaleViewport;
|
||||
|
||||
GameObject overlayCamera = new GameObject(name + " Overlay Camera")
|
||||
{
|
||||
#if !DEBUG_OVERLAY_CANVAS
|
||||
hideFlags = HideFlags.HideInHierarchy | HideFlags.NotEditable
|
||||
#endif
|
||||
};
|
||||
overlayCamera.transform.SetParent(transform, false);
|
||||
|
||||
_camera = overlayCamera.AddComponent<Camera>();
|
||||
_camera.stereoTargetEye = StereoTargetEyeMask.None;
|
||||
_camera.transform.position = transform.position - transform.forward;
|
||||
_camera.orthographic = true;
|
||||
_camera.enabled = false;
|
||||
_camera.targetTexture = _renderTexture;
|
||||
_camera.cullingMask = 1 << gameObject.layer;
|
||||
_camera.clearFlags = CameraClearFlags.SolidColor;
|
||||
_camera.backgroundColor = Color.clear;
|
||||
_camera.orthographicSize = 0.5f * paddedHeight * _rectTransform.localScale.y;
|
||||
_camera.nearClipPlane = 0.99f;
|
||||
_camera.farClipPlane = 1.01f;
|
||||
|
||||
_quad = new Mesh()
|
||||
{
|
||||
name = name + " Overlay Quad",
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
|
||||
_quad.vertices = new Vector3[] { new Vector3(-0.5f, -0.5f), new Vector3(-0.5f, 0.5f), new Vector3(0.5f, 0.5f), new Vector3(0.5f, -0.5f) };
|
||||
_quad.uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) };
|
||||
_quad.triangles = new int[] { 0, 1, 2, 2, 3, 0 };
|
||||
_quad.bounds = new Bounds(Vector3.zero, Vector3.one);
|
||||
_quad.UploadMeshData(true);
|
||||
|
||||
switch(Opacity)
|
||||
{
|
||||
case DrawMode.Opaque:
|
||||
_defaultMat = new Material(_opaqueShader);
|
||||
break;
|
||||
case DrawMode.OpaqueWithClip:
|
||||
_defaultMat = new Material(_opaqueShader);
|
||||
_defaultMat.EnableKeyword("WITH_CLIP");
|
||||
break;
|
||||
case DrawMode.TransparentDefaultAlpha:
|
||||
_defaultMat = new Material(_transparentShader);
|
||||
_defaultMat.EnableKeyword("ALPHA_SQUARED");
|
||||
break;
|
||||
case DrawMode.TransparentCorrectAlpha:
|
||||
_defaultMat = new Material(_transparentShader);
|
||||
break;
|
||||
}
|
||||
_defaultMat.mainTexture = _renderTexture;
|
||||
_defaultMat.color = Color.black;
|
||||
_defaultMat.mainTextureOffset = new Vector2(0.5f - 0.5f * insetRectWidth, 0.5f - 0.5f * insetRectHeight);
|
||||
_defaultMat.mainTextureScale = new Vector2(insetRectWidth, insetRectHeight);
|
||||
|
||||
GameObject meshRenderer = new GameObject(name + " MeshRenderer")
|
||||
{
|
||||
#if !DEBUG_OVERLAY_CANVAS
|
||||
hideFlags = HideFlags.HideInHierarchy | HideFlags.NotEditable
|
||||
#endif
|
||||
};
|
||||
|
||||
meshRenderer.transform.SetParent(transform, false);
|
||||
meshRenderer.AddComponent<MeshFilter>().sharedMesh = _quad;
|
||||
_meshRenderer = meshRenderer.AddComponent<MeshRenderer>();
|
||||
_meshRenderer.sharedMaterial = _defaultMat;
|
||||
meshRenderer.layer = Layer;
|
||||
meshRenderer.transform.localScale = new Vector3(rectWidth - opaqueTrim.x, rectHeight - opaqueTrim.y, 1);
|
||||
|
||||
GameObject overlay = new GameObject(name + " Overlay")
|
||||
{
|
||||
#if !DEBUG_OVERLAY_CANVAS
|
||||
hideFlags = HideFlags.HideInHierarchy | HideFlags.NotEditable
|
||||
#endif
|
||||
};
|
||||
overlay.transform.SetParent(transform, false);
|
||||
_overlay = overlay.AddComponent<OVROverlay>();
|
||||
_overlay.isDynamic = true;
|
||||
_overlay.noDepthBufferTesting = true;
|
||||
_overlay.isAlphaPremultiplied = !Application.isMobilePlatform;
|
||||
_overlay.textures[0] = _renderTexture;
|
||||
_overlay.currentOverlayType = OVROverlay.OverlayType.Underlay;
|
||||
_overlay.transform.localScale = new Vector3(paddedWidth, paddedHeight, 1);
|
||||
_overlay.useExpensiveSuperSample = Expensive;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Destroy(_defaultMat);
|
||||
Destroy(_quad);
|
||||
Destroy(_renderTexture);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_overlay)
|
||||
{
|
||||
_meshRenderer.enabled = true;
|
||||
_overlay.enabled = true;
|
||||
}
|
||||
if (_camera)
|
||||
{
|
||||
_camera.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_overlay)
|
||||
{
|
||||
_overlay.enabled = false;
|
||||
_meshRenderer.enabled = false;
|
||||
}
|
||||
|
||||
if (_camera)
|
||||
{
|
||||
_camera.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Plane[] _FrustumPlanes = new Plane[6];
|
||||
protected virtual bool ShouldRender()
|
||||
{
|
||||
if (DrawRate > 1)
|
||||
{
|
||||
if (Time.frameCount % DrawRate != DrawFrameOffset % DrawRate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Camera.main != null)
|
||||
{
|
||||
// Perform Frustum culling
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var eye = (Camera.StereoscopicEye)i;
|
||||
var mat = Camera.main.GetStereoProjectionMatrix(eye) * Camera.main.GetStereoViewMatrix(eye);
|
||||
GeometryUtility.CalculateFrustumPlanes(mat, _FrustumPlanes);
|
||||
if (GeometryUtility.TestPlanesAABB(_FrustumPlanes, _meshRenderer.bounds))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (ShouldRender())
|
||||
{
|
||||
if (ScaleViewport)
|
||||
{
|
||||
if (Camera.main != null)
|
||||
{
|
||||
float d = (Camera.main.transform.position - transform.position).magnitude;
|
||||
|
||||
float size = PixelsPerUnit * Mathf.Max(_rectTransform.rect.width * transform.lossyScale.x, _rectTransform.rect.height * transform.lossyScale.y) / d;
|
||||
|
||||
// quantize to even pixel sizes
|
||||
const float quantize = 8;
|
||||
float pixelHeight = Mathf.Ceil(size / quantize * _renderTexture.height) * quantize;
|
||||
|
||||
// clamp between or min size and our max size
|
||||
pixelHeight = Mathf.Clamp(pixelHeight, MinTextureSize, _renderTexture.height);
|
||||
|
||||
float innerPixelHeight = pixelHeight - 2;
|
||||
|
||||
_camera.orthographicSize = 0.5f * _rectTransform.rect.height * _rectTransform.localScale.y * pixelHeight / innerPixelHeight;
|
||||
|
||||
float aspect = (_rectTransform.rect.width / _rectTransform.rect.height);
|
||||
|
||||
float innerPixelWidth = innerPixelHeight * aspect;
|
||||
float pixelWidth = Mathf.Ceil((innerPixelWidth + 2) * 0.5f) * 2;
|
||||
|
||||
float sizeX = pixelWidth / _renderTexture.width;
|
||||
float sizeY = pixelHeight / _renderTexture.height;
|
||||
|
||||
// trim a half pixel off each size if this is opaque (transparent should fade)
|
||||
float inset = Opacity == DrawMode.Opaque ? 1.001f : 0;
|
||||
|
||||
float innerSizeX = (innerPixelWidth - inset) / _renderTexture.width;
|
||||
float innerSizeY = (innerPixelHeight - inset) / _renderTexture.height;
|
||||
|
||||
// scale the camera rect
|
||||
_camera.rect = new Rect((1 - sizeX) / 2, (1 - sizeY) / 2, sizeX, sizeY);
|
||||
|
||||
Rect src = new Rect(0.5f - (0.5f * innerSizeX), 0.5f - (0.5f * innerSizeY), innerSizeX, innerSizeY);
|
||||
|
||||
_defaultMat.mainTextureOffset = src.min;
|
||||
_defaultMat.mainTextureScale = src.size;
|
||||
|
||||
// update the overlay to use this same size
|
||||
_overlay.overrideTextureRectMatrix = true;
|
||||
src.y = 1 - src.height - src.y;
|
||||
Rect dst = new Rect(0, 0, 1, 1);
|
||||
_overlay.SetSrcDestRects(src, src, dst, dst);
|
||||
}
|
||||
}
|
||||
|
||||
_camera.Render();
|
||||
}
|
||||
}
|
||||
|
||||
public bool overlayEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _overlay && _overlay.enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_overlay)
|
||||
{
|
||||
_overlay.enabled = value;
|
||||
_defaultMat.color = value ? Color.black : Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a2598d6fa300904caa7c672805a8263
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- _transparentShader: {fileID: 4800000, guid: 3e744168f165d504fb0f5f3e0a6ae824,
|
||||
type: 3}
|
||||
- _opaqueShader: {fileID: 4800000, guid: 1d90b910cd5a4854598ecfe4f74358d1, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c482279fbaaa85b44858c3ead9094dad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,115 @@
|
||||
// This shader is identical to UI/Default except the Alpha blend mode results in correct Alpha
|
||||
Shader "UI/Default Corrected"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
|
||||
_Color ("Tint", Color) = (1,1,1,1)
|
||||
|
||||
_StencilComp ("Stencil Comparison", Float) = 8
|
||||
_Stencil ("Stencil ID", Float) = 0
|
||||
_StencilOp ("Stencil Operation", Float) = 0
|
||||
_StencilWriteMask ("Stencil Write Mask", Float) = 255
|
||||
_StencilReadMask ("Stencil Read Mask", Float) = 255
|
||||
|
||||
_ColorMask ("Color Mask", Float) = 15
|
||||
|
||||
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Default"
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
float4 worldPosition : TEXCOORD1;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _Color;
|
||||
fixed4 _TextureSampleAdd;
|
||||
float4 _ClipRect;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert(appdata_t v)
|
||||
{
|
||||
v2f OUT;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
||||
OUT.worldPosition = v.vertex;
|
||||
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
|
||||
|
||||
OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
|
||||
OUT.color = v.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
|
||||
|
||||
#ifdef UNITY_UI_CLIP_RECT
|
||||
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip (color.a - 0.001);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e720ef9c6dcfbe4489d043ddf61706f8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
Shader "UI/Prerendered Opaque"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Texture", 2D) = "white" {}
|
||||
_Color("Color", Color) = (1,1,1,1)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags {"Queue"="Geometry" "IgnoreProjector"="True" "RenderType"="Opaque"}
|
||||
|
||||
Blend One Zero, Zero Zero
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile _ WITH_CLIP
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t v) {
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target {
|
||||
#if !WITH_CLIP
|
||||
if (_Color.x == 0 && _Color.y == 0 && _Color.z == 0)
|
||||
{
|
||||
return _Color;
|
||||
}
|
||||
#endif
|
||||
fixed4 col = tex2D(_MainTex, i.texcoord);
|
||||
col *= _Color;
|
||||
|
||||
#if WITH_CLIP
|
||||
clip(col.a - 0.5);
|
||||
#endif
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d90b910cd5a4854598ecfe4f74358d1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
Shader "UI/Prerendered"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex("Texture", 2D) = "white" {}
|
||||
_Color("Color", Color) = (1,1,1,1)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
|
||||
|
||||
Blend One OneMinusSrcAlpha, Zero Zero
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile _ ALPHA_SQUARED
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t v) {
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target {
|
||||
fixed4 col = tex2D(_MainTex, i.texcoord);
|
||||
|
||||
#if ALPHA_SQUARED
|
||||
// prerended UI will have a = Alpha * SrcAlpha, so we need to sqrt
|
||||
// to get the original alpha value
|
||||
col.a = sqrt(col.a);
|
||||
#endif
|
||||
|
||||
// It should be noted that with Gamma lighting on PC,
|
||||
// the blend will result in not correct colors of transparent
|
||||
// portions of the overlay
|
||||
|
||||
col *= _Color;
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e744168f165d504fb0f5f3e0a6ae824
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user