Beispiel #1
0
        public void Generate(GraphicsDevice device, ContentManager content, Texture2D[] textures, float size = 250.0f)
        {
            if (textures.Length != 6)
            {
                throw new Exception("The array of texture names must contains 6 elements.");
            }

            if (SkyboxEffect == null)
            {
                SkyboxEffect = content.Load <Effect>("FX/SkyboxEffect");
            }

            _geometry.Size = new Vector3(size);
            _geometry.Build();

            _texture = new TextureCube(device, textures[0].Width, false, SurfaceFormat.Color);
            Color[] textureData;

            for (int i = 0; i < 6; i++)
            {
                textureData = new Color[textures[i].Width * textures[i].Height];
                textures[i].GetData <Color>(textureData);
                _texture.SetData <Color>((CubeMapFace)i, textureData);
            }

            Enabled = true;
        }
Beispiel #2
0
        public static void RenderFaces(GraphicsDevice device, TextureCube cubeMap, int resolution, SurfaceFormat format, int mipMapLevel, Action <Matrix> applyEffect)
        {
            using var faceRenderTarget = new RenderTarget2D(device, resolution, resolution, false, format, DepthFormat.None, 0, RenderTargetUsage.DiscardContents);
            using var cube             = new CubeMapCube(device);

            var data  = new HalfVector4[resolution * resolution];
            var faces = CubeMapFaces;

            for (var i = 0; i < faces.Count; i++)
            {
                var face       = faces[i];
                var view       = GetViewForFace(face);
                var projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1.0f, 0.1f, 1.5f);

                device.SetRenderTarget(faceRenderTarget);
                device.Clear(Color.CornflowerBlue);

                applyEffect(view * projection);

                device.SetVertexBuffer(cube.VertexBuffer, 0);
                device.Indices = cube.IndexBuffer;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, cube.Primitives);

                device.SetRenderTarget(null);

                faceRenderTarget.GetData(data);
                cubeMap.SetData(face, mipMapLevel, null, data, 0, data.Length);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a reflection textureCube
        /// </summary>
        static TextureCube GetReflectCube()
        {
            if (reflectCube != null)
            {
                return(reflectCube);
            }

            Color[] cc = new Color[]
            {
                new Color(1, 0, 0), new Color(0.9f, 0, 0.1f),
                new Color(0.8f, 0, 0.2f), new Color(0.7f, 0, 0.3f),
                new Color(0.6f, 0, 0.4f), new Color(0.5f, 0, 0.5f),
                new Color(0.4f, 0, 0.6f), new Color(0.3f, 0, 0.7f),
                new Color(0.2f, 0, 0.8f), new Color(0.1f, 0, 0.9f),
                new Color(0.1f, 0, 0.9f), new Color(0.0f, 0, 1.0f),
            };

            reflectCube = new TextureCube(ShipGameGame.GetInstance().GraphicsDevice,
                                          8, true, SurfaceFormat.Color);

            Random rand = new Random();

            for (int s = 0; s < 6; s++)
            {
                Color[] sideData = new Color[reflectCube.Size * reflectCube.Size];
                for (int i = 0; i < sideData.Length; i++)
                {
                    sideData[i] = cc[rand.Next(cc.Length)];
                }
                reflectCube.SetData((CubeMapFace)s, sideData);
            }

            return(reflectCube);
        }
Beispiel #4
0
        /// <summary>
        /// PX, NX, PY, NY, PZ, NZ
        /// </summary>
        /// <param name="textures"></param>
        /// <returns></returns>
        public static TextureCube CreateCubeMap(Texture2D[] textures)
        {
            if (textures.Length != 6)
            {
                throw new Exception($"Can't create the CubeMap, 6 textures required, {textures.Length} provided.");
            }

            var width       = textures[0].Width;
            var height      = textures[0].Height;
            var cubeMap     = new TextureCube(Application.GraphicsDevice, width, false, SurfaceFormat.Color);
            var textureData = new Color[width * height];

            for (var i = 0; i < 6; i++)
            {
                if (textures[i].Width != width || textures[i].Height != height)
                {
                    throw new Exception($"The size of the texture at index {i} have not the same size of the first texture. {width}x{height} required.");
                }

                textures[i].GetData <Color>(textureData);
                cubeMap.SetData <Color>((CubeMapFace)i, textureData);
            }

            return(cubeMap);
        }
Beispiel #5
0
        private void SetFaceData(TextureCube cube, CubeMapFace face, Texture2D data)
        {
            var colors = new Color[data.Width * data.Height];

            data.GetData(colors);
            cube.SetData(face, colors);
        }
Beispiel #6
0
        private TextureCube CreateTextureCube(MipMapChainCollection mipMapChainCollection)
        {
            ImageData   mip0     = mipMapChainCollection[0][0];
            int         cubeSize = mip0.Width;
            int         mipCount = mipMapChainCollection[0].Count;
            TextureCube tex      = new TextureCube(cubeSize, mipCount > 1, GetSurfaceFormat(mip0));

            foreach (MipMapChain mipChain in mipMapChainCollection)
            {
                mip0 = mipChain[0];

                //Not sure the order of our faces, so explicitly look at it and set by face. Not even sure if DevIL will give us all 6
                //if one is missing.
                EnvironmentMapFace face = mip0.CubeFace;
                bool        unknownFace = false;
                CubeMapFace cubeFace    = CubeMapFace.PositiveX;
                switch (face)
                {
                case EnvironmentMapFace.PositiveX:
                    cubeFace = CubeMapFace.PositiveX;
                    break;

                case EnvironmentMapFace.NegativeX:
                    cubeFace = CubeMapFace.NegativeX;
                    break;

                case EnvironmentMapFace.PositiveY:
                    cubeFace = CubeMapFace.PositiveY;
                    break;

                case EnvironmentMapFace.NegativeY:
                    cubeFace = CubeMapFace.NegativeY;
                    break;

                case EnvironmentMapFace.PositiveZ:
                    cubeFace = CubeMapFace.PositiveZ;
                    break;

                case EnvironmentMapFace.NegativeZ:
                    cubeFace = CubeMapFace.NegativeZ;
                    break;

                default:
                    unknownFace = true;
                    break;
                }

                if (!unknownFace)
                {
                    for (int i = 0; i < mipChain.Count; i++)
                    {
                        ImageData mip  = mipChain[i];
                        byte[]    data = (mip.HasCompressedData) ? mip.CompressedData : mip.Data;
                        tex.SetData <byte>(cubeFace, data, i, null, 0, data.Length);
                    }
                }
            }

            return(tex);
        }
Beispiel #7
0
        public override void LoadContent()
        {
            base.LoadContent();

            // To hacked for now
            if (!_environmentTextureLoaded && _environmentTextureNames != null)
            {
                // Detect the texture size if it doesn't specified
                if (_environmentTextureSize == 0)
                {
                    Texture2D firstTexture = YnG.Content.Load <Texture2D>(_environmentTextureNames[0]);
                    _environmentTextureSize = Math.Min(firstTexture.Width, firstTexture.Height);
                }

                // Create the environment texture
                _environmentTexture = new TextureCube(YnG.GraphicsDevice, _environmentTextureSize, _enableTextureMipmap, SurfaceFormat.Color);

                Texture2D texture = null;   // Temp texture
                Color[]   textureData;      // Temp textureData array
                string[]  tempTextureNames = new string[6];

                // If the texture array has not a size of 6, we replace empty texture by the latest
                int nbTextures = _environmentTextureNames.Length;

                for (int i = 0; i < 6; i++)
                {
                    if (i < nbTextures) // Texture
                    {
                        tempTextureNames[i] = _environmentTextureNames[i];
                    }
                    else // Copied texture
                    {
                        tempTextureNames[i] = _environmentTextureNames[nbTextures - 1];
                    }

                    // Load the texture and add it to the TextureCube
                    texture     = YnG.Content.Load <Texture2D>(tempTextureNames[i]);
                    textureData = new Color[texture.Width * texture.Height];
                    texture.GetData <Color>(textureData);
                    _environmentTexture.SetData <Color>((CubeMapFace)i, textureData);
                }

                // Update the texture names array
                _environmentTextureNames  = tempTextureNames;
                _environmentTextureLoaded = true;

                // If the first texture is null we create a dummy texture with the same size of environment texture
                if (_texture == null)
                {
                    _texture       = YnGraphics.CreateTexture(Color.White, _environmentTextureSize, _environmentTextureSize);
                    _textureLoaded = true;
                }
            }

            if (!_effectLoaded)
            {
                _effect       = new EnvironmentMapEffect(YnG.GraphicsDevice);
                _effectLoaded = true;
            }
        }
        ///<summary>
        ///    Copies a region from normal memory to a region of this pixelbuffer. The source
        ///    image can be in any pixel format supported by Axiom, and in any size.
        ///</summary>
        ///<param name="src">PixelBox containing the source pixels and format in memory</param>
        ///<param name="dstBox">Image.BasicBox describing the destination region in this buffer</param>
        ///<remarks>
        ///    The source and destination regions dimensions don't have to match, in which
        ///    case scaling is done. This scaling is generally done using a bilinear filter in hardware,
        ///    but it is faster to pass the source image in the right dimensions.
        ///    Only call this function when both buffers are unlocked.
        ///</remarks>
        public override void BlitFromMemory(PixelBox src, BasicBox dstBox)
        {
            var converted   = src;
            var bufGCHandle = new GCHandle();
            var bufSize     = 0;

            // Get src.Data as byte[]
            bufSize = PixelUtil.GetMemorySize(src.Width, src.Height, src.Depth, Format);
            var newBuffer = new byte[bufSize];

            //bufGCHandle = GCHandle.Alloc( newBuffer, GCHandleType.Pinned );
            //XnaHelper.Convert(XFG.SurfaceFormat) would never have returned SurfaceFormat.Unknown anyway...
            //if (XnaHelper.Convert(src.Format) != XFG.SurfaceFormat.Unknown)
            {
                converted = new PixelBox(src.Width, src.Height, src.Depth, Format, BufferBase.Wrap(newBuffer));
                PixelConverter.BulkPixelConversion(src, converted);
            }
            //else
            //{
            //    Memory.Copy(converted.Data, BufferBase.Wrap(newBuffer), bufSize);
            //}

            if (surface != null)
            {
                surface.SetData(mipLevel, XnaHelper.ToRectangle(dstBox), newBuffer, 0, bufSize);
            }
            else if (cube != null)
            {
                cube.SetData(face, mipLevel, XnaHelper.ToRectangle(dstBox), newBuffer, 0, bufSize);
            }
            else
            {
                throw new NotSupportedException("BlitFromMemory on Volume Textures not supported.");
            }

            // If we allocated a buffer for the temporary conversion, free it here
            if (bufGCHandle.IsAllocated)
            {
                bufGCHandle.Free();
            }

            if (doMipmapGen)
            {
                GenMipmaps();
            }
        }
Beispiel #9
0
        public static void SetCubeFaceTexture(this TextureCube cube, CubeMapFace face, Texture2D texture)
        {
            //if(texture.Width || cube.RenderSize != texture.Height) throw new ArgumentOutOfRangeException(nameof(texture.RenderBounds));

            uint[] imgData = new uint[texture.Width * texture.Height];

            texture.GetData(imgData);
            cube.SetData(face, imgData);
        }
        public Skybox(string[] skyboxTextures, ContentManager Content, GraphicsDevice g)
        {
            skyBox        = Content.Load <Model>("skybox/cube");
            skyBoxEffect  = Content.Load <Effect>("Skybox");
            skyBoxTexture = new TextureCube(g, 512, false, SurfaceFormat.Color);
            byte[] data = new byte[512 * 512 * 4];

            Texture2D tempTexture = Content.Load <Texture2D>(skyboxTextures[0]);

            tempTexture.GetData <byte>(data);
            skyBoxTexture.SetData <byte>(CubeMapFace.PositiveX, data);

            tempTexture = Content.Load <Texture2D>(skyboxTextures[1]);
            tempTexture.GetData <byte>(data);
            skyBoxTexture.SetData <byte>(CubeMapFace.NegativeX, data);

            tempTexture = Content.Load <Texture2D>(skyboxTextures[2]);
            tempTexture.GetData <byte>(data);
            skyBoxTexture.SetData <byte>(CubeMapFace.PositiveY, data);

            tempTexture = Content.Load <Texture2D>(skyboxTextures[3]);
            tempTexture.GetData <byte>(data);
            skyBoxTexture.SetData <byte>(CubeMapFace.NegativeY, data);

            tempTexture = Content.Load <Texture2D>(skyboxTextures[4]);
            tempTexture.GetData <byte>(data);
            skyBoxTexture.SetData <byte>(CubeMapFace.PositiveZ, data);

            tempTexture = Content.Load <Texture2D>(skyboxTextures[5]);
            tempTexture.GetData <byte>(data);
            skyBoxTexture.SetData <byte>(CubeMapFace.NegativeZ, data);
        }
        private void RenderCubeMap(GraphicsDevice Graphics, Vector3 Position)
        {
            List <Geometry3D> RenderTargetGeometries = SceneNode.GetAllGeometries(Position);

            for (int i = 0; i < CubeDirections.Length; i++)
            {
                Graphics.SetRenderTarget(RenderTarget);
                Graphics.DepthStencilState = DepthStencilState.Default;

                RenderCamera.GenerateLookAtViewMatrix(RenderCamera.Position, RenderCamera.Position + CubeDirections[i], CubeUpVectors[i]);

                Matrix CameraProjection = RenderCamera.ProjectionMatrix;
                Matrix CameraView       = RenderCamera.ViewMatrix;
                Graphics.Clear(Color.CornflowerBlue);

                for (int j = 0; j < RenderTargetGeometries.Count; j++)
                {
                    Geometry3D Geom   = RenderTargetGeometries[j];
                    Effect     Shader = Geom.Shader;

                    if (Geom.HasCull)
                    {
                        continue;
                    }

                    if (Shader.GetType() == typeof(BasicEffect))
                    {
                        BasicEffect CastShader = (BasicEffect)Shader;
                        CastShader.Projection = CameraProjection;
                        CastShader.View       = CameraView;
                        CastShader.World      = Matrix.CreateTranslation(Geom.Position);
                    }
                    else
                    {
                        Geom.Shader.Parameters["WorldViewProjection"].SetValue(CameraView * CameraProjection);
                    }

                    foreach (var pass in Shader.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        Graphics.SetVertexBuffer(Geom.VertexBuffer);
                        Graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, Geom.VertexBuffer.VertexCount / 3);
                    }
                }
                Graphics.SetRenderTarget(null);
                Color[] Data = new Color[RenderTarget.Width * RenderTarget.Height];
                RenderTarget.GetData(Data);

                CubeMap.SetData(CubeFaces[i], Data);
            }
            HasRendered = true;
        }
Beispiel #12
0
        public static TextureCube CreateCubeMap(Texture2D texture)
        {
            var cubeMap = new TextureCube(Application.GraphicsDevice, texture.Width, false, SurfaceFormat.Color);

            Color[] textureData = new Color[texture.Width * texture.Height];
            texture.GetData <Color>(textureData);

            for (int i = 0; i < 6; i++)
            {
                cubeMap.SetData <Color>((CubeMapFace)i, textureData);
            }

            return(cubeMap);
        }
        public Skybox(string[] textures, ContentManager content, GraphicsDevice g, int size)
        {
            cube   = content.Load <Model>("Cube");
            effect = content.Load <Effect>("Skybox");

            skyboxTexture = new TextureCube(g, size, false, SurfaceFormat.Color);
            byte[]    data = new byte[size * size * 4];
            Texture2D tempTexture;

            for (int i = 0; i < 6; i++)
            {
                tempTexture = content.Load <Texture2D>(textures[i]);
                tempTexture.GetData <byte>(data);
                skyboxTexture.SetData <byte>(faces[i], data);
            }
        }
Beispiel #14
0
        private TextureCube GenerateSkybox(Color color)
        {
            var skybox = new TextureCube(this.Device, 1, false, SurfaceFormat.Color);

            skybox.SetData(CubeMapFace.PositiveX, new Color[] { color });
            skybox.SetData(CubeMapFace.NegativeX, new Color[] { color });
            skybox.SetData(CubeMapFace.PositiveY, new Color[] { color });
            skybox.SetData(CubeMapFace.NegativeY, new Color[] { color });
            skybox.SetData(CubeMapFace.PositiveZ, new Color[] { color });
            skybox.SetData(CubeMapFace.NegativeZ, new Color[] { color });

            return(skybox);
        }
Beispiel #15
0
        public TextureCube BuildSkyBox(Color color)
        {
            var skybox = new TextureCube(this.Device, 1, false, SurfaceFormat.Color);

            skybox.SetData(CubeMapFace.PositiveX, new Color[] { Color.Black });
            skybox.SetData(CubeMapFace.NegativeX, new Color[] { Color.Black });
            skybox.SetData(CubeMapFace.PositiveY, new Color[] { Color.Black });
            skybox.SetData(CubeMapFace.NegativeY, new Color[] { Color.Black });
            skybox.SetData(CubeMapFace.PositiveZ, new Color[] { Color.Black });
            skybox.SetData(CubeMapFace.NegativeZ, new Color[] { Color.Black });

            return(skybox);
        }
Beispiel #16
0
        private static TextureCube LoadTextureCube(DDSImageInfo image, BinaryReader input, SurfaceFormat format)
        {
            DDSHeader header = image.Header;

            int width  = header.DwWidth;
            int height = header.DwHeight;
            int flags  = header.ImageFormat.DwFlags;

            bool compressedFormat = IsSet(flags, (int)DDSPixelFlags.FourCC);

            int[]       mipMapSizes = new int[header.DwMipMapCount];
            TextureCube tex         = new TextureCube(width, mipMapSizes.Length > 1, format);

            if (compressedFormat)
            {
                int num = 16;
                if (format == SurfaceFormat.DXT1)
                {
                    num = 8;
                }
                for (int face = 0; face < 6; face++)
                {
                    int mipLevel = 0;
                    while (mipLevel < header.DwMipMapCount)
                    {
                        byte[] data = input.ReadBytes(CalculateMipMapSize(true, width, height, num, mipLevel));
                        tex.SetData <byte>((CubeMapFace)face, data, mipLevel, null, 0, data.Length);

                        width  = System.Math.Max(width / 2, 1);
                        height = System.Math.Max(height / 2, 1);
                        mipLevel++;
                    }

                    width  = header.DwWidth;
                    height = header.DwHeight;
                }
            }
            return(tex);
        }
        public void ShouldSetAndGetData(int size)
        {
            var dataSize    = size * size;
            var textureCube = new TextureCube(gd, size, false, SurfaceFormat.Color);

            for (var i = 0; i < 6; i++)
            {
                var savedData = new Color[dataSize];
                for (var index = 0; index < dataSize; index++)
                {
                    savedData[index] = new Color(index + i, index + i, index + i);
                }
                textureCube.SetData((CubeMapFace)i, savedData);

                var readData = new Color[dataSize];
                textureCube.GetData((CubeMapFace)i, readData);

                Assert.AreEqual(savedData, readData);
            }

            textureCube.Dispose();
        }
Beispiel #18
0
        public void ShouldSetAndGetData(int size)
        {
            Game.DrawWith += (sender, e) =>
            {
                var dataSize = size * size;
                var textureCube = new TextureCube(Game.GraphicsDevice, size, false, SurfaceFormat.Color);

                for (var i = 0; i < 6; i++)
                {
                    var savedData = new Color[dataSize];
                    for (var index = 0; index < dataSize; index++)
                        savedData[index] = new Color(index + i, index + i, index + i);
                    textureCube.SetData((CubeMapFace) i, savedData);

                    var readData = new Color[dataSize];
                    textureCube.GetData((CubeMapFace) i, readData);

                    Assert.AreEqual(savedData, readData);
                }
            };
            Game.Run();
        }
Beispiel #19
0
        static TextureCube GetTextureCube(ref DDS_HEADER header, BinaryReader reader)
        {
            SurfaceFormat fmt;
            int           w, h;
            var           sfc = LoadSurface(ref header, reader, out fmt, out w, out h);
            var           tex = new TextureCube(w, sfc.Length > 1, fmt);

            //Positive X
            for (int i = 0; i < sfc.Length; i++)
            {
                tex.SetData(CubeMapFace.PositiveX, 0, null, sfc[i], 0, sfc[i].Length);
            }
            //Negative
            sfc = LoadSurface(ref header, reader, out fmt, out w, out h);
            for (int i = 0; i < sfc.Length; i++)
            {
                tex.SetData(CubeMapFace.NegativeX, 0, null, sfc[i], 0, sfc[i].Length);
            }
            //Positive Y
            sfc = LoadSurface(ref header, reader, out fmt, out w, out h);
            for (int i = 0; i < sfc.Length; i++)
            {
                tex.SetData(CubeMapFace.PositiveY, 0, null, sfc[i], 0, sfc[i].Length);
            }
            //Negative Y
            sfc = LoadSurface(ref header, reader, out fmt, out w, out h);
            for (int i = 0; i < sfc.Length; i++)
            {
                tex.SetData(CubeMapFace.NegativeY, 0, null, sfc[i], 0, sfc[i].Length);
            }
            //Positive Z
            sfc = LoadSurface(ref header, reader, out fmt, out w, out h);
            for (int i = 0; i < sfc.Length; i++)
            {
                tex.SetData(CubeMapFace.PositiveZ, 0, null, sfc[i], 0, sfc[i].Length);
            }
            //Negative Z
            sfc = LoadSurface(ref header, reader, out fmt, out w, out h);
            for (int i = 0; i < sfc.Length; i++)
            {
                tex.SetData(CubeMapFace.NegativeZ, 0, null, sfc[i], 0, sfc[i].Length);
            }
            return(tex);
        }
Beispiel #20
0
        public void ShouldSetAndGetData(int size)
        {
            Game.DrawWith += (sender, e) =>
            {
                var dataSize    = size * size;
                var textureCube = new TextureCube(Game.GraphicsDevice, size, false, SurfaceFormat.Color);

                for (var i = 0; i < 6; i++)
                {
                    var savedData = new Color[dataSize];
                    for (var index = 0; index < dataSize; index++)
                    {
                        savedData[index] = new Color(index + i, index + i, index + i);
                    }
                    textureCube.SetData((CubeMapFace)i, savedData);

                    var readData = new Color[dataSize];
                    textureCube.GetData((CubeMapFace)i, readData);

                    Assert.AreEqual(savedData, readData);
                }
            };
            Game.Run();
        }
Beispiel #21
0
 public static Material SkyboxFromImages(
     string imagePositiveX,
     string imageNegativeX,
     string imagePositiveY,
     string imageNegativeY,
     string imagePositiveZ,
     string imageNegativeZ)
 {
     var cache = Application.Current.ResourceCache;
     var material = new Material();
     TextureCube cube = new TextureCube();
     cube.SetData(CubeMapFace.PositiveX, cache.GetFile(imagePositiveX, false));
     cube.SetData(CubeMapFace.NegativeX, cache.GetFile(imageNegativeX, false));
     cube.SetData(CubeMapFace.PositiveY, cache.GetFile(imagePositiveY, false));
     cube.SetData(CubeMapFace.NegativeY, cache.GetFile(imageNegativeY, false));
     cube.SetData(CubeMapFace.PositiveZ, cache.GetFile(imagePositiveZ, false));
     cube.SetData(CubeMapFace.NegativeZ, cache.GetFile(imageNegativeZ, false));
     material.SetTexture(TextureUnit.Diffuse, cube);
     material.SetTechnique(0, CoreAssets.Techniques.DiffSkybox, 0, 0);
     material.CullMode = CullMode.None;
     return material;
 }
Beispiel #22
0
        /// <summary>
        ///
        /// Load every texture from content to textures list
        /// IMPORTANT!!! SET NAME FOR EVERY ELEMENT
        /// </summary>
        /// <param name="game"></param>
        public void LoadTextures()
        {
            // Adding "default" textures for all maps containing only one pixel in one color
            uint whiteColor = 0xFFFFFFFF;
            uint normColor  = 0xFFFF0F0F;
            uint blackColor = 0xFF000000;

            if (!Textures.ContainsKey("DefaultDiffuse"))
            {
                Texture2D defDiff = new Texture2D(TrashSoupGame.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                defDiff.SetData <uint>(new uint[] { blackColor });
                Textures.Add("DefaultDiffuse", defDiff);
            }
            if (!Textures.ContainsKey("DefaultDiffuseWhite"))
            {
                Texture2D defDiffW = new Texture2D(TrashSoupGame.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                defDiffW.SetData <uint>(new uint[] { whiteColor });
                Textures.Add("DefaultDiffuseWhite", defDiffW);
            }
            if (!Textures.ContainsKey("DefaultNormal"))
            {
                Texture2D defNrm = new Texture2D(TrashSoupGame.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                defNrm.SetData <uint>(new uint[] { normColor });
                Textures.Add("DefaultNormal", defNrm);
            }
            if (!TexturesCube.ContainsKey("DefaultCube"))
            {
                TextureCube defCbc = new TextureCube(TrashSoupGame.Instance.GraphicsDevice, 1, false, SurfaceFormat.Color);
                defCbc.SetData <uint>(CubeMapFace.NegativeX, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.PositiveX, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.NegativeY, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.PositiveY, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.NegativeZ, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.PositiveZ, new uint[] { blackColor });
                TexturesCube.Add("DefaultCube", defCbc);
            }
            ///////////////////////////////////////////
        }
Beispiel #23
0
        public static Material SkyboxFromImages(
            string imagePositiveX,
            string imageNegativeX,
            string imagePositiveY,
            string imageNegativeY,
            string imagePositiveZ,
            string imageNegativeZ)
        {
            var         cache    = Application.Current.ResourceCache;
            var         material = new Material();
            TextureCube cube     = new TextureCube();

            cube.SetData(CubeMapFace.PositiveX, cache.GetFile(imagePositiveX, false));
            cube.SetData(CubeMapFace.NegativeX, cache.GetFile(imageNegativeX, false));
            cube.SetData(CubeMapFace.PositiveY, cache.GetFile(imagePositiveY, false));
            cube.SetData(CubeMapFace.NegativeY, cache.GetFile(imageNegativeY, false));
            cube.SetData(CubeMapFace.PositiveZ, cache.GetFile(imagePositiveZ, false));
            cube.SetData(CubeMapFace.NegativeZ, cache.GetFile(imageNegativeZ, false));
            material.SetTexture(TextureUnit.Diffuse, cube);
            material.SetTechnique(0, CoreAssets.Techniques.DiffSkybox, 0, 0);
            material.CullMode = CullMode.None;
            return(material);
        }
Beispiel #24
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // UI
            MyraEnvironment.Game = this;
            _mainPanel           = new MainPanel();

            Desktop.Root = _mainPanel;

            // Nursia
            Nrs.Game = this;

            var folder = @"C:\Projects\Nursia\samples";

            // Model
            _model                  = LoadModel(Path.Combine(folder, @"models\knight.g3dj"));
            _model.Transform        = Matrix.CreateTranslation(new Vector3(0, 10, 0));
            _model.CurrentAnimation = _model.Animations["Attack"];

            // Terrain
            var grassy = LoadTexture(Path.Combine(folder, @"terrain\grassy2.png"));

            _scene.Terrain = new Terrain(400);

            // Generate height
            var generator = new HeightMapGenerator();

            GenerationConfig.Instance.WorldSize = (int)_scene.Terrain.Size;
            var heightMap = generator.Generate();

            _scene.Terrain.HeightFunc = (x, z) =>
            {
                if (x < 0)
                {
                    x = 0;
                }

                if (x >= heightMap.GetLength(0))
                {
                    x = heightMap.GetLength(0) - 1;
                }

                if (z < 0)
                {
                    z = 0;
                }

                if (z >= heightMap.GetLength(1))
                {
                    z = heightMap.GetLength(1) - 1;
                }

                var result = (heightMap[(int)x, (int)z] * 100) - 50;

                return(result);

/*				int r = (int)(x / 100) + (int)(z / 100);
 *
 *                              return r % 2 == 0 ? -10 : 10;*/
            };

            _scene.Terrain.SetTexture(grassy);

            // Water
            _scene.WaterTiles.Add(new WaterTile(0, 0, 0, _scene.Terrain.Size));

            // Skybox
            var skyboxFolder = Path.Combine(folder, "skybox");
            var texture      = new TextureCube(GraphicsDevice, 1024,
                                               false, SurfaceFormat.Color);

            byte[] data = null;
            LoadColors(Path.Combine(skyboxFolder, @"negX.png"), out data);
            texture.SetData(CubeMapFace.NegativeX, data);
            LoadColors(Path.Combine(skyboxFolder, @"negY.png"), out data);
            texture.SetData(CubeMapFace.NegativeY, data);
            LoadColors(Path.Combine(skyboxFolder, @"negZ.png"), out data);
            texture.SetData(CubeMapFace.NegativeZ, data);
            LoadColors(Path.Combine(skyboxFolder, @"posX.png"), out data);
            texture.SetData(CubeMapFace.PositiveX, data);
            LoadColors(Path.Combine(skyboxFolder, @"posY.png"), out data);
            texture.SetData(CubeMapFace.PositiveY, data);
            LoadColors(Path.Combine(skyboxFolder, @"posZ.png"), out data);
            texture.SetData(CubeMapFace.PositiveZ, data);

            _scene.Skybox = new Skybox(100)
            {
                Texture = texture
            };

            _scene.Lights.Add(new DirectLight
            {
                Color     = Color.White,
                Position  = new Vector3(10000, 10000, -10000),
                Direction = new Vector3(0, -1, 0)
            });

            _controller = new CameraInputController(_scene.Camera);
        }
Beispiel #25
0
        /// <summary>
        /// Creates a reflection textureCube
        /// </summary>
        static TextureCube GetReflectCube()
        {
            if (reflectCube != null)
                return reflectCube;

            Color[] cc = new Color[]
            {
                new Color(1,0,0), new Color(0.9f,0,0.1f),
                new Color(0.8f,0,0.2f), new Color(0.7f,0,0.3f),
                new Color(0.6f,0,0.4f), new Color(0.5f,0,0.5f),
                new Color(0.4f,0,0.6f), new Color(0.3f,0,0.7f),
                new Color(0.2f,0,0.8f), new Color(0.1f,0,0.9f),
                new Color(0.1f,0,0.9f), new Color(0.0f,0,1.0f),
            };

            reflectCube = new TextureCube(ShipGameGame.GetInstance().GraphicsDevice,
                8, true, SurfaceFormat.Color);

            Random rand = new Random();

            for (int s = 0; s < 6; s++)
            {
                Color[] sideData = new Color[reflectCube.Size * reflectCube.Size];
                for (int i = 0; i < sideData.Length; i++)
                {
                    sideData[i] = cc[rand.Next(cc.Length)];
                }
                reflectCube.SetData((CubeMapFace)s, sideData);
            }

            return reflectCube;
        }
Beispiel #26
0
        /// <summary>
        /// <para>Reads in a 2D texture in RGBM format, and extracts the cube faces.</para>
        /// <para>It also generates a Spherical Harmonic from the input, to approximate indirect lighting</para>
        /// </summary>
        public RgbmCubeMap(Texture2D sourceRgbmImage2D, Texture2D sourceRgbmAlphaImage2D, float maxRange)
        {
            //the two textures represent the RGB and M values of an RGBM texture. They have
            //been separated to make it easier to view their colour channels.
            //This is somewhat wasteful however. Normally it would be wise to combine them into one texture.

            if (sourceRgbmImage2D == null || sourceRgbmAlphaImage2D == null)
                throw new ArgumentNullException();
            if (sourceRgbmImage2D.Width != sourceRgbmImage2D.Height * 6 ||
                sourceRgbmAlphaImage2D.Width != sourceRgbmImage2D.Width ||
                sourceRgbmAlphaImage2D.Height != sourceRgbmImage2D.Height)
                throw new ArgumentException("Invalid size");	//expected to have 6 cube faces
            if (sourceRgbmImage2D.Format != SurfaceFormat.Color ||
                sourceRgbmAlphaImage2D.Format != SurfaceFormat.Color)
                throw new ArgumentException("Unexpected image format");

            if (maxRange <= 0.0f)
                throw new ArgumentException("MaxRange");

            this.MaxRange = maxRange;

            //extract the RGB pixels
            Color[] pixelDataRGB = new Color[sourceRgbmImage2D.Width * sourceRgbmImage2D.Height];
            sourceRgbmImage2D.GetData(pixelDataRGB);

            //extract the M pixels
            Color[] pixelDataM = new Color[sourceRgbmAlphaImage2D.Width * sourceRgbmAlphaImage2D.Height];
            sourceRgbmAlphaImage2D.GetData(pixelDataM);

            //at this point, the source textures are no longer needed

            //extract the faces from the cubemap,
            //and generate a spherical harmonic based off it's colours

            //width/height of each face of the cubemap
            int cubeFaceSize = sourceRgbmImage2D.Height;

            this.SphericalHarmonic = new Xen.Ex.SphericalHarmonicL2RGB();
            this.cubeMap = new TextureCube(sourceRgbmImage2D.GraphicsDevice, cubeFaceSize, false, SurfaceFormat.Color);

            int textureLineStride = sourceRgbmImage2D.Width;

            //storage for the decoded cubemap faces
            Vector3[][] cubeFaces = new Vector3[6][];

            //temporary storage of a single face of the cube
            Color[] singleFaceRGBM = new Color[cubeFaceSize * cubeFaceSize];

            //extract the 6 faces of the cubemap.
            for (int face = 0; face < 6; face++)
            {
                CubeMapFace faceId = (CubeMapFace)face;

                //cube face data
                Vector3[] singleFaceRGB = new Vector3[cubeFaceSize * cubeFaceSize];
                cubeFaces[face] = singleFaceRGB;

                //each face is stored next to each other in the 2D texture
                int startPixel = cubeFaceSize * face;

                //copy the face from the 2D texture data into singleFace

                int writeIndex = 0;
                int readIndex = startPixel;

                for (int y = 0; y < cubeFaceSize; y++) // each hoizontal line
                {
                    for (int x = 0; x < cubeFaceSize; x++) // each pixel in the line
                    {
                        Color encodedRgb = pixelDataRGB[readIndex + x];
                        Color encodedM = pixelDataM[readIndex + x];

                        //combine to get the RGBM value
                        Color rgbm = new Color(encodedRgb.R, encodedRgb.G, encodedRgb.B, encodedM.R);

                        //decode the pixel
                        Vector3 rgb = RgbmTools.DecodeRGBM(rgbm, maxRange);

                        //convert to linear
                        rgb = rgb * rgb;

                        //store
                        singleFaceRGB[writeIndex + x] = rgb;
                        singleFaceRGBM[writeIndex + x] = rgbm;
                    }

                    //jump to the next line
                    readIndex += textureLineStride;
                    writeIndex += cubeFaceSize;
                }

                //write the pixels into the cubemap
                cubeMap.SetData(faceId, singleFaceRGBM);
            }

            //Generate the SH from the cubemap faces
            this.SphericalHarmonic = Xen.Ex.SphericalHarmonicL2RGB.GenerateSphericalHarmonicFromCubeMap(cubeFaces);
        }
Beispiel #27
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // UI
            MyraEnvironment.Game = this;
            _mainForm            = new MainForm();

            _propertyGrid = new PropertyGrid();
            _mainForm._panelProperties.Widgets.Add(_propertyGrid);

            _mainForm._listExplorer.SelectedIndexChanged += _listExplorer_SelectedIndexChanged;

            _desktop = new Desktop();
            _desktop.Widgets.Add(_mainForm);

            // Nursia
            Nrs.Game = this;

            var folder = @"D:\Projects\Nursia\samples";

            // Light
            _scene.Lights.Add(new DirectLight
            {
                Color     = Color.White,
                Position  = new Vector3(10000, 10000, -10000),
                Direction = new Vector3(0, -1, 0)
            });

            // Water
            _scene.WaterTiles.Add(new WaterTile(0, 0, 0, 100));

            // Skybox
            var skyboxFolder = Path.Combine(folder, "skybox");
            var texture      = new TextureCube(GraphicsDevice, 1024,
                                               false, SurfaceFormat.Color);

            Color[] data = null;
            LoadColors(Path.Combine(skyboxFolder, @"negX.png"), ref data);
            texture.SetData(CubeMapFace.NegativeX, data);
            LoadColors(Path.Combine(skyboxFolder, @"negY.png"), ref data);
            texture.SetData(CubeMapFace.NegativeY, data);
            LoadColors(Path.Combine(skyboxFolder, @"negZ.png"), ref data);
            texture.SetData(CubeMapFace.NegativeZ, data);
            LoadColors(Path.Combine(skyboxFolder, @"posX.png"), ref data);
            texture.SetData(CubeMapFace.PositiveX, data);
            LoadColors(Path.Combine(skyboxFolder, @"posY.png"), ref data);
            texture.SetData(CubeMapFace.PositiveY, data);
            LoadColors(Path.Combine(skyboxFolder, @"posZ.png"), ref data);
            texture.SetData(CubeMapFace.PositiveZ, data);

            _scene.Skybox = new Skybox(500)
            {
                Texture = texture
            };

            // Set camera
            _scene.Camera.SetLookAt(new Vector3(10, 10, 10), Vector3.Zero);

            _controller = new CameraInputController(_scene.Camera);

            RefreshExplorer();
        }
Beispiel #28
0
        public void Draw(Matrix projection, Vector3 cameraTarget, Vector3 cameraPosition, float rotation, GraphicsDeviceManager graphics, GraphicsDevice graphicsDevice)
        {
            if (frame > 240)
            {
                frame = 0;
            }

            if ((drawcount + 59) % 60 == 0)
            {
                tc = new TextureCube(graphicsDevice, 1024, false, SurfaceFormat.Color);
                tc.SetData <byte>(CubeMapFace.PositiveX, getface("0", graphicsDevice, frame));
                drawcount++;
            }


            if ((drawcount + 10) % 60 == 0)
            {
                tc.SetData <byte>(CubeMapFace.NegativeZ, getface("90", graphicsDevice, frame));
            }


            if ((drawcount + 20) % 60 == 0)
            {
                tc.SetData <byte>(CubeMapFace.NegativeX, getface("180", graphicsDevice, frame));
            }

            if ((drawcount + 30) % 60 == 0)
            {
                tc.SetData <byte>(CubeMapFace.PositiveZ, getface("270", graphicsDevice, frame));
            }

            if ((drawcount + 40) % 60 == 0)
            {
                tc.SetData <byte>(CubeMapFace.PositiveY, getface("up", graphicsDevice, frame));
            }


            if ((drawcount - 50) % 60 == 0)
            {
                skyBoxTexture = tc;
                frame++;
            }


            skyBoxEffect.Parameters["SkyBoxTexture"].SetValue(skyBoxTexture);
            //drawcount++;



            RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState;
            RasterizerState rasterizerState         = new RasterizerState();

            rasterizerState.CullMode = CullMode.None;
            graphics.GraphicsDevice.RasterizerState = rasterizerState;

            Matrix view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.UnitY);


            foreach (EffectPass pass in skyBoxEffect.CurrentTechnique.Passes)
            {
                pass.Apply();


                foreach (ModelMesh mesh in skyBox.Meshes)
                {
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        part.Effect = skyBoxEffect;
                        part.Effect.Parameters["World"].SetValue(
                            Matrix.CreateScale(size) * Matrix.CreateTranslation(new Vector3(cameraPosition.X, cameraPosition.Y, cameraPosition.Z)) * Matrix.CreateRotationY(rotation));
                        part.Effect.Parameters["View"].SetValue(view);
                        part.Effect.Parameters["Projection"].SetValue(projection);

                        //part.Effect.Parameters["frame"].SetValue( float(.2f));
                        //    cameraPosition.Y = 1800 - 50;
                        part.Effect.Parameters["CameraPosition"].SetValue(cameraPosition);
                    }


                    mesh.Draw();
                }
            }

            graphics.GraphicsDevice.RasterizerState = originalRasterizerState;
        }
Beispiel #29
0
        /// <summary>
        /// <para>Reads in a 2D texture in RGBM format, and extracts the cube faces.</para>
        /// <para>It also generates a Spherical Harmonic from the input, to approximate indirect lighting</para>
        /// </summary>
        public RgbmCubeMap(Texture2D sourceRgbmImage2D, Texture2D sourceRgbmAlphaImage2D, float maxRange)
        {
            //the two textures represent the RGB and M values of an RGBM texture. They have
            //been separated to make it easier to view their colour channels.
            //This is somewhat wasteful however. Normally it would be wise to combine them into one texture.

            if (sourceRgbmImage2D == null || sourceRgbmAlphaImage2D == null)
            {
                throw new ArgumentNullException();
            }
            if (sourceRgbmImage2D.Width != sourceRgbmImage2D.Height * 6 ||
                sourceRgbmAlphaImage2D.Width != sourceRgbmImage2D.Width ||
                sourceRgbmAlphaImage2D.Height != sourceRgbmImage2D.Height)
            {
                throw new ArgumentException("Invalid size");                    //expected to have 6 cube faces
            }
            if (sourceRgbmImage2D.Format != SurfaceFormat.Color ||
                sourceRgbmAlphaImage2D.Format != SurfaceFormat.Color)
            {
                throw new ArgumentException("Unexpected image format");
            }

            if (maxRange <= 0.0f)
            {
                throw new ArgumentException("MaxRange");
            }

            this.MaxRange = maxRange;

            //extract the RGB pixels
            Color[] pixelDataRGB = new Color[sourceRgbmImage2D.Width * sourceRgbmImage2D.Height];
            sourceRgbmImage2D.GetData(pixelDataRGB);

            //extract the M pixels
            Color[] pixelDataM = new Color[sourceRgbmAlphaImage2D.Width * sourceRgbmAlphaImage2D.Height];
            sourceRgbmAlphaImage2D.GetData(pixelDataM);

            //at this point, the source textures are no longer needed


            //extract the faces from the cubemap,
            //and generate a spherical harmonic based off it's colours

            //width/height of each face of the cubemap
            int cubeFaceSize = sourceRgbmImage2D.Height;

            this.SphericalHarmonic = new Xen.Ex.SphericalHarmonicL2RGB();
            this.cubeMap           = new TextureCube(sourceRgbmImage2D.GraphicsDevice, cubeFaceSize, 1, TextureUsage.None, SurfaceFormat.Color);

            int textureLineStride = sourceRgbmImage2D.Width;

            //storage for the decoded cubemap faces
            Vector3[][] cubeFaces = new Vector3[6][];

            //temporary storage of a single face of the cube
            Color[] singleFaceRGBM = new Color[cubeFaceSize * cubeFaceSize];

            //extract the 6 faces of the cubemap.
            for (int face = 0; face < 6; face++)
            {
                CubeMapFace faceId = (CubeMapFace)face;

                //cube face data
                Vector3[] singleFaceRGB = new Vector3[cubeFaceSize * cubeFaceSize];
                cubeFaces[face] = singleFaceRGB;

                //each face is stored next to each other in the 2D texture
                int startPixel = cubeFaceSize * face;

                //copy the face from the 2D texture data into singleFace

                int writeIndex = 0;
                int readIndex  = startPixel;

                for (int y = 0; y < cubeFaceSize; y++)                 // each hoizontal line
                {
                    for (int x = 0; x < cubeFaceSize; x++)             // each pixel in the line
                    {
                        Color encodedRgb = pixelDataRGB[readIndex + x];
                        Color encodedM   = pixelDataM[readIndex + x];

                        //combine to get the RGBM value
                        Color rgbm = new Color(encodedRgb.R, encodedRgb.G, encodedRgb.B, encodedM.R);

                        //decode the pixel
                        Vector3 rgb = RgbmTools.DecodeRGBM(rgbm, maxRange);

                        //convert to linear
                        rgb = rgb * rgb;

                        //store
                        singleFaceRGB[writeIndex + x]  = rgb;
                        singleFaceRGBM[writeIndex + x] = rgbm;
                    }

                    //jump to the next line
                    readIndex  += textureLineStride;
                    writeIndex += cubeFaceSize;
                }

                //write the pixels into the cubemap
                cubeMap.SetData(faceId, singleFaceRGBM);
            }

            //Generate the SH from the cubemap faces
            this.SphericalHarmonic = Xen.Ex.SphericalHarmonicL2RGB.GenerateSphericalHarmonicFromCubeMap(cubeFaces);
        }
        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.MoveToContent();
            reader.ReadStartElement();

            Name     = reader.ReadElementString("Name", "");
            MyEffect = ResourceManager.Instance.LoadEffect(reader.ReadElementString("EffectPath", ""));

            uint      normColor  = 0xFFFF0F0F;
            uint      blackColor = 0xFF000000;
            Texture2D defDiff    = null;

            if (!ResourceManager.Instance.Textures.TryGetValue("DefaultDiffuse", out defDiff))
            {
                defDiff = new Texture2D(TrashSoupGame.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                defDiff.SetData <uint>(new uint[] { blackColor });
                ResourceManager.Instance.Textures.Add("DefaultDiffuse", defDiff);
            }
            Texture2D defNrm = null;

            if (!ResourceManager.Instance.Textures.TryGetValue("DefaultNormal", out defNrm))
            {
                defNrm = new Texture2D(TrashSoupGame.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                defNrm.SetData <uint>(new uint[] { normColor });
                ResourceManager.Instance.Textures.Add("DefaultNormal", defNrm);
            }
            TextureCube defCbc = null;

            if (!ResourceManager.Instance.TexturesCube.TryGetValue("DefaultCube", out defCbc))
            {
                defCbc = new TextureCube(TrashSoupGame.Instance.GraphicsDevice, 1, false, SurfaceFormat.Color);
                defCbc.SetData <uint>(CubeMapFace.NegativeX, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.PositiveX, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.NegativeY, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.PositiveY, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.NegativeZ, new uint[] { blackColor });
                defCbc.SetData <uint>(CubeMapFace.PositiveZ, new uint[] { blackColor });
                ResourceManager.Instance.TexturesCube.Add("DefaultCube", defCbc);
            }

            DiffuseMap = ResourceManager.Instance.LoadTexture(reader.ReadElementString("DiffusePath", ""));
            if (reader.Name == "NormalPath")
            {
                NormalMap = ResourceManager.Instance.LoadTexture(reader.ReadElementString("NormalPath", ""));
            }
            if (reader.Name == "CubePath")
            {
                CubeMap = ResourceManager.Instance.LoadTextureCube(reader.ReadElementString("CubePath", ""));
            }

            reader.ReadStartElement("DiffuseColor");
            DiffuseColor = new Vector3(reader.ReadElementContentAsFloat("X", ""),
                                       reader.ReadElementContentAsFloat("Y", ""),
                                       reader.ReadElementContentAsFloat("Z", ""));
            reader.ReadEndElement();

            reader.ReadStartElement("SpecularColor");
            SpecularColor = new Vector3(reader.ReadElementContentAsFloat("X", ""),
                                        reader.ReadElementContentAsFloat("Y", ""),
                                        reader.ReadElementContentAsFloat("Z", ""));
            reader.ReadEndElement();

            Glossiness = reader.ReadElementContentAsFloat("Glossiness", "");

            reader.ReadStartElement("ReflectivityColor");
            ReflectivityColor = new Vector3(reader.ReadElementContentAsFloat("X", ""),
                                            reader.ReadElementContentAsFloat("Y", ""),
                                            reader.ReadElementContentAsFloat("Z", ""));
            reader.ReadEndElement();

            ReflectivityBias = reader.ReadElementContentAsFloat("ReflectivityBias", "");
            Transparency     = reader.ReadElementContentAsFloat("Transparency", "");
            PerPixelLighting = reader.ReadElementContentAsBoolean("PerPixelLighting", "");
            RecieveShadows   = reader.ReadElementContentAsBoolean("ReceiveShadows", "");
            Unlit            = reader.ReadElementContentAsBoolean("Unlit", "");

            AssignParamsInitialize();

            if (this.GetType() == typeof(Material))
            {
                reader.ReadEndElement();
            }
        }
Beispiel #31
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                {
                    content = new ContentManager(ScreenManager.Game.Services, "Content");
                }

                topViewport    = ScreenManager.GraphicsDevice.Viewport;
                bottomViewport = ScreenManager.GraphicsDevice.Viewport;

                if (ScreenManager.ScreenHorizontal == true)
                {
                    topViewport.Height    = topViewport.Height / 2;
                    bottomViewport.Height = bottomViewport.Height / 2;
                    bottomViewport.Y      = topViewport.Height;

                    camera.AspectRatio = (float)ScreenManager.GraphicsDevice.Viewport.Width /
                                         (ScreenManager.GraphicsDevice.Viewport.Height / 2);
                    camera2.AspectRatio = (float)ScreenManager.GraphicsDevice.Viewport.Width /
                                          (ScreenManager.GraphicsDevice.Viewport.Height / 2);

                    camera.FieldOfView  = MathHelper.ToRadians(45);
                    camera2.FieldOfView = MathHelper.ToRadians(45);
                }
                else
                {
                    topViewport.Width    = topViewport.Width / 2;
                    bottomViewport.Width = bottomViewport.Width / 2;
                    bottomViewport.X     = topViewport.Width;

                    camera.AspectRatio = (float)(ScreenManager.GraphicsDevice.Viewport.Width / 2) /
                                         ScreenManager.GraphicsDevice.Viewport.Height;
                    camera2.AspectRatio = (float)(ScreenManager.GraphicsDevice.Viewport.Width / 2) /
                                          ScreenManager.GraphicsDevice.Viewport.Height;

                    camera.FieldOfView  = MathHelper.ToRadians(60);
                    camera2.FieldOfView = MathHelper.ToRadians(60);
                }

                gameFont    = content.Load <SpriteFont>("gamefont");
                rockModel   = content.Load <Model>("Rock");
                shipModel   = content.Load <Model>("SpaceShip1");
                shipModel2  = content.Load <Model>("SpaceShip2");
                groundModel = content.Load <Model>("Ground");
                cubeModel   = content.Load <Model>("cube");
                bulletModel = content.Load <Model>("Cone");
                skyBoxModel = content.Load <Model>("Space_SkyBox");
                audioEngine = ScreenManager.AudioEngine;
                soundBank   = ScreenManager.SoundBank;
                waveBank    = ScreenManager.WaveBank;
                acSFX       = audioEngine.GetCategory("SFX");
                acMusic     = audioEngine.GetCategory("Music");

                // Environmental Map Effect for Player 1
                envEffect1            = new EnvironmentMapEffect(ScreenManager.GraphicsDevice);
                envEffect1.Projection = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f);
                envEffect1.View = Matrix.CreateLookAt(
                    new Vector3(2, 3, 32), Vector3.Zero, Vector3.Up);
                textureCube1 = new TextureCube(ScreenManager.GraphicsDevice, 256, false, SurfaceFormat.Color);
                Color[] facedata1 = new Color[256 * 256];
                for (int i = 0; i < 6; i++)
                {
                    envEffect1.Texture = content.Load <Texture2D>("skybox" + i.ToString());
                    envEffect1.Texture.GetData <Color>(facedata1);
                    textureCube1.SetData <Color>((CubeMapFace)i, facedata1);
                }
                envEffect1.Texture        = (shipModel.Meshes[0].Effects[0] as EnvironmentMapEffect).Texture;
                envEffect1.EnvironmentMap = textureCube1;
                envEffect1.EnableDefaultLighting();
                envEffect1.EnvironmentMapAmount   = 1.0f;
                envEffect1.FresnelFactor          = 1.0f;
                envEffect1.EnvironmentMapSpecular = Vector3.Zero;

                // Environmental Map Effect for Player 2
                envEffect2            = new EnvironmentMapEffect(ScreenManager.GraphicsDevice);
                envEffect2.Projection = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f);
                envEffect2.View = Matrix.CreateLookAt(
                    new Vector3(2, 3, 32), Vector3.Zero, Vector3.Up);
                textureCube2 = new TextureCube(ScreenManager.GraphicsDevice, 256, false, SurfaceFormat.Color);
                Color[] facedata2 = new Color[256 * 256];
                for (int i = 0; i < 6; i++)
                {
                    envEffect2.Texture = content.Load <Texture2D>("skybox" + i.ToString());
                    envEffect2.Texture.GetData <Color>(facedata2);
                    textureCube2.SetData <Color>((CubeMapFace)i, facedata2);
                }
                envEffect2.Texture        = (shipModel2.Meshes[0].Effects[0] as EnvironmentMapEffect).Texture;
                envEffect2.EnvironmentMap = textureCube2;
                envEffect2.EnableDefaultLighting();
                envEffect2.EnvironmentMapAmount   = 1.0f;
                envEffect2.FresnelFactor          = 1.0f;
                envEffect2.EnvironmentMapSpecular = Vector3.Zero;

                //audioEngine = ScreenManager.AudioEngine;
                //soundBank = ScreenManager.SoundBank;
                //waveBank = ScreenManager.WaveBank;

                if (ScreenManager.AudioEnabled == true)
                {
                    acSFX.SetVolume(ScreenManager.SFXVolume);
                    acMusic.SetVolume(ScreenManager.AudioVolume);
                }
                else
                {
                    acSFX.SetVolume(0);
                    acMusic.SetVolume(0);
                }

                FxCue = soundBank.GetCue("ShotFx");
                //FxCue.Apply3D(shipListen1, shipEmit1);

                ship1Pos = new Vector3(10000, 350, 10000);
                ship2Pos = new Vector3(100, 350, 100);

                // Create shiplllllllllllllllllllllllllllll
                ship  = new Ship(ScreenManager.GraphicsDevice, ship1Pos, soundBank);
                ship2 = new Ship(ScreenManager.GraphicsDevice, ship2Pos, soundBank);
                //ship2.Position = new Vector3(100, 100, 100);

                RandomRockSpawner();

                UpdateCameraChaseTarget(ship, camera);
                UpdateCameraChaseTarget(ship2, camera2);

                camera.Reset();
                camera2.Reset();

                // A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                Thread.Sleep(1000);

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
                ScreenManager.Game.ResetElapsedTime();
            }

#if WINDOWS_PHONE
            if (Microsoft.Phone.Shell.PhoneApplicationService.Current.State.ContainsKey("PlayerPosition"))
            {
                playerPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["PlayerPosition"];
                enemyPosition  = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["EnemyPosition"];
            }
#endif
        }
        public int BuildCubeMap(int Size, string Name, int PositiveXID, int PositiveYID, int PositiveZID, int NegativeXID, int NegativeYID, int NegativeZID, RSURFACEFORMAT Format)
        {
            Texture2D posX = ((Texture2D)_instance._textureList[PositiveXID]);
            Texture2D posY = ((Texture2D)_instance._textureList[PositiveYID]);
            Texture2D posZ = ((Texture2D)_instance._textureList[NegativeZID]);
            Texture2D negX = ((Texture2D)_instance._textureList[NegativeXID]);
            Texture2D negY = ((Texture2D)_instance._textureList[NegativeYID]);
            Texture2D negZ = ((Texture2D)_instance._textureList[PositiveZID]);

            TextureCube cube = new TextureCube(REngine.Instance._graphics.GraphicsDevice, Size, true, (SurfaceFormat)Format);
            Color[] data0 = new Color[(Size * Size) * 1];
            Color[] data1 = new Color[(Size * Size) * 1];
            Color[] data2 = new Color[(Size * Size) * 1];
            Color[] data3 = new Color[(Size * Size) * 1];
            Color[] data4 = new Color[(Size * Size) * 1];
            Color[] data5 = new Color[(Size * Size) * 1];
            negX.GetData<Color>(data0);
            cube.SetData<Color>(CubeMapFace.NegativeX, data0);
            negY.GetData<Color>(data1);
            cube.SetData<Color>(CubeMapFace.NegativeY, data1);
            negZ.GetData<Color>(data2);
            cube.SetData<Color>(CubeMapFace.NegativeZ, data2);
            posX.GetData<Color>(data3);
            cube.SetData<Color>(CubeMapFace.PositiveX, data3);
            posY.GetData<Color>(data4);
            cube.SetData<Color>(CubeMapFace.PositiveY, data4);
            posZ.GetData<Color>(data5);
            cube.SetData<Color>(CubeMapFace.PositiveZ, data5);

            _instance._textureList.Add(cube);
            int index = _instance._textureList.LastIndexOf(cube);
            _instance._textureTable.Add(Name, index);
            return index;
        }
Beispiel #33
0
        //loads the data from a stream in to a texture object.
        private static void InternalDDSFromStream(Stream stream, GraphicsDevice device, int streamOffset, bool loadMipMap, out Texture texture)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream), "Can't read from a null stream");
            }

            using (BinaryReader reader = new BinaryReader(stream))
            {
                if (streamOffset > reader.BaseStream.Length)
                {
                    throw new Exception("The stream you offered is smaller then the offset you are proposing for it.");
                }

                reader.BaseStream.Seek(streamOffset, SeekOrigin.Begin);

                //First element of a dds file is a "magic-number" a system to identify that the file is a dds if translated as asci chars the first 4 charachters should be 'DDS '
                if (!(reader.ReadUInt32() == DDS_MAGIC))
                {
                    throw new InvalidDataException("Can't open non DDS data.");
                }

                reader.BaseStream.Position += 8;

                //size in pixels for the texture.
                int height = reader.ReadInt32();
                int width  = reader.ReadInt32();

                reader.BaseStream.Position += 4;

                //depth
                int depth = reader.ReadInt32();

                //number of mip-maps.
                int numMips = reader.ReadInt32();

                reader.BaseStream.Position += 4 * 12;

                //pixel format flags
                uint pixelFlags = reader.ReadUInt32();

                // (FOURCC code)
                uint pixelFourCC = reader.ReadUInt32();

                //color bit depth
                int rgbBitCount = reader.ReadInt32();

                //mask for red.
                uint rBitMask = reader.ReadUInt32();

                //mask for green.
                uint gBitMask = reader.ReadUInt32();

                //mask for blue.
                uint bBitMask = reader.ReadUInt32();


                //mask for alpha.
                uint aBitMask = reader.ReadUInt32();

                //reader.BaseStream.Position += 16;

                //texture + mip-map flags.
                int ddsCaps1 = reader.ReadInt32();

                //extra info flags.
                int ddsCaps2 = reader.ReadInt32();
                //ddsCaps3
                //reader.ReadInt32();
                //ddsCaps4
                //reader.ReadInt32();

                //reader.ReadInt32();

                reader.BaseStream.Position += 12;

                bool isCubeMap       = IsCubemapTest(ddsCaps1, ddsCaps2);
                bool isVolumeTexture = IsVolumeTextureTest(ddsCaps2);

                FourCC compressionFormat = GetCompressionFormat(pixelFlags, pixelFourCC);

                if (compressionFormat == FourCC.DX10)
                {
                    throw new NotImplementedException("The Dxt 10 header reader is not implemented");
                }

                LoadSurfaceFormat loadSurfaceFormat = GetLoadSurfaceFormat(pixelFlags, pixelFourCC, rgbBitCount, rBitMask, gBitMask, bBitMask, aBitMask);

                bool isCompressed  = IsCompressedTest(pixelFlags);
                bool hasMipMaps    = CheckFullMipChain(width, height, numMips);
                bool hasAnyMipmaps = numMips > 0;
                hasMipMaps &= loadMipMap;

                if (isCubeMap)
                {
                    TextureCube tex = GenerateNewCubeTexture(loadSurfaceFormat, compressionFormat, device, width, pixelFlags, rgbBitCount);

                    int byteAcumulator = 0;

                    if (numMips == 0)
                    {
                        numMips = 1;
                    }

                    if (!hasMipMaps)
                    {
                        for (int j = 0; j < numMips; j++)
                        {
                            byteAcumulator += MipMapSizeInBytes(j, width, height, isCompressed, compressionFormat, rgbBitCount);
                        }
                    }

                    for (int j = 0; j < numMips; j++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps(streamOffset, j, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        if (hasMipMaps)
                        {
                            byteAcumulator += numBytes;
                        }

                        if (j == 0 || hasMipMaps)
                        {
                            tex.SetData(CubeMapFace.PositiveX, j, null, localMipData, 0, numBytes);
                        }
                        else
                        {
                            break;
                        }
                    }

                    for (int j = 0; j < numMips; j++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps(byteAcumulator + streamOffset, j, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        if (j == 0 || hasMipMaps)
                        {
                            tex.SetData(CubeMapFace.NegativeX, j, null, localMipData, 0, numBytes);
                        }
                        else
                        {
                            break;
                        }
                    }

                    for (int j = 0; j < numMips; j++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps((byteAcumulator * 2) + streamOffset, j, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        if (j == 0 || hasMipMaps)
                        {
                            tex.SetData(CubeMapFace.PositiveY, j, null, localMipData, 0, numBytes);
                        }
                        else
                        {
                            break;
                        }
                    }

                    for (int j = 0; j < numMips; j++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps((byteAcumulator * 3) + streamOffset, j, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        if (j == 0 || hasMipMaps)
                        {
                            tex.SetData(CubeMapFace.NegativeY, j, null, localMipData, 0, numBytes);
                        }
                        else
                        {
                            break;
                        }
                    }

                    for (int j = 0; j < numMips; j++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps((byteAcumulator * 4) + streamOffset, j, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        if (j == 0 || hasMipMaps)
                        {
                            tex.SetData(CubeMapFace.PositiveZ, j, null, localMipData, 0, numBytes);
                        }
                        else
                        {
                            break;
                        }
                    }

                    for (int j = 0; j < numMips; j++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps((byteAcumulator * 5) + streamOffset, j, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        if (j == 0 || hasMipMaps)
                        {
                            tex.SetData(CubeMapFace.NegativeZ, j, null, localMipData, 0, numBytes);
                        }
                        else
                        {
                            break;
                        }
                    }

                    texture = tex;
                }
                else if (isVolumeTexture)
                {
                    Texture3D tex = GenerateNewTexture3D(loadSurfaceFormat, compressionFormat, device, width, height, depth, hasMipMaps, pixelFlags, rgbBitCount);

                    int localStreamOffset = streamOffset;
                    for (int i = 0; i < tex.LevelCount; i++)
                    {
                        int localWidth  = MipMapSize(i, width);
                        int localHeight = MipMapSize(i, height);
                        int localDepth  = MipMapSize(i, depth);
                        for (int j = 0; j < localDepth; j++)
                        {
                            byte[] localMipData = mipData;
                            GetMipMaps(localStreamOffset, 0, localWidth, localHeight, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                            localStreamOffset += numBytes;
                            mipData            = localMipData;

                            tex.SetData(i, 0, 0, localWidth, localHeight, j, j + 1, localMipData, 0, numBytes);
                        }
                    }

                    texture = tex;
                }
                else
                {
                    Texture2D tex = GenerateNewTexture2D(loadSurfaceFormat, compressionFormat, device, width, height, hasMipMaps, pixelFlags, rgbBitCount);

                    for (int i = 0; i < tex.LevelCount; i++)
                    {
                        byte[] localMipData = mipData;
                        GetMipMaps(streamOffset, i, width, height, isCompressed, compressionFormat, rgbBitCount, reader, loadSurfaceFormat, ref localMipData, out int numBytes);
                        mipData = localMipData;

                        tex.SetData(i, null, localMipData, 0, numBytes);
                    }

                    texture = tex;
                }
            }
        }
Beispiel #34
0
 /// <summary>
 /// Loads a texture from Content and asign it to the cubemaps face.
 /// </summary>
 /// <param name="cubeMap"></param>
 /// <param name="filepath"></param>
 /// <param name="face"></param>
 private void LoadCubemapFace(TextureCube cubeMap, string filepath, CubeMapFace face)
 {
     Texture2D texture = content.Load<Texture2D>(filepath);
     byte[] data = new byte[texture.Width * texture.Height * 4];
     texture.GetData<byte>(data);
     cubeMap.SetData<byte>(face, data);
 }
        public override void LoadContent()
        {
            base.LoadContent();

            // To hacked for now
            if (!_environmentTextureLoaded && _environmentTextureNames != null)
            {
                // Detect the texture size if it doesn't specified
                if (_environmentTextureSize == 0)
                {
                    Texture2D firstTexture = YnG.Content.Load<Texture2D>(_environmentTextureNames[0]);
                    _environmentTextureSize = Math.Min(firstTexture.Width, firstTexture.Height);
                }

                // Create the environment texture
                _environmentTexture = new TextureCube(YnG.GraphicsDevice, _environmentTextureSize, _enableTextureMipmap, SurfaceFormat.Color);

                Texture2D texture = null;   // Temp texture
                Color[] textureData;        // Temp textureData array
                string[] tempTextureNames = new string[6];

                // If the texture array has not a size of 6, we replace empty texture by the latest
                int nbTextures = _environmentTextureNames.Length;

                for (int i = 0; i < 6; i++)
                {
                    if (i < nbTextures) // Texture
                        tempTextureNames[i] = _environmentTextureNames[i];
                    else // Copied texture
                        tempTextureNames[i] = _environmentTextureNames[nbTextures - 1];

                    // Load the texture and add it to the TextureCube
                    texture = YnG.Content.Load<Texture2D>(tempTextureNames[i]);
                    textureData = new Color[texture.Width * texture.Height];
                    texture.GetData<Color>(textureData);
                    _environmentTexture.SetData<Color>((CubeMapFace)i, textureData);
                }
                
                // Update the texture names array
                _environmentTextureNames = tempTextureNames;
                _environmentTextureLoaded = true;

                // If the first texture is null we create a dummy texture with the same size of environment texture
                if (_texture == null)
                {
                    _texture = YnGraphics.CreateTexture(Color.White, _environmentTextureSize, _environmentTextureSize);
                    _textureLoaded = true;
                }
            }

            if (!_effectLoaded)
            {
                _effect = new EnvironmentMapEffect(YnG.GraphicsDevice);
				_effectLoaded = true;
            }
        }
Beispiel #36
0
        protected override void LoadContent()
        {
            defaultViewport      = GraphicsDevice.Viewport;
            leftViewport         = defaultViewport;
            centerViewport       = defaultViewport;
            rightViewport        = defaultViewport;
            leftViewport.Width   = leftViewport.Width / 3;
            centerViewport.Width = rightViewport.Width / 3;
            rightViewport.Width  = rightViewport.Width / 3;
            centerViewport.X     = leftViewport.Width;
            rightViewport.X      = leftViewport.Width * 2;
            spriteBatch          = new SpriteBatch(GraphicsDevice);


            carpos = new Important_positions_struct[4];

            models.Add(new CModel(Content.Load <Model>("Models/CAR2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.7f), GraphicsDevice));
            //   models.Add(new CModel(Content.Load<Model>("Models/world"), Vector3.Zero, Vector3.Zero, new Vector3(1.00f), GraphicsDevice));
            models.Add(new CModel(Content.Load <Model>("Models/world2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice));
            models.Add(new CModel(Content.Load <Model>("Models/worldD"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice));
            models.Add(new CModel(Content.Load <Model>("Models/worldU"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice));
            models.Add(new CModel(Content.Load <Model>("Models/worldM"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(1.00f), GraphicsDevice));

            Bus_models.Add(new BusModel(Content.Load <Model>("Models/BUS_FRONT"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));
            Bus_models.Add(new BusModel(Content.Load <Model>("Models/BUS_REAR"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));
            Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));
            Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire2"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));
            Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));
            Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));

            Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));
            Bus_models.Add(new BusModel(Content.Load <Model>("Models/tire"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));

            Bus_models.Add(new BusModel(Content.Load <Model>("Models/volante"), Microsoft.Xna.Framework.Vector3.Zero, Microsoft.Xna.Framework.Vector3.Zero, new Microsoft.Xna.Framework.Vector3(0.800f), GraphicsDevice));



            TextureCube tc;

            tc = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color);
            tc.SetData <byte>(CubeMapFace.PositiveX, RealSkyBox.getface("270", GraphicsDevice, 23));
            tc.SetData <byte>(CubeMapFace.NegativeZ, RealSkyBox.getface("0", GraphicsDevice, 23));
            tc.SetData <byte>(CubeMapFace.NegativeX, RealSkyBox.getface("90", GraphicsDevice, 23));
            tc.SetData <byte>(CubeMapFace.PositiveZ, RealSkyBox.getface("180", GraphicsDevice, 23));
            tc.SetData <byte>(CubeMapFace.PositiveY, RealSkyBox.getface("up", GraphicsDevice, 23));

            skybox2 = new RealSkyBox(Content);
            skybox2.skyBoxTexture = tc;

            //   models.Add(new CModel(Content.Load<Model>("Models/PRUEBA"), Vector3.Zero, Vector3.Zero, new Vector3(0.26f), GraphicsDevice));
            CModel.skyboxTexture = Content.Load <TextureCube>("Skyboxes/Nice");
            //    CModel.skyboxTexture  = Content.Load<TextureCube>("Skyboxes/Sunset");
            CModel.effect = Content.Load <Microsoft.Xna.Framework.Graphics.Effect>("Effects/Reflection");
            skybox        = new Skybox("Skyboxes/Nice", Content);
            // skybox = new Skybox("Skyboxes/Sunset", Content);
            yalt        = 1.100f;
            dis         = 1.800f;
            angle       = -0.0f;
            translation = new Microsoft.Xna.Framework.Vector3(((float)Math.Sin(angle)) * dis, yalt, ((float)Math.Cos(angle)) * dis);

            camera         = new TargetCamera(translation, car_position, GraphicsDevice);
            yxalt          = .600f;
            lastMouseState = Microsoft.Xna.Framework.Input.Mouse.GetState();
            //carga el escenario
            resolve_collision.generate_last_index(100);
            compute_tiles();



            Bus_models[0].position = car_position;
            Bus_models[0].Rotation = new Microsoft.Xna.Framework.Vector3(0, 0, 0);
        }