Пример #1
0
    private void SpStylize(RenderTexture faceMask, float gamma = 0.433f)
    {
        var mat = new Material(Shader.Find("Hidden/ImageLevels"));

        if (!faceMask)
        {
            Debug.LogWarning("SpStylize: no facePPBlend");
        }
        else
        {
            mat.SetTexture("_MaskTex", faceMask);
        }
        mat.SetFloat("_Gamma", gamma);
        mat.SetFloat("_Blend", 1);
        mat.SetVector("_Param", new Vector4(0, 1, 0, 1));

        var temp = RenderTexture.GetTemporary(_manager.FaceProcess.descriptor);

        Graphics.Blit(_manager.FaceProcess, temp, mat);
        TexTracker.Track(temp, "sp.temp");

        _manager.FaceProcess.DiscardContents();
        Graphics.Blit(temp, _manager.FaceProcess);
        TexTracker.Track(_manager.FaceProcess, "sp");

        Object.Destroy(mat);
    }
Пример #2
0
    public static void ConvertUv(Texture tex, Vector2[] uv, Vector2[] toUV, int[] triangles, RenderTexture dest, Material material = null, Texture mask = null)
    {
        Assert.AreEqual(uv.Length, toUV.Length);

        bool destroyMat = false;

        if (null == material)
        {
            material   = new Material(Shader.Find("Unlit/FaceMaskConvert"));
            destroyMat = true;
        }

        material.mainTexture = tex;
        if (material.HasProperty("_MaskTex"))
        {
            material.SetTexture("_MaskTex", mask);
        }

        var uvMesh = new Mesh
        {
            vertices  = toUV.Select(item => (Vector3)item).ToArray(),
            triangles = triangles,
            uv        = uv,
            uv4       = toUV,
        };

        DrawUvMesh(uvMesh, material, dest, clear: Color.clear);
        if (destroyMat && material)
        {
            Object.Destroy(material);
        }

        TexTracker.Track(tex, "ARFace.GraphicsUtils.ConvertUv/src");
        TexTracker.Track(dest, "ARFace.GraphicsUtils.ConvertUv/target");
    }
Пример #3
0
    public static RenderTexture RotateTexture(RenderTexture texture, float angle)
    {
        var width1  = texture.width;
        var height1 = texture.height;

        bool          reverse = (int)Math.Abs(angle) / 90 % 2 == 1;
        RenderTexture dest;

        if (reverse)
        {
            dest = new RenderTexture(height1, width1, 0, texture.format, texture.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear);
        }
        else
        {
            dest = new RenderTexture(width1, height1, 0, texture.format, texture.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear);
        }

        if (texture)
        {
            var rotateMat = new Material(Shader.Find("Unlit/UVRotateShader"));
            rotateMat.SetTexture("_MainTex", texture);
            rotateMat.SetFloat("_Rotate", angle);
            Graphics.Blit(texture, dest, rotateMat);
            UnityEngine.Object.Destroy(rotateMat);
        }

        TexTracker.Track(dest, "rotate tex");
        return(dest);
    }
Пример #4
0
    public IEnumerator PostProcess()
    {
        var mesh = _manager.data[0].Face;

        //todo 精度下降测试
        var temp = RenderTexture.GetTemporary(_manager.FaceProcess.descriptor);

        GraphicsUtils.ConvertUv(_manager.FaceProcess, _manager.data[0].faceARkitUVs, _manager.config.liuhongTop, _manager.data[0].triangles, temp);
        TexTracker.Track(temp, "texture_remap");

        Graphics.Blit(temp, _manager.ResultTexture, _manager.config.liuhongMat);
        RenderTexture.ReleaseTemporary(temp);

        TexTracker.Track(_manager.ResultTexture, "combTex");

        yield return(0);

        //烘顶点色
        var vertexLut = new RenderTexture(2048, 2048, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);

        //todo 精度下降测试
        MeshUtils.GenVertexLut(vertexLut, mesh, _manager.config.liuhongTop, _manager.config.faceToHead);
        //todo 精度下降测试
        _manager.vertexLutTexture2D = vertexLut.ToNewTexture2D(TextureFormat.RGBAFloat);
        TexTracker.Track(vertexLut, "vertexLut");

        UnityEngine.Object.Destroy(vertexLut);

        isFinished = true;
    }
Пример #5
0
    public RenderTexture CaptureVideoImage(Rect clipBoxUV)
    {
        if (null == manager)
        {
            Debug.LogWarning("manager is not running");
            return(null);
        }
        if (!IsReady)
        {
            Debug.LogWarning("CaptureVideoImage: not ready");
            return(null);
        }
        try
        {
            var size      = GetRawSize();
            var screenBox = RenderTexture.GetTemporary(size.x, size.y, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
            Graphics.Blit(null, screenBox, ARVideo.m_ClearMaterial);
            TexTracker.Track(screenBox, "CaptureVideoImage.screenBox");
            var clipBox = MeshUtils.UvRectToPixelRect(clipBoxUV, size);
            if (manager.delighting)
            {
                clipBox   = Util.MakeSquare(clipBox, new RectInt(Vector2Int.zero, screenBox.Size()));
                clipBoxUV = MeshUtils.PixelRectToUvRect(clipBox, screenBox.Size());
            }
            var clipBoxRt = new RenderTexture(clipBox.width, clipBox.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

            Util.Clip(screenBox, clipBoxUV, clipBoxRt);

            RenderTexture.ReleaseTemporary(screenBox);

            if (manager.delighting)
            {
                clipBoxUV = Util.ResizeRect(clipBoxUV, 1.2f);
                var temp      = new RenderTexture(1024, 1024, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
                var rectScale = new Rect(0, 0, 1, 1);
                rectScale = Util.ResizeRect(rectScale, 1.2f);
                Util.Clip(clipBoxRt, rectScale, temp);

                Debug.Log("CaptureVideoImage! END");
                TexTracker.Track(clipBoxRt, "CaptureVideoImage");
                Destroy(clipBoxRt);

                //clipBoxRt
                TexTracker.Track(temp, "resize");
                return(temp);
            }
            else
            {
                return(clipBoxRt);
            }
        }
        catch (Exception ex)
        {
            Debug.Log("CaptureVideoImage! failed!! ");
            Debug.LogException(ex);
            return(null);
        }
    }
Пример #6
0
 public override void Update()
 {
     if (_manager.IsLeftReady())
     {
         _manager.Capture(out data);
         TexTracker.Track(data.faceTexture, data.Face, "left");
         isFinished = true;
     }
 }
Пример #7
0
    protected override void Init()
    {
        hslMat = new Material(Shader.Find("Custom/HSLShader"));
        ChangeHSL(_manager.config.hsl);
        var temp = RenderTexture.GetTemporary(_manager.FaceProcess.descriptor);

        Graphics.Blit(_manager.FaceProcess, temp, hslMat);
        TexTracker.Track(temp, "hsl.temp");

        _manager.FaceProcess.DiscardContents();
        Graphics.Blit(temp, _manager.FaceProcess);
        TexTracker.Track(_manager.FaceProcess, "hsl");
    }
Пример #8
0
    void ProcessMultiCap(RenderTexture main, RenderTexture left, RenderTexture right, RenderTexture dest)
    {
        if (main && left && right)
        {
            Material mat = _manager.config.threeToOne;
            mat.SetTexture("_MainTex", main);
            mat.SetTexture("_LeftTex", left);
            mat.SetTexture("_RightTex", right);

            dest.DiscardContents();
            Graphics.Blit(null, dest, mat);
            TexTracker.Track(dest, "3t1");
        }
    }
Пример #9
0
    protected override void ReqFaceLandmark()
    {
        CaptureData data = _manager.data[0];

        TexTracker.Track(data.faceTexture, "LandmarkApplyStep.input");

        Set();
        _manager.WhateverFaceMesh.callbackFinal = (success, landmarkDict) =>
        {
            if (success)
            {
                isFinished = true;
            }
        };
        _manager.WhateverFaceMesh.OnRecvFaceData(GetDic(data.faceLandmarkList));
    }
Пример #10
0
    protected virtual void ReqFaceLandmark()
    {
        CaptureData data = _manager.data[0];

        TexTracker.Track(data.faceTexture, "LandmarkStep.input");
        Set();
        _manager.WhateverFaceMesh.callbackFinal = (success, landmarkDict) =>
        {
            if (success)
            {
                data.faceLandmarkList = landmarkDict.Values.ToList();
                isFinished            = true;
            }
        };

        LandmarkManager.GetLandmark(data.faceTexture, LandmarkManager.ActiveLandmarkType, _manager.WhateverFaceMesh.OnRecvFaceData);
    }
Пример #11
0
    void OnMTMakeup(byte[] bytes, string error)
    {
        if (!string.IsNullOrEmpty(error) || bytes == null)
        {
            resultCallback(false, error, null);
            return;
        }

        Texture texture = GraphicsUtils.LoadTexture(bytes);

        TexTracker.Track(texture, "beauty.makeup.req");
        if (!texture)
        {
            resultCallback(false, "bytes is broken", null);
            return;
        }

        resultCallback(true, null, texture);
        UnityEngine.Object.Destroy(texture);
    }
Пример #12
0
    void OnMeituOnlineHD(byte[] datas, string error)
    {
        if (datas == null)
        {
            resultCallback.Invoke(false, error, null);
            return;
        }

        Texture texture = GraphicsUtils.LoadTexture(datas);

        TexTracker.Track(texture, "beauty.hd.req");
        if (!texture)
        {
            resultCallback(false, "bytes is broken", null);
            return;
        }
        UnityEngine.Object.Destroy(texture);

        _manager.AIBeauty.GetMTMakeupPicture(datas, OnMTMakeup, MTShowShowConfig.MT_MAKEUP_0, MTMakeupAlpha, MTBeautyAlpha, 0);
    }
Пример #13
0
 public override void Update()
 {
     _manager.Capture(out data);
     TexTracker.Track(data.faceTexture, data.Face, "font");
     isFinished = true;
 }