Ejemplo n.º 1
0
 public void Dispose()
 {
     sector    = null;
     lightInfo = null;
     if (textureSpread != null)
     {
         textureSpread.Dispose();
     }
 }
Ejemplo n.º 2
0
            public SectorLightData(sector_t in_sector, Game1.Floorlightinfo in_lightInfo)
            {
                sector    = in_sector;
                lightInfo = in_lightInfo;
                lightInfo.makeColor();

                // Generate the stuff
                float bbminX = 100000;
                float bbminY = 100000;
                float bbmaxX = -100000;
                float bbmaxY = -100000;

                sector.floorBatch.boundingBox(ref bbminX, ref bbminY, ref bbmaxX, ref bbmaxY);

                int texW = Math.Max(1, (int)Math.Ceiling(((bbmaxX - bbminX) / PRECISION) + lightInfo.spread * 16 + 4));
                int texH = Math.Max(1, (int)Math.Ceiling(((bbmaxY - bbminY) / PRECISION) + lightInfo.spread * 16 + 4));
                int pow2 = 1; while (pow2 < texW)

                {
                    pow2 *= 2;
                }
                texW = pow2;

                pow2 = 1; while (pow2 < texH)
                {
                    pow2 *= 2;
                }
                texH = pow2;

                // Center it
                limits.X = ((bbmaxX + bbminX) - ((float)texW * PRECISION)) * .5f;
                limits.Y = ((bbmaxY + bbminY) - ((float)texH * PRECISION)) * .5f;
                limits.Z = limits.X + (float)texW * PRECISION;
                limits.W = limits.Y + (float)texH * PRECISION;

                textureSpread = new RenderTarget2D(Game1.instance.GraphicsDevice, texW, texH);
                RenderTarget2D textureTemp = new RenderTarget2D(Game1.instance.GraphicsDevice, texW, texH);

                Game1.instance.fxSectorLightInfo.Parameters["texSize"].SetValue(new Vector2((float)texW, (float)texH));
                Game1.instance.fxSectorLightInfo.Parameters["spread"].SetValue(lightInfo.spread);

                // Render to target the sector
                Game1.instance.GraphicsDevice.SetRenderTarget(textureSpread);
                Game1.instance.GraphicsDevice.Clear(Color.Transparent);
                Game1.instance.fxSectorLightInfo.CurrentTechnique = Game1.instance.fxSectorLightInfo.Techniques["TechniquePlain"];
                Game1.instance.fxSectorLightInfo.Parameters["World"].SetValue(Matrix.Identity);
                Game1.instance.fxSectorLightInfo.Parameters["View"].SetValue(Matrix.Identity);
                Game1.instance.fxSectorLightInfo.Parameters["Projection"].SetValue(Matrix.CreateOrthographicOffCenter(limits.X, limits.Z, limits.Y, limits.W, -999, 999));
                Game1.instance.fxSectorLightInfo.CurrentTechnique.Passes[0].Apply();
                Game1.instance.GraphicsDevice.SetVertexBuffer(sector.floorBatch.vb);
                Game1.instance.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, sector.floorBatch.triCount);
                Game1.instance.GraphicsDevice.SetRenderTargets(null);

                // Grow the texels for the base, and start bluring for the spread
                Game1.instance.GraphicsDevice.SetRenderTarget(textureTemp);
                Game1.instance.GraphicsDevice.Clear(Color.Transparent);
                Game1.instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone,
                                                 Game1.instance.fxSectorLightInfo);
                Game1.instance.fxSectorLightInfo.CurrentTechnique = Game1.instance.fxSectorLightInfo.Techniques["TechniqueBlurU"];
                Game1.instance.spriteBatch.Draw(textureSpread, new Rectangle(0, 0, textureSpread.Width, textureSpread.Height), Color.White);
                Game1.instance.spriteBatch.End();
                Game1.instance.GraphicsDevice.SetRenderTargets(null);

                // Lastly blur in V to finalize it
                Game1.instance.GraphicsDevice.SetRenderTarget(textureSpread);
                Game1.instance.GraphicsDevice.Clear(Color.Transparent);
                Game1.instance.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone,
                                                 Game1.instance.fxSectorLightInfo);
                Game1.instance.fxSectorLightInfo.CurrentTechnique = Game1.instance.fxSectorLightInfo.Techniques["TechniqueBlurV"];
                Game1.instance.spriteBatch.Draw(textureTemp, new Rectangle(0, 0, textureTemp.Width, textureTemp.Height), Color.White);
                Game1.instance.spriteBatch.End();
                Game1.instance.GraphicsDevice.SetRenderTargets(null);

                textureTemp.Dispose();
            }