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.
101 lines
2.8 KiB
101 lines
2.8 KiB
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UC
|
|
{
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(Camera))]
|
|
[AddComponentMenu("Image Effects/Homography")]
|
|
public class ScreenHomography : MonoBehaviour
|
|
{
|
|
public Color color;
|
|
[Range(0.0f, 1.0f)]
|
|
public float amount = 0f;
|
|
|
|
[SerializeField]
|
|
private Shader m_Shader;
|
|
public Shader shader
|
|
{
|
|
get
|
|
{
|
|
if (m_Shader == null)
|
|
m_Shader = Shader.Find("Hidden/ScreenHomography");
|
|
|
|
return m_Shader;
|
|
}
|
|
}
|
|
#if false
|
|
public Vector2 resolution;
|
|
public Texture cornerTexture;
|
|
#endif
|
|
private Material m_Material;
|
|
public Material material
|
|
{
|
|
get
|
|
{
|
|
if (m_Material == null)
|
|
m_Material = ImageEffectHelper.CheckShaderAndCreateMaterial(shader);
|
|
|
|
return m_Material;
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (!ImageEffectHelper.IsSupported(shader, true, false, this))
|
|
enabled = false;
|
|
GetComponent<Camera>().depthTextureMode = DepthTextureMode.DepthNormals;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (m_Material != null)
|
|
DestroyImmediate(m_Material);
|
|
|
|
m_Material = null;
|
|
}
|
|
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
material.SetColor("blend_color", color);
|
|
material.SetFloat("amount", amount);
|
|
Graphics.Blit(source, destination, material);
|
|
}
|
|
|
|
#if false
|
|
GameObject obj = null;
|
|
void Awake()
|
|
{
|
|
if (Application.isPlaying)
|
|
{
|
|
var camera = GetComponent<Camera>();
|
|
obj = new GameObject();
|
|
obj.transform.parent = transform;
|
|
obj.name = "Homography";
|
|
obj.AddComponent<RectTransform>();
|
|
var canvas = obj.AddComponent<Canvas>();
|
|
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
|
canvas.targetDisplay = camera.targetDisplay;
|
|
obj.AddComponent<GraphicRaycaster>();
|
|
obj.AddComponent<CanvasGroup>();
|
|
var homo = obj.AddComponent<DoHomography>();
|
|
homo.homography = this;
|
|
homo.resolution = resolution;
|
|
homo.cornerTexture = cornerTexture;
|
|
homo.reset = true;
|
|
}
|
|
|
|
}
|
|
void OnDestroy()
|
|
{
|
|
if (obj != null)
|
|
{
|
|
if (Application.isEditor)
|
|
Object.DestroyImmediate(obj);
|
|
else
|
|
Object.Destroy(obj);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|