當前位置: 首頁>>代碼示例>>C#>>正文


C# Texture2D.GenerateMipMaps方法代碼示例

本文整理匯總了C#中Microsoft.Xna.Framework.Graphics.Texture2D.GenerateMipMaps方法的典型用法代碼示例。如果您正苦於以下問題:C# Texture2D.GenerateMipMaps方法的具體用法?C# Texture2D.GenerateMipMaps怎麽用?C# Texture2D.GenerateMipMaps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Xna.Framework.Graphics.Texture2D的用法示例。


在下文中一共展示了Texture2D.GenerateMipMaps方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Generate2DNoise

        public Texture2D Generate2DNoise(NoiseParameters noiseParams, int width, int height, int mipCount)
        {
            Vector2 invRes = Vector2.One / new Vector2(width, height);
            noise2DShader.SetupShader();
            GFX.Device.SetVertexShaderConstant(0, invRes);
            GFX.Device.SetPixelShaderConstant(0, invRes);
            GFX.Device.SetPixelShaderConstant(1, new Vector4(noiseParams.Amplitude, noiseParams.Frequency, noiseParams.Persistance, noiseParams.Octaves));
            GFX.Device.Textures[0] = ComputeRandomTexture(width / 2, height / 2);

            RenderTarget2D rtNoise = new RenderTarget2D(GFX.Device, width, height, 1, SurfaceFormat.Color);
            DepthStencilBuffer dsOld = GFX.Device.DepthStencilBuffer;
            GFX.Device.DepthStencilBuffer = GFX.Inst.dsBufferLarge;
            GFX.Device.SetRenderTarget(0, rtNoise);
            GFXPrimitives.Quad.Render();
            GFX.Device.SetRenderTarget(0, null);
            GFX.Device.DepthStencilBuffer = dsOld;

            Color[] colorData = new Color[width * height];
            rtNoise.GetTexture().GetData<Color>(colorData);
            Texture2D noiseTexture = new Texture2D(GFX.Device, width, height, mipCount, TextureUsage.None, SurfaceFormat.Color);
            noiseTexture.SetData<Color>(colorData);
            noiseTexture.GenerateMipMaps(TextureFilter.GaussianQuad);
            return noiseTexture;
        }
開發者ID:MattVitelli,項目名稱:IslandAdventure,代碼行數:24,代碼來源:PerlinNoiseSimulator.cs

示例2: WaterRenderer

        public WaterRenderer(ContentManager contentManager, Scene scene, Camera camera)
            : base(contentManager)
        {
            effect = Content.Load<Effect>("water");
             bumpTexture = Content.Load<Texture2D>("water_texture");

             bumpTexture.GenerateMipMaps(TextureFilter.Anisotropic);
             this.camera = camera;

             var vertices = new VertexPositionTexture[6 * scene.Water.WaterQuads.Count];
             int idx = 0;
             foreach (var quad in scene.Water.WaterQuads)
             {
            vertices[idx++] = new VertexPositionTexture(new Vector3(quad.Xmin, quad.Level, -quad.Ymin),
               new Vector2(quad.Xmin, -quad.Ymin) / WaterTextureCoordsDivisor);
            vertices[idx++] = new VertexPositionTexture(new Vector3(quad.Xmax, quad.Level, -quad.Ymin),
               new Vector2(quad.Xmax, -quad.Ymin) / WaterTextureCoordsDivisor);
            vertices[idx++] = new VertexPositionTexture(new Vector3(quad.Xmin, quad.Level, -quad.Ymax),
               new Vector2(quad.Xmin, -quad.Ymax) / WaterTextureCoordsDivisor);

            vertices[idx++] = new VertexPositionTexture(new Vector3(quad.Xmax, quad.Level, -quad.Ymin),
               new Vector2(quad.Xmax, -quad.Ymin) / WaterTextureCoordsDivisor);
            vertices[idx++] = new VertexPositionTexture(new Vector3(quad.Xmax, quad.Level, -quad.Ymax),
               new Vector2(quad.Xmax, -quad.Ymax) / WaterTextureCoordsDivisor);
            vertices[idx++] = new VertexPositionTexture(new Vector3(quad.Xmin, quad.Level, -quad.Ymax),
               new Vector2(quad.Xmin, -quad.Ymax) / WaterTextureCoordsDivisor);
             }

             vertexBuffer = new VertexBuffer(Device, vertices.Length * VertexPositionTexture.SizeInBytes, BufferUsage.None);
             vertexBuffer.SetData(vertices);
             vertexDeclaration = new VertexDeclaration(Device, VertexPositionTexture.VertexElements);
             primitivesToDraw = scene.Water.WaterQuads.Count * 2;

             projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Device.Viewport.AspectRatio,
            Config.Instance.Rendering.NearClippingDistance, Config.Instance.Rendering.FarClippingDistance);
        }
開發者ID:dennisyolkin,項目名稱:gta_gameworld_renderer,代碼行數:36,代碼來源:WaterRenderer.cs

示例3: CopyTextureToRenderTarget

 private void CopyTextureToRenderTarget(Texture2D src, RenderTarget2D rt, ref Texture2D dest)
 {
     var dsb = GraphicsDevice.DepthStencilBuffer;
     GraphicsDevice.DepthStencilBuffer = null;
     GraphicsDevice.SetRenderTarget(0, rt);
     spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
     spriteBatch.Draw(src, new Rectangle(0, 0, src.Width, src.Height), Color.White);
     spriteBatch.End();
     GraphicsDevice.SetRenderTarget(0, null);
     GraphicsDevice.DepthStencilBuffer = dsb;
     dest = rt.GetTexture();
     dest.GenerateMipMaps(TextureFilter.Linear);
 }
開發者ID:romainpi,項目名稱:berkelium-managed,代碼行數:13,代碼來源:BerkeliumTestGame.cs


注:本文中的Microsoft.Xna.Framework.Graphics.Texture2D.GenerateMipMaps方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。