Пример #1
0
        public StatefulParticleSystem(
            Renderer renderer,
            WrappedContentManager wrappedContent,
            GraphicsDevice device
            )
        {
            this.renderer                = renderer;
            this.emitters                = new List <ParticleEmitter>();
            this.nextParticleIndex       = 0;
            this.device                  = device;
            this.remainingDt             = 0.0;
            this.activeTexture           = 0;
            this.positionTextures        = null;
            this.velocityTextures        = null;
            this.localCreateVertices     = null;
            this.createVertexBuffer      = null;
            this.createVertexDeclaration = null;
            this.particleCreateEffect    = null;
            this.particleUpdateEffect    = null;
            this.particleRenderingEffect = null;
            spriteBatch                  = new SpriteBatch(device);
            this.nextEmitterId           = 0;
            this.freeEmitterIds          = new List <int>();

            LoadResources(renderer, wrappedContent, device);
        }
Пример #2
0
 public Smoke(
     Renderer renderer,
     WrappedContentManager wrappedContent,
     GraphicsDevice device
     )
     :   base(renderer, wrappedContent, device)
 {
 }
Пример #3
0
 public Flamethrower(
     Renderer renderer,
     WrappedContentManager wrappedContent,
     GraphicsDevice device
     )
     :   base(renderer, wrappedContent, device)
 {
 }
Пример #4
0
 public IceExplosion(
     Renderer renderer,
     WrappedContentManager wrappedContent,
     GraphicsDevice device
     )
     :   base(renderer, wrappedContent, device)
 {
 }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="device"></param>
 /// <param name="wrappedContent"></param>
 /// <param name="fontName"></param>
 /// <param name="userMail"></param>
 public CrashDebugger(
     GraphicsDevice device,
     WrappedContentManager wrappedContent,
     string fontName,
     string userMail
     )
 {
     font = wrappedContent.Load <SpriteFont>(fontName);
     //testTexture = wrappedContent.Load<Texture2D>("Textures/custom_uv_diag");
     spriteBatch   = new SpriteBatch(device);
     this.userMail = userMail;
 }
Пример #6
0
 public LavaExplosion(
     Renderer renderer,
     WrappedContentManager wrappedContent,
     GraphicsDevice device,
     float explosionSize,
     float explosionRgbMultiplier,
     float explosionDotMultiplier
     )
     :   base(renderer, wrappedContent, device)
 {
     this.explosionSize          = explosionSize;
     this.explosionRgbMultiplier = explosionRgbMultiplier;
     this.explosionDotMultiplier = explosionDotMultiplier;
 }
Пример #7
0
        public IceSpike(
            Renderer renderer,
            WrappedContentManager wrappedContent,
            GraphicsDevice device
            )
            :   base(renderer, wrappedContent, device)
        {
            Effect effect   = LoadEffect(wrappedContent);
            int    rowCount = effect.Parameters["IceSpikePositionArray"].Elements.Count;

            positionArray     = new Vector3[rowCount];
            directionArray    = new Vector3[rowCount];
            deadArray         = new bool[rowCount];
            gravityStartArray = new float[rowCount];
        }
Пример #8
0
        protected virtual void LoadResources(
            Renderer renderer,
            WrappedContentManager wrappedContent,
            GraphicsDevice device
            )
        {
            // create texture maps
            activeTexture = 0;

            positionTextures    = new RenderTarget2D[2];
            positionTextures[0] = renderer.StatefulParticleResourceManager.AllocateStateTexture(GetSystemSize());
            positionTextures[1] = renderer.StatefulParticleResourceManager.AllocateStateTexture(GetSystemSize());
            velocityTextures    = new RenderTarget2D[2];
            velocityTextures[0] = renderer.StatefulParticleResourceManager.AllocateStateTexture(GetSystemSize());
            velocityTextures[1] = renderer.StatefulParticleResourceManager.AllocateStateTexture(GetSystemSize());

            // initialize the first two textures
            RenderTargetBinding[] currentRenderTargets = device.GetRenderTargets();
            device.SetRenderTargets(positionTextures[0], velocityTextures[0]);
            device.Clear(ClearOptions.Target, new Vector4(0, 0, 0, 0), 0, 0);
            device.SetRenderTargets(currentRenderTargets);

            //positionTextures[0].GetTexture().Save("PositionMaps/initial.dds", ImageFileFormat.Dds);

            // create effect
            localCreateVertices     = new CreateVertex[createVertexBufferSize];
            createVertexDeclaration = new VertexDeclaration(CreateVertex.SizeInBytes, CreateVertex.VertexElements);
            createVertexBuffer      = new DynamicVertexBuffer(device, createVertexDeclaration, CreateVertex.SizeInBytes * createVertexBufferSize, /*BufferUsage.Points |*/ BufferUsage.WriteOnly);
            // no more point sprites... :-( TODO: fix

            particleCreateEffect = LoadCreateEffect(wrappedContent).Clone();
            particleCreateEffect.CurrentTechnique = particleCreateEffect.Techniques["CreateParticles"];

            // update effect
            particleUpdateEffect = LoadUpdateEffect(wrappedContent).Clone();
            particleUpdateEffect.CurrentTechnique = particleUpdateEffect.Techniques["UpdateParticles"];

            // rendering effect
            particleRenderingEffect = LoadRenderEffect(wrappedContent).Clone();
            particleRenderingEffect.CurrentTechnique = particleRenderingEffect.Techniques["RenderParticles"];

            spriteTexture = LoadSprite(wrappedContent);
        }
Пример #9
0
 public Snow(
     Renderer renderer,
     WrappedContentManager wrappedContent,
     GraphicsDevice device,
     float snowLifeTime,
     float snowMaxAlpha,
     float snowBaseSize,
     float snowRandomSizeModification,
     float snowMeltingStart,
     float snowMeltingEnd
     )
     :   base(renderer, wrappedContent, device)
 {
     this.snowLifeTime = snowLifeTime;
     this.snowMaxAlpha = snowMaxAlpha;
     this.snowBaseSize = snowBaseSize;
     this.snowRandomSizeModification = snowRandomSizeModification;
     this.snowMeltingStart           = snowMeltingStart;
     this.snowMeltingEnd             = snowMeltingEnd;
 }
Пример #10
0
        public RendererUpdateQueue Initialize(
            WrappedContentManager wrappedContent,
            string simulationLevel,
            string rendererLevel,
            double startTime
            )
        {
            try
            {
                simTime = new SimulationTime(startTime);

                StartOperation(); // needs a valid simTime!

                paused = false;

                currentUpdateQueue.AddUpdate(new Renderer.Renderer.ChangeLevelUpdate(rendererLevel));
                SetPhase(SimulationPhase.Intro, "", null);

                // load level data
                levelData = wrappedContent.Load <LevelData>(simulationLevel);
                entityManager.Load(levelData);
                soundRegistry.Load();
                LevelLoaded();

                // start to play sounds
                MusicSettingsLoaded();

                Game.Instance.AudioPlayer.Play(soundRegistry.CaveBackgroundLoop, true);
                Game.Instance.AudioPlayer.Play(soundRegistry.LavaBackgroundLoop, true);

                return(EndOperation());
            }
            finally
            {
                currentUpdateQueue = null;
            }
        }
Пример #11
0
        public Profiler(WrappedContentManager wrappedContent, string name)
        {
            rootSection  = new Section(this, null, "root");
            sectionStack = new List <Section>(100);
            frameNumber  = 0;
            inBeginFrame = false;
            this.name    = name;

            filterList = new List <string>();
            filterList.Add("root");
            filterList.Add("root.draw");
            filterList.Add("root.draw.beginning_stuff");
            filterList.Add("root.draw.rendering.*");

            if (wrappedContent != null)
            {
                overlayBackground = new Texture2D(Game.Instance.GraphicsDevice, 32, 32);
                Color[] colorData = new Color[overlayBackground.Width * overlayBackground.Height];
                for (int i = 0; i < overlayBackground.Width * overlayBackground.Height; ++i)
                {
                    colorData[i] = Color.Black;
                }
                overlayBackground.SetData <Color>(colorData);

                overlayBackground2 = new Texture2D(Game.Instance.GraphicsDevice, 32, 32);
                for (int i = 0; i < overlayBackground2.Width * overlayBackground2.Height; ++i)
                {
                    colorData[i] = Color.Yellow;
                }
                overlayBackground2.SetData <Color>(colorData);

                spriteBatch = new SpriteBatch(Game.Instance.GraphicsDevice);

                font = wrappedContent.Load <SpriteFont>("Fonts/kootenay20");
            }
        }
Пример #12
0
 protected abstract Effect LoadEffect(WrappedContentManager wrappedContent);
Пример #13
0
 protected override Effect LoadRenderEffect(WrappedContentManager wrappedContent)
 {
     return(LoadEffect(wrappedContent));
 }
Пример #14
0
 private Effect LoadEffect(WrappedContentManager wrappedContent)
 {
     return(wrappedContent.Load <Effect>("Effects/Sfx/ParticleSystem/Stateful/Implementations/IceSpike"));
 }
Пример #15
0
 protected override void LoadResources(Renderer renderer, WrappedContentManager wrappedContent, GraphicsDevice device)
 {
     base.LoadResources(renderer, wrappedContent, device);
 }
Пример #16
0
        public Renderer(
            WrappedContentManager wrappedContent,
            GraphicsDevice device
            )
        {
            EnablePostProcessing = true;

            renderTime = new RenderTime(Game.Instance.GlobalClock.ContinuousMilliseconds,
                                        Game.Instance.GlobalClock.PausableMilliseconds);

            entityManager = new RendererEntityManager();

            this.device       = device;
            updateRenderables = new List <Renderable>();
            //            shadowCaster = new List<Renderable>();
            opaqueRenderables          = new List <Renderable>();
            transparentRenderablesTEST = new List <Renderable>();
            transparentRenderables     = new List <Renderable>();
            overlays = new List <Renderable>();

            shadowEffect = wrappedContent.Load <Effect>("Effects/ShadowEffect");

            lightPosition   = new Vector3(0, 10000, 0); // later: replace by orthographic light, not lookAt
            lightTarget     = Vector3.Zero;
            lightProjection = Matrix.CreateOrthographic(1500, 1500, 0.0f, 10000.0f);

            // Set the light to look at the center of the scene.
            lightView = Matrix.CreateLookAt(
                lightPosition,
                lightTarget,
                new Vector3(0, 0, -1));

            // later: replace by something like this:

            lightRenderTarget = new RenderTarget2D(
                device,
                shadowMapSize,
                shadowMapSize,
                false,
                SurfaceFormat.Single,
                DepthFormat.Depth24Stencil8
                );

            vectorCloudTexture = wrappedContent.Load <Texture2D>("Textures/Lava/vectorclouds");
            Color[] vectorCloudTextureData = new Color[vectorCloudTexture.Width * vectorCloudTexture.Height];
            vectorCloudTexture.GetData <Color>(vectorCloudTextureData);

            HalfVector4[] vectorCloudTexture4vsData = new HalfVector4[vectorCloudTexture.Width * vectorCloudTexture.Height];
            for (int i = 0; i < vectorCloudTexture.Width * vectorCloudTexture.Height; ++i)
            {
                Color current = vectorCloudTextureData[i];
                float r       = (float)current.R / (float)Byte.MaxValue;
                float g       = (float)current.G / (float)Byte.MaxValue;
                float b       = (float)current.B / (float)Byte.MaxValue;
                vectorCloudTexture4vsData[i] = new HalfVector4(r, g, b, 1);
            }

            vectorCloudTextureForVertexShaders = new Texture2D(device, vectorCloudTexture.Width, vectorCloudTexture.Height, false, SurfaceFormat.HalfVector4);
            vectorCloudTextureForVertexShaders.SetData(vectorCloudTexture4vsData);

            // set up render targets
            PresentationParameters pp = Device.PresentationParameters;
            int width  = pp.BackBufferWidth;
            int height = pp.BackBufferHeight;
            //SurfaceFormat format = SurfaceFormat.HalfVector4;
            //SurfaceFormat format = SurfaceFormat.Vector4;
            SurfaceFormat format = pp.BackBufferFormat;

            if (EnablePostProcessing)
            {
                //ResolveTarget = new ResolveTexture2D(Device, width, height, 1, format);
                targetOpaqueColorBuffer = new RenderTarget2D(Device, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);
                targetAlphaColorBuffer  = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
                targetHDRColorBuffer    = new RenderTarget2D(Device, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);
                targetHorizontalBlurredHDRColorBuffer = new RenderTarget2D(Device, width / 2, height / 2, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);
                targetBlurredHDRColorBuffer           = new RenderTarget2D(Device, width / 2, height / 2, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);

                targetOpaqueRenderChannels            = new RenderTarget2D(Device, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);
                targetAlphaRenderChannels             = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
                targetRenderChannels                  = new RenderTarget2D(Device, width, height, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);
                targetHorizontalBlurredRenderChannels = new RenderTarget2D(Device, width / 2, height / 2, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);
                targetBlurredRenderChannels           = new RenderTarget2D(Device, width / 2, height / 2, false, SurfaceFormat.HalfVector4, DepthFormat.Depth24Stencil8);

                targetOpaqueDepth = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Vector2, DepthFormat.Depth24Stencil8);
                targetAlphaDepth  = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Single, DepthFormat.Depth24Stencil8);
                targetDepth       = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Vector2, DepthFormat.Depth24Stencil8);

                restoreDepthBufferPass = new RestoreDepthBufferPass(this);
                combinePass            = new CombinePass(this);
                combineDepthPass       = new CombineDepthPass(this);
                glowPass       = new GlowPass(this);
                hdrCombinePass = new HdrCombinePass(this);
            }

            statefulParticleResourceManager = new ProjectMagma.Renderer.ParticleSystem.Stateful.ResourceManager(wrappedContent, device);


            updateQueues = new List <RendererUpdateQueue>();

            billboard = new Billboard(this, new Vector3(0, 200, 0), 250, 250, Vector4.One);
        }
Пример #17
0
 public static Profiler CreateProfiler(WrappedContentManager wrappedContent, string name)
 {
     Console.WriteLine("profiling code using {0}!", name);
     return(new Profiler(wrappedContent, name));
 }
Пример #18
0
 protected override Effect LoadEffect(WrappedContentManager wrappedContent)
 {
     return(wrappedContent.Load <Effect>("Effects/Sfx/ParticleSystem/Stateful/Implementations/IceExplosion"));
 }
Пример #19
0
 protected override Effect LoadRenderEffect(WrappedContentManager wrappedContent)
 {
     return(wrappedContent.Load <Effect>("Effects/ParticleSystem/Stateful/Implementations/Smoke"));
 }
Пример #20
0
 protected virtual Texture2D LoadSprite(WrappedContentManager wrappedContent)
 {
     return(wrappedContent.Load <Texture2D>("Textures/xna_logo"));
 }
Пример #21
0
 protected virtual Effect LoadRenderEffect(WrappedContentManager wrappedContent)
 {
     return(wrappedContent.Load <Effect>("Effects/ParticleSystem/Stateful/Default"));
 }
Пример #22
0
 protected override Texture2D LoadSprite(WrappedContentManager wrappedContent)
 {
     return(wrappedContent.Load <Texture2D>("Textures/Sfx/IceExplosion"));
 }
Пример #23
0
        public ResourceManager(
            WrappedContentManager wrappedContent,
            GraphicsDevice device
            )
        {
            this.device = device;

            // create the vertex declaration for rendering
            renderingVertexDeclaration = new VertexDeclaration(RenderVertex.SizeInBytes, RenderVertex.VertexElements);

            // Create vertexbuffers. One for each particle map size
            renderingVertexBuffers = new VertexBuffer[(int)Size.SizeCount];
            for (int i = 0; i < (int)Size.SizeCount; ++i)
            {
                Vector2        positionHalfPixel = new Vector2(1.0f / (2.0f * SizeMap[i]), 1.0f / (2.0f * SizeMap[i]));
                RenderVertex[] vertices          = new RenderVertex[SizeMap[i] * SizeMap[i] * 6];
                for (int x = 0; x < SizeMap[i]; ++x)
                {
                    for (int y = 0; y < SizeMap[i]; ++y)
                    {
                        int particleIndex = y * SizeMap[i] + x;

                        Vector2 particleCoordinate = new Vector2(
                            positionHalfPixel.X + 2 * x * positionHalfPixel.X,
                            positionHalfPixel.Y + 2 * y * positionHalfPixel.Y
                            );

                        // corners are
                        Short2[] corners =
                        {
                            new Short2(-1, -1),
                            new Short2(1,  -1),
                            new Short2(1,   1),
                            new Short2(-1, 1)
                        };

                        int[] cornerIndices =
                        {
                            0, 1, 2,
                            0, 2, 3
                        };

                        for (int j = 0; j < 6; ++j)
                        {
                            vertices[particleIndex * 6 + j].corner             = corners[cornerIndices[j]];
                            vertices[particleIndex * 6 + j].particleCoordinate = particleCoordinate;
                        }
                    }
                }

                renderingVertexBuffers[i] = new VertexBuffer(device, renderingVertexDeclaration, RenderVertex.SizeInBytes * vertices.Length, BufferUsage.WriteOnly);
                renderingVertexBuffers[i].SetData <RenderVertex>(vertices);
            }

            // allocate the stateMapLists
            stateMapLists = new List <RenderTarget2D> [(int)Size.SizeCount];
            for (int i = 0; i < (int)Size.SizeCount; ++i)
            {
                stateMapLists[i] = new List <RenderTarget2D>();
            }

            this.createVertexArrays = new List <CreateVertexArray>(CreateVertexArrayMaxPoolSize);
        }