136 lines
3.5 KiB
C#
136 lines
3.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace Thousandto.Launcher.ExternalLibs
|
|
{
|
|
/// <summary>
|
|
/// 通用的算法类
|
|
/// </summary>
|
|
public class CmdBufferUtils
|
|
{
|
|
//一个全屏的Mesh
|
|
private static Mesh _quadMesh;
|
|
public static Mesh QuadMesh
|
|
{
|
|
get
|
|
{
|
|
if (_quadMesh == null)
|
|
{
|
|
_quadMesh = CreateMesh();
|
|
}
|
|
return _quadMesh;
|
|
}
|
|
}
|
|
//进行blit复制的材质
|
|
private static Material _blitMat;
|
|
public static Material BlitMat
|
|
{
|
|
get
|
|
{
|
|
if (_blitMat == null)
|
|
{
|
|
_blitMat = CreateMaterial();
|
|
}
|
|
return _blitMat;
|
|
}
|
|
}
|
|
|
|
//主纹理的ID
|
|
private static int _mainTexID = -1;
|
|
public static int MainTexID
|
|
{
|
|
get
|
|
{
|
|
if (_mainTexID < 0)
|
|
{
|
|
_mainTexID = Shader.PropertyToID("_MainTex");
|
|
}
|
|
return _mainTexID;
|
|
}
|
|
}
|
|
|
|
//全屏纹理ID
|
|
private static int _fullScreenTexID = -1;
|
|
public static int FullScreenTexID
|
|
{
|
|
get
|
|
{
|
|
if (_fullScreenTexID < 0)
|
|
{
|
|
_fullScreenTexID = Shader.PropertyToID("_MainTex");
|
|
}
|
|
return _fullScreenTexID;
|
|
}
|
|
}
|
|
|
|
//初始化模型
|
|
private static Mesh CreateMesh()
|
|
{
|
|
var mesh = new Mesh();
|
|
mesh.name = "FullQuadMesh";
|
|
mesh.hideFlags = HideFlags.DontSave;
|
|
Vector3[] vertices = new Vector3[]
|
|
{
|
|
new Vector3(-1f, -1f, 0.5f),
|
|
new Vector3(-1f, 1f, 0.5f),
|
|
new Vector3(1f, 1f, 0.5f),
|
|
new Vector3(1f, -1f, 0.5f)
|
|
};
|
|
|
|
Vector2[] uv = new Vector2[]
|
|
{
|
|
new Vector2(0f, 0f),
|
|
new Vector2(0f, 1f),
|
|
new Vector2(1f, 1f),
|
|
new Vector2(1f, 0f)
|
|
};
|
|
|
|
Color[] colors = new Color[]
|
|
{
|
|
new Color(0f, 0f, 1f),
|
|
new Color(0f, 1f, 1f),
|
|
new Color(1f, 1f, 1f),
|
|
new Color(1f, 0f, 1f)
|
|
};
|
|
|
|
int[] triangles = new int[]
|
|
{
|
|
0,
|
|
2,
|
|
1,
|
|
0,
|
|
3,
|
|
2
|
|
};
|
|
mesh.vertices = vertices;
|
|
mesh.uv = uv;
|
|
mesh.triangles = triangles;
|
|
mesh.colors = colors;
|
|
mesh.UploadMeshData(true);
|
|
|
|
return mesh;
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建Blit材质球
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static Material CreateMaterial()
|
|
{
|
|
var sh = RuntimeUtilities.FindShader("Hidden/Ares/PostEffect/Blit");
|
|
if (sh != null)
|
|
{
|
|
var mat = new Material(sh);
|
|
mat.hideFlags = HideFlags.DontSave;
|
|
return mat;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("没有找到Shader:Hidden/Ares/PostEffect/Blit");
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|