public void FromMatrix(ref Matrix matrix)
 {
     Position = matrix.Translation;
     Quaternion q;
     Quaternion.CreateFromRotationMatrix(ref matrix, out q);
     Orientation = new HalfVector4(q.ToVector4());
 }
예제 #2
0
 public BlockVertex(Vector3 position, HalfVector2 blockTextureCoordinate, HalfVector4 light, Color tint)
 {
     m_position = position;
     m_blockTextureCoordinate = blockTextureCoordinate;
     m_light = light;
     m_tint = new HalfVector4(tint.ToVector4());
 }
예제 #3
0
 public MyInstanceData(Matrix m)
 {
     m_row0       = new HalfVector4(m.M11, m.M21, m.M31, m.M41);
     m_row1       = new HalfVector4(m.M12, m.M22, m.M32, m.M42);
     m_row2       = new HalfVector4(m.M13, m.M23, m.M33, m.M43);
     ColorMaskHSV = new HalfVector4();
 }
예제 #4
0
        /// <summary>
        /// Read HalfVector4
        /// </summary>
        static HalfVector4 ReadHalfVector4(BinaryReader reader)
        {
            HalfVector4 vct = new HalfVector4();

            vct.PackedValue = reader.ReadUInt64();
            return(vct);
        }
예제 #5
0
        public void FromMatrix(ref Matrix matrix)
        {
            Position = matrix.Translation;
            Quaternion q;

            Quaternion.CreateFromRotationMatrix(ref matrix, out q);
            Orientation = new HalfVector4(q.ToVector4());
        }
예제 #6
0
        public void FromMatrix(ref VRageMath.Matrix matrix)
        {
            Quaternion quaternion;

            this.Position = matrix.Translation;
            Quaternion.CreateFromRotationMatrix(ref matrix, out quaternion);
            this.Orientation = new HalfVector4(quaternion.ToVector4());
        }
예제 #7
0
        public void HalfVector4()
        {
            // Test PackedValue
            Assert.Equal(0uL, new HalfVector4(Vector4.Zero).PackedValue);
            Assert.Equal(4323521613979991040uL, new HalfVector4(Vector4.One).PackedValue);
            Assert.Equal(13547034390470638592uL, new HalfVector4(-Vector4.One).PackedValue);
            Assert.Equal(15360uL, new HalfVector4(Vector4.UnitX).PackedValue);
            Assert.Equal(1006632960uL, new HalfVector4(Vector4.UnitY).PackedValue);
            Assert.Equal(65970697666560uL, new HalfVector4(Vector4.UnitZ).PackedValue);
            Assert.Equal(4323455642275676160uL, new HalfVector4(Vector4.UnitW).PackedValue);
            Assert.Equal(4035285078724390502uL, new HalfVector4(0.1f, 0.3f, 0.4f, 0.5f).PackedValue);

            // Test ToVector4
            Assert.True(Equal(Vector4.Zero, new HalfVector4(Vector4.Zero).ToVector4()));
            Assert.True(Equal(Vector4.One, new HalfVector4(Vector4.One).ToVector4()));
            Assert.True(Equal(-Vector4.One, new HalfVector4(-Vector4.One).ToVector4()));
            Assert.True(Equal(Vector4.UnitX, new HalfVector4(Vector4.UnitX).ToVector4()));
            Assert.True(Equal(Vector4.UnitY, new HalfVector4(Vector4.UnitY).ToVector4()));
            Assert.True(Equal(Vector4.UnitZ, new HalfVector4(Vector4.UnitZ).ToVector4()));
            Assert.True(Equal(Vector4.UnitW, new HalfVector4(Vector4.UnitW).ToVector4()));

            // Test ToScaledVector4.
            Vector4 scaled = new HalfVector4(-Vector4.One).ToScaledVector4();

            Assert.Equal(0, scaled.X);
            Assert.Equal(0, scaled.Y);
            Assert.Equal(0, scaled.Z);
            Assert.Equal(0, scaled.W);

            // Test PackFromScaledVector4.
            var pixel = default(HalfVector4);

            pixel.PackFromScaledVector4(scaled);
            Assert.Equal(13547034390470638592uL, pixel.PackedValue);

            // Test ordering
            float x = .25F;
            float y = .5F;
            float z = .75F;
            float w = 1F;

            var rgb  = default(Rgb24);
            var rgba = default(Rgba32);
            var bgr  = default(Bgr24);
            var bgra = default(Bgra32);

            new HalfVector4(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(64, 128, 191));

            new HalfVector4(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(64, 128, 191, 255));

            new HalfVector4(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(64, 128, 191));

            new HalfVector4(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(64, 128, 191, 255));
        }
예제 #8
0
        private static HalfVector4[] ReadArrayOfHalfVector4(BinaryReader reader)
        {
            var length           = reader.ReadInt32();
            var halfVector4Array = new HalfVector4[length];

            for (var index = 0; index < length; ++index)
            {
                halfVector4Array[index] = ReadHalfVector4(reader);
            }
            return(halfVector4Array);
        }
예제 #9
0
        private HalfVector4 SampleHalfFloat4(Texture2D tex, Vector2 texCoord)
        {
            Rectangle sourceRectangle =
                new Rectangle((int)(texCoord.X * tex.Width), (int)(texCoord.Y * tex.Height), 1, 1);

            HalfVector4[] retrievedColor = new HalfVector4[1];

            tex.GetData(0, sourceRectangle, retrievedColor, 0, 1);

            return(retrievedColor[0]); //retrievedColor[0].ToVector4();
        }
예제 #10
0
파일: MyModel.cs 프로젝트: wriley/SEToolbox
        /// <summary>
        /// Read array of HalfVector4
        /// </summary>
        private static HalfVector4[] ReadArrayOfHalfVector4(BinaryReader reader)
        {
            var nCount      = reader.ReadInt32();
            var vectorArray = new HalfVector4[nCount];

            for (var i = 0; i < nCount; ++i)
            {
                vectorArray[i] = ReadHalfVector4(reader);
            }

            return(vectorArray);
        }
예제 #11
0
        /// <summary>
        /// Read array of HalfVector4
        /// </summary>
        static HalfVector4[] ReadArrayOfHalfVector4(BinaryReader reader)
        {
            int nCount = reader.ReadInt32();

            HalfVector4[] vctArr = new HalfVector4[nCount];
            for (int i = 0; i < nCount; ++i)
            {
                vctArr[i] = ReadHalfVector4(reader);
            }

            return(vctArr);
        }
예제 #12
0
        public void HalfVector4_ToBgr24()
        {
            // arrange
            var halfVector = new HalfVector4(.25F, .5F, .75F, 1F);
            var actual     = default(Bgr24);
            var expected   = new Bgr24(64, 128, 191);

            // act
            halfVector.ToBgr24(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
예제 #13
0
        public void HalfVector4_Rgba32()
        {
            // arrange
            var halfVector = new HalfVector4(.25F, .5F, .75F, 1F);
            var actual     = default(Rgba32);
            var expected   = new Rgba32(64, 128, 191, 255);

            // act
            halfVector.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
예제 #14
0
        public void HalfVector4_ToScaledVector4()
        {
            // arrange
            var halfVector4 = new HalfVector4(-Vector4.One);

            // act
            Vector4 actual = halfVector4.ToScaledVector4();

            // assert
            Assert.Equal(0, actual.X);
            Assert.Equal(0, actual.Y);
            Assert.Equal(0, actual.Z);
            Assert.Equal(0, actual.W);
        }
예제 #15
0
        public void HalfVector4_FromScaledVector4()
        {
            // arrange
            var     halfVector4 = default(HalfVector4);
            Vector4 scaled      = new HalfVector4(-Vector4.One).ToScaledVector4();
            ulong   expected    = 13547034390470638592uL;

            // act
            halfVector4.FromScaledVector4(scaled);
            ulong actual = halfVector4.PackedValue;

            // assert
            Assert.Equal(expected, actual);
        }
예제 #16
0
        public void Encode(VertexElement element, XNAV4 value)
        {
            var dstVertex = _Vertex.Slice(element.Offset);

            if (element.VertexElementFormat == VertexElementFormat.Vector4)
            {
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref value);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Byte4)
            {
                var c = new Byte4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref c);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Color)
            {
                var c = new Color(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref c);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.Short4)
            {
                var ns = new Short4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref ns);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.NormalizedShort4)
            {
                var ns = new NormalizedShort4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref ns);
                return;
            }

            if (element.VertexElementFormat == VertexElementFormat.HalfVector4)
            {
                var ns = new HalfVector4(value);
                System.Runtime.InteropServices.MemoryMarshal.Write(dstVertex, ref ns);
                return;
            }

            throw new ArgumentException(nameof(element));
        }
예제 #17
0
        public void SetGlobalEmissivity(float emissivity)
        {
            MyInstanceMaterial instanceMaterial = MyInstanceMaterial.Default;

            instanceMaterial.Emissivity = emissivity;

            // Set emissivity for parts, that are not instanced:
            GlobalColorMultEmissivity = new HalfVector4(1, 1, 1, emissivity);

            // Fill emissivity to all parts, that are not explictly set
            for (int i = 0; i < m_instanceMaterials.GetSize(); i++)
            {
                if (!m_instanceMaterials.IsExplicitlySet(i))
                {
                    m_instanceMaterials.Set(i, instanceMaterial);
                }
            }
        }
예제 #18
0
        public bool ExportDataPackedAsHV4(string tagName, Vector3[] vctArr)
        {
            WriteTag(tagName);

            if (vctArr == null)
            {
                m_writer.Write(0);
                return(true);
            }

            m_writer.Write(vctArr.Length);
            foreach (Vector3 vctVal in vctArr)
            {
                Vector3     v   = vctVal;
                HalfVector4 vct = VF_Packer.PackPosition(ref v);
                WriteHalfVector4(ref vct);
            }

            return(true);
        }
예제 #19
0
        void IDrawableGroupStrategy.Fill(int bufferOffset, MyInstanceComponent instance, MyLod lod, int multiTransformI, int instanceMaterialOffsetInData, MyInstanceLodState state, float stateData)
        {
            HalfVector4 packedColorMultEmissivity = MyInstanceMaterial.Default.PackedColorMultEmissivity;

            if (instanceMaterialOffsetInData != -1) // if instance material is defined
            {
                MyInstanceMaterial instanceMaterial = instance.GetInstanceMaterial(instanceMaterialOffsetInData);
                packedColorMultEmissivity = instanceMaterial.PackedColorMultEmissivity;
            }
            else
            {
                packedColorMultEmissivity = instance.GlobalColorMultEmissivity;
            }

            HalfVector4 packedKeyColorDithering = instance.KeyColor.ToHalfVector4();
            HalfVector4 dithering = new HalfVector4();

            dithering.PackedValue = (ulong)HalfUtils.Pack(stateData);
            packedKeyColorDithering.PackedValue = packedKeyColorDithering.PackedValue | dithering.PackedValue << 48;

            MyVbConstantElement element = new MyVbConstantElement
            {
                //WorldMatrixRow0 = new Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14),
                //WorldMatrixRow1 = new Vector4(matrix.M21, matrix.M22, matrix.M23, matrix.M24),
                //WorldMatrixRow2 = new Vector4(matrix.M31, matrix.M32, matrix.M33, matrix.M34),
                KeyColorDithering   = packedKeyColorDithering,
                ColorMultEmissivity = packedColorMultEmissivity,
            };

            // much faster approach than naive:
            instance.GetMatrixCols(multiTransformI,
                                   out element.WorldMatrixRow0,
                                   out element.WorldMatrixRow1,
                                   out element.WorldMatrixRow2);

            m_vbData[bufferOffset] = element;

            m_validElements++;
        }
예제 #20
0
        private static HalfVector4[] GenerateRawCubeGridElements(Vector2I gridSize)
        {
            Func <HalfVector4[]> initializer = () =>
            {
                HalfVector4[] cubeElements = GenerateRawCubeElements();
                HalfVector4[] gridElements = new HalfVector4[gridSize.Size() * cubeElements.Length];

                for (int i = 0; i < gridSize.Size(); i++)
                {
                    int    baseIdx = i * cubeElements.Length;
                    ushort offset  = (ushort)(i * 8);

                    for (int j = 0; j < cubeElements.Length; j++)
                    {
                        gridElements[baseIdx + j] = cubeElements[j] + offset;
                    }
                }

                return(gridElements);
            };

            return(FirstFactoryHelper(initializer, CubeGridElements, gridSize));
        }
예제 #21
0
        public void HalfVector4()
        {
            //Test PackedValue
            Assert.AreEqual(0uL, new HalfVector4(Vector4.Zero).PackedValue);
            Assert.AreEqual(4323521613979991040uL, new HalfVector4(Vector4.One).PackedValue);
            Assert.AreEqual(13547034390470638592uL, new HalfVector4(-Vector4.One).PackedValue);
            Assert.AreEqual(15360uL, new HalfVector4(Vector4.UnitX).PackedValue);
            Assert.AreEqual(1006632960uL, new HalfVector4(Vector4.UnitY).PackedValue);
            Assert.AreEqual(65970697666560uL, new HalfVector4(Vector4.UnitZ).PackedValue);
            Assert.AreEqual(4323455642275676160uL, new HalfVector4(Vector4.UnitW).PackedValue);
            Assert.AreEqual(4035285078724390502uL, new HalfVector4(0.1f, 0.3f, 0.4f, 0.5f).PackedValue);

            //Test ToVector4
            Assert.AreEqual(Vector4.Zero, new HalfVector4(Vector4.Zero).ToVector4());
            Assert.AreEqual(Vector4.One, new HalfVector4(Vector4.One).ToVector4());
            Assert.AreEqual(-Vector4.One, new HalfVector4(-Vector4.One).ToVector4());
            Assert.AreEqual(Vector4.UnitX, new HalfVector4(Vector4.UnitX).ToVector4());
            Assert.AreEqual(Vector4.UnitY, new HalfVector4(Vector4.UnitY).ToVector4());
            Assert.AreEqual(Vector4.UnitZ, new HalfVector4(Vector4.UnitZ).ToVector4());
            Assert.AreEqual(Vector4.UnitW, new HalfVector4(Vector4.UnitW).ToVector4());

            var x        = 0.1f;
            var y        = -0.3f;
            var z        = 0.5f;
            var w        = -0.7f;
            var packed   = new HalfVector4(x, y, z, w).PackedValue;
            var unpacked = new HalfVector4()
            {
                PackedValue = packed
            }.ToVector4();

            Assert.AreEqual(x, unpacked.X, 0.01f);
            Assert.AreEqual(y, unpacked.Y, 0.01f);
            Assert.AreEqual(z, unpacked.Z, 0.01f);
            Assert.AreEqual(w, unpacked.W, 0.01f);
        }
예제 #22
0
 internal MyVertexFormatPositionPackedColor(HalfVector4 position, Byte4 color)
 {
     Position = position;
     Color = color;
 }
예제 #23
0
        private void FillShadowedVertices(Particle.ParticleSystemInstance instance)
        {
            if (m_shadowedVertices1 == null || m_shadowedVertices1.Length < m_sorter.SortedIndices.Length * 4)
            {
                m_shadowedVertices1 = new ParticleVertex1[m_sorter.SortedIndices.Length * 4];
                m_shadowedVertices2 = new ParticleVertex2[m_sorter.SortedIndices.Length * 4];
                for (int i = 0; i < m_shadowedVertices1.Length; ++i)
                {
                    m_shadowedVertices1[i].corner = (Byte)(i & 0x3);
                }
            }

            var texture = instance.System.TextureObject ?? m_whiteTexture;
            float invTexWidth = 1f / texture.Width;
            float invTexHeight = 1f / texture.Height;

            int writePos = 0;
            foreach (var effect in instance.EffectInstances)
            {
                XnaRect uvBounds = effect.Effect.UVBounds;

                var uvParamX = (float)uvBounds.Width * invTexWidth;
                var uvParamY = -(float)uvBounds.Height * invTexHeight;
                var uvParamZ = 0.5f * uvParamX + (uvBounds.X - 0.5f) * invTexWidth;
                var uvParamW = -0.5f * uvParamY + (uvBounds.Y - 0.5f) * invTexHeight;
                var uvParams = new HalfVector4(uvParamX, uvParamY, uvParamZ, uvParamW);

                var expand = (Byte)(effect.Effect.Alignment == Particle.Alignment.Screen ? 12 : 0);

                var startWritePos = writePos;

                effect.BatchProcess((particles, begin, end) =>
                {
                    for (int i = begin; i < end; ++i)
                    {
                        var p = particles[i];

                        m_shadowedVertices1[writePos].position = p.m_position;
                        m_shadowedVertices1[writePos].expand = expand;
                        m_shadowedVertices1[writePos].size = p.m_size;
                        m_shadowedVertices1[writePos].rotation = p.m_rotation;
                        m_shadowedVertices1[writePos].uvparams = uvParams;
                        m_shadowedVertices1[writePos].color = p.m_color;
                        ++writePos;

                        m_shadowedVertices1[writePos].position = p.m_position;
                        m_shadowedVertices1[writePos].expand = expand;
                        m_shadowedVertices1[writePos].size = p.m_size;
                        m_shadowedVertices1[writePos].rotation = p.m_rotation;
                        m_shadowedVertices1[writePos].uvparams = uvParams;
                        m_shadowedVertices1[writePos].color = p.m_color;
                        ++writePos;

                        m_shadowedVertices1[writePos].position = p.m_position;
                        m_shadowedVertices1[writePos].expand = expand;
                        m_shadowedVertices1[writePos].size = p.m_size;
                        m_shadowedVertices1[writePos].rotation = p.m_rotation;
                        m_shadowedVertices1[writePos].uvparams = uvParams;
                        m_shadowedVertices1[writePos].color = p.m_color;
                        ++writePos;

                        m_shadowedVertices1[writePos].position = p.m_position;
                        m_shadowedVertices1[writePos].expand = expand;
                        m_shadowedVertices1[writePos].size = p.m_size;
                        m_shadowedVertices1[writePos].rotation = p.m_rotation;
                        m_shadowedVertices1[writePos].uvparams = uvParams;
                        m_shadowedVertices1[writePos].color = p.m_color;
                        ++writePos;
                    }
                });

                writePos = startWritePos;

                effect.BatchProcess((particles, localFrames, begin, end) =>
                {
                    if (effect.Effect.Alignment == Particle.Alignment.Local)
                    {
                        for (int i = begin; i < end; ++i)
                        {
                            var col0 = localFrames[i].Col0;
                            var col1 = localFrames[i].Col1;
                            var col2 = localFrames[i].Col2;
                            var col3 = localFrames[i].Col3;

                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                        }
                    }
                    else
                    {
                        var col0 = Vector4.UnitX;
                        var col1 = Vector4.UnitY;
                        var col2 = Vector4.UnitZ;
                        var col3 = Vector4.UnitW;
                        for (int i = begin; i < end; ++i)
                        {
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                            m_shadowedVertices2[writePos].col0 = col0;
                            m_shadowedVertices2[writePos].col1 = col1;
                            m_shadowedVertices2[writePos].col2 = col2;
                            m_shadowedVertices2[writePos++].col3 = col3;
                        }
                    }
                });
            }
        }
예제 #24
0
 internal MyVertexFormatPositionSkinning(HalfVector4 position, Byte4 indices, Vector4 weights)
 {
     Position = position;
     BoneIndices = indices;
     BoneWeights = new HalfVector4(weights);
 }
예제 #25
0
 internal MyVertexFormatSpritePositionTextureRotationColor(HalfVector4 position, HalfVector4 texcoord, HalfVector4 originTangent, Byte4 color)
 {
     ClipspaceOffsetScale = position;
     TexcoordOffsetScale = texcoord;
     OriginTangent = originTangent; 
     Color = color;
 }
예제 #26
0
    //--------------------------------------------------------------
    #region Creation & Cleanup
    //--------------------------------------------------------------

    /// <summary>
    /// Initializes a new instance of the <see cref="TerrainVertex"/> struct.
    /// </summary>
    /// <param name="position">The position of the vertex.</param>
    public TerrainVertex(HalfVector4 position)
    {
      Position = position;
    }
예제 #27
0
 static public Vector3 UnpackPosition(ref HalfVector4 position)
 {
     Vector4 unpacked = position.ToVector4();
     return unpacked.W * new Vector3(unpacked.X, unpacked.Y, unpacked.Z);
 }
예제 #28
0
        static public Vector3 UnpackPosition(ref HalfVector4 position)
        {
            Vector4 unpacked = position.ToVector4();

            return(unpacked.W * new Vector3(unpacked.X, unpacked.Y, unpacked.Z));
        }
예제 #29
0
        private static bool ExportData(this BinaryWriter writer, string tagName, HalfVector4[] vectorArray)
        {
            WriteTag(writer, tagName);

            if (vectorArray == null)
            {
                writer.Write(0);
                return true;
            }

            writer.Write(vectorArray.Length);
            foreach (var vectorVal in vectorArray)
            {
                writer.Write(vectorVal.PackedValue);
            }

            return true;
        }
예제 #30
0
 internal MyVertexFormatPositionPackedColor(Vector3 position, Color color)
 {
     Position = new HalfVector4(position.X, position.Y, position.Z, 1);
     Color = new Byte4(color.PackedValue);
 }
예제 #31
0
 internal MyVertexFormatPositionH4(Vector3 position)
 {
     
     Position = VF_Packer.PackPosition(ref position);
 }
 /// <summary>
 /// 64 bits
 /// </summary>
 public static void Write(this BitStream stream, HalfVector4 vec)
 {
     stream.WriteUInt64(vec.PackedValue);
 }
 /// <summary>
 /// 64 bits
 /// </summary>
 public static void Serialize(this BitStream stream, ref HalfVector4 vec)
 {
     stream.Serialize(ref vec.PackedValue);
 }
예제 #34
0
        private static Submesh GetStarfieldMesh(StarfieldNode node, RenderContext context)
        {
            // The mesh is cached in the scene node.
              var mesh = node.RenderData as Submesh;
              if (mesh == null)
              {
            mesh = new Submesh { PrimitiveType = PrimitiveType.TriangleList };
            node.RenderData = mesh;
              }

              if (mesh.VertexBuffer == null || mesh.VertexBuffer.IsDisposed)
              {
            int numberOfStars = node.Stars.Count;

            // The total number of stars is limited by the graphics device max primitives per call limit.
            var graphicsDevice = context.GraphicsService.GraphicsDevice;
            int maxNumberOfStars = graphicsDevice.GetMaxPrimitivesPerCall() / 2;
            if (numberOfStars > maxNumberOfStars)
              throw new GraphicsException("The number of stars must be less than " + maxNumberOfStars);

            // Create a vertex buffer with a quad for each star.
            //   1--2
            //   | /|
            //   |/ |
            //   0--3
            mesh.VertexCount = numberOfStars * 4;
            var vertices = new StarVertex[numberOfStars * 4];
            for (int i = 0; i < numberOfStars; i++)
            {
              var star = node.Stars[i];
              var positionAndSize = new HalfVector4(star.Position.X, star.Position.Y, star.Position.Z, star.Size);
              var color = new HalfVector4(star.Color.X, star.Color.Y, star.Color.Z, 1);

              vertices[i * 4 + 0].PositionAndSize = positionAndSize;
              vertices[i * 4 + 0].Color = color;
              vertices[i * 4 + 0].Texture = new Vector2(0, 1);

              vertices[i * 4 + 1].PositionAndSize = positionAndSize;
              vertices[i * 4 + 1].Color = color;
              vertices[i * 4 + 1].Texture = new Vector2(0, 0);

              vertices[i * 4 + 2].PositionAndSize = positionAndSize;
              vertices[i * 4 + 2].Color = color;
              vertices[i * 4 + 2].Texture = new Vector2(1, 0);

              vertices[i * 4 + 3].PositionAndSize = positionAndSize;
              vertices[i * 4 + 3].Color = color;
              vertices[i * 4 + 3].Texture = new Vector2(1, 1);
            }
            mesh.VertexBuffer = new VertexBuffer(graphicsDevice, typeof(StarVertex), vertices.Length, BufferUsage.None);
            mesh.VertexBuffer.SetData(vertices);

            // Create index buffer for quad (= two triangles, clockwise).
            var indices = new ushort[numberOfStars * 6];
            for (int i = 0; i < numberOfStars; i++)
            {
              indices[i * 6 + 0] = (ushort)(i * 4 + 0);
              indices[i * 6 + 1] = (ushort)(i * 4 + 1);
              indices[i * 6 + 2] = (ushort)(i * 4 + 2);
              indices[i * 6 + 3] = (ushort)(i * 4 + 0);
              indices[i * 6 + 4] = (ushort)(i * 4 + 2);
              indices[i * 6 + 5] = (ushort)(i * 4 + 3);
            }
            mesh.IndexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None);
            mesh.IndexBuffer.SetData(indices);

            mesh.PrimitiveCount = numberOfStars * 2;
              }

              return mesh;
        }
예제 #35
0
파일: MyModel.cs 프로젝트: wriley/SEToolbox
 /// <summary>
 /// Write HalfVector4
 /// </summary>
 private static void WriteHalfVector4(this BinaryWriter writer, ref HalfVector4 value)
 {
     writer.Write(value.PackedValue);
 }
예제 #36
0
 private void WriteVector(HalfVector4 val)
 {
     m_writer.Write(val.PackedValue);
 }
예제 #37
0
        /// <summary>
        /// Read array of HalfVector4
        /// </summary>
        private static HalfVector4[] ReadArrayOfHalfVector4(BinaryReader reader)
        {
            var nCount = reader.ReadInt32();
            var vectorArray = new HalfVector4[nCount];

            for (var i = 0; i < nCount; ++i)
            {
                vectorArray[i] = ReadHalfVector4(reader);
            }

            return vectorArray;
        }
예제 #38
0
 /// <summary>
 /// 64 bits
 /// </summary>
 public static void Serialize(this BitStream stream, ref HalfVector4 vec)
 {
     stream.Serialize(ref vec.PackedValue);
 }
        /// <summary>
        /// Copies the billboard to vertex buffer.
        /// </summary>
        /// <param name="billboarIdx">The billboar idx.</param>
        static void CopyBillboardToVertices(int billboarIdx, MyBillboard billboard)
        {
            int startIndex = (billboarIdx) * MyTransparentGeometryConstants.VERTICES_PER_TRANSPARENT_GEOMETRY;
            HalfVector4 colorHalf = new HalfVector4(billboard.Color);
            MyTransparentMaterial materialProperties = MyTransparentMaterials.GetMaterial(billboard.Material);

            billboard.Position0.AssertIsValid();
            billboard.Position1.AssertIsValid();
            billboard.Position2.AssertIsValid();
            billboard.Position3.AssertIsValid();

            
            m_vertices[startIndex + 0].Color = colorHalf;
            m_vertices[startIndex + 0].TexCoord = new HalfVector4(materialProperties.UVOffset.X + billboard.UVOffset.X, materialProperties.UVOffset.Y + billboard.UVOffset.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            
            m_vertices[startIndex + 1].Color = colorHalf;
            m_vertices[startIndex + 1].TexCoord = new HalfVector4(materialProperties.UVOffset.X + materialProperties.UVSize.X + billboard.UVOffset.X, materialProperties.UVOffset.Y + billboard.UVOffset.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            
            m_vertices[startIndex + 2].Color = colorHalf;
            m_vertices[startIndex + 2].TexCoord = new HalfVector4(materialProperties.UVOffset.X + materialProperties.UVSize.X + billboard.UVOffset.X, materialProperties.UVOffset.Y + materialProperties.UVSize.Y + billboard.UVOffset.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            m_vertices[startIndex + 3].Color = colorHalf;
            m_vertices[startIndex + 3].TexCoord = new HalfVector4(materialProperties.UVOffset.X + billboard.UVOffset.X, materialProperties.UVOffset.Y + materialProperties.UVSize.Y + billboard.UVOffset.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            Vector3D pos0 = billboard.Position0;
            Vector3D pos1 = billboard.Position1;
            Vector3D pos2 = billboard.Position2;
            Vector3D pos3 = billboard.Position3;

            if (billboard.ParentID != -1)
            {
                MyRenderObject renderObject;
                if (MyRender.m_renderObjects.TryGetValue((uint)billboard.ParentID, out renderObject))
                {
                    MyRenderTransformObject transformObject = renderObject as MyRenderTransformObject;
                    MyManualCullableRenderObject cullableObject = renderObject as MyManualCullableRenderObject;
                    if (transformObject != null)
                    {
                        var worldMatrix = transformObject.WorldMatrix;

                        Vector3D.Transform(ref pos0, ref worldMatrix, out pos0);
                        Vector3D.Transform(ref pos1, ref worldMatrix, out pos1);
                        Vector3D.Transform(ref pos2, ref worldMatrix, out pos2);
                        Vector3D.Transform(ref pos3, ref worldMatrix, out pos3);
                    }
                    else if (cullableObject != null)
                    {
                        var worldMatrix = cullableObject.WorldMatrix;

                        Vector3D.Transform(ref pos0, ref worldMatrix, out pos0);
                        Vector3D.Transform(ref pos1, ref worldMatrix, out pos1);
                        Vector3D.Transform(ref pos2, ref worldMatrix, out pos2);
                        Vector3D.Transform(ref pos3, ref worldMatrix, out pos3);
                    }
                }
            }

            if (billboard.CustomViewProjection != -1)
            {
                System.Diagnostics.Debug.Assert(MyRenderProxy.BillboardsViewProjectionRead.ContainsKey(billboard.CustomViewProjection));

                if (MyRenderProxy.BillboardsViewProjectionRead.ContainsKey(billboard.CustomViewProjection))
                {
                    var billboardViewProjection = MyRenderProxy.BillboardsViewProjectionRead[billboard.CustomViewProjection];

                    pos0 -= billboardViewProjection.CameraPosition;
                    pos1 -= billboardViewProjection.CameraPosition;
                    pos2 -= billboardViewProjection.CameraPosition;
                    pos3 -= billboardViewProjection.CameraPosition;
                }
                else
                {
                    pos0 -= MyRenderCamera.Position;
                    pos1 -= MyRenderCamera.Position;
                    pos2 -= MyRenderCamera.Position;
                    pos3 -= MyRenderCamera.Position;
                }
            }
            else
            {
                pos0 -= MyRenderCamera.Position;
                pos1 -= MyRenderCamera.Position;
                pos2 -= MyRenderCamera.Position;
                pos3 -= MyRenderCamera.Position;
            }

            m_vertices[startIndex + 0].Position = pos0;
            m_vertices[startIndex + 1].Position = pos1;
            m_vertices[startIndex + 2].Position = pos2;
            m_vertices[startIndex + 3].Position = pos3;

            pos0.AssertIsValid();
            pos1.AssertIsValid();
            pos2.AssertIsValid();
            pos3.AssertIsValid();

            if (materialProperties.Reflectivity > 0)
            {
                var normal = Vector3.Cross(billboard.Position1 - billboard.Position0, billboard.Position2 - billboard.Position0);

                var NormalRefl = new HalfVector4(normal.X, normal.Y, normal.Z, billboard.Reflectivity);
                m_vertices[startIndex + 0].TexCoord2 = NormalRefl;
                m_vertices[startIndex + 1].TexCoord2 = NormalRefl;
                m_vertices[startIndex + 2].TexCoord2 = NormalRefl;
                m_vertices[startIndex + 3].TexCoord2 = NormalRefl;
            }
            else if (billboard.BlendTextureRatio > 0)
            {
                MyTransparentMaterial blendMaterialProperties = MyTransparentMaterials.GetMaterial(billboard.BlendMaterial);
                m_vertices[startIndex + 0].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + billboard.UVOffset.Y, 0, 0);
                m_vertices[startIndex + 1].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + blendMaterialProperties.UVSize.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + billboard.UVOffset.Y, 0, 0);
                m_vertices[startIndex + 2].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + blendMaterialProperties.UVSize.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + blendMaterialProperties.UVSize.Y + billboard.UVOffset.Y, 0, 0);
                m_vertices[startIndex + 3].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + blendMaterialProperties.UVSize.Y + billboard.UVOffset.Y, 0, 0);
            }

        }
        /// <summary>
        /// Computes the gradients at each voxel using the 3D Central Differences method and places 
        /// them together with the isovalues. This method will try to load a gradient file for the
        /// asset if it exists; if it doesn't, it does the gradient computations and saves it to a file.
        /// </summary>
        /// <param name="volumeData">Scaled volume data of the model.</param>
        /// <param name="textureData">Texture data that is returned.</param>
        private void CreateTextureData(float[] volumeData, out HalfVector4[] textureData)
        {
            Vector3[] volumeGradients = new Vector3[width * height * depth];

            string ext = volumeAssetName.Substring(volumeAssetName.LastIndexOf('.'));
            string gradientFile = volumeAssetName.Replace(ext, ".grad");

            if (File.Exists(gradientFile))
            {
                // Gradient file already exists, so load it.
                FileStream file = new FileStream(gradientFile, FileMode.Open);
                BinaryReader reader = new BinaryReader(file);

                int index = 0;
                for (int i = 0; i < volumeGradients.Length; ++i)
                {
                    Vector3 gradient;
                    gradient.X = reader.ReadSingle();
                    gradient.Y = reader.ReadSingle();
                    gradient.Z = reader.ReadSingle();

                    volumeGradients[index++] = gradient;
                }

                reader.Close();
                file.Close();
            }
            else
            {
                // Gradient file doesn't exist, so do the computations.
                int index = 0;
                for (int z = 0; z < depth; ++z)
                    for (int y = 0; y < height; ++y)
                        for (int x = 0; x < width; ++x)
                        {
                            // Get the "previous" data.
                            Vector3 v1;
                            v1.X = GetVolumeDataBounded(volumeData, x - 1, y, z);
                            v1.Y = GetVolumeDataBounded(volumeData, x, y - 1, z);
                            v1.Z = GetVolumeDataBounded(volumeData, x, y, z - 1);

                            // Get the "next" data.
                            Vector3 v2;
                            v2.X = GetVolumeDataBounded(volumeData, x + 1, y, z);
                            v2.Y = GetVolumeDataBounded(volumeData, x, y + 1, z);
                            v2.Z = GetVolumeDataBounded(volumeData, x, y, z + 1);

                            // Compute the gradient.
                            volumeGradients[index] = v2 - v1;
                            if (volumeGradients[index] != Vector3.Zero)
                                volumeGradients[index] = Vector3.Normalize(volumeGradients[index]);

                            Debug.Assert(!float.IsNaN(volumeGradients[index].X));
                            index++;
                        }

                // Save the gradients in binary format to a file so we don't have to recompute them again.
                FileStream file = new FileStream(gradientFile, FileMode.Create);
                BinaryWriter writer = new BinaryWriter(file);

                for (int i = 0; i < volumeGradients.Length; ++i)
                {
                    writer.Write(volumeGradients[i].X);
                    writer.Write(volumeGradients[i].Y);
                    writer.Write(volumeGradients[i].Z);
                }

                writer.Close();
                file.Close();
            }

            // Pack the gradients and isovalues into a 16-bit Vector4 (accuracy should be sufficient,
            // but with half the memory usage).
            textureData = new HalfVector4[width * height * depth];
            for (int i = 0; i < textureData.Length; ++i)
                textureData[i] = new HalfVector4(volumeGradients[i].X, volumeGradients[i].Y, volumeGradients[i].Z, volumeData[i]);
        }
예제 #41
0
        public bool ExportData(string tagName, HalfVector4[] vctArr)
        {
            WriteTag(tagName);

            if (vctArr == null)
            {
                m_writer.Write(0);
                return true;
            }

            m_writer.Write(vctArr.Length);
            foreach (HalfVector4 vctVal in vctArr)
            {
                WriteVector(vctVal);
            }

            return true;
        }
예제 #42
0
        private void GetColorData(Texture2D texture2D)
        {
            int colorDataLength = texture2D.Width * texture2D.Height;
            colorData = new Color[colorDataLength];

            switch (texture2D.Format)
            {
                case SurfaceFormat.Color:
                    texture2D.GetData<Color>(colorData);
                    break;

                case SurfaceFormat.Alpha8:
                    var alpha8Data = new Alpha8[colorDataLength];
                    texture2D.GetData<Alpha8>(alpha8Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)alpha8Data[i]).ToVector4());
                    }

                    break;
                
                case SurfaceFormat.Bgr565:
                    var bgr565Data = new Bgr565[colorDataLength];
                    texture2D.GetData<Bgr565>(bgr565Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)bgr565Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Bgra4444:
                    var bgra4444Data = new Bgra4444[colorDataLength];
                    texture2D.GetData<Bgra4444>(bgra4444Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)bgra4444Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Bgra5551:
                    var bgra5551Data = new Bgra5551[colorDataLength];
                    texture2D.GetData<Bgra5551>(bgra5551Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)bgra5551Data[i]).ToVector4());
                    }
                    break;

                case SurfaceFormat.HalfSingle:
                    var halfSingleData = new HalfSingle[colorDataLength];
                    texture2D.GetData<HalfSingle>(halfSingleData);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)halfSingleData[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.HalfVector2:
                    var halfVector2Data = new HalfVector2[colorDataLength];
                    texture2D.GetData<HalfVector2>(halfVector2Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)halfVector2Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.HalfVector4:
                    var halfVector4Data = new HalfVector4[colorDataLength];
                    texture2D.GetData<HalfVector4>(halfVector4Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)halfVector4Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.NormalizedByte2:
                    var normalizedByte2Data = new NormalizedByte2[colorDataLength];
                    texture2D.GetData<NormalizedByte2>(normalizedByte2Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)normalizedByte2Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.NormalizedByte4:
                    var normalizedByte4Data = new NormalizedByte4[colorDataLength];
                    texture2D.GetData<NormalizedByte4>(normalizedByte4Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)normalizedByte4Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Rg32:
                    var rg32Data = new Rg32[colorDataLength];
                    texture2D.GetData<Rg32>(rg32Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)rg32Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Rgba64:
                    var rgba64Data = new Rgba64[colorDataLength];
                    texture2D.GetData<Rgba64>(rgba64Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)rgba64Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Rgba1010102:
                    var rgba1010102Data = new Rgba1010102[colorDataLength];
                    texture2D.GetData<Rgba1010102>(rgba1010102Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)rgba1010102Data[i]).ToVector4());
                    }

                    break;

                default:
                    throw new Exception("Texture surface format not supported");
            }
        }
예제 #43
0
 /// <summary>
 /// 64 bits
 /// </summary>
 public static void Write(this BitStream stream, HalfVector4 vec)
 {
     stream.WriteUInt64(vec.PackedValue);
 }
예제 #44
0
 internal MyVertexFormatPositionPackedColor(Vector3 position, Byte4 color)
 {
     Position = new HalfVector4(position.X, position.Y, position.Z, 1);
     Color    = color;
 }
예제 #45
0
 internal MyVertexFormatPositionPackedColor(Vector3 position, Color color)
 {
     Position = new HalfVector4(position.X, position.Y, position.Z, 1);
     Color    = new Byte4(color.PackedValue);
 }
예제 #46
0
 internal MyVertexFormatPositionH4(HalfVector4 position)
 {
     Position = position;
 }
예제 #47
0
 internal MyVertexFormatSpritePositionTextureColor(HalfVector4 position, HalfVector4 texcoord, Byte4 color)
 {
     ClipspaceOffsetScale = position;
     TexcoordOffsetScale = texcoord;
     Color = color;
 }
예제 #48
0
 internal MyVertexFormatPositionH4(Vector3 position)
 {
     Position = VF_Packer.PackPosition(ref position);
 }
예제 #49
0
 internal MyVertexFormatPositionTextureSkinning(HalfVector4 position, HalfVector2 texcoord, Byte4 indices, Vector4 weights)
 {
     Position = position;
     Texcoord = texcoord;
     BoneIndices = indices;
     BoneWeights = new HalfVector4(weights);
 }
예제 #50
0
 internal MyVertexFormatPositionHTextureH(HalfVector4 position, HalfVector2 texcoord)
 {
     Position = position;
     Texcoord = texcoord;
 }
예제 #51
0
 internal MyVertexFormatPositionPackedColor(Vector3 position, Byte4 color)
 {
     Position = new HalfVector4(position.X, position.Y, position.Z, 1);
     Color = color;
 }
예제 #52
0
 static public Vector3 UnpackPosition(HalfVector4 position)
 {
     return PositionPacker.UnpackPosition(ref position);
 }
예제 #53
0
 internal MyVertexFormatPositionH4(HalfVector4 position)
 {
     Position = position;
 }
예제 #54
0
        //--------------------------------------------------------------
        /// <summary>
        /// Gets the texture data of the specified mipmap level as a <see cref="Vector4"/> array.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="level">The mipmap level to read. Currently only 0 is supported!</param>
        /// <returns>
        /// The array containing the data of the specified mipmap level.
        /// (One <see cref="Vector4"/> element per pixel.)
        /// </returns>
        /// <remarks>
        /// <para>
        /// This method can be used with following texture surface formats:
        /// <see cref="SurfaceFormat.Alpha8"/>, <see cref="SurfaceFormat.Color"/>, 
        /// <see cref="SurfaceFormat.Rg32"/>, <see cref="SurfaceFormat.Rgba64"/>,
        /// <see cref="SurfaceFormat.Single"/>, <see cref="SurfaceFormat.Vector2"/>,
        /// <see cref="SurfaceFormat.Vector4"/>, <see cref="SurfaceFormat.HalfSingle"/>,
        /// <see cref="SurfaceFormat.HalfVector2"/>, <see cref="SurfaceFormat.HalfVector4"/>
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="texture"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="NotImplementedException">
        /// Invalid mipmap level. Extracting mipmap levels other than 0 is not yet implemented.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// Texture format is not yet supported.
        /// </exception>
        public static Vector4[] GetTextureLevelVector4(Texture2D texture, int level)
        {
            if (texture == null)
            throw new ArgumentNullException("texture");
              if (level < 0)
            throw new ArgumentOutOfRangeException("level");
              if (level > 0)
            throw new NotImplementedException("GetTextureLevelVector4 for levels other than 0 is not yet implemented.");

              var bufferLevel0 = new Vector4[texture.Width * texture.Height];

              if (texture.Format == SurfaceFormat.Alpha8)
              {
            var buffer = new byte[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(0, 0, 0, buffer[i] / 255.0f);
              }
              else if (texture.Format == SurfaceFormat.Color)
              {
            var buffer = new Color[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = buffer[i].ToVector4();
              }
              else if (texture.Format == SurfaceFormat.Rg32)
              {
            var buffer = new Rg32[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
            {
              var v = buffer[i].ToVector2();
              bufferLevel0[i] = new Vector4(v.X, v.Y, 0, 0);
            }
              }
              else if (texture.Format == SurfaceFormat.Rgba64)
              {
            var buffer = new Rgba64[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = buffer[i].ToVector4();
              }
              else if (texture.Format == SurfaceFormat.Single)
              {
            var buffer = new Single[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(buffer[i]);
              }
              else if (texture.Format == SurfaceFormat.Vector2)
              {
            var buffer = new Vector2[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(buffer[i].X, buffer[i].Y, 0, 0);
              }
              else if (texture.Format == SurfaceFormat.Vector4)
              {
            texture.GetData(bufferLevel0);
              }
              else if (texture.Format == SurfaceFormat.HalfSingle)
              {
            var buffer = new HalfSingle[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(buffer[i].ToSingle(), 0, 0, 0);
              }
              else if (texture.Format == SurfaceFormat.HalfVector2)
              {
            var buffer = new HalfVector2[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
            {
              var v = buffer[i].ToVector2();
              bufferLevel0[i] = new Vector4(v.X, v.Y, 0, 0);
            }
              }
              else if (texture.Format == SurfaceFormat.HalfVector4)
              {
            var buffer = new HalfVector4[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = buffer[i].ToVector4();
              }
              else
              {
            throw new NotSupportedException("Texture format '" + texture.Format + "' is not yet supported.");
              }

              return bufferLevel0;
        }
예제 #55
0
 internal MyVertexFormatPositionHTextureH(HalfVector4 position, HalfVector2 texcoord)
 {
     Position = position;
     Texcoord = texcoord;
 }
예제 #56
0
        public static void SetTextureLevel(Texture2D texture, int level, float[] data)
        {
            if (texture == null)
            throw new ArgumentNullException("texture");
              if (data == null)
            throw new ArgumentNullException("data");

              if (texture.Format == SurfaceFormat.Alpha8)
              {
            var buffer = new byte[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = (byte)(data[i] * 255.0f);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Color)
              {
            var buffer = new Color[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Color(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Rg32)
              {
            var buffer = new Rg32[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Rg32(data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Rgba64)
              {
            var buffer = new Rgba64[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Rgba64(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Single)
              {
            texture.SetData(level, null, data, 0, data.Length);
              }
              else if (texture.Format == SurfaceFormat.Vector2)
              {
            var buffer = new Vector2[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Vector2(data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Vector4)
              {
            var buffer = new Vector4[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Vector4(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.HalfSingle)
              {
            var buffer = new HalfSingle[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new HalfSingle(data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.HalfVector2)
              {
            var buffer = new HalfVector2[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new HalfVector2(data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.HalfVector4)
              {
            var buffer = new HalfVector4[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new HalfVector4(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else
              {
            throw new NotSupportedException("Texture format '" + texture.Format + "' is not yet supported.");
              }
        }
 public MyInstanceData(Matrix m)
 {
     m_row0 = new HalfVector4(m.M11, m.M21, m.M31, m.M41);
     m_row1 = new HalfVector4(m.M12, m.M22, m.M32, m.M42);
     m_row2 = new HalfVector4(m.M13, m.M23, m.M33, m.M43);
     ColorMaskHSV = new HalfVector4();
 }
예제 #58
0
 internal MyVertexFormatSpritePositionTextureRotationColor(HalfVector4 position, HalfVector4 texcoord, HalfVector4 originTangent, Byte4 color)
 {
     ClipspaceOffsetScale = position;
     TexcoordOffsetScale  = texcoord;
     OriginTangent        = originTangent;
     Color = color;
 }
        /// <summary>
        /// Copies the billboard to vertex buffer.
        /// </summary>
        /// <param name="billboarIdx">The billboar idx.</param>
        static void CopyTriBillboardToVertices(int billboarIdx, MyTriangleBillboard billboard)
        {
            int startIndex = (billboarIdx) * MyTransparentGeometryConstants.VERTICES_PER_TRANSPARENT_GEOMETRY;
            HalfVector4 colorHalf = new HalfVector4(billboard.Color);
            MyTransparentMaterial materialProperties = MyTransparentMaterials.GetMaterial(billboard.Material);

            var position0 = billboard.Position0;
            var position1 = billboard.Position1;
            var position2 = billboard.Position2;

            var normal0 = (Vector3D)billboard.Normal0;
            var normal1 = (Vector3D)billboard.Normal1;
            var normal2 = (Vector3D)billboard.Normal2;
            
            if (billboard.ParentID != -1)
            {
                MyRenderObject renderObject;
                if (MyRender.m_renderObjects.TryGetValue((uint)billboard.ParentID, out renderObject))
                {
                    MyRenderTransformObject transformObject = renderObject as MyRenderTransformObject;
                    if (transformObject != null)
                    {
                        var worldMatrix = transformObject.WorldMatrix;
                        Vector3D.Transform(ref billboard.Position0, ref worldMatrix, out position0);
                        Vector3D.Transform(ref billboard.Position1, ref worldMatrix, out position1);
                        Vector3D.Transform(ref billboard.Position2, ref worldMatrix, out position2);

                        Vector3D.TransformNormal(ref billboard.Normal0, ref worldMatrix, out normal0);
                        Vector3D.TransformNormal(ref billboard.Normal1, ref worldMatrix, out normal1);
                        Vector3D.TransformNormal(ref billboard.Normal2, ref worldMatrix, out normal2);
                    }
                }
            }

            if (billboard.CustomViewProjection != -1)
            {
                var billboardViewProjection = MyRenderProxy.BillboardsViewProjectionRead[billboard.CustomViewProjection];

                position0 -= billboardViewProjection.CameraPosition;
                position1 -= billboardViewProjection.CameraPosition;
                position2 -= billboardViewProjection.CameraPosition;
            }
            else
            {
                position0 -= MyRenderCamera.Position;
                position1 -= MyRenderCamera.Position;
                position2 -= MyRenderCamera.Position;
            }

            billboard.Position0.AssertIsValid();
            billboard.Position1.AssertIsValid();
            billboard.Position2.AssertIsValid();
            billboard.Position3.AssertIsValid();

            m_vertices[startIndex + 0].Position = position0;
            m_vertices[startIndex + 0].Color = colorHalf;
            m_vertices[startIndex + 0].TexCoord = new HalfVector4(billboard.UV0.X, billboard.UV0.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            m_vertices[startIndex + 1].Position = position1;
            m_vertices[startIndex + 1].Color = colorHalf;
            m_vertices[startIndex + 1].TexCoord = new HalfVector4(billboard.UV1.X, billboard.UV1.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            m_vertices[startIndex + 2].Position = position2;
            m_vertices[startIndex + 2].Color = colorHalf;
            m_vertices[startIndex + 2].TexCoord = new HalfVector4(billboard.UV2.X, billboard.UV2.Y, billboard.BlendTextureRatio, materialProperties.Emissivity);

            m_vertices[startIndex + 3] = m_vertices[startIndex + 0];

            if (materialProperties.Reflectivity > 0)
            {
                m_vertices[startIndex + 0].TexCoord2 = new HalfVector4((float)normal0.X, (float)normal0.Y, (float)normal0.Z, billboard.Reflectivity);
                m_vertices[startIndex + 1].TexCoord2 = new HalfVector4((float)normal1.X, (float)normal1.Y, (float)normal1.Z, billboard.Reflectivity);
                m_vertices[startIndex + 2].TexCoord2 = new HalfVector4((float)normal2.X, (float)normal2.Y, (float)normal2.Z, billboard.Reflectivity);
                m_vertices[startIndex + 3].TexCoord2 = m_vertices[startIndex + 0].TexCoord2;
            }
            else if (billboard.BlendTextureRatio > 0)
            {
                MyTransparentMaterial blendMaterialProperties = MyTransparentMaterials.GetMaterial(billboard.BlendMaterial);
                m_vertices[startIndex + 0].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + billboard.UVOffset.Y, 0, 0);
                m_vertices[startIndex + 1].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + blendMaterialProperties.UVSize.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + billboard.UVOffset.Y, 0, 0);
                m_vertices[startIndex + 2].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + blendMaterialProperties.UVSize.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + blendMaterialProperties.UVSize.Y + billboard.UVOffset.Y, 0, 0);
                m_vertices[startIndex + 3].TexCoord2 = new HalfVector4(blendMaterialProperties.UVOffset.X + billboard.UVOffset.X, blendMaterialProperties.UVOffset.Y + blendMaterialProperties.UVSize.Y + billboard.UVOffset.Y, 0, 0);
            }

        }
예제 #60
0
 internal MyVertexFormatPositionPackedColor(HalfVector4 position, Byte4 color)
 {
     Position = position;
     Color    = color;
 }