123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- namespace UnityEngine.PostProcessing
- {
- public static class GraphicsUtils
- {
- public static bool isLinearColorSpace
- {
- get
- {
- return QualitySettings.activeColorSpace == ColorSpace.Linear;
- }
- }
- public static bool supportsDX11
- {
- get
- {
- return SystemInfo.graphicsShaderLevel >= 50 && SystemInfo.supportsComputeShaders;
- }
- }
- public static Texture2D whiteTexture
- {
- get
- {
- if (GraphicsUtils.s_WhiteTexture != null)
- {
- return GraphicsUtils.s_WhiteTexture;
- }
- GraphicsUtils.s_WhiteTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
- GraphicsUtils.s_WhiteTexture.SetPixel(0, 0, new Color(1f, 1f, 1f, 1f));
- GraphicsUtils.s_WhiteTexture.Apply();
- return GraphicsUtils.s_WhiteTexture;
- }
- }
- public static Mesh quad
- {
- get
- {
- if (GraphicsUtils.s_Quad != null)
- {
- return GraphicsUtils.s_Quad;
- }
- Vector3[] vertices = new Vector3[]
- {
- new Vector3(-1f, -1f, 0f),
- new Vector3(1f, 1f, 0f),
- new Vector3(1f, -1f, 0f),
- new Vector3(-1f, 1f, 0f)
- };
- Vector2[] uv = new Vector2[]
- {
- new Vector2(0f, 0f),
- new Vector2(1f, 1f),
- new Vector2(1f, 0f),
- new Vector2(0f, 1f)
- };
- int[] triangles = new int[]
- {
- 0,
- 1,
- 2,
- 1,
- 0,
- 3
- };
- GraphicsUtils.s_Quad = new Mesh
- {
- vertices = vertices,
- uv = uv,
- triangles = triangles
- };
- GraphicsUtils.s_Quad.RecalculateNormals();
- GraphicsUtils.s_Quad.RecalculateBounds();
- return GraphicsUtils.s_Quad;
- }
- }
- public static void Blit(Material material, int pass)
- {
- GL.PushMatrix();
- GL.LoadOrtho();
- material.SetPass(pass);
- GL.Begin(5);
- GL.TexCoord2(0f, 0f);
- GL.Vertex3(0f, 0f, 0.1f);
- GL.TexCoord2(1f, 0f);
- GL.Vertex3(1f, 0f, 0.1f);
- GL.TexCoord2(0f, 1f);
- GL.Vertex3(0f, 1f, 0.1f);
- GL.TexCoord2(1f, 1f);
- GL.Vertex3(1f, 1f, 0.1f);
- GL.End();
- GL.PopMatrix();
- }
- public static void ClearAndBlit(Texture source, RenderTexture destination, Material material, int pass, bool clearColor = true, bool clearDepth = false)
- {
- RenderTexture active = RenderTexture.active;
- RenderTexture.active = destination;
- GL.Clear(false, clearColor, Color.clear);
- GL.PushMatrix();
- GL.LoadOrtho();
- material.SetTexture("_MainTex", source);
- material.SetPass(pass);
- GL.Begin(5);
- GL.TexCoord2(0f, 0f);
- GL.Vertex3(0f, 0f, 0.1f);
- GL.TexCoord2(1f, 0f);
- GL.Vertex3(1f, 0f, 0.1f);
- GL.TexCoord2(0f, 1f);
- GL.Vertex3(0f, 1f, 0.1f);
- GL.TexCoord2(1f, 1f);
- GL.Vertex3(1f, 1f, 0.1f);
- GL.End();
- GL.PopMatrix();
- RenderTexture.active = active;
- }
- public static void Destroy(Object obj)
- {
- if (obj != null)
- {
- Object.Destroy(obj);
- }
- }
- public static void Dispose()
- {
- GraphicsUtils.Destroy(GraphicsUtils.s_Quad);
- }
- private static Texture2D s_WhiteTexture;
- private static Mesh s_Quad;
- }
- }
|