상속: Microsoft.Xna.Framework.Graphics.Texture2D
예제 #1
1
        public TileCanvas(TileLayer tileLayer)
        {
            TileLayer = tileLayer;

            //Init the textures array
            Size texSize = new Size(MAX_TEXTURE_SIZE - (MAX_TEXTURE_SIZE % TileLayer.Definition.Grid.Width), MAX_TEXTURE_SIZE - (MAX_TEXTURE_SIZE % TileLayer.Definition.Grid.Height));

            Size maxSize = new Size(TileLayer.Definition.Grid.Width * TileLayer.TileCellsX, TileLayer.Definition.Grid.Height * TileLayer.TileCellsY);

            // TODO: Clip the dimensions of the tiles that draw over the edges of the level.
            Textures = new List<TextureInfo>();
            for (int i = 0; i < maxSize.Width; i += texSize.Width)
            {
                for (int j = 0; j < maxSize.Height; j += texSize.Height)
                {
                    RenderTarget2D tex = new RenderTarget2D(
                        Ogmo.EditorDraw.GraphicsDevice,
                        Math.Min(maxSize.Width - i, texSize.Width),
                        Math.Min(maxSize.Height - j, texSize.Height));
                    Textures.Add(new TextureInfo(tex, new Point(i, j)));
                }
            }

            RefreshAll();
        }
예제 #2
1
 public WaterSubMesh(Mesh mesh, RenderTarget2D reflectionBuffer, RenderTarget2D refractionBuffer, Texture2D offsetMap, Texture2D normalMap) : base(mesh)
 {
     m_ReflectionTarget = reflectionBuffer;
     m_RefractionTarget = refractionBuffer;
     m_OffsetMap = offsetMap;
     m_NormalMap = normalMap;
 }
예제 #3
0
 /// <summary>
 /// Bakes the specified <c>RenderTarget2D</c>.
 /// </summary>
 /// <param name="drawProvider">The RenderTarget to draw.</param>
 /// <exception cref="System.Exception">BeginBake must be called before Bake</exception>
 public void Bake(RenderTarget2D drawProvider)
 {
     if (_state != 1)
         if (_state == 0)
             throw new Exception("BeginBake must be called before Bake");
     Game1.Instance.SpriteBatch.Draw(drawProvider, Vector2.Zero, Color.White);
 }
예제 #4
0
        public Edge(SpriteBatch spriteBatch, Settings settings, Effect normalDepthMapEffect, Effect edgeEffect)
            : base(spriteBatch)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (normalDepthMapEffect == null) throw new ArgumentNullException("normalDepthMapEffect");
            if (edgeEffect == null) throw new ArgumentNullException("edgeEffect");

            this.settings = settings;

            var pp = GraphicsDevice.PresentationParameters;
            var width = (int) (pp.BackBufferWidth * settings.MapScale);
            var height = (int) (pp.BackBufferHeight * settings.MapScale);

            //----------------------------------------------------------------
            // エフェクト

            // 法線深度マップ
            this.normalDepthMapEffect = new NormalDepthMapEffect(normalDepthMapEffect);

            // エッジ強調
            this.edgeEffect = new EdgeEffect(edgeEffect);
            this.edgeEffect.MapWidth = width;
            this.edgeEffect.MapHeight = height;

            //----------------------------------------------------------------
            // レンダ ターゲット

            normalDepthMap = new RenderTarget2D(GraphicsDevice, width, height,
                false, SurfaceFormat.Vector4, DepthFormat.Depth24, 0, RenderTargetUsage.DiscardContents);
        }
예제 #5
0
        public void Process(RenderTarget2D scene, IntermediateBuffer show = IntermediateBuffer.Result)
        {
            device.SetRenderTarget(scene);

            device.SamplerStates[1] = SamplerState.LinearClamp;

            bloomExtract.Parameters["BloomThreshold"].SetValue(0.25F);

            RenderQuad(scene, primary, bloomExtract, IntermediateBuffer.PreBloom);

            SetBlurParameters(0, 1.0f / (float)primary.Width);

            RenderQuad(primary, secondary, blurGaussian, IntermediateBuffer.BlurHorizontal);

            SetBlurParameters(0, 1.0f / (float)primary.Height);

            RenderQuad(secondary, primary, blurGaussian, IntermediateBuffer.BlurAll);

            device.SetRenderTarget(null);

            var parameters = bloomCombine.Parameters;
            parameters["BloomIntensity"].SetValue(1.25F);
            parameters["BaseIntensity"].SetValue(1.0F);
            parameters["BloomSaturation"].SetValue(1.0F);
            parameters["BaseSaturation"].SetValue(1.0F);

            device.Textures[1] = scene;

            var view = device.Viewport;
            RenderQuad(primary, view.Width, view.Height, bloomCombine, IntermediateBuffer.Result);
        }
예제 #6
0
        public void onSceneBackBufferSizeChanged( int newWidth, int newHeight )
        {
            // dont recreate the mosaic unless we really need to
            if( _lastMosaicScale != scene.pixelPerfectScale )
            {
                createMosaicTexture( scene.pixelPerfectScale );
                _lastMosaicScale = scene.pixelPerfectScale;
            }

            if( _mosaicRenderTex != null )
            {
                _mosaicRenderTex.Dispose();
                _mosaicRenderTex = RenderTarget.create( newWidth * scene.pixelPerfectScale, newHeight * scene.pixelPerfectScale, DepthFormat.None );
            }
            else
            {
                _mosaicRenderTex = RenderTarget.create( newWidth * scene.pixelPerfectScale, newHeight * scene.pixelPerfectScale, DepthFormat.None );
            }

            // based on the look of games by: http://deepnight.net/games/strike-of-rage/
            // use the mosaic to render to a full sized RenderTarget repeating the mosaic
            Core.graphicsDevice.setRenderTarget( _mosaicRenderTex );
            Graphics.instance.batcher.begin( BlendState.Opaque, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone );
            Graphics.instance.batcher.draw( _mosaicTexture, Vector2.Zero, new Rectangle( 0, 0, _mosaicRenderTex.Width, _mosaicRenderTex.Height ), Color.White );
            Graphics.instance.batcher.end();

            // let our Effect know about our rendered, full screen mosaic
            effect.Parameters["_secondTexture"].SetValue( _mosaicRenderTex );
        }
예제 #7
0
        public Lightning(Vector2 p1, Vector2 p2, float width = 2f, int life = 60, int detailLevel = 6, bool sound = false, 
            float volume = 0.1f)
        {
            sound = false;//TODO rm

            MaxLife = life;
            w = width;
            GEN_DEPTH = detailLevel;

            Position = p1;

            float l = (p2 - p1).Length() * 4;
            rot = (float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
            transform = Matrix.CreateRotationZ(rot);
            fbo = new RenderTarget2D(GraphicsEngine.Renderer.GraphicsDevice, (int)l + 64, (int)l + 64);

            GenLightning(new Vector2(32, 32 + l / 2), new Vector2(32 + l, 32 + l / 2));
            var r = GraphicsEngine.Renderer;
            r.EnableFBO(fbo);
            r.GraphicsDevice.Clear(Color.Transparent);
            r.BeginUnscaled();
            DrawFBO(r);
            r.End();
            r.DisableFBO();

            if (sound)
                _sound = Sound.Sounds.tesla.Play(volume, (float)(new Random().Next(-250, 250)) / 1000f, 0f);
        }
        //Creates a white 1*1 Texture that is used for the lines by scaling and rotating it
        public void CreatePixelTexture()
        {
            int TargetWidth = 1;
            int TargetHeight = 1;

            RenderTarget2D LevelRenderTarget = new RenderTarget2D(graphicsDevice, TargetWidth, TargetHeight, 1,
                graphicsDevice.PresentationParameters.BackBufferFormat, graphicsDevice.PresentationParameters.MultiSampleType,
                graphicsDevice.PresentationParameters.MultiSampleQuality, RenderTargetUsage.PreserveContents);

            DepthStencilBuffer stencilBuffer = new DepthStencilBuffer(graphicsDevice, TargetWidth, TargetHeight,
                graphicsDevice.DepthStencilBuffer.Format, graphicsDevice.PresentationParameters.MultiSampleType,
                graphicsDevice.PresentationParameters.MultiSampleQuality);

            graphicsDevice.SetRenderTarget(0, LevelRenderTarget);

            // Cache the current depth buffer
            DepthStencilBuffer old = graphicsDevice.DepthStencilBuffer;
            // Set our custom depth buffer
            graphicsDevice.DepthStencilBuffer = stencilBuffer;

            graphicsDevice.Clear(Color.White);

            graphicsDevice.SetRenderTarget(0, null);

            // Reset the depth buffer
            graphicsDevice.DepthStencilBuffer = old;
            pixel = LevelRenderTarget.GetTexture();
        }
예제 #9
0
        public static Texture2D ConvertToPreMultipliedAlphaGPU(Texture2D texture)
        {
            // code borrowed from http://jakepoz.com/jake_poznanski__speeding_up_xna.html

            // Set up a render target to hold our final texture which will have premulitplied alpha values
            RenderTarget2D result = new RenderTarget2D(device, texture.Width, texture.Height);

            device.SetRenderTarget(result);
            device.Clear(Color.Black);

            // Multiply each color by the source alpha, and write in just the color values into the final texture
            SpriteBatch spriteBatch = new SpriteBatch(device);
            spriteBatch.Begin(SpriteSortMode.Immediate, blendColor);
            spriteBatch.Draw(texture, texture.Bounds, Color.White);
            spriteBatch.End();

            // Now copy over the alpha values from the PNG source texture to the final one, without multiplying them
            spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha);
            spriteBatch.Draw(texture, texture.Bounds, Color.White);
            spriteBatch.End();

            // Release the GPU back to drawing to the screen
            device.SetRenderTarget(null);

            return result as Texture2D;
        }
예제 #10
0
        public FireParticle(Vector3 pos, Game1 game, float dist)
        {
            this.model = TextureManager.dirSquare;
            this.game = game;
            startPos = pos;
            scalef = Utilities.nextFloat() + .25f;

            direction.X = (float)Utilities.random.NextDouble() * 2 - 1;
            direction.Y = (float)Utilities.random.NextDouble() * 1.5f - .5f;
            direction.Z = (float)Utilities.random.NextDouble() * 2 - 1;
            direction.Normalize();

            startPos += direction * Utilities.nextFloat() / 2;

            goalPos = pos + direction * dist;
            speed = 4.5f + Utilities.nextFloat();
            alpha = 1;

            rTarg = new RenderTarget2D(game.GraphicsDevice, 128, 128);
            sb = new SpriteBatch(game.GraphicsDevice);

            game.GraphicsDevice.SetRenderTarget(rTarg);
            sb.Begin();
            sb.Draw(TextureManager.pyroFlame, Vector2.Zero, Color.Lerp(Color.Red, Color.White, Utilities.nextFloat()));
            sb.End();
            game.GraphicsDevice.SetRenderTarget(null);
        }
예제 #11
0
        public void Apply(IPostEffectData data, RenderTarget2D target)
        {
            data.Effect.GraphicsDevice.SetRenderTargets(m_ParticleTarget, m_DataTarget);
            data.Effect.GraphicsDevice.Clear(Color.Transparent);

            data.Effect.CurrentTechnique = data.Effect.Techniques["DrawEmitters"];
            foreach(ParticleEmitter emitter in m_ParticleEngine.Emitters)
                DrawEmitter(data.Device, data.Effect, emitter);

            //merge particletarget with scene
            data.Effect.GraphicsDevice.SetRenderTarget(target);
            data.Effect.Parameters["SceneTexture"].SetValue(data.Scene);
            data.Effect.Parameters["ParticlesTexture"].SetValue(m_ParticleTarget); //debug this shit
            data.Effect.Parameters["ParticleDataTexture"].SetValue(m_DataTarget);

            if (Keyboard.GetState().IsKeyDown(Keys.P))
            {
                Thread.Sleep(1000);
                data.Scene.ToFile("Scene");
                m_ParticleTarget.ToFile("Particle");
                m_DataTarget.ToFile("Data");
            }

            data.Effect.GraphicsDevice.SetVertexBuffer(m_ScreenBuffer.Get().Buffer);
            data.Effect.CurrentTechnique = data.Effect.Techniques["MergeSceneAndParticles"];
            foreach (EffectPass pass in data.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                data.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }
        }
예제 #12
0
        public GaussianBlur(Game game)
        {
            this.game = game;
            this.device = game.GraphicsDevice;
            this.spriteBatch = (game as GameManager).spriteBatch;

            effect = game.Content.Load<Effect>(@"Effects\GaussianBlur");

            // Since we're performing a Gaussian blur on a texture image the
            // render targets are half the size of the source texture image.
            // This will help improve the blurring effect.
            renderTargetWidth = device.Viewport.Width / 4;
            renderTargetHeight = device.Viewport.Height / 4;

            blurHTarget = new RenderTarget2D(device, renderTargetWidth, renderTargetHeight,
                false, SurfaceFormat.Color, DepthFormat.Depth24);
            blurVTarget = new RenderTarget2D(device, renderTargetWidth, renderTargetHeight,
                false, SurfaceFormat.Color, DepthFormat.Depth24);

            Radius = 7;
            Amount = 3.0f;

            ComputeKernel(Radius, Amount);
            ComputeOffsets(renderTargetWidth, renderTargetHeight);
        }
예제 #13
0
 public ShallowWaterRC(Texture2D p_txTextre, Vector2 p_v2Pos)
     : base(p_txTextre, new TransformComponent(p_v2Pos))
 {
     this.enType = RenderComponent.ComponentType.StaticRenderComponent;
     this.graphics = Program.game.GraphicsDevice;
     this.rt2dDistortionMos = new RenderTarget2D(this.graphics, 640, 360);
 }
예제 #14
0
        protected override void LoadContent()
        {
            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            refractionRenderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat);

            base.LoadContent();
        }
예제 #15
0
파일: Scale.cs 프로젝트: ylyking/Myre
        public void Scale(RenderTarget2D source, RenderTarget2D destination)
        {
            _effect.CurrentTechnique = source.Format.IsFloatingPoint() ? _effect.Techniques["Software"] : _effect.Techniques["Hardware"];

            Vector2 resolution = new Vector2(source.Width, source.Height);
            float scaleFactor = (destination.Width > source.Width) ? 2 : 0.5f;

            RenderTarget2D input = source;

            while (IntermediateNeeded(resolution, destination, scaleFactor))
            {
                resolution *= scaleFactor;

                RenderTarget2D output = RenderTargetManager.GetTarget(_device, (int)resolution.X, (int)resolution.Y, source.Format, name:"scaled");
                Draw(input, output);

                if (input != source)
                    RenderTargetManager.RecycleTarget(input);
                input = output;
            }

            Draw(input, destination);

            if (input != source)
                RenderTargetManager.RecycleTarget(input);
        }
예제 #16
0
파일: Scale.cs 프로젝트: ylyking/Myre
 private bool IntermediateNeeded(Vector2 currentResolution, RenderTarget2D target, float scale)
 {
     // ReSharper disable CompareOfFloatsByEqualityOperator
     return (scale == 2) ? (currentResolution.X * 2 < target.Width && currentResolution.Y * 2 < target.Height)
     // ReSharper restore CompareOfFloatsByEqualityOperator
                         : (currentResolution.X / 2 > target.Width && currentResolution.Y / 2 > target.Height);
 }
예제 #17
0
        private Texture2D CreateBackground(GraphicsDevice gd, SpriteBatch sb, ContentManager cm)
        {
            RenderTarget2D target = new RenderTarget2D(gd, 2048, 2048);
            //tell the GraphicsDevice we want to render to the gamesMenu rendertarget (an in-memory buffer)
            gd.SetRenderTarget(target);

            //clear the background
            gd.Clear(Color.Transparent);

            //begin drawing
            sb.Begin();
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    sb.Draw(cm.Load<Texture2D>("Backgrounds/" + _level.ToString()), new Vector2(x * 400, y * 256), Color.White);
                }
            }

            sb.End();
            //reset the GraphicsDevice to draw on the backbuffer (directly to the backbuffer)
            gd.SetRenderTarget(null);

            return (Texture2D)target;
        }
예제 #18
0
        public void Combine(List<Texture2D> textures, SpriteBatch spriteBatch, RenderTarget2D target, out Dictionary<Texture2D, Microsoft.Xna.Framework.Rectangle> mapping)
        {
            mapping = new Dictionary<Texture2D, Microsoft.Xna.Framework.Rectangle>();

            textures.Sort((a, b) => System.Math.Max(a.Width, a.Height).CompareTo(System.Math.Max(b.Width, b.Height)));

            RectangleTree rectangleTree = new RectangleTree();

            for(int i = 0; i < textures.Count; i++)
            {
                rectangleTree.TryInsert(i, textures[i].Width, textures[i].Height);
            }

            spriteBatch.GraphicsDevice.SetRenderTarget(target);

            spriteBatch.Begin();

            foreach(var rectangle in rectangleTree.ClosedNodes)
            {
                var texture = textures[rectangle.ID];

                spriteBatch.Draw(texture, new Microsoft.Xna.Framework.Vector2(rectangle.X, rectangle.Y), Microsoft.Xna.Framework.Color.White);

                var rectangleForMapping = new Microsoft.Xna.Framework.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);

                mapping.Add(texture, rectangleForMapping);
            }

            spriteBatch.End();
        }
예제 #19
0
 public LightArea(GraphicsDevice graphicsDevice, ShadowmapSize size)
 {
     int baseSize = 2 << (int)size;
     LightAreaSize = new Vector2(baseSize);
     RenderTarget = new RenderTarget2D(graphicsDevice, baseSize, baseSize);
     this.graphicsDevice = graphicsDevice;
 }
예제 #20
0
        protected override void Initialize()
        {
            Engine.Instance.GetDevice += Instance_GetDevice;
            Engine.Instance.GameRenderEnd += Instance_GameRenderEnd;
            Engine.Instance.GameRenderBegin += Instance_GameRenderBegin;
            Margin = new System.Windows.Forms.Padding(0);
            Padding = new System.Windows.Forms.Padding(0);

            masterSpriteBatch = new SpriteBatch(GraphicsDevice);
            masterRenderingTarget = new RenderTarget2D(GraphicsDevice, Width, Height, false, SurfaceFormat.Bgr565, DepthFormat.None);

            ntsc = snes_ntsc_alloc();
            ntscInit(snes_ntsc_setup_t.snes_ntsc_composite);

            ntscTexture = new Texture2D(GraphicsDevice, 602, 448, false, SurfaceFormat.Bgr565);

            ntscPixelsDimmed = new ushort[ushort.MaxValue+1];
            for (int i = 0; i <= ushort.MaxValue; i++)
            {
                int red = (i & 0xf800);
                int green = (i & 0x7e0);
                int blue = (i & 0x1f);
                red = ((red - (red >> 3)) & 0xf800);
                green = ((green - (green >> 3)) & 0x7e0);
                blue = ((blue - (blue >> 3)) & 0x1f);
                ntscPixelsDimmed[i] = (ushort)(red | green | blue);
            }
        }
예제 #21
0
파일: KarmaWorld.cs 프로젝트: heyx3/GGJ2014
        public KarmaWorld(GraphicsDevice device, ContentManager content)
        {
            KarmaWorld.World = this;

            GraphicsDevice = device;
            ContentManager = content;
            RenderedWorld = new RenderTarget2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight,
                                               true, device.DisplayMode.Format, DepthFormat.Depth24);

            Timers = new Utilities.TimerManager();
            Input = new ButtonInputManager();

            Input.AddInput("Zoom In", new ComboButton(new KeyboardButton(Keys.LeftControl, false), new KeyboardButton(Keys.PageUp, true)));
            Input.AddInput("Zoom Out", new ComboButton(new KeyboardButton(Keys.LeftControl, false), new KeyboardButton(Keys.PageDown, true)));

            CurrentTime = new GameTime(TimeSpan.Zero, TimeSpan.Zero);

            currentZoom = ZoomLevels.Three;

            Camera = new KarmaCamera(device);
            Camera.Zoom = GetCameraZoom(currentZoom);

            CurrentZoom = currentZoom;
            ZoomingIn = false;
            ZoomingOut = false;
            foreach (ZoomLevels zooms in WorldData.AscendingZooms)
                if (WorldData.Minigames[zooms] != null)
                    WorldData.Minigames[zooms].ResetGame();

            JoustingInput.InitializeInput();

            Camera.Update(new GameTime(TimeSpan.FromSeconds(0.016667), TimeSpan.FromSeconds(0.016667)));
            Camera.Zoom = GetCameraZoom(currentZoom);
        }
예제 #22
0
        public static RenderTarget2D GenerateShadows(RenderTarget2D shadowCaster,SpriteBatch spriteBatch,GraphicsDevice graphicsDevice)
        {
            foreach (LightSource CurrentLight in LightList)
            {
                if (CurrentLight.distance < 1000)
                {
                    CurrentLight.GenerateShadow(shadowCaster, spriteBatch, graphicsDevice, ShadowEffectList);
                }
            }
            graphicsDevice.SetRenderTarget(shadowMap);
            graphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin(SpriteSortMode.Immediate,BlendState.NonPremultiplied);
            //draw every small shadow map to the bigger one
            TestClass.DebugFrame.debugText += "Number of lights:" + LightList.Count().ToString()+"\n";
            foreach (LightSource CurrentLight in LightList)
            {

                    spriteBatch.Draw(CurrentLight.area,
                    CurrentLight.RenderArea,
                    Color.White);

            }
            spriteBatch.End();
            return shadowMap;
        }
예제 #23
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            GraphicsDevice.SetRenderTarget(final);
            GraphicsDevice.Clear(Color.Black);
            DebugMap.Draw(spriteBatch);
            Player.Draw(spriteBatch);

            #region shadowmap
            GraphicsDevice.SetRenderTarget(shadowmap);
            GraphicsDevice.Clear(Color.White);
            Player.ShadowDraw(spriteBatch);
            GraphicsDevice.SetRenderTarget(null);
            spriteBatch.End();
            shadowmap=Lighting.Databse.GenerateShadows(shadowmap,spriteBatch, GraphicsDevice);
            #endregion shadowmap
            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Draw(final, new Rectangle(0, 0, 640, 640), Color.White);
            spriteBatch.Draw(shadowmap, new Rectangle(0, 0, 640, 640), Color.White);

            //Lighting.Databse.ApplyShadows(spriteBatch);

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            ParticleSystem.Draw(spriteBatch, 1, -(Player.sprite.position- new Vector2(320)));
            DebugFrame.Draw(spriteBatch);
            spriteBatch.End();
        }
예제 #24
0
 public WaterMesh(RenderTarget2D reflectionTarget, RenderTarget2D refractionTarget, Texture2D offsetMap, Texture2D normalMap) : base()
 {
     m_ReflectionTarget = reflectionTarget;
     m_RefractionTarget = refractionTarget;
     m_OffsetMap = offsetMap;
     m_NormalMap = normalMap;
 }
예제 #25
0
 public RoomEditor()
 {
     editorSurface = new RenderTarget2D(Engine.Instance.GraphicsDevice, Engine.WINDOW_WIDTH * 2, Engine.WINDOW_HEIGHT * 2);
     Player p = new Player(Vector2.Zero, this);
     this.objects.Add(p);
     cameraTarget = p;
 }
 /// <summary>
 /// Creates a new RenderTargetImageSource.
 /// </summary>
 /// <param name="graphics">The GraphicsDevice to use.</param>
 /// <param name="width">The width of the image source.</param>
 /// <param name="height">The height of the image source.</param>
 public RenderTargetImageSource(GraphicsDevice graphics, int width, int height)
 {
     // create the render target and buffer to hold the data
     renderTarget = new RenderTarget2D(graphics, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
     buffer = new byte[width * height * 4];
     writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);
 }
예제 #27
0
파일: Water.cs 프로젝트: Zalrioth/BitSmith
        public Water(GraphicsDevice device, Texture2D particleTexture)
        {
            pb = new PrimitiveBatch(device);
            this.particleTexture = particleTexture;
            spriteBatch = new SpriteBatch(device);
            metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            drawTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            alphaTest = new AlphaTestEffect(device);
            alphaTest.ReferenceAlpha = 175;

            var view = device.Viewport;
            alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1);

            for (int i = 0; i < columns.Length; i++)
            {
                columns[i] = new WaterColumn()
                {
                    Height = 240,
                    TargetHeight = 240,
                    Speed = 0
                };
            }
        }
        // 188/157!09
        #endregion

        #region Getter & Setter
        #endregion

        #region Constructor
        public CreditsScene()
        {
            isActiv = true;
            _name = "Credits";
            _backgroundColor = Color.Black;

            _partikelTop = new RectanglePartikelEmitter(@"Partikel\circle",new Vector4(0,1280,0,100), 220);
            _partikelTop.SetColor(new Color(255, 223, 76), new Color(145, 24, 25));
            _partikelBottom = new RectanglePartikelEmitter(@"Partikel\circle", new Vector4(0, 1280, 620, 720), 220);
            _partikelBottom.SetColor(new Color(255, 223, 76), new Color(145, 24, 25));
            _partikelLeft = new RectanglePartikelEmitter(@"Partikel\circle", new Vector4(0, 100, 100, 620), 140);
            _partikelLeft.SetColor(new Color(255, 223, 76), new Color(145, 24, 25));
            _partikelRight = new RectanglePartikelEmitter(@"Partikel\circle", new Vector4(1180, 1280, 100, 620), 140);
            _partikelRight.SetColor(new Color(255, 223, 76), new Color(145, 24, 25));

            //_partikelCenter = new CirclePartikelEmitter("circle", new Vector2(640, 360), 500, 180, 0, false);
            //_partikelCenter.SetColor(Color.Green, Color.Yellow);
            //_partikelCenter2 = new CirclePartikelEmitter("circle", new Vector2(640, 360), 500, 220, 0, true);
            //_partikelCenter2.SetColor(Color.Green, Color.Yellow);

            _spriteBatch = new SpriteBatch(SceneManager.Graphics.GraphicsDevice);
            _renderTarget = new RenderTarget2D(SceneManager.Graphics.GraphicsDevice, 1280, 720);

            for(int i = 0; i < 3; i++)
                TextureManager.Instance.LoadContentFromStream(@"\Content\Credits\" + i + ".png", "credits" + i);

            _backgroundColor = new Color(188, 157, 109, 255);
 }
예제 #29
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels, 
            CCSurfaceFormat colorFormat=CCSurfaceFormat.Color, 
            CCDepthFormat depthFormat=CCDepthFormat.None, 
            CCRenderTargetUsage usage=CCRenderTargetUsage.DiscardContents) : this()
        {
            int textureWidth = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            renderTarget2D = drawManager.CreateRenderTarget(
                textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc = CCBlendFunc.AlphaBlend;

            CCPoint center = contentSize.Center;

            renderViewMatrix = 
                Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            renderProjMatrix = 
                Matrix.CreateOrthographic(contentSize.Width, contentSize.Height, 1024f, -1024);
            renderViewport = new Viewport(0, 0, textureWidth, textureHeight);


            clearColor = CCColor4B.Transparent;
            drawManager.SetRenderTarget(Texture);
            drawManager.Clear(clearColor);
            drawManager.RestoreRenderTarget();
        }
예제 #30
0
 public DefaultLightContext(
     Texture2D deferredColorMap, 
     Texture2D deferredNormalMap,
     Texture2D deferredDepthMap, 
     Texture2D deferredSpecularMap,
     RenderTarget2D diffuseLightRenderTarget,
     RenderTarget2D specularLightRenderTarget,
     BlendState lightBlendState,
     RasterizerState rasterizerStateCullNone,
     RasterizerState rasterizerStateCullClockwiseFace, 
     RasterizerState rasterizerStateCullCounterClockwiseFace, 
     Vector2 halfPixel)
 {
     DeferredColorMap = deferredColorMap;
     DeferredNormalMap = deferredNormalMap;
     DeferredDepthMap = deferredDepthMap;
     DeferredSpecularMap = deferredSpecularMap;
     DiffuseLightRenderTarget = diffuseLightRenderTarget;
     SpecularLightRenderTarget = specularLightRenderTarget;
     LightBlendState = lightBlendState;
     RasterizerStateCullNone = rasterizerStateCullNone;
     RasterizerStateCullClockwiseFace = rasterizerStateCullClockwiseFace;
     RasterizerStateCullCounterClockwiseFace = rasterizerStateCullCounterClockwiseFace;
     HalfPixel = halfPixel;
 }
예제 #31
0
        public void handleFinalRender(Color letterboxColor, Microsoft.Xna.Framework.Graphics.RenderTarget2D source, Rectangle finalRenderDestinationRect, Microsoft.Xna.Framework.Graphics.SamplerState samplerState)
        {
            Core.graphicsDevice.SetRenderTarget(null);
            Core.graphicsDevice.Clear(letterboxColor);
            Graphics.instance.batcher.begin(BlendState.Opaque, samplerState, DepthStencilState.None, RasterizerState.CullNone, null);
            Graphics.instance.batcher.draw(source, finalRenderDestinationRect, Color.White);
            Graphics.instance.batcher.end();

            _screenSpaceRenderer.render(scene);
        }
예제 #32
0
		public void SetRenderTargets (params RenderTargetBinding[] renderTargets) 
		{
			
			currentRenderTargets = renderTargets;
			
			if (currentRenderTargets != null) 
			{				
				// TODO: For speed we need to consider using FBO switching instead
				// of multiple FBO's if they are the same size.
				
				// http://www.songho.ca/opengl/gl_fbo.html
				
				// Get the currently bound frame buffer object. On most platforms this just gives 0.				
				GL.GetInteger(All.FramebufferBindingOes, ref originalFbo);
				
				frameBufferIDs = new int[currentRenderTargets.Length];
				
				renderBufferIDs = new int[currentRenderTargets.Length];
				GL.Oes.GenRenderbuffers(currentRenderTargets.Length, renderBufferIDs);
				
				for (int i = 0; i < currentRenderTargets.Length; i++) 
				{
					RenderTarget2D target = (RenderTarget2D)currentRenderTargets[i].RenderTarget;
					
					// create a renderbuffer object to store depth info
					GL.Oes.BindRenderbuffer(All.RenderbufferOes, renderBufferIDs[i]);
					
					ClearOptions clearOptions = ClearOptions.Target | ClearOptions.DepthBuffer;
					
					switch (target.DepthStencilFormat) 
					{
						case DepthFormat.Depth16:
							GL.Oes.RenderbufferStorage(All.RenderbufferOes, All.DepthComponent16Oes,
							target.Width, target.Height);
							break;
						case DepthFormat.Depth24:
							GL.Oes.RenderbufferStorage(All.RenderbufferOes, All.DepthComponent24Oes,
							target.Width, target.Height);
							break;
						case DepthFormat.Depth24Stencil8:
							GL.Oes.RenderbufferStorage(All.RenderbufferOes, All.Depth24Stencil8Oes,
							target.Width, target.Height);
							GL.Oes.FramebufferRenderbuffer(All.FramebufferOes, All.StencilAttachmentOes,
							All.RenderbufferOes, renderBufferIDs[i]);
							clearOptions = clearOptions | ClearOptions.Stencil;
							break;
						default :
							GL.Oes.RenderbufferStorage(All.RenderbufferOes, All.DepthComponent24Oes,
							target.Width, target.Height);
							break;
					}					
					
					// create framebuffer
					GL.Oes.GenFramebuffers(1, ref frameBufferIDs[i]);
					GL.Oes.BindFramebuffer(All.FramebufferOes, frameBufferIDs[i]);
					
					// attach the texture to FBO color attachment point
					GL.Oes.FramebufferTexture2D(All.FramebufferOes, All.ColorAttachment0Oes, All.Texture2D, target.ID, 0);
					
					// attach the renderbuffer to depth attachment point
					GL.Oes.FramebufferRenderbuffer(All.FramebufferOes, All.DepthAttachmentOes,
							All.RenderbufferOes, renderBufferIDs[i]);							
					
					if (target.RenderTargetUsage == RenderTargetUsage.DiscardContents)
						Clear (clearOptions, Color.Transparent, 0, 0);
					
					GL.Oes.BindRenderbuffer(All.FramebufferOes, originalFbo);
						
				}
				
				All status = GL.Oes.CheckFramebufferStatus(All.FramebufferOes);
				
				if (status != All.FramebufferCompleteOes)
					throw new Exception("Error creating framebuffer: " + status);
				
				// We need to start saving off the ViewPort and setting the current ViewPort to
				// the width and height of the texture.  Then when we pop off the rendertarget
				// it needs to be reset.  This causes drawing problems if we do not set the viewport.
				// Makes sense once you follow the flow (hits head on desk)
				// For an example of this take a look at NetRumble's sample for the BloomPostprocess
               
				// Save off the current viewport to be reset later
				savedViewport = Viewport;

				// Create a new Viewport
				Viewport renderTargetViewPort = new Viewport();

				// Set the new viewport to the width and height of the render target
				Texture2D target2 = (Texture2D)currentRenderTargets[0].RenderTarget;
				renderTargetViewPort.Width = target2.Width;
				renderTargetViewPort.Height = target2.Height;

				// now we set our viewport to the new rendertarget viewport just created.
				Viewport = renderTargetViewPort;				
			}
		}
예제 #33
0
        protected override bool init(DisposableI parent, string fileName, Image image, int width, int height, bool generateMipmaps, MultiSampleTypes multiSampleType, SurfaceFormats surfaceFormat, RenderTargetUsage renderTargetUsage, BufferUsages usage, bool isRenderTarget, Loader.LoadedCallbackMethod loadedCallback)
        {
            if (!base.init(parent, fileName, image, width, height, false, multiSampleType, surfaceFormat, renderTargetUsage, usage, true, loadedCallback))
            {
                return(false);
            }

            try
            {
                if (usage == BufferUsages.Write)
                {
                    Debug.ThrowError("RenderTarget", "Only Textures may be writable");
                }

                if (fileName == null)
                {
                    // TODO: handle multiSampleType types
                                        #if SILVERLIGHT
                    var xUsage = X.RenderTargetUsage.PreserveContents;
                                        #else
                    var xUsage = X.RenderTargetUsage.PlatformContents;
                                        #endif
                    switch (renderTargetUsage)
                    {
                    case RenderTargetUsage.PlatformDefault:
                                                        #if SILVERLIGHT
                        xUsage = X.RenderTargetUsage.PreserveContents;
                                                        #else
                        xUsage = X.RenderTargetUsage.PlatformContents;
                                                        #endif
                        break;

                    case RenderTargetUsage.PreserveContents: xUsage = X.RenderTargetUsage.PreserveContents; break;

                    case RenderTargetUsage.DiscardContents: xUsage = X.RenderTargetUsage.DiscardContents; break;
                    }

                    X.DepthFormat format = X.DepthFormat.None;
                    if (initDepthStencilFormat != DepthStencilFormats.None)
                    {
                        switch (initDepthStencilFormat)
                        {
                        case DepthStencilFormats.Defualt: format = X.DepthFormat.Depth24; break;

                        case DepthStencilFormats.Depth24Stencil8: format = X.DepthFormat.Depth24Stencil8; break;

                        case DepthStencilFormats.Depth16: format = X.DepthFormat.Depth16; break;

                        case DepthStencilFormats.Depth24: format = X.DepthFormat.Depth24; break;

                        default:
                            Debug.ThrowError("RenderTarget", "Unsuported DepthStencilFormat type");
                            break;
                        }
                    }

                    renderTarget = new X.RenderTarget2D(video.Device, width, height, false, Video.surfaceFormat(surfaceFormat), format, 0, xUsage);
                }
                else
                {
                    Debug.ThrowError("RenderTarget", "(Load image data into RenderTarget Texture) -- Not implemented yet...");
                }

                texture = renderTarget;
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null)
                {
                    loadedCallback(this, false);
                }
                return(false);
            }

            Loaded = true;
            if (loadedCallback != null)
            {
                loadedCallback(this, true);
            }
            return(true);
        }