当前位置: 首页>>代码示例>>C#>>正文


C# TextureCube.SetData方法代码示例

本文整理汇总了C#中TextureCube.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# TextureCube.SetData方法的具体用法?C# TextureCube.SetData怎么用?C# TextureCube.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextureCube的用法示例。


在下文中一共展示了TextureCube.SetData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldSetAndGetData

        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();
        }
开发者ID:KennethYap,项目名称:MonoGame,代码行数:22,代码来源:TextureCubeTest.cs

示例2: SkyboxFromImages

 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;
 }
开发者ID:Zamir7,项目名称:urho,代码行数:22,代码来源:Material.cs

示例3: LoadContent

        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;
            }
        }
开发者ID:shaoleibo,项目名称:YnaEngine,代码行数:56,代码来源:EnvironmentMapMaterial.cs

示例4: RgbmCubeMap

        /// <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
//.........这里部分代码省略.........
开发者ID:apeape,项目名称:Xen-Game-Client,代码行数:101,代码来源:RGBM+Cubemap.cs

示例5: GetReflectCube

        /// <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;
        }
开发者ID:CS583,项目名称:The3dgamesample,代码行数:35,代码来源:ScreenPlayer.cs

示例6: LoadCubemapFace

 /// <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);
 }
开发者ID:MintL,项目名称:datx02-rally,代码行数:13,代码来源:GamePlayView.cs

示例7: BuildCubeMap

        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;
        }
开发者ID:reisergames,项目名称:reactor-v1,代码行数:34,代码来源:TextureFactory.cs


注:本文中的TextureCube.SetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。