Exemple #1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // Force aspect ratio
            SceneSystem.GraphicsCompositor      = GraphicsCompositorHelper.CreateDefault(false, clearColor: Color.Green, graphicsProfile: GraphicsProfile.Level_9_1);
            SceneSystem.GraphicsCompositor.Game = new ForceAspectRatioSceneRenderer {
                Child = SceneSystem.GraphicsCompositor.Game, FixedAspectRatio = 3.0f, ForceAspectRatio = true
            };

            Scene = new Scene();

            Texture png;

            using (var pngStream = Content.FileProvider.OpenStream("PngImage", VirtualFileMode.Open, VirtualFileAccess.Read))
                using (var pngImage = Image.Load(pngStream, GraphicsDevice.ColorSpace == ColorSpace.Linear))
                    png = Texture.New(GraphicsDevice, pngImage);

            var camera = new Entity {
                new CameraComponent {
                    Slot = SceneSystem.GraphicsCompositor.Cameras[0].ToSlotId()
                }
            };
            var plane = new Entity {
                new BackgroundComponent {
                    Texture = png
                }
            };

            Scene.Entities.Add(plane);
            Scene.Entities.Add(camera);

            SceneSystem.SceneInstance = new SceneInstance(Services, Scene);
        }
Exemple #2
0
        private void CreateScenePipeline()
        {
            // The gizmo scene
            EditorScene = new Scene();

            // The gizmo  scene
            var gizmoAmbientLight1 = new Entity("Gizmo Ambient Light1")
            {
                new LightComponent {
                    Type = new LightAmbient(), Intensity = 0.1f
                }
            };
            var gizmoDirectionalLight1 = new Entity("Gizmo Directional Light1")
            {
                new LightComponent {
                    Type = new LightDirectional(), Intensity = 0.45f
                }
            };
            var gizmoDirectionalLight2 = new Entity("Gizmo Directional Light2")
            {
                new LightComponent {
                    Type = new LightDirectional(), Intensity = 0.45f
                }
            };

            gizmoDirectionalLight1.Transform.Rotation = Quaternion.RotationY(MathUtil.Pi * 1.125f);
            gizmoDirectionalLight2.Transform.Rotation = Quaternion.RotationY(MathUtil.Pi * 0.125f);
            EditorScene.Entities.Add(gizmoAmbientLight1);
            EditorScene.Entities.Add(gizmoDirectionalLight1);
            EditorScene.Entities.Add(gizmoDirectionalLight2);

            // Root scene
            var rootScene = new Scene();

            // Setup the scene instance
            SceneSystem.SceneInstance = new SceneInstance(Services, rootScene, ExecutionMode.Editor);

            // Create editor scene
            EditorSceneSystem = new SceneSystem(Services)
            {
                SceneInstance = new SceneInstance(Services, EditorScene, ExecutionMode.Editor)
            };
            GameSystems.Add(EditorSceneSystem);

            EditorSceneSystem.DrawOrder          = SceneSystem.DrawOrder + 1;
            EditorSceneSystem.GraphicsCompositor = GraphicsCompositorHelper.CreateDefault(true, EditorGraphicsCompositorHelper.EditorForwardShadingEffect, groupMask: GizmoBase.DefaultGroupMask);

            // Do a few adjustments to the default compositor
            EditorSceneSystem.GraphicsCompositor.RenderFeatures.OfType <MeshRenderFeature>().FirstOrDefault()?.RenderFeatures.Add(new WireframeRenderFeature());
            EditorSceneSystem.GraphicsCompositor.Game = new EditorTopLevelCompositor
            {
                Child = new ForwardRenderer
                {
                    Clear                  = null, // Don't clear (we want to keep reusing same render target and depth buffer)
                    OpaqueRenderStage      = EditorSceneSystem.GraphicsCompositor.RenderStages.FirstOrDefault(x => x.Name == "Opaque"),
                    TransparentRenderStage = EditorSceneSystem.GraphicsCompositor.RenderStages.FirstOrDefault(x => x.Name == "Transparent"),
                },
            };
        }
Exemple #3
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            Window.AllowUserResizing = true;

            // Instantiate a scene with a single entity and model component
            var scene = new Scene();

            // Create a cube entity
            cubeEntity = new Entity();

            // Create a procedural model with a diffuse material
            var model    = new Model();
            var material = Material.New(GraphicsDevice, new MaterialDescriptor
            {
                Attributes =
                {
                    Diffuse      = new MaterialDiffuseMapFeature(new ComputeColor(Color.White)),
                    DiffuseModel = new MaterialDiffuseLambertModelFeature()
                }
            });

            model.Materials.Add(material);
            cubeEntity.Add(new ModelComponent(model));

            var modelDescriptor = new ProceduralModelDescriptor(new CubeProceduralModel());

            modelDescriptor.GenerateModel(Services, model);

            // Add the cube to the scene
            scene.Entities.Add(cubeEntity);

            // Use this graphics compositor
            SceneSystem.GraphicsCompositor = GraphicsCompositorHelper.CreateDefault(false, graphicsProfile: GraphicsProfile.Level_9_1);

            // Create a camera entity and add it to the scene
            var cameraEntity = new Entity {
                new CameraComponent {
                    Slot = Services.GetSafeServiceAs <SceneSystem>().GraphicsCompositor.Cameras[0].ToSlotId()
                }
            };

            cameraEntity.Transform.Position = new Vector3(0, 0, 5);
            scene.Entities.Add(cameraEntity);

            // Create a light
            var lightEntity = new Entity()
            {
                new LightComponent()
            };

            lightEntity.Transform.Position = new Vector3(0, 0, 1);
            lightEntity.Transform.Rotation = Quaternion.RotationY(MathUtil.DegreesToRadians(45));
            scene.Entities.Add(lightEntity);

            // Create a scene instance
            SceneSystem.SceneInstance = new SceneInstance(Services, scene);
        }
Exemple #4
0
        protected async override Task LoadContent()
        {
            await base.LoadContent();

            Window.AllowUserResizing = true;

            SpriteBatch = new SpriteBatch(GraphicsDevice);

            Arial18 = Content.Load <SpriteFont>("DynamicFonts/Arial18");

            SceneSystem.GraphicsCompositor = GraphicsCompositorHelper.CreateDefault(false, graphicsProfile: GraphicsProfile.Level_9_1);
            SceneSystem.SceneInstance      = new SceneInstance(Services, await BuildScene());
        }
Exemple #5
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            Window.AllowUserResizing = true;

            await base.LoadContent();

            Window.AllowUserResizing = true;

            arial16 = Content.Load <SpriteFont>("DynamicFonts/Arial16");

            // Instantiate a scene with a single entity and model component
            var scene = new Scene();

            // Fixed size
            scene.Entities.Add(GetUIEntity(arial16, true, new Vector3(0, 0, 4)));
            scene.Entities.Add(GetUIEntity(arial16, true, new Vector3(-2, 1, 0)));
            scene.Entities.Add(GetUIEntity(arial16, true, new Vector3(2, 2, -2)));
            scene.Entities.Add(GetUIEntity(arial16, true, new Vector3(0, 1, 0)));
            scene.Entities.Add(GetUIEntity(arial16, true, new Vector3(0, 2, -2)));

            scene.Entities.Add(GetUIEntity(arial16, false, new Vector3(0, -0.3f, 4)));
            scene.Entities.Add(GetUIEntity(arial16, false, new Vector3(-2, 0, 0)));
            scene.Entities.Add(GetUIEntity(arial16, false, new Vector3(2, 1, -2)));

            // Use this graphics compositor
            SceneSystem.GraphicsCompositor = GraphicsCompositorHelper.CreateDefault(false, graphicsProfile: GraphicsProfile.Level_9_1);

            // Create a camera entity and add it to the scene
            var cameraEntity = new Entity {
                new CameraComponent {
                    Slot = SceneSystem.GraphicsCompositor.Cameras[0].ToSlotId()
                }
            };

            cameraEntity.Transform.Position = new Vector3(0, 0, 5);
            scene.Entities.Add(cameraEntity);


            // Create a scene instance
            SceneSystem.SceneInstance = new SceneInstance(Services, scene);
        }
Exemple #6
0
        protected override GraphicsCompositor GetGraphicsCompositor()
        {
            var graphicsCompositor = GraphicsCompositorHelper.CreateDefault(RenderingMode == RenderingMode.HDR, modelEffectName,
                                                                            camera.Get <CameraComponent>(), RenderingMode == RenderingMode.HDR ? EditorServiceGame.EditorBackgroundColorHdr : EditorServiceGame.EditorBackgroundColorLdr);

            var opaqueStage      = graphicsCompositor.RenderStages.First(x => x.Name.Equals("Opaque"));
            var transparentStage = graphicsCompositor.RenderStages.First(x => x.Name.Equals("Transparent"));

            // Add particles, UI and SpriteStudio renderers
            graphicsCompositor.RenderFeatures.Add(
                new ParticleEmitterRenderFeature()
            {
                RenderStageSelectors =
                {
                    new ParticleEmitterTransparentRenderStageSelector
                    {
                        EffectName             = "Particles",
                        OpaqueRenderStage      = opaqueStage,
                        TransparentRenderStage = transparentStage,
                    }
                },
            });

            graphicsCompositor.RenderFeatures.Add(
                new SpriteStudioRenderFeature()
            {
                RenderStageSelectors =
                {
                    new SimpleGroupToRenderStageSelector()
                    {
                        EffectName  = "SpriteStudio",
                        RenderStage = transparentStage,
                    }
                }
            });

            return(graphicsCompositor);
        }
Exemple #7
0
        /// <inheritdoc/>
        protected override GraphicsCompositor CreateSharedGraphicsCompositor(GraphicsDevice device)
        {
            var result = GraphicsCompositorHelper.CreateDefault(false, ModelEffectName, null, ThumbnailBackgroundColor);

            var opaqueStage      = result.RenderStages.First(x => x.Name.Equals("Opaque"));
            var transparentStage = result.RenderStages.First(x => x.Name.Equals("Transparent"));

            // Add particles, UI and SpriteStudio renderers
            result.RenderFeatures.Add(
                new ParticleEmitterRenderFeature
            {
                RenderStageSelectors =
                {
                    new ParticleEmitterTransparentRenderStageSelector
                    {
                        EffectName             = "Particles",
                        OpaqueRenderStage      = opaqueStage,
                        TransparentRenderStage = transparentStage,
                    }
                },
            });

            result.RenderFeatures.Add(
                new SpriteStudioRenderFeature
            {
                RenderStageSelectors =
                {
                    new SimpleGroupToRenderStageSelector()
                    {
                        EffectName  = "SpriteStudio",
                        RenderStage = transparentStage,
                    }
                }
            });

            return(result);
        }
Exemple #8
0
        /// <inheritdoc />
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // mount the common database in this micro-thread to have access to the built effects, etc.
            MicrothreadLocalDatabases.MountCommonDatabase();

            // Create fallback effect to use when material is still loading
            fallbackColorMaterial = Material.New(GraphicsDevice, new MaterialDescriptor
            {
                Attributes =
                {
                    Diffuse      = new MaterialDiffuseMapFeature(new ComputeTextureColor()),
                    DiffuseModel = new MaterialDiffuseLambertModelFeature()
                }
            });

            fallbackTextureMaterial = Material.New(GraphicsDevice, new MaterialDescriptor
            {
                Attributes =
                {
                    Diffuse           = new MaterialDiffuseMapFeature(new ComputeTextureColor {
                        FallbackValue = null
                    }),                                                                                        // Do not use fallback value, we want a DiffuseMap
                    DiffuseModel      = new MaterialDiffuseLambertModelFeature()
                }
            });

            // Listen to all Renderer Initialized to plug dynamic effect compilation
            RenderContext.GetShared(Services).RendererInitialized += SceneGameRendererInitialized;
            // Update the marker render target setter viewport
            //OnClientSizeChanged(this, EventArgs.Empty);

            // Initialize the services
            var initialized = new List <IEditorGameService>();

            foreach (var service in EditorServices.OrderByDependency())
            {
                // Check that the current service dependencies have been initialized
                foreach (var dependency in service.Dependencies)
                {
                    if (!initialized.Any(x => dependency.IsInstanceOfType(x)))
                    {
                        throw new InvalidOperationException($"The service [{service.GetType().Name}] requires a service of type [{dependency.Name}] to be initialized first.");
                    }
                }
                if (await service.InitializeService(this))
                {
                    initialized.Add(service);
                }

                var mouseService = service as EditorGameMouseServiceBase;
                mouseService?.RegisterMouseServices(EditorServices);
            }

            // TODO: Maybe define this scene default graphics compositor as an asset?
            var defaultGraphicsCompositor = GraphicsCompositorHelper.CreateDefault(true, EditorGraphicsCompositorHelper.EditorForwardShadingEffect);

            // Add UI (engine doesn't depend on it)
            defaultGraphicsCompositor.RenderFeatures.Add(new UIRenderFeature
            {
                RenderStageSelectors =
                {
                    new SimpleGroupToRenderStageSelector
                    {
                        RenderStage = defaultGraphicsCompositor.RenderStages.First(x => x.Name == "Transparent"),
                        EffectName  = "Test",
                        RenderGroup = GizmoBase.DefaultGroupMask
                    }
                }
            });

            // Make the game switch to this graphics compositor
            UpdateGraphicsCompositor(defaultGraphicsCompositor);

            gameContentLoadedTaskSource.SetResult(true);
        }