protected override void Initialise()
        {
            Resource.EnableResourceTracking();

            //draw targets usually need a camera.
            Xen.Ex.Camera.FirstPersonControlledCamera3D camera = new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager);

            //don't allow the camera to move
            camera.MovementSensitivity *= 0;
            camera.Position             = new Vector3(0, 5, 0);

            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);
            drawToScreen.ClearBuffer.ClearColour = new Color(64, 64, 64);


            //create the particle system
            this.particles = new ParticleSystem(this.UpdateManager);

            //the snow particles will be drawn as velocity particles
            this.snowDrawer = new Xen.Ex.Graphics.Display.VelocityBillboardParticles3D(this.particles, false, 0.1f);

            //the fog particles will be drawn as normal billboards
            this.fogDrawer = new Xen.Ex.Graphics.Display.BillboardParticles3D(this.particles);

            //add a ground plane to show the horizon
            drawToScreen.Add(new DarkGroundPlane(new Vector4(0.225f, 0.225f, 0.225f, 1f)));

            //add the particles
            drawToScreen.Add(fogDrawer);
            drawToScreen.Add(snowDrawer);

            //Note: The particle drawers are masked in the LoadContent method

            //add draw stats
            stats = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);
            drawToScreen.Add(stats);
        }
Beispiel #2
0
        protected override void Initialise()
        {
            Resource.EnableResourceTracking();

            Camera3D camera = new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager, Vector3.Zero, true);

            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);
            drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue;

            //NEW CODE
            //create a BatchModel, this class stores the ModelData and will draw BatchModelInstances
            this.batchModel = new BatchModel();

            //NEW CODE
            //create a large number of actors (1600)
            for (float x = -20; x < 20; x++)
            {
                for (float y = -20; y < 20; y++)
                {
                    drawToScreen.Add(new Actor(this.batchModel, new Vector3(x * 5, y * 5, -5)));
                }
            }

            //this is the most important bit...
            //always add the BatchModel itself to the draw target,
            //this should be added *after* all BatchModelInstances have been added

            //Note: each time a BatchModelInstance is drawn, it will store it's world matrix in the BatchModel
            //If the BatchModel is not drawn, the buffer storing these matrices will not be emptied, and will
            //eventually throw an OutOfMemoryException exception.

            this.drawToScreen.Add(batchModel);

            statistics = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);
            this.drawToScreen.Add(statistics);
        }
Beispiel #3
0
        protected override void Initialise()
        {
            //create the camera
            Xen.Ex.Camera.FirstPersonControlledCamera3D camera =
                new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager, Vector3.Zero);
            camera.Projection.FarClip *= 10;

            this.camera = camera;


            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);

            //25,000 instances
            const int   instanceCount = 25000;
            const float areaRadius    = 500;


            //create the mesh instance drawer, (but add it to the screen later)
            InstancedMeshGeometry meshDrawer = new InstancedMeshGeometry(instanceCount);

            //the instances are added to a StaticBinaryTreePartition, which sorts the items
            //into a binary tree, for more efficient culling.
            //This class assumes it's children do not move (ie they are static)

            Xen.Ex.Scene.StaticBinaryTreePartition sceneTree = new Xen.Ex.Scene.StaticBinaryTreePartition();

            //add it to the screen
            drawToScreen.Add(sceneTree);


            //create the instances
            Random random = new Random();

            for (int i = 0; i < instanceCount; i++)
            {
                //create a random position in a sphere
                Vector3 position = new Vector3((float)(random.NextDouble() - .5),
                                               (float)(random.NextDouble() - .5),
                                               (float)(random.NextDouble() - .5));
                position.Normalize();
                position *= (float)Math.Sqrt(random.NextDouble()) * areaRadius;


                //create the instance
                MeshInstance instance = new MeshInstance(meshDrawer, position);

                //add the instance to the StaticBinaryTreePartition
                sceneTree.Add(instance);
            }

            //now add the drawer (instances will be drawn by the StaticBinaryPartition, before the drawer)
            drawToScreen.Add(meshDrawer);

            //Note that if the StaticBinaryTreePartition was not used, then
            //in each frame, every single instance would perform a CullTest to the screen
            //CullTests, despite their simplicity can be very costly in large numbers.
            //The StaticBinaryTreePartition will usually perform a maximum number of CullTests
            //that is approximately ~30% the number of children. (in this case, ~8000 tests)
            //At it's best, when it's entirely off or on screen, it will perform only 1 or 2 CullTests.

            //The number of cull tests performed will be displayed in debug builds of this tutorial:

            //add some statusText to display on screen to show the stats
            statusText          = new TextElement();
            statusText.Position = new Vector2(50, -50);
            drawToScreen.Add(statusText);
        }
Beispiel #4
0
        protected override void Initialise()
        {
            Resource.EnableResourceTracking();

            //draw targets usually need a camera.
            Xen.Ex.Camera.FirstPersonControlledCamera3D camera = new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager, Vector3.Zero, false);

            //don't allow the camera to move too fast
            camera.MovementSensitivity *= 0.1f;
            camera.LookAt(new Vector3(0, 3, 0), new Vector3(1, 5, 10), new Vector3(0, 1, 0));

            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);
            drawToScreen.ClearBuffer.ClearColour = new Color(45, 50, 60);


            //create the fire and smoke particle system
            this.fireParticleSystem  = new ParticleSystem(this.UpdateManager);
            this.smokeParticleSystem = new ParticleSystem(this.UpdateManager);

            //IMPORTANT
            //The following flags are FALSE by default.
            //For looping effects, such as the fire and smoke, it's highly
            //recommended to enable this flag. Otherwise, while the effect
            //is offscreen, the particle system will continue to process.
            this.fireParticleSystem.PauseUpdatingWhileCulled  = true;
            this.smokeParticleSystem.PauseUpdatingWhileCulled = true;


            this.drawSorted   = new Xen.Ex.Scene.DepthDrawSorter(Xen.Ex.Scene.DepthSortMode.BackToFront);
            this.drawUnsorted = new DrawList();

            Xen.Ex.Graphics.Display.ParticleDrawer3D fireDrawer  = new Xen.Ex.Graphics.Display.VelocityBillboardParticles3D(this.fireParticleSystem, true);
            Xen.Ex.Graphics.Display.ParticleDrawer3D smokeDrawer = new Xen.Ex.Graphics.Display.BillboardParticles3D(this.smokeParticleSystem);

            for (int i = 0; i < 10; i++)
            {
                Vector3 position = new Vector3((float)Math.Cos(i * Math.PI / 5.0) * 6.0f, 0, (float)Math.Sin(i * Math.PI / 5.0) * 6.0f);

                CullableParticleWrapper fireEffect, smokeEffect;

                fireEffect  = new CullableParticleWrapper(fireDrawer, position, new Vector3(0, 2, 0), 4);
                smokeEffect = new CullableParticleWrapper(smokeDrawer, position, new Vector3(0, 6, 0), 5);

                this.drawSorted.Add(fireEffect);
                this.drawSorted.Add(smokeEffect);

                this.drawUnsorted.Add(fireEffect);
                this.drawUnsorted.Add(smokeEffect);

                GroundLightDisk light = new GroundLightDisk(position);
                this.drawSorted.Add(light);
                this.drawUnsorted.Add(light);
            }


            //setup the burst effect
            this.burstParticleSystem = new ParticleSystem(this.UpdateManager);

            //for this case, PauseUpdatingWhileCulled is not set to true.
            //The particle emitting is culled when offscreen. If set to true,
            //Any particles left offscreen could 'pause', when they naturally
            //wouldn't be emitted anyway.
            //(The particle system will use very few resources when it has no
            //active particles)

            this.burstSources = new BurstSource[20];
            Random rand = new Random();

            for (int i = 0; i < this.burstSources.Length; i++)
            {
                //create the bursts out in the distance
                Vector3 position = new Vector3((float)i * 5.0f - this.burstSources.Length * 2.5f, 0, -20);
                float   radius   = 10;             // with a decent radius

                //give them a random starting time
                this.burstSources[i] = new BurstSource(position, radius, (float)rand.NextDouble() * 2);

                this.drawSorted.Add(this.burstSources[i]);
                this.drawUnsorted.Add(this.burstSources[i]);
            }

            //the bursts need to be drawn as a group..
            ParticleDrawer3D burstDrawer = new Xen.Ex.Graphics.Display.VelocityBillboardParticles3D(this.burstParticleSystem, false, 0.5f);

            this.drawSorted.Add(burstDrawer);
            this.drawUnsorted.Add(burstDrawer);

            //Use all the burst sources to cull the drawer (may not be ideal if there were many sources...)
            //Use the particle drawer CullProxy to do it
            burstDrawer.CullProxy = new BurstCullProxy(this.burstSources);



            //add a ground plane to show the horizon
            drawToScreen.Add(new Tutorial_22.DarkGroundPlane(new Vector4(0.125f, 0.15f, 0.135f, 1)));

            //add the sorted and unsorted lists
            drawToScreen.Add(drawSorted);
            drawToScreen.Add(drawUnsorted);


            //finally, create a CullTestVisualizer, which will visually show the cull tests performed
            cullTestVisualizer = new Xen.Ex.Scene.CullTestVisualizer(this.drawToScreen.Camera);

            //the visualizer is added as a draw modifier
            this.drawToScreen.AddModifier(cullTestVisualizer);

            //add help text
            this.text = new TextElement();
            this.text.VerticalAlignment = VerticalAlignment.Bottom;
            this.text.Position          = new Vector2(50, 100);
            drawToScreen.Add(this.text);

            //add draw stats
            stats = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);
            drawToScreen.Add(stats);
        }
Beispiel #5
0
        protected override void Initialise()
        {
            //DrawStatisticsDisplay requires that resource tracking is enabled
            Resource.EnableResourceTracking();


            //Xen.Ex provides a very useful Camera3D called 'FirstPersonControlledCamera3D'.
            //This camera uses player input to act as a simple first-person style flythrough camera
            Xen.Ex.Camera.FirstPersonControlledCamera3D camera = null;

            //it uses player input, so the UpdateManager must be passed in
            camera = new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager);

            //in this case, we want the z-axis to be the up/down axis (otherwise it's the Y-axis)
            camera.ZAxisUp = true;
            //also it's default is a bit too fast moving
            camera.MovementSensitivity *= 0.1f;
            camera.LookAt(new Vector3(1, 0, 0), new Vector3(), new Vector3(0, 0, 1));

            this.camera = camera;

            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);


            //create a large number of actor instance from tutorial 10..
            for (int n = 0; n <= 16; n++)
            {
                //create in a half circle
                float   angle    = (n / 16.0f) * MathHelper.Pi;
                Vector3 position = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0);

                //not too close together
                position *= 10;

                drawToScreen.Add(new Tutorial_10.Actor(this.Content, position));
            }


            //this element will display the camera position
            positionDisplay = new TextElement();

            //TextElement (unlike other Elements) defaults to Top Left alignment
            //So, in order to bring it closer to the centre of the screen (due to potential overscan)
            //it's position needs to be set 'right' and 'down' from 'top left'
            //(this is just an example, see XNA docs for correct overscan compensation behaviour)
            positionDisplay.Position = new Vector2(40, -40);             //offset from top left corner alignment

            //add it to the screen
            drawToScreen.Add(positionDisplay);



            Vector2 sizeInPixels = new Vector2(400, 200);

            //create the main block of yellow text
            this.yellowElement        = new TextElementRect(sizeInPixels);
            this.yellowElement.Colour = Color.Yellow;

            //first line of text... this will have a flashing 2D element embedded
            string embeddedText  = @"This is a text box with a large amount of custom text! It also includes an embedded 2D element: , which is a 16x16 SolidColourElement";
            uint   insertAtIndex = 96;           // Hard coded to insert a 2D element at character index 96               which is about here: ^

            //add a bunch of text...
            this.yellowElement.Text.AppendLine(embeddedText);
            this.yellowElement.Text.AppendLine();
            this.yellowElement.Text.AppendLine(@"This class is:");
            this.yellowElement.Text.AppendLine(this.GetType().FullName);
            this.yellowElement.Text.AppendLine(@"It is located in assembly:");
            this.yellowElement.Text.AppendLine(this.GetType().Assembly.FullName);
            this.yellowElement.Text.AppendLine();

            //add an embedded 2D element within the text
            //create it..
            this.embeddedElement = new SolidColourElement(Color.Red, new Vector2(16, 16));             // quite small
            this.embeddedElement.AlphaBlendState = AlphaBlendState.Alpha;
            //add it.
            this.yellowElement.AddInline(this.embeddedElement, insertAtIndex);


#if XBOX360
            this.yellowElement.Text.AppendLine(@"Press and hold both thumbsticks to show the debug overlay");
#else
            this.yellowElement.Text.AppendLine(@"Press F12 to show the debug overlay");
#endif


            //align the element rectangle to the bottom centre of the screen
            this.yellowElement.VerticalAlignment   = VerticalAlignment.Bottom;
            this.yellowElement.HorizontalAlignment = HorizontalAlignment.Centre;

            //centre align the text
            this.yellowElement.TextHorizontalAlignment = TextHorizontalAlignment.Centre;
            //centre the text in the middle of the 400x200 area of the element rectangle
            this.yellowElement.TextVerticalAlignment = VerticalAlignment.Centre;

            //add it to the screen
            drawToScreen.Add(yellowElement);



            //create the statistics display
            //this class will query the DrawState for the previous frames DrawStatistics structure.
            //this structure provides a large number of statistics for the drawn frame.
            //The DrawStatisticsDisplay displays some of the more important statistics. It will also
            //display thread activity on the xbox.

            //DrawStatistics are only available in DEBUG xen builds
            //They can be accessed at runtime with DrawState GetPreviousFrameStatistics()

            //at runtime, pressing 'F12' will toggle the overlay (or holding both thumbsticks on x360)
            this.statisticsOverlay = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);

            //As of xen 1.5, by default the DrawStatisticsDisplay displays a significantly reduced number of graphs.
            //To display the full set of graphs (which generally takes up the entire screen), set the following
            //property to 'true':
            //this.statisticsOverlay.DisplayFullGraphList = true;


            //then add it to the screen
            drawToScreen.Add(statisticsOverlay);
        }
Beispiel #6
0
        protected override void Initialise()
        {
            Resource.EnableResourceTracking();

            //setup the view camera first
            //--------------------------------------

            viewCamera = new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager);
            viewCamera.Projection.FieldOfView *= 0.65f;
            viewCamera.MovementSensitivity    *= 0.05f;
            viewCamera.LookAt(new Vector3(-3, 4, 2), new Vector3(6, 6, 2), new Vector3(0, 1, 0));
            viewCamera.Projection.NearClip = 0.1f;

            //shadow map setup:
            //--------------------------------------

            const float shadowArea          = 4;
            const int   shadowMapResolution = 1024;

            //setup the shadow map rendering camera
            shadowCamera = new Camera3D();

            //setup the shadow map projection to roughly cover the character
            shadowCamera.Projection.Orthographic = true;
            shadowCamera.Projection.NearClip     = shadowArea * 2;
            shadowCamera.Projection.FarClip      = -shadowArea * 2;
            shadowCamera.Projection.Region       = new Vector4(1, -1.8f, -1, 0.2f) * shadowArea;

            //setup the shadow map draw target

            //find a desirable format for the shadow map,
            SurfaceFormat format = SurfaceFormat.Color;

            //ideally use a high precision format, but only if it's supported. Avoid full 32bit float
            if (DrawTargetTexture2D.SupportsFormat(SurfaceFormat.Rg32))
            {
                format = SurfaceFormat.Rg32;                                                                                                            //ushort * 2
            }
            else if (DrawTargetTexture2D.SupportsFormat(SurfaceFormat.HalfVector2))
            {
                format = SurfaceFormat.HalfVector2;                                                                                     //fp16 * 2
            }
            else if (DrawTargetTexture2D.SupportsFormat(SurfaceFormat.HalfVector4))
            {
                format = SurfaceFormat.HalfVector4;                                                                                 //fp16 * 4
            }
            //create the shadow map
            shadowMap = new DrawTargetTexture2D(shadowCamera, shadowMapResolution, shadowMapResolution, format, DepthFormat.Depth24);
            shadowMap.ClearBuffer.ClearColour = Color.White;

            //setup the shadow map drawer..
            shadowDrawer = new Tutorial_25.ShadowMapDrawer(null, new Tutorial_25.ShadowOutputShaderProvider());
            this.shadowMap.Add(shadowDrawer);



            //create the main draw targets.
            //--------------------------------------

            drawToScreen = new DrawTargetScreen(this, new Camera2D());
            drawToScreen.ClearBuffer.ClearColourEnabled = false;

            drawToRenderTarget = new DrawTargetTexture2D(viewCamera, this.WindowWidth, this.WindowHeight, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, false, MultiSampleType.FourSamples, RenderTargetUsage.PlatformContents);
            drawToRenderTarget.ClearBuffer.ClearColourEnabled = false;

            //setup the bloom draw targets
            //--------------------------------------

            //scale to reduce the size of the bloom target, compared to main render target
            const int bloomDownsample = 8;              //eight times smaller

            bloomRenderTarget = new DrawTargetTexture2D(new Camera2D(), Math.Max(1, drawToRenderTarget.Width / bloomDownsample), Math.Max(1, drawToRenderTarget.Height / bloomDownsample), SurfaceFormat.Color);
            bloomRenderTarget.ClearBuffer.ClearColourEnabled = false;

            bloomIntermediateRenderTarget = null;
#if WINDOWS
            //the bloom intermediate target is not needed on the xbox, as the full bloom target fits in EDRAM
            bloomIntermediateRenderTarget = new DrawTargetTexture2D(viewCamera, bloomRenderTarget.Width, bloomRenderTarget.Height, SurfaceFormat.Color);
            bloomIntermediateRenderTarget.ClearBuffer.ClearColourEnabled = false;
#endif
            //setup the blur filter, with a large 31 sample radius.
            bloomBlurPass = new Xen.Ex.Filters.BlurFilter(Xen.Ex.Filters.BlurFilterFormat.ThirtyOneSampleBlur_FilteredTextureFormat, 1.0f, bloomRenderTarget, bloomIntermediateRenderTarget);


            //setup the character model
            this.model         = new ModelInstance();           //(the model is setup in LoadContent)
            this.modelRotation = new DrawRotated(model);
            this.modelRotation.RotationAngle = 3;

            //add the model to be drawn
            drawToRenderTarget.Add(modelRotation);

            //setup the shaders
            this.characterRenderShader      = new Shaders.Character();
            this.characterBlendRenderShader = new Shaders.CharacterBlend();

            //setup the output and bloom shaders
            outputShader = new Shaders.RgbmDecode();
            drawToScreen.Add(new ShaderElement(outputShader, new Vector2(1, 1), true));

            bloomPassShader = new Shaders.RgbmDecodeBloomPass();
            bloomRenderTarget.Add(new ShaderElement(bloomPassShader, new Vector2(1, 1), true));

            //add a background to be drawn
            drawToRenderTarget.Add(new BackgroundDrawer());


            //setup the debug image displays
            //--------------------------------------

            this.rgmbTextureAlphaShader  = new Shaders.AlphaWrite();
            this.bloomTextureDisplay     = new TexturedElement(this.bloomRenderTarget, new Vector2(0.2f, 0.2f), true);
            this.rgbmTextureDisplay      = new TexturedElement(this.drawToRenderTarget, new Vector2(0.2f, 0.2f), true);
            this.rgbmTextureAlphaDisplay = new ShaderElement(this.rgmbTextureAlphaShader, new Vector2(0.2f, 0.2f), true);

            this.rgbmTextureAlphaDisplay.Position = new Vector2(0.7f, 0.2f);
            this.rgbmTextureDisplay.Position      = new Vector2(0.7f, 0.4f);
            this.bloomTextureDisplay.Position     = new Vector2(0.7f, 0.6f);

            this.drawToScreen.Add(this.rgbmTextureDisplay);
            this.drawToScreen.Add(this.rgbmTextureAlphaDisplay);
            this.drawToScreen.Add(this.bloomTextureDisplay);

            //setup the render config
            this.configEditor = new RenderConfigEditor(this.Content);

            this.drawToScreen.Add(configEditor);
            this.UpdateManager.Add(configEditor);


            //add a statistics overlay.
            drawStats = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);
            drawToScreen.Add(drawStats);
        }