public void Render(IRenderArgs args) { Graphics.DepthStencilState = DepthStencilState.Default; Graphics.SamplerStates[0] = SamplerState.PointWrap; if (UseDepthMap) { ChunkManager.Draw(args, true); } SkyRenderer.Draw(args); ChunkManager.Draw(args, false); EntityManager.Render(args); //TestItemRender.Render(args.GraphicsDevice, (Camera.Position + (Camera.Direction * 2.5f))); if (Camera is ThirdPersonCamera) { Player.RenderEntity = true; } else { Player.RenderEntity = false; } Player.Camera = Camera; Player.Render(args); }
protected override void OnLoad(EventArgs e) { multisampling = new Multisampling(4); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.ClearColor(State.ClearColor); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.MinSampleShading(1.0f); Map.New(2048); debug = new ObjectRenderer(); camera = new Camera(); terrain = new TerrainRenderer(camera); water = new WaterRenderer(); light = new Light(); assets = new AssetRenderer(); ui = new Ui(); sky = new SkyRenderer(); shadows = new ShadowBox(); }
public void Render(IRenderArgs args) { Graphics.DepthStencilState = DepthStencilState.Default; Graphics.SamplerStates[0] = SamplerState.PointWrap; if (UseDepthMap) { ChunkManager.Draw(args, true); } SkyRenderer.Draw(args); ChunkManager.Draw(args, false, RenderStage.OpaqueFullCube, RenderStage.Opaque); EntityManager.Render(args); ChunkManager.Draw(args, false, RenderStage.Transparent, RenderStage.Translucent, RenderStage.Animated, RenderStage.AnimatedTranslucent, RenderStage.Liquid); //TestItemRender.Render(args.GraphicsDevice, (Camera.Position + (Camera.Direction * 2.5f))); //Player.Camera = Camera; Player.Render(args); }
protected override void OnUpdate(GameTime gameTime) { var args = new UpdateArgs() { Camera = World.Camera, GraphicsDevice = Graphics, GameTime = gameTime }; // if (Alex.IsActive) { var newAspectRatio = Graphics.Viewport.AspectRatio; if (AspectRatio != newAspectRatio) { World.Camera.UpdateAspectRatio(newAspectRatio); AspectRatio = newAspectRatio; } UpdateRayTracer(Alex.GraphicsDevice, World); if (!_playingHud.Chat.Focused) { World.Player.Controller.CheckInput = Alex.IsActive; CheckInput(gameTime); } else { World.Player.Controller.CheckInput = false; } SkyRenderer.Update(args); World.Update(args, SkyRenderer); var now = DateTime.UtcNow; if (now - _previousMemUpdate > TimeSpan.FromSeconds(5)) { _previousMemUpdate = now; //Task.Run(() => { _ramUsage = Environment.WorkingSet; ThreadPool.GetMaxThreads(out int maxThreads, out int maxCompletionPorts); ThreadPool.GetAvailableThreads(out int availableThreads, out int availableComplPorts); _threadsUsed = maxThreads - availableThreads; _complPortUsed = maxCompletionPorts - availableComplPorts; _maxThreads = maxThreads; _maxComplPorts = maxCompletionPorts; var pos = World.Player.KnownPosition.GetCoordinates3D(); var biomeId = World.GetBiome(pos.X, pos.Y, pos.Z); var biome = BiomeUtils.GetBiomeById(biomeId); _currentBiomeId = biomeId; _currentBiome = biome; } //); } } base.OnUpdate(gameTime); }
public PostProcessingGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _sampleFramework = services.GetInstance <SampleFramework>(); _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); _clearGBufferRenderer = new ClearGBufferRenderer(GraphicsService); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); _meshRenderer = new MeshRenderer(); _skyRenderer = new SkyRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048); Scene = new Scene(); PostProcessors = new PostProcessorChain(GraphicsService); // Use 2D texture for reticle. var contentManager = services.GetInstance <ContentManager>(); _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; }
protected override void OnDraw(IRenderArgs args) { args.Camera = World.Camera; SkyRenderer.Draw(args); World.Render(args); base.OnDraw(args); Draw2D(args); }
public void Update(UpdateArgs args) { var camera = Camera; args.Camera = camera; if (Player.FOVModifier != _fovModifier) { _fovModifier = Player.FOVModifier; camera.FOV += _fovModifier; camera.UpdateProjectionMatrix(); camera.FOV -= _fovModifier; } camera.Update(args); BrightnessMod = SkyRenderer.BrightnessModifier; SkyRenderer.Update(args); ChunkManager.Update(args); EntityManager.Update(args, SkyRenderer); PhysicsEngine.Update(args.GameTime); var diffuseColor = Color.White.ToVector3() * SkyRenderer.BrightnessModifier; ChunkManager.AmbientLightColor = diffuseColor; if (Math.Abs(ChunkManager.BrightnessModifier - SkyRenderer.BrightnessModifier) > 0f) { ChunkManager.BrightnessModifier = SkyRenderer.BrightnessModifier; } Player.ModelRenderer.DiffuseColor = diffuseColor; Player.Update(args); if (Player.IsInWater) { ChunkManager.FogColor = new Vector3(0.2666667F, 0.6862745F, 0.9607844F) * BrightnessModifier; ChunkManager.FogDistance = (float)Math.Pow(Options.VideoOptions.RenderDistance, 2) * 0.15f; } else { ChunkManager.FogColor = SkyRenderer.WorldFogColor.ToVector3(); ChunkManager.FogDistance = (float)Options.VideoOptions.RenderDistance * 16f * 0.8f; } if (Ticker.Update(args)) { if (DoDaylightcycle) { Time++; } } }
protected override void OnUnload() { // Detach the scene nodes from the scene. if (_skyGroupNode.Parent != null) { _skyGroupNode.Parent.Children.Remove(_skyGroupNode); } _lightGroupNode.Parent.Children.Remove(_lightGroupNode); // Dispose allocated resources. _skyGroupNode.Dispose(false); _lightGroupNode.Dispose(false); if (_enableClouds) { _cloudLayerNode0.CloudMap.Dispose(); _cloudLayerNode1.CloudMap.Dispose(); } if (_cacheSky) { _sceneCaptureNode.RenderToTexture.Texture.Dispose(); _sceneCaptureNode.Dispose(false); _cloudMapRenderer.Dispose(); _skyRenderer.Dispose(); _colorEncoder.Dispose(); _sceneCaptureRenderer.Dispose(); } // Set references to null. _cameraObject = null; _skyGroupNode = null; _lightGroupNode = null; _milkyWayNode = null; _starfieldNode = null; _sunNode = null; _moonNode = null; _scatteringSkyNode = null; _ambientLightNode = null; _sunlightNode = null; _moonlightNode = null; _cloudLayerNode0 = null; _cloudLayerNode1 = null; _sceneCaptureNode = null; SkyboxNode = null; _cloudMapRenderer = null; _skyRenderer = null; _colorEncoder = null; _sceneCaptureRenderer = null; }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public SplitScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); _meshRenderer = new MeshRenderer(); _decalRenderer = new DecalRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048) { EnableSoftParticles = true, }; _transparentSceneRenderer = new SceneRenderer(); _transparentSceneRenderer.Renderers.Add(_meshRenderer); _transparentSceneRenderer.Renderers.Add(_billboardRenderer); _cloudMapRenderer = new CloudMapRenderer(GraphicsService); _shadowMapRenderer = new ShadowMapRenderer(_meshRenderer); _shadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2); _gBufferRenderer = new GBufferRenderer(GraphicsService, _meshRenderer, _decalRenderer); _lightBufferRenderer = new LightBufferRenderer(GraphicsService); _lensFlareRenderer = new LensFlareRenderer(GraphicsService, _spriteBatch); _skyRenderer = new SkyRenderer(GraphicsService); _fogRenderer = new FogRenderer(GraphicsService); _internalDebugRenderer = new DebugRenderer(GraphicsService, _spriteBatch, null); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); Scene = new Scene(); PostProcessors = new PostProcessorChain(GraphicsService); PostProcessors.Add(new HdrFilter(GraphicsService) { MinExposure = 0, MaxExposure = 4, BloomIntensity = 1, BloomThreshold = 0.6f, }); var contentManager = services.GetInstance <ContentManager>(); _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; }
public void Update(UpdateArgs args) { var camera = Camera; args.Camera = camera; /*if (Math.Abs(Player.FOVModifier - _fovModifier) > 0f) * { * _fovModifier = Player.FOVModifier; * * camera.FOV += _fovModifier; * camera.UpdateProjectionMatrix(); * camera.FOV -= _fovModifier; * }*/ camera.Update(args); //_brightnessMod = SkyRenderer.BrightnessModifier; SkyRenderer.Update(args); ChunkManager.Update(args); EntityManager.Update(args); PhysicsEngine.Update(args.GameTime); if (Math.Abs(_brightnessMod - SkyRenderer.BrightnessModifier) > 0f) { _brightnessMod = SkyRenderer.BrightnessModifier; var diffuseColor = Color.White.ToVector3() * SkyRenderer.BrightnessModifier; ChunkManager.AmbientLightColor = diffuseColor; if (Math.Abs(ChunkManager.Shaders.BrightnessModifier - SkyRenderer.BrightnessModifier) > 0f) { ChunkManager.Shaders.BrightnessModifier = SkyRenderer.BrightnessModifier; } var modelRenderer = Player?.ModelRenderer; if (modelRenderer != null) { modelRenderer.DiffuseColor = diffuseColor; } } Player.Update(args); }
private void UpdateCubeMap(TimeSpan deltaTime) { if (_cloudMapRenderer == null) { // This is the first call of UpdateCubeMap. Create the renderers which // we need to render the cube map. // The CloudMapRenderer creates and animates the LayeredCloudMaps. _cloudMapRenderer = new CloudMapRenderer(_graphicsService); // The SkyRenderer renders SkyNodes. _skyRenderer = new SkyRenderer(_graphicsService); // We use a ColorEncoder to encode a HDR image in a normal Color texture. _colorEncoder = new ColorEncoder(_graphicsService) { SourceEncoding = ColorEncoding.Rgb, TargetEncoding = SkyboxNode.Encoding, }; // The SceneCaptureRenderer handles SceneCaptureNodes. We need to specify // a render callback which is called in SceneCaptureNode.Render(). _sceneCaptureRenderer = new SceneCaptureRenderer(RenderSky); // Normally, the render context is managed by the graphics service. // When we call renderer outside of a GraphicsScreen, we have to use our // own context instance. _context = new RenderContext(_graphicsService); } // Update render context. For off-screen rendering we must at least update // the time properties (e.g. for cloud animations). _context.DeltaTime = deltaTime; _context.Time += deltaTime; _context.Frame++; // Create cloud maps. _cloudMapRenderer.Render(_skyGroupNode.Children, _context); // Capture sky in cube map. _sceneCaptureRenderer.Render(_sceneCaptureNode, _context); }
public void Render(IRenderArgs args) { Graphics.DepthStencilState = DepthStencilState.Default; Graphics.SamplerStates[0] = SamplerState.PointWrap; SkyRenderer.Draw(args); ChunkManager.Draw(args, RenderStage.OpaqueFullCube, RenderStage.Opaque); EntityManager.Render(args); ChunkManager.Draw(args, RenderStage.Transparent, RenderStage.Translucent, RenderStage.Animated, // RenderStage.AnimatedTranslucent, RenderStage.Liquid); Player.Render(args); }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public DeferredGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); // Let's create the necessary scene node renderers: // The current sample contains MeshNodes (opaque and transparent), DecalNodes // and ParticleSystemNodes (transparent). _meshRenderer = new MeshRenderer(); _decalRenderer = new DecalRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048) { EnableSoftParticles = true, // If you have an extreme amount of particles that cover the entire screen, // you can turn on offscreen rendering to improve performance. //EnableOffscreenRendering = true, }; // The _alphaBlendSceneRenderer combines all renderers for transparent // (= alpha blended) objects. AlphaBlendSceneRenderer = new SceneRenderer(); AlphaBlendSceneRenderer.Renderers.Add(_meshRenderer); AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer); // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.) _cloudMapRenderer = new CloudMapRenderer(GraphicsService); // Shadows _shadowMapRenderer = new ShadowMapRenderer(_meshRenderer); _shadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2); // Renderers which create the intermediate render targets: // Those 2 renderers are implemented in this sample. Those functions could // be implemented directly in this class but we have created separate classes // to make the code more readable. _gBufferRenderer = new GBufferRenderer(GraphicsService, _meshRenderer, _decalRenderer); LightBufferRenderer = new LightBufferRenderer(GraphicsService); // Other specialized renderers: _lensFlareRenderer = new LensFlareRenderer(GraphicsService, _spriteBatch); _skyRenderer = new SkyRenderer(GraphicsService); _fogRenderer = new FogRenderer(GraphicsService); _internalDebugRenderer = new DebugRenderer(GraphicsService, _spriteBatch, null); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); Scene = new Scene(); // This screen needs a HDR filter to map high dynamic range values back to // low dynamic range (LDR). PostProcessors = new PostProcessorChain(GraphicsService); PostProcessors.Add(new HdrFilter(GraphicsService) { EnableBlueShift = true, BlueShiftCenter = 0.00007f, BlueShiftRange = 0.5f, BlueShiftColor = new Vector3F(0, 0, 2f), MinExposure = 0, MaxExposure = 10, BloomIntensity = 1, BloomThreshold = 0.6f, }); // Use 2D texture for reticle. var contentManager = services.GetInstance <ContentManager>(); _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("Default"); DebugRenderer = new DebugRenderer(GraphicsService, _spriteBatch, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; EnableLod = true; }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public DeferredGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { var contentManager = services.GetInstance <ContentManager>(); SpriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); // Let's create the necessary scene node renderers: // The current sample contains MeshNodes (opaque and transparent), DecalNodes // and ParticleSystemNodes (transparent). MeshRenderer = new MeshRenderer(); _decalRenderer = new DecalRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048) { EnableSoftParticles = true, // If you have an extreme amount of particles that cover the entire screen, // you can turn on offscreen rendering to improve performance. //EnableOffscreenRendering = true, }; // The _alphaBlendSceneRenderer combines all renderers for transparent // (= alpha blended) objects. AlphaBlendSceneRenderer = new SceneRenderer(); AlphaBlendSceneRenderer.Renderers.Add(MeshRenderer); AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer); AlphaBlendSceneRenderer.Renderers.Add(new WaterRenderer(GraphicsService)); #if !TRIAL // The FogSphereSample is not included in the trial version. AlphaBlendSceneRenderer.Renderers.Add(new FogSphereRenderer(GraphicsService)); #endif // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.) _cloudMapRenderer = new CloudMapRenderer(GraphicsService); // Renderer for SceneCaptureNodes. See also SceneCapture2DSample. // In the constructor we specify a method is called in SceneCaptureRenderer.Render() // when the scene must be rendered for the SceneCaptureNodes. _sceneCaptureRenderer = new SceneCaptureRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context); // Render scene (with post-processing, with lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, true, true, false, false); }); // Renderer for PlanarReflectionNodes. See also PlanarReflectionSample. // In the constructor we specify a method is called in PlanarReflectionRenderer.Render() // to create the reflection images. _planarReflectionRenderer = new PlanarReflectionRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context); // Planar reflections are often for WaterNodes. These nodes should not be rendered // into their own reflection map. But when the water surface is displaced by waves, // some waves could be visible in the reflection. // Simple solution: Do not render any water nodes into the reflection map. for (int i = 0; i < sceneQuery.RenderableNodes.Count; i++) { if (sceneQuery.RenderableNodes[i] is WaterNode) { sceneQuery.RenderableNodes[i] = null; } } // Render scene (no post-processing, no lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, false, false, false, false); }); _waterWavesRenderer = new WaterWavesRenderer(GraphicsService); // Shadows _shadowMapRenderer = new ShadowMapRenderer(MeshRenderer); _shadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2); // Renderers which create the intermediate render targets: // Those 2 renderers are implemented in this sample. Those functions could // be implemented directly in this class but we have created separate classes // to make the code more readable. _gBufferRenderer = new GBufferRenderer(GraphicsService, MeshRenderer, _decalRenderer); LightBufferRenderer = new LightBufferRenderer(GraphicsService); // Other specialized renderers: _lensFlareRenderer = new LensFlareRenderer(GraphicsService, SpriteBatch); _skyRenderer = new SkyRenderer(GraphicsService); _fogRenderer = new FogRenderer(GraphicsService); _internalDebugRenderer = new DebugRenderer(GraphicsService, SpriteBatch, null); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); Scene = new Scene(); // This screen needs a HDR filter to map high dynamic range values back to // low dynamic range (LDR). PostProcessors = new PostProcessorChain(GraphicsService); PostProcessors.Add(new HdrFilter(GraphicsService) { EnableBlueShift = true, BlueShiftCenter = 0.00007f, BlueShiftRange = 0.5f, BlueShiftColor = new Vector3F(0, 0, 2f), MinExposure = 0, MaxExposure = 10, BloomIntensity = 1, BloomThreshold = 0.6f, }); _underwaterPostProcessor = new UnderwaterPostProcessor(GraphicsService, contentManager); PostProcessors.Add(_underwaterPostProcessor); // Use 2D texture for reticle. _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("Default"); DebugRenderer = new DebugRenderer(GraphicsService, SpriteBatch, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; EnableLod = true; }
public LdrSkySample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); GameObjectService.Objects.Add(_cameraObject); var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); _cieSkyFilter = new CieSkyFilter(GraphicsService); _cieSkyFilter.Exposure = 5; _cieSkyFilter.Strength = 0.9f; _gradientSky = new GradientSkyNode(); //_gradientSky.GroundColor = new Vector4F(0, 0, 1, 1); //_gradientSky.ZenithColor = new Vector4F(0, 0, 1, 1); //_gradientSky.FrontColor = new Vector4F(0, 0, 1, 1); //_gradientSky.BackColor = new Vector4F(0, 0, 1, 1); //_gradientSky.FrontZenithShift = 0.3f; //_gradientSky.FrontGroundShift = 0.1f; //_gradientSky.BackGroundShift = 0.1f; _gradientSky.CieSkyStrength = 0; _gradientTextureSky = new GradientTextureSkyNode(); _gradientTextureSky.TimeOfDay = _time.TimeOfDay; _gradientTextureSky.Color = new Vector4F(1); _gradientTextureSky.FrontTexture = ContentManager.Load <Texture2D>("Sky/GradientSkyFront"); _gradientTextureSky.BackTexture = ContentManager.Load <Texture2D>("Sky/GradientSkyBack"); _gradientTextureSky.CieSkyStrength = 1; _scatteringSky = new ScatteringSkyNode(); _scatteringSky.SunIntensity *= 2; _scatteringSky.BetaMie *= 2; _scatteringSky.GMie = 0.75f; _scatteringSky.ScaleHeight = _scatteringSky.AtmosphereHeight * 0.25f; InitializeStarfield(); _cloudMapRenderer = new CloudMapRenderer(GraphicsService); _skyRenderer = new SkyRenderer(GraphicsService); _milkyWay = ContentManager.Load <TextureCube>("Sky/MilkyWay"); _milkyWaySkybox = new SkyboxNode(_milkyWay) { Color = new Vector3F(0.05f) }; _sun = new SkyObjectNode { GlowColor0 = new Vector3F(1, 1, 1) * 5, GlowExponent0 = 4000, //GlowColor1 = new Vector3F(0.4f) * 0.1f, //GlowExponent1 = 100 }; _moon = new SkyObjectNode { Texture = new PackedTexture(ContentManager.Load <Texture2D>("Sky/Moon")), SunLight = new Vector3F(1, 1, 1) * 1, AmbientLight = new Vector3F(0.001f) * 1, LightWrap = 0.1f, LightSmoothness = 1, AngularDiameter = new Vector2F(MathHelper.ToRadians(5)), GlowColor0 = new Vector3F(0.005f * 0), GlowCutoffThreshold = 0.001f, GlowExponent0 = 100 }; var cloudMap = new LayeredCloudMap { Density = 10, Coverage = 0.5f, Size = 1024, }; var scale = CreateScale(0.2f); cloudMap.Layers[0] = new CloudMapLayer(null, scale * CreateScale(1), -0.5f, 1, 0.011f * 0); cloudMap.Layers[1] = new CloudMapLayer(null, scale * CreateScale(1.7f), -0.5f, 1f / 2f, 0.017f * 0); cloudMap.Layers[2] = new CloudMapLayer(null, scale * CreateScale(3.97f), -0.5f, 1f / 4f, 0.033f * 0); cloudMap.Layers[3] = new CloudMapLayer(null, scale * CreateScale(8.1f), -0.5f, 1f / 8f, 0.043f * 0); cloudMap.Layers[4] = new CloudMapLayer(null, scale * CreateScale(16, 17), -0.5f, 1f / 16f, 0.051f * 0); cloudMap.Layers[5] = new CloudMapLayer(null, scale * CreateScale(32, 31), -0.5f, 1f / 32f, 0.059f * 0); cloudMap.Layers[6] = new CloudMapLayer(null, scale * CreateScale(64, 67), -0.5f, 1f / 64f, 0.067f * 0); cloudMap.Layers[7] = new CloudMapLayer(null, scale * CreateScale(128, 127), -0.5f, 1f / 128f, 0.081f * 0); _cloudLayerNode = new CloudLayerNode(cloudMap) { ForwardScatterScale = 2.5f, ForwardScatterOffset = 0.3f, TextureMatrix = CreateScale(0.5f), SkyCurvature = 0.9f, NumberOfSamples = 16, }; _ephemeris = new Ephemeris(); // Approx. location of Ternberg: Latitude = 48, Longitude = 15, Altitude = 300 _ephemeris.Latitude = 0; _ephemeris.Longitude = 15; _ephemeris.Altitude = 300; #if XBOX //_time = new DateTime(2013, 5, 1, 17, 17, 0, 0); _time = DateTime.Now; #else _time = new DateTimeOffset(2013, 5, 1, 12, 0, 0, 0, TimeSpan.Zero); //_time = DateTimeOffset.UtcNow; #endif UpdateEphemeris(); _milkyWaySkybox.DrawOrder = 0; _starfield.DrawOrder = 1; _sun.DrawOrder = 2; _moon.DrawOrder = 3; _scatteringSky.DrawOrder = 4; _gradientSky.DrawOrder = 4; _gradientTextureSky.DrawOrder = 4; _cloudLayerNode.DrawOrder = 5; _skyNodes = new SceneNode[] { _milkyWaySkybox, _starfield, _sun, _moon, _scatteringSky, //_gradientSky, //_gradientTextureSky, _cloudLayerNode, }; var graphicsDevice = GraphicsService.GraphicsDevice; _skybox = new SkyboxNode( new RenderTargetCube(graphicsDevice, 512, false, SurfaceFormat.Color, DepthFormat.None)) { Encoding = ColorEncoding.Rgbm, }; _hdrFilter = new HdrFilter(GraphicsService) { MinExposure = 0.5f, MaxExposure = 2, BloomIntensity = 1, BloomThreshold = 0.6f, AdaptionSpeed = 100, }; _colorEncoder = new ColorEncoder(GraphicsService) { SourceEncoding = ColorEncoding.Rgb, TargetEncoding = _skybox.Encoding, }; }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- public DeferredGraphicsScreen(IServiceLocator services) : base(services.GetInstance <IGraphicsService>()) { _sampleFramework = services.GetInstance <SampleFramework>(); var contentManager = services.GetInstance <ContentManager>(); SpriteBatch = GraphicsService.GetSpriteBatch(); // Let's create the necessary scene node renderers: #if !XBOX360 TerrainRenderer = new TerrainRenderer(GraphicsService); #endif MeshRenderer = new MeshRenderer(); // The _opaqueMeshSceneRenderer combines all renderers for opaque // (= not alpha blended) meshes. _opaqueMeshSceneRenderer = new SceneRenderer(); #if !XBOX360 _opaqueMeshSceneRenderer.Renderers.Add(TerrainRenderer); #endif _opaqueMeshSceneRenderer.Renderers.Add(MeshRenderer); _decalRenderer = new DecalRenderer(GraphicsService); _billboardRenderer = new BillboardRenderer(GraphicsService, 2048) { EnableSoftParticles = true, // If you have an extreme amount of particles that cover the entire screen, // you can turn on offscreen rendering to improve performance. //EnableOffscreenRendering = true, }; // The AlphaBlendSceneRenderer combines all renderers for transparent // (= alpha blended) objects. AlphaBlendSceneRenderer = new SceneRenderer(); AlphaBlendSceneRenderer.Renderers.Add(MeshRenderer); AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer); AlphaBlendSceneRenderer.Renderers.Add(new WaterRenderer(GraphicsService)); AlphaBlendSceneRenderer.Renderers.Add(new FogSphereRenderer(GraphicsService)); AlphaBlendSceneRenderer.Renderers.Add(new VolumetricLightRenderer(GraphicsService)); #if !XBOX360 // Update terrain clipmaps. (Only necessary if TerrainNodes are used.) _terrainClipmapRenderer = new TerrainClipmapRenderer(GraphicsService); #endif // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.) _cloudMapRenderer = new CloudMapRenderer(GraphicsService); // Renderer for SceneCaptureNodes. See also SceneCapture2DSample. // In the constructor we specify a method which is called in SceneCaptureRenderer.Render() // when the scene must be rendered for the SceneCaptureNodes. SceneCaptureRenderer = new SceneCaptureRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context); // Render scene (with post-processing, with lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, true, true, false, false); }); // Renderer for PlanarReflectionNodes. See also PlanarReflectionSample. // In the constructor we specify a method which is called in PlanarReflectionRenderer.Render() // to create the reflection images. _planarReflectionRenderer = new PlanarReflectionRenderer(context => { // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context); var planarReflectionNode = (PlanarReflectionNode)context.ReferenceNode; // Planar reflections are often for WaterNodes. These nodes should not be rendered // into their own reflection map because when the water surface is displaced by waves, // some waves could be visible in the reflection. // --> Remove the water node from the renderable nodes. (In our samples, the water // node is the parent of the reflection node.) if (planarReflectionNode.Parent is WaterNode) { var index = sceneQuery.RenderableNodes.IndexOf(planarReflectionNode.Parent); if (index >= 0) { sceneQuery.RenderableNodes[index] = null; } } // Render scene (no post-processing, no lens flares, no debug rendering, no reticle). RenderScene(sceneQuery, context, false, false, false, false); }); _waterWavesRenderer = new WaterWavesRenderer(GraphicsService); // The shadow map renderer renders a depth image from the viewpoint of the light and // stores it in LightNode.Shadow.ShadowMap. ShadowMapRenderer = new ShadowMapRenderer(context => { var query = context.Scene.Query <ShadowCasterQuery>(context.CameraNode, context); if (query.ShadowCasters.Count == 0) { return(false); } _opaqueMeshSceneRenderer.Render(query.ShadowCasters, context); return(true); }); // The shadow mask renderer evaluates the shadow maps, does shadow filtering // and stores the resulting shadow factor in a screen space image //(see LightNode.Shadow.ShadowMask/ShadowMaskChannel). ShadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2); // Optionally, we can blur the shadow mask to make the shadows smoother. var blur = new Blur(GraphicsService) { IsAnisotropic = false, IsBilateral = true, EdgeSoftness = 0.05f, Scale = 1f, Enabled = false, // Disable blur by default. }; blur.InitializeGaussianBlur(11, 3, true); ShadowMaskRenderer.Filter = blur; // Renderers which create the intermediate render targets: // Those 2 renderers are implemented in this sample. Those functions could // be implemented directly in this class but we have created separate classes // to make the code more readable. _gBufferRenderer = new GBufferRenderer(GraphicsService, _opaqueMeshSceneRenderer, _decalRenderer); LightBufferRenderer = new LightBufferRenderer(GraphicsService); // Other specialized renderers: _lensFlareRenderer = new LensFlareRenderer(GraphicsService); _skyRenderer = new SkyRenderer(GraphicsService); _fogRenderer = new FogRenderer(GraphicsService); _internalDebugRenderer = new DebugRenderer(GraphicsService, null); _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService); Scene = new Scene(); // This screen needs a HDR filter to map high dynamic range values back to // low dynamic range (LDR). PostProcessors = new PostProcessorChain(GraphicsService); PostProcessors.Add(new HdrFilter(GraphicsService) { EnableBlueShift = true, BlueShiftCenter = 0.0004f, BlueShiftRange = 0.5f, //BlueShiftColor = new Vector3F(1.05f / 4f, 0.97f / 4f, 1.27f / 4f), // Default physically-based blue-shift BlueShiftColor = new Vector3F(0.25f, 0.25f, 0.7f), // More dramatic blue-shift MinExposure = 0, MaxExposure = 10, BloomIntensity = 1, BloomThreshold = 0.6f, }); _underwaterPostProcessor = new UnderwaterPostProcessor(GraphicsService, contentManager); PostProcessors.Add(_underwaterPostProcessor); // Use 2D texture for reticle. _reticle = contentManager.Load <Texture2D>("Reticle"); // Use the sprite font of the GUI. var uiContentManager = services.GetInstance <ContentManager>("UIContent"); var spriteFont = uiContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); DebugRenderer = new DebugRenderer(GraphicsService, spriteFont) { DefaultColor = new Color(0, 0, 0), DefaultTextPosition = new Vector2F(10), }; EnableLod = true; }
/// <summary> /// Creates the sky renderer and loads all the cube maps /// for the sky box /// </summary> public void CreateSky() { Sky = new SkyRenderer( TextureManager.GetTexture(ContentPaths.Sky.moon), TextureManager.GetTexture(ContentPaths.Sky.sun), Content.Load<TextureCube>(ContentPaths.Sky.day_sky), Content.Load<TextureCube>(ContentPaths.Sky.night_sky), TextureManager.GetTexture(ContentPaths.Gradients.skygradient), Content.Load<Model>(ContentPaths.Models.sphereLowPoly), Content.Load<Effect>(ContentPaths.Shaders.SkySphere)); }
private void UpdateCubeMap(TimeSpan deltaTime) { if (_cloudMapRenderer == null) { // This is the first call of UpdateCubeMap. Create the renderers which // we need to render the cube map. // The CloudMapRenderer creates and animates the LayeredCloudMaps. _cloudMapRenderer = new CloudMapRenderer(_graphicsService); // The SkyRenderer renders SkyNodes. _skyRenderer = new SkyRenderer(_graphicsService); // We use a ColorEncoder to encode a HDR image in a normal Color texture. _colorEncoder = new ColorEncoder(_graphicsService) { SourceEncoding = ColorEncoding.Rgb, TargetEncoding = SkyboxNode.Encoding, }; // The SceneCaptureRenderer handles SceneCaptureNodes. We need to specify // a delegate which is called in SceneCaptureNode.Render(). _sceneCaptureRenderer = new SceneCaptureRenderer(context => { var graphicsDevice = _graphicsService.GraphicsDevice; var renderTargetPool = _graphicsService.RenderTargetPool; // We have to render into this render target. var ldrTarget = context.RenderTarget; // Reset render states. graphicsDevice.BlendState = BlendState.Opaque; graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; // Use an intermediate HDR render target with the same resolution as the final target. var format = new RenderTargetFormat(ldrTarget) { SurfaceFormat = SurfaceFormat.HdrBlendable, DepthStencilFormat = DepthFormat.Depth24Stencil8 }; var hdrTarget = renderTargetPool.Obtain2D(format); graphicsDevice.SetRenderTarget(hdrTarget); context.RenderTarget = hdrTarget; graphicsDevice.Clear(Color.Black); // Render the sky. _skyRenderer.Render(_skyGroupNode.Children, context); // Convert the HDR image to RGBM image. context.SourceTexture = hdrTarget; context.RenderTarget = ldrTarget; _colorEncoder.Process(context); context.SourceTexture = null; // Clean up. renderTargetPool.Recycle(hdrTarget); context.RenderTarget = ldrTarget; }); // Normally, the render context is managed by the graphics service. // When we call renderer outside of a GraphicsScreen, we have to use our // own context instance. _context = new RenderContext(_graphicsService); } // Update render context. // Frame needs to be updated to tell the renderers that this is a new "frame". // (Otherwise, they might abort early to avoid duplicate work in the same frame.) _context.Frame++; // DeltaTime is relevant for renderers such as the CloudMapRenderer because it // might have to animate the clouds. _context.DeltaTime = deltaTime; // Create cloud maps. _cloudMapRenderer.Render(_skyGroupNode.Children, _context); // Capture sky in cube map. _sceneCaptureRenderer.Render(_sceneCaptureNode, _context); }