Пример #1
0
        private void UpdateRenderer(FrustumFitter frustum, Camera cam, Vector2 tiling, Vector2 offset, Renderer rdr)
        {
            var uvs = new List <Vector2>()
            {
                offset + tiling * new Vector2(0, 0),
                offset + tiling * new Vector2(1, 0),
                offset + tiling * new Vector2(1, 1),
                offset + tiling * new Vector2(0, 1),
            };
            var src = new List <Point2 <float> >();

            foreach (var uv in uvs)
            {
                src.Add(new Point2 <float>(uv.x, uv.y));
            }

            var dst = new List <Point2 <float> >();

            foreach (var c in frustum.corners)
            {
                var p = cam.WorldToViewportPoint(c, Camera.MonoOrStereoscopicEye.Mono);
                dst.Add(new Point2 <float>(p.x, p.y));
            }
            var       h**o   = SingleHomographyHelper.FindHomography(src, dst);
            var       matrix = Matrix4x4.identity;
            const int DIM    = 3;

            for (int i = 0; i < h**o.Elements.Count; ++i)
            {
                int row = i / DIM;
                int col = i % DIM;
                matrix[row, col] = h**o.Elements[i];
            }

            var prop = new MaterialPropertyBlock();

            prop.SetMatrix(PROP_HOMOGRAPHY, matrix);
            prop.SetVector(PROP_TILING, tiling);
            prop.SetVector(PROP_OFFSET, offset);
            prop.SetTexture(PROP_MAIN_TEXTURE, (source == SoureType.DEMO) ? demoTexture : spoutTexture);

            rdr.SetPropertyBlock(prop);
        }
 public static HomographyMatrix <float> FindHomography(IReadOnlyList <Point2 <float> > srcPoints, IReadOnlyList <Point2 <float> > dstPoints)
 => SingleHomographyHelper.FindHomography(srcPoints, dstPoints);