|
@@ -259,6 +259,7 @@ public partial class ScreenLocate : o0InfraredCameraHandler
|
|
|
|
|
|
|
|
[NonSerialized] public RectTransform BackQuad = null;
|
|
[NonSerialized] public RectTransform BackQuad = null;
|
|
|
|
|
|
|
|
|
|
+ public Material quadMaskMat;
|
|
|
static public ScreenLocate Main { get; private set; }
|
|
static public ScreenLocate Main { get; private set; }
|
|
|
|
|
|
|
|
static public void AutoLightPixels(Color[] pixels, int width, int height)
|
|
static public void AutoLightPixels(Color[] pixels, int width, int height)
|
|
@@ -359,6 +360,9 @@ public partial class ScreenLocate : o0InfraredCameraHandler
|
|
|
|
|
|
|
|
//if (mUVCDrawer)
|
|
//if (mUVCDrawer)
|
|
|
// mUVCDrawer.StartPreviewAction += UVCIsReady;
|
|
// mUVCDrawer.StartPreviewAction += UVCIsReady;
|
|
|
|
|
+
|
|
|
|
|
+ //获取master
|
|
|
|
|
+ quadMaskMat = new Material(Shader.Find("Custom/CameraPointsMaskShader"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void OnDestroy()
|
|
void OnDestroy()
|
|
@@ -1417,6 +1421,48 @@ public partial class ScreenLocate : o0InfraredCameraHandler
|
|
|
RenderTexture.ReleaseTemporary(renderTexture);
|
|
RenderTexture.ReleaseTemporary(renderTexture);
|
|
|
return _texture2D;
|
|
return _texture2D;
|
|
|
}
|
|
}
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 制作一个填充黑边的texture,把识别点之后的外围区域填充成黑色部分,用shader处理
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="inputTexture"></param>
|
|
|
|
|
+ /// <param name="shaderMat"></param>
|
|
|
|
|
+ /// <param name="quadUV"></param>
|
|
|
|
|
+ /// <param name="width"></param>
|
|
|
|
|
+ /// <param name="height"></param>
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ private Texture2D TextureToTexture2DWithShader(Texture inputTexture, Material shaderMat, List<Vector2> quadUV, int width = 0, int height = 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (width == 0) width = inputTexture.width;
|
|
|
|
|
+ if (height == 0) height = inputTexture.height;
|
|
|
|
|
+
|
|
|
|
|
+ // 设置四点裁剪(传给 shader)
|
|
|
|
|
+ shaderMat.SetVector("_QuadP0", quadUV[0]);
|
|
|
|
|
+ shaderMat.SetVector("_QuadP1", quadUV[1]);
|
|
|
|
|
+ shaderMat.SetVector("_QuadP2", quadUV[2]);
|
|
|
|
|
+ shaderMat.SetVector("_QuadP3", quadUV[3]);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 创建临时 RT
|
|
|
|
|
+ RenderTexture currentRT = RenderTexture.active;
|
|
|
|
|
+ RenderTexture tempRT = RenderTexture.GetTemporary(
|
|
|
|
|
+ width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
|
|
|
|
|
+
|
|
|
|
|
+ // Blit 带 Shader 的处理
|
|
|
|
|
+ Graphics.Blit(inputTexture, tempRT, shaderMat);
|
|
|
|
|
+
|
|
|
|
|
+ // 从 RT 读取像素到 Texture2D
|
|
|
|
|
+ Texture2D resultTex = new Texture2D(width, height, TextureFormat.ARGB32, false, true);
|
|
|
|
|
+ RenderTexture.active = tempRT;
|
|
|
|
|
+ resultTex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
|
|
|
|
+ resultTex.Apply();
|
|
|
|
|
+
|
|
|
|
|
+ // 清理
|
|
|
|
|
+ RenderTexture.active = currentRT;
|
|
|
|
|
+ RenderTexture.ReleaseTemporary(tempRT);
|
|
|
|
|
+
|
|
|
|
|
+ return resultTex;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//public void CreateUVCTexture2DFocusSizeIfNeeded(int width, int height)
|
|
//public void CreateUVCTexture2DFocusSizeIfNeeded(int width, int height)
|
|
|
//{
|
|
//{
|
|
@@ -1443,7 +1489,26 @@ public partial class ScreenLocate : o0InfraredCameraHandler
|
|
|
{
|
|
{
|
|
|
if (mUVCTexture2D != null)
|
|
if (mUVCTexture2D != null)
|
|
|
Destroy(mUVCTexture2D);
|
|
Destroy(mUVCTexture2D);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取 Quad
|
|
|
|
|
+ var quadInCamera = screenIdentification?.Screen?.QuadInCamera;
|
|
|
|
|
+ if (quadInCamera != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ List<Vector2> quad = quadInCamera.GetUnityVertexNormalizedList();
|
|
|
|
|
+ if (quad != null && quad.Count == 4)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 原顺序:左下、右下、左上、右上
|
|
|
|
|
+ mUVCTexture2D = TextureToTexture2DWithShader(mUVCTexture, quadMaskMat, quad);
|
|
|
|
|
+
|
|
|
|
|
+ // 纹理测试显示
|
|
|
|
|
+ InfraredDemo._ins.MyCameraRender6.texture = mUVCTexture2D;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 无效 quad 或为空时直接复制原始纹理
|
|
|
mUVCTexture2D = TextureToTexture2D(mUVCTexture, width, height);
|
|
mUVCTexture2D = TextureToTexture2D(mUVCTexture, width, height);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#region DoubleButton
|
|
#region DoubleButton
|