From c987240b5ea677734a04cd4b4b8a7df755cd8430 Mon Sep 17 00:00:00 2001 From: codeimp Date: Thu, 4 Dec 2008 22:35:45 +0000 Subject: [PATCH] added a small layer of fog to the far plane (looks nicer than just cutting off the geometry) --- Source/BuilderModes/VisualModes/BaseVisualMode.cs | 8 ++++++-- Source/Rendering/IRenderer3D.cs | 1 + Source/Rendering/Renderer2D.cs | 10 +++++++--- Source/Rendering/Renderer3D.cs | 15 +++++++++++++++ Source/Windows/PreferencesForm.Designer.cs | 1 + 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Source/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/BuilderModes/VisualModes/BaseVisualMode.cs index a552539c..bced2e61 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualMode.cs @@ -48,7 +48,8 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constants // Object picking interval - private double PICK_INTERVAL = 100.0d; + private const double PICK_INTERVAL = 100.0d; + private const float PICK_RANGE = 0.98f; #endregion @@ -104,7 +105,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Find the object we are aiming at Vector3D start = CameraPosition; Vector3D delta = CameraTarget - CameraPosition; - delta = delta.GetFixedLength(General.Settings.ViewDistance); + delta = delta.GetFixedLength(General.Settings.ViewDistance * PICK_RANGE); VisualPickResult newtarget = PickObject(start, start + delta); // Object changed? @@ -170,6 +171,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Start drawing if(renderer.Start()) { + // Use fog! + renderer.SetFogMode(true); + // Begin with geometry renderer.StartGeometry(); diff --git a/Source/Rendering/IRenderer3D.cs b/Source/Rendering/IRenderer3D.cs index 84e7f497..cb207d61 100644 --- a/Source/Rendering/IRenderer3D.cs +++ b/Source/Rendering/IRenderer3D.cs @@ -56,5 +56,6 @@ namespace CodeImp.DoomBuilder.Rendering // Rendering methods void AddGeometry(VisualGeometry g); void RenderCrosshair(); + void SetFogMode(bool usefog); } } diff --git a/Source/Rendering/Renderer2D.cs b/Source/Rendering/Renderer2D.cs index 1c4fbc90..d8f3b262 100644 --- a/Source/Rendering/Renderer2D.cs +++ b/Source/Rendering/Renderer2D.cs @@ -204,6 +204,7 @@ namespace CodeImp.DoomBuilder.Rendering // Renderstates that count for this whole sequence graphics.Device.SetRenderState(RenderState.CullMode, Cull.None); graphics.Device.SetRenderState(RenderState.ZEnable, false); + graphics.Device.SetRenderState(RenderState.FogEnable, false); graphics.Device.SetStreamSource(0, screenverts, 0, sizeof(FlatVertex)); graphics.Device.SetTransform(TransformState.World, Matrix.Identity); graphics.Shaders.Display2D.Begin(); @@ -590,7 +591,8 @@ namespace CodeImp.DoomBuilder.Rendering { if(renderlayer != RenderLayers.None) throw new InvalidOperationException("Renderer starting called before finished previous layer. Call Finish() first!"); renderlayer = RenderLayers.Plotter; - + graphics.Device.SetRenderState(RenderState.FogEnable, false); + // Rendertargets available? if(plottertex != null) { @@ -625,7 +627,8 @@ namespace CodeImp.DoomBuilder.Rendering { if(renderlayer != RenderLayers.None) throw new InvalidOperationException("Renderer starting called before finished previous layer. Call Finish() first!"); renderlayer = RenderLayers.Things; - + graphics.Device.SetRenderState(RenderState.FogEnable, false); + // Rendertargets available? if(thingstex != null) { @@ -663,7 +666,8 @@ namespace CodeImp.DoomBuilder.Rendering { if(renderlayer != RenderLayers.None) throw new InvalidOperationException("Renderer starting called before finished previous layer. Call Finish() first!"); renderlayer = RenderLayers.Overlay; - + graphics.Device.SetRenderState(RenderState.FogEnable, false); + // Rendertargets available? if(overlaytex != null) { diff --git a/Source/Rendering/Renderer3D.cs b/Source/Rendering/Renderer3D.cs index d69c5cec..f22cc02e 100644 --- a/Source/Rendering/Renderer3D.cs +++ b/Source/Rendering/Renderer3D.cs @@ -44,6 +44,8 @@ namespace CodeImp.DoomBuilder.Rendering private const int RENDER_PASSES = 4; private const float PROJ_NEAR_PLANE = 1f; private const float CROSSHAIR_SCALE = 0.06f; + private const float FOG_RANGE = 0.9f; + #endregion #region ================== Variables @@ -254,6 +256,13 @@ namespace CodeImp.DoomBuilder.Rendering graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); graphics.Device.SetRenderState(RenderState.TextureFactor, -1); + graphics.Device.SetRenderState(RenderState.FogEnable, false); + graphics.Device.SetRenderState(RenderState.FogDensity, 1.0f); + graphics.Device.SetRenderState(RenderState.FogColor, General.Colors.Background.ToInt()); + graphics.Device.SetRenderState(RenderState.FogStart, General.Settings.ViewDistance * FOG_RANGE); + graphics.Device.SetRenderState(RenderState.FogEnd, General.Settings.ViewDistance); + graphics.Device.SetRenderState(RenderState.FogTableMode, FogMode.Linear); + graphics.Device.SetRenderState(RenderState.RangeFogEnable, false); // Matrices ApplyMatrices3D(); @@ -447,6 +456,12 @@ namespace CodeImp.DoomBuilder.Rendering graphics.Shaders.Display2D.EndPass(); graphics.Shaders.Display2D.End(); } + + // This switches fog on and off + public void SetFogMode(bool usefog) + { + graphics.Device.SetRenderState(RenderState.FogEnable, usefog); + } #endregion } diff --git a/Source/Windows/PreferencesForm.Designer.cs b/Source/Windows/PreferencesForm.Designer.cs index e027059b..2c10b7c9 100644 --- a/Source/Windows/PreferencesForm.Designer.cs +++ b/Source/Windows/PreferencesForm.Designer.cs @@ -560,6 +560,7 @@ namespace CodeImp.DoomBuilder.Windows // this.viewdistance.LargeChange = 2; this.viewdistance.Location = new System.Drawing.Point(103, 196); + this.viewdistance.Maximum = 15; this.viewdistance.Minimum = 1; this.viewdistance.Name = "viewdistance"; this.viewdistance.Size = new System.Drawing.Size(150, 42);