public static async Task SetupFactory(EngineContext engineContext, string effectName = "Simple") { var renderingSetup = RenderingSetup.Singleton; renderingSetup.RegisterLighting(engineContext); // Setup lighting LightingPlugin lightingPlugin; if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("LightingPlugin", out lightingPlugin)) { var shadowMapEntity = new Entity(); shadowMapEntity.Set(TransformationComponent.Key, TransformationTRS.CreateComponent()); shadowMapEntity.Set(LightComponent.Key, new LightComponent { Type = LightType.Directional, Intensity = 0.9f, Color = new Color3(1.0f, 1.0f, 1.0f), LightDirection = new Vector3(-1.0f, -1.0f, -1.0f), ShadowMap = true, DecayStart = 40000.0f }); engineContext.EntityManager.AddEntity(shadowMapEntity); } // Load asset var entity = await engineContext.AssetManager.LoadAsync <Entity>("/global_data/factoryfbx.hotei#"); // Flip it and scale it var transformationComponent = (TransformationTRS)entity.Transformation.Value; transformationComponent.Scaling *= 0.1f; //await engineContext.EntitySystem.Prepare(entity); await engineContext.EntityManager.AddEntityAsync(entity); }
public static async Task Run(EngineContext engineContext) { var renderingSetup = RenderingSetup.Singleton; renderingSetup.RegisterLighting(engineContext); ParticlePlugin particlePlugin; if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("ParticlePlugin", out particlePlugin)) { ScriptParticleSmoke.Run(engineContext); } var yebisPlugin = engineContext.RenderContext.RenderPassPlugins.OfType <YebisPlugin>().FirstOrDefault(); if (yebisPlugin != null) { var yebisConfig = AppConfig.GetConfiguration <YebisConfig>("Yebis"); // yebisPlugin.ToneMap.Type = ToneMapType.Linear; yebisPlugin.ToneMap.Gamma = yebisConfig.Gamma; yebisPlugin.ColorCorrection.Saturation = yebisConfig.Saturation; yebisPlugin.ColorCorrection.Contrast = yebisConfig.Contrast; yebisPlugin.ColorCorrection.Brightness = yebisConfig.Brightness; yebisPlugin.ColorCorrection.ColorTemperature = yebisConfig.ColorTemperature; yebisPlugin.Lens.Vignette.Enable = true; yebisPlugin.Lens.Vignette.PowerOfCosine = 5.0f; yebisPlugin.Lens.Distortion.Enable = true; yebisPlugin.Lens.Distortion.EdgeRoundness = 0.1f; yebisPlugin.Lens.Distortion.EdgeSmoothness = 1.0f; } // Run the script to animate the intro fade-in/fade-out engineContext.Scheduler.Add(async() => await AnimateIntroAndEndScene(engineContext)); var cameraEntityRootPrefab = await engineContext.AssetManager.LoadAsync <Entity>("/global_data/gdc_demo/char/camera.hotei#"); var lightCamEntityRootPrefab = await engineContext.AssetManager.LoadAsync <Entity>("/global_data/gdc_demo/char/light_cam.hotei#"); var lightCamEntityRoot = Prefab.Inherit(lightCamEntityRootPrefab); var cameraEntityRoot = Prefab.Inherit(cameraEntityRootPrefab); engineContext.EntityManager.AddEntity(cameraEntityRoot); engineContext.EntityManager.AddEntity(lightCamEntityRoot); Scheduler.Current.Add(() => AnimScript.AnimateFBXModel(engineContext, cameraEntityRoot, CaveSceneTotalTime, CaveSceneRestart)); Scheduler.Current.Add(() => AnimScript.AnimateFBXModel(engineContext, lightCamEntityRoot, CaveSceneTotalTime, CaveSceneRestart)); foreach (var light in ParameterContainerExtensions.CollectEntityTree(lightCamEntityRoot)) { var lightComp = light.Get(LightComponent.Key); if (lightComp != null) { if (!lightComp.ShadowMap && lightComp.Type == LightType.Directional) { lightComp.Intensity *= 0.1f; } } } var config = AppConfig.GetConfiguration <Script1.Config>("Script1"); var shadowMap1 = new Entity(); var shadowMap2 = new Entity(); shadowMap1.Set(TransformationComponent.Key, TransformationTRS.CreateComponent()); shadowMap2.Set(TransformationComponent.Key, TransformationTRS.CreateComponent()); shadowMap1.Set(LightComponent.Key, new LightComponent { Type = LightType.Directional, Intensity = 0.9f, Color = new Color3(0.9f, 0.9f, 1.0f), LightDirection = new Vector3(-0.2f, -0.1f, -1.0f), ShadowMap = true, DecayStart = 40000.0f }); shadowMap2.Set(LightComponent.Key, new LightComponent { Type = LightType.Directional, Color = new Color3(1.0f, 1.0f, 1.0f), LightDirection = new Vector3(-0.5f, 0.1f, -1.0f), ShadowMap = true, DecayStart = 40000.0f }); shadowMap1.Set(LightShaftsComponent.Key, new LightShaftsComponent { Color = new Color3(1.0f, 1.0f, 1.0f), LightShaftsBoundingBoxes = { new EffectMeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollection{ { TransformationKeys.World, Matrix.Scaling(3000, 3500, 3000) * Matrix.Translation(-2500, 0, 1500) } } } } }); shadowMap2.Set(LightShaftsComponent.Key, new LightShaftsComponent { Color = new Color3(1.0f, 1.0f, 1.0f), LightShaftsBoundingBoxes = { new EffectMeshData { MeshData = MeshDataHelper.CreateBox(1, 1, 1, Color.White, true), Parameters = new ParameterCollection{ { TransformationKeys.World, Matrix.Scaling(3500, 3500, 3000) * Matrix.Translation(-3000, 0, 1500) } } } } }); engineContext.EntityManager.AddEntity(shadowMap1); engineContext.EntityManager.AddEntity(shadowMap2); var dragon = await LoadDragon(engineContext); await LoadCave(engineContext, dragon); var dragonHead = engineContext.EntityManager.Entities.FirstOrDefault(x => x.Name == "English DragonHead"); TransformationTRS headCameraTransfo = null; if (dragonHead != null) { var headCamera = new Entity("Head camera"); headCamera.Set(CameraComponent.Key, new CameraComponent { AspectRatio = 16.0f / 9.0f, VerticalFieldOfView = (float)Math.PI * 0.3f, Target = dragonHead, AutoFocus = true, NearPlane = 10.0f }); headCamera.Set(TransformationComponent.Key, new TransformationComponent(new TransformationTRS { Translation = new Vector3(100.0f, -100.0f, 300.0f) })); //engineContext.EntitySystem.Entities.Add(headCamera); dragonHead.Transformation.Children.Add(headCamera.Transformation); } engineContext.Scheduler.Add(() => AnimateLights(engineContext)); // Performs several full GC after the scene has been loaded for (int i = 0; i < 10; i++) { GC.Collect(); Thread.Sleep(1); } while (true) { await engineContext.Scheduler.NextFrame(); if (headCameraTransfo != null) { var time = (double)DateTime.UtcNow.Ticks / (double)TimeSpan.TicksPerSecond; float rotationSpeed = 0.317f; var position = new Vector2((float)Math.Cos(time * rotationSpeed), (float)Math.Sin(time * rotationSpeed)) * 330.0f * ((float)Math.Sin(time * 0.23f) * 0.4f + 0.9f); headCameraTransfo.Translation = new Vector3(position.X, -150.0f + (float)Math.Cos(time * rotationSpeed) * 50.0f, position.Y); } if (engineContext.InputManager.IsKeyPressed(Keys.F1)) { bool isWireframeEnabled = renderingSetup.ToggleWireframe(); if (yebisPlugin != null) { yebisPlugin.DepthOfField.Enable = !isWireframeEnabled; yebisPlugin.Lens.Vignette.Enable = !isWireframeEnabled; yebisPlugin.Lens.Distortion.Enable = !isWireframeEnabled; } } if (engineContext.InputManager.IsKeyPressed(Keys.D1)) { engineContext.CurrentTime = TimeSpan.FromSeconds(0); } if (engineContext.InputManager.IsKeyPressed(Keys.D2)) { engineContext.CurrentTime = TimeSpan.FromSeconds(10); } if (engineContext.InputManager.IsKeyPressed(Keys.D3)) { engineContext.CurrentTime = TimeSpan.FromSeconds(20); } if (engineContext.InputManager.IsKeyPressed(Keys.D4)) { engineContext.CurrentTime = TimeSpan.FromSeconds(30); } if (engineContext.InputManager.IsKeyPressed(Keys.D5)) { engineContext.CurrentTime = TimeSpan.FromSeconds(40); } if (engineContext.InputManager.IsKeyPressed(Keys.D6)) { engineContext.CurrentTime = TimeSpan.FromSeconds(50); } if (engineContext.InputManager.IsKeyPressed(Keys.D7)) { engineContext.CurrentTime = TimeSpan.FromSeconds(60); } if (engineContext.InputManager.IsKeyPressed(Keys.D8)) { engineContext.CurrentTime = TimeSpan.FromSeconds(70); } if (engineContext.InputManager.IsKeyPressed(Keys.T)) { if (particlePlugin != null) { particlePlugin.EnableSorting = !particlePlugin.EnableSorting; } } } }