Improved texture filtering in Visual Mode. When filtering is Off, it interpolates the mipmaps to reduce the banding effect on walls/floors. With filtering On, it now uses anisotropic filtering up to level 8. (you can change the anisotropy level by editing the 'filteranisotropy' value in the program configuration)

This commit is contained in:
codeimp 2010-10-03 11:51:38 +00:00
parent 1c02c7e62a
commit 59df505df6
4 changed files with 34 additions and 7 deletions

View file

@ -92,6 +92,7 @@ namespace CodeImp.DoomBuilder.Config
private bool toolbargeometry;
private bool toolbartesting;
private bool toolbarfile;
private float filteranisotropy;
// These are not stored in the configuration, only used at runtime
private string defaulttexture;
@ -153,6 +154,7 @@ namespace CodeImp.DoomBuilder.Config
public bool ToolbarGeometry { get { return toolbargeometry; } internal set { toolbargeometry = value; } }
public bool ToolbarTesting { get { return toolbartesting; } internal set { toolbartesting = value; } }
public bool ToolbarFile { get { return toolbarfile; } internal set { toolbarfile = value; } }
public float FilterAnisotropy { get { return filteranisotropy; } internal set { filteranisotropy = value; } }
public string DefaultTexture { get { return defaulttexture; } set { defaulttexture = value; } }
public string DefaultFloorTexture { get { return defaultfloortexture; } set { defaultfloortexture = value; } }
@ -231,6 +233,7 @@ namespace CodeImp.DoomBuilder.Config
toolbargeometry = cfg.ReadSetting("toolbargeometry", true);
toolbartesting = cfg.ReadSetting("toolbartesting", true);
toolbarfile = cfg.ReadSetting("toolbarfile", true);
filteranisotropy = cfg.ReadSetting("filteranisotropy", 8.0f);
// Success
return true;
@ -291,6 +294,7 @@ namespace CodeImp.DoomBuilder.Config
cfg.WriteSetting("toolbargeometry", toolbargeometry);
cfg.WriteSetting("toolbartesting", toolbartesting);
cfg.WriteSetting("toolbarfile", toolbarfile);
cfg.WriteSetting("filteranisotropy", filteranisotropy);
// Save settings configuration
General.WriteLogLine("Saving program configuration...");

View file

@ -229,7 +229,7 @@ namespace CodeImp.DoomBuilder.Rendering
device.Material = material;
// Shader settings
shaders.World3D.SetConstants(General.Settings.VisualBilinear, true);
shaders.World3D.SetConstants(General.Settings.VisualBilinear, true, General.Settings.FilterAnisotropy);
// Texture filters
postfilter = Filter.Point;
@ -317,7 +317,7 @@ namespace CodeImp.DoomBuilder.Rendering
shaders = new ShaderManager(this);
// Font
postfilter = Filter.Box;
postfilter = Filter.Box; // Only for the font. This will be reset in SetupSettings (see below)
font = new TextFont();
fonttexture = new ResourceImage("CodeImp.DoomBuilder.Resources.Font.png");
fonttexture.LoadImage();

View file

@ -45,6 +45,8 @@ namespace CodeImp.DoomBuilder.Rendering
private EffectHandle worldviewproj;
private EffectHandle minfiltersettings;
private EffectHandle magfiltersettings;
private EffectHandle mipfiltersettings;
private EffectHandle maxanisotropysetting;
private EffectHandle modulatecolor;
private EffectHandle highlightcolor;
@ -72,8 +74,10 @@ namespace CodeImp.DoomBuilder.Rendering
texture1 = effect.GetParameter(null, "texture1");
minfiltersettings = effect.GetParameter(null, "minfiltersettings");
magfiltersettings = effect.GetParameter(null, "magfiltersettings");
mipfiltersettings = effect.GetParameter(null, "mipfiltersettings");
modulatecolor = effect.GetParameter(null, "modulatecolor");
highlightcolor = effect.GetParameter(null, "highlightcolor");
maxanisotropysetting = effect.GetParameter(null, "maxanisotropysetting");
}
// Initialize world vertex declaration
@ -101,8 +105,10 @@ namespace CodeImp.DoomBuilder.Rendering
if(worldviewproj != null) worldviewproj.Dispose();
if(minfiltersettings != null) minfiltersettings.Dispose();
if(magfiltersettings != null) magfiltersettings.Dispose();
if(mipfiltersettings != null) mipfiltersettings.Dispose();
if(modulatecolor != null) modulatecolor.Dispose();
if(highlightcolor != null) highlightcolor.Dispose();
if(maxanisotropysetting != null) maxanisotropysetting.Dispose();
// Done
base.Dispose();
@ -114,19 +120,33 @@ namespace CodeImp.DoomBuilder.Rendering
#region ================== Methods
// This sets the constant settings
public void SetConstants(bool bilinear, bool useanisotropic)
public void SetConstants(bool bilinear, bool useanisotropic, float maxanisotropy)
{
if(manager.Enabled)
{
if(bilinear)
{
effect.SetValue(magfiltersettings, (int)TextureFilter.Linear);
if(useanisotropic) effect.SetValue<int>(minfiltersettings, (int)TextureFilter.Anisotropic);
if(useanisotropic)
{
effect.SetValue(magfiltersettings, (int)TextureFilter.Linear);
effect.SetValue(minfiltersettings, (int)TextureFilter.Anisotropic);
effect.SetValue(mipfiltersettings, (int)TextureFilter.Linear);
effect.SetValue(maxanisotropysetting, maxanisotropy);
}
else
{
effect.SetValue(magfiltersettings, (int)TextureFilter.Linear);
effect.SetValue(minfiltersettings, (int)TextureFilter.Linear);
effect.SetValue(mipfiltersettings, (int)TextureFilter.Linear);
effect.SetValue(maxanisotropysetting, 1.0f);
}
}
else
{
effect.SetValue(magfiltersettings, (int)TextureFilter.Point);
effect.SetValue(minfiltersettings, (int)TextureFilter.Point);
effect.SetValue(mipfiltersettings, (int)TextureFilter.Linear);
effect.SetValue(maxanisotropysetting, 1.0f);
}
}
}
@ -168,7 +188,7 @@ namespace CodeImp.DoomBuilder.Rendering
{
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Point);
device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
device.SetSamplerState(0, SamplerState.MipMapLodBias, 0f);
}

View file

@ -32,6 +32,8 @@ texture texture1;
// Filter settings
dword minfiltersettings;
dword magfiltersettings;
dword mipfiltersettings;
float maxanisotropysetting;
// Texture sampler settings
sampler2D texturesamp = sampler_state
@ -39,8 +41,9 @@ sampler2D texturesamp = sampler_state
Texture = <texture1>;
MagFilter = magfiltersettings;
MinFilter = minfiltersettings;
MipFilter = magfiltersettings;
MipFilter = mipfiltersettings;
MipMapLodBias = 0.0f;
MaxAnisotropy = maxanisotropysetting;
};
// Vertex shader