Пример #1
0
        // Monogame's BasicEffect uses Phong's shading, while glTF uses PBR shading, so
        // given monogame's limitations, we try to guess the most appropiate values
        // to have a reasonably good looking renders.

        public Effect UseRigidEffect(Schema2.Material srcMaterial)
        {
            if (_Device == null)
            {
                throw new InvalidOperationException();
            }

            if (srcMaterial == null)
            {
                if (_DefaultRigid == null)
                {
                    _DefaultRigid = new BasicEffect(_Device);
                    _Disposables.AddDisposable(_DefaultRigid);
                }

                return(_DefaultRigid);
            }

            if (_RigidEffects.TryGetValue(srcMaterial, out Effect dstMaterial))
            {
                return(dstMaterial);
            }

            dstMaterial = srcMaterial.Alpha == Schema2.AlphaMode.MASK ? CreateAlphaTestEffect(srcMaterial) : CreateBasicEffect(srcMaterial);

            _RigidEffects[srcMaterial] = dstMaterial;

            return(dstMaterial);
        }
Пример #2
0
        public Texture2D UseTexture(Memory.MemoryImage image, string name = null)
        {
            if (_Device == null)
            {
                throw new InvalidOperationException();
            }

            if (!image.IsValid)
            {
                return(null);
            }

            if (_Textures.TryGetValue(image, out Texture2D tex))
            {
                return(tex);
            }

            using (var m = image.Open())
            {
                tex = Texture2D.FromStream(_Device, m);
                _Disposables.AddDisposable(tex);

                tex.Name = name;

                _Textures[image] = tex;

                return(tex);
            }
        }
Пример #3
0
        private VertexBuffer CreateVertexBuffer <T>(T[] dstVertices) where T : struct, IVertexType
        {
            var vb = new VertexBuffer(_Device, typeof(T), dstVertices.Length, BufferUsage.None);

            _Disposables.AddDisposable(vb);

            vb.SetData(dstVertices);
            return(vb);
        }