Changed, Visual mode: adjusted fog density calculation to better match with GZDoom.

Fixed, Visual mode: alpha-based texture picking didn't work correctly on HiRes images.
Fixed, Visual mode: fog density was calculated incorrectly for things lit by dynamic lights.
Fixed, Edit Sector window, UDMF: "Fade" and "Light" color pickers initial values were incorrect when displaying mixed values.
Fixed, Edit Thing window, UDMF: "Color" color picker initial value was incorrect when displaying mixed values.
This commit is contained in:
MaxED 2016-03-23 21:26:26 +00:00 committed by spherallic
parent b9d86faf3e
commit 5fe6c91ffc
7 changed files with 101 additions and 113 deletions

View file

@ -51,6 +51,7 @@ namespace CodeImp.DoomBuilder.Controls
{
// Apply new color
panel.BackColor = dialog.Color;
//mxd. Dispatch Event
if(ColorChanged != null) ColorChanged(this, EventArgs.Empty);
}
@ -59,14 +60,10 @@ namespace CodeImp.DoomBuilder.Controls
// Resized
private void ColorControl_Resize(object sender, EventArgs e)
{
try
{
button.Left = ClientSize.Width - button.Width;
panel.Left = ClientSize.Width - button.Width - panel.Width - 3;
label.Left = 0;
label.Width = panel.Left;
}
catch(Exception) { }
button.Left = ClientSize.Width - button.Width;
panel.Left = ClientSize.Width - button.Width - panel.Width - 3;
label.Left = 0;
label.Width = panel.Left;
}
// Mouse pressed on button

View file

@ -2,10 +2,10 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization;
using CodeImp.DoomBuilder.Rendering;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
#endregion
@ -15,93 +15,109 @@ namespace CodeImp.DoomBuilder.GZBuilder.Controls
{
#region ================== Events
public event EventHandler OnValueChanged; //mxd
public event EventHandler OnValueChanged;
#endregion
#region ================== Variables
private int defaultValue;
private int defaultvalue;
private string field;
private bool blockUpdate;
private bool blockupdate;
private bool blockevents;
#endregion
#region ================== Properties
public int DefaultValue { get { return defaultValue; } set { defaultValue = value; } }
public int DefaultValue { get { return defaultvalue; } set { defaultvalue = value; } }
public string Label { get { return cpColor.Label; } set { cpColor.Label = value; } }
public string Field { get { return field; } set { field = value; } }
#endregion
#region ================== Constructor
public ColorFieldsControl()
{
InitializeComponent();
}
public void SetValueFrom(UniFields fields)
#endregion
#region ================== Methods
public void SetValueFrom(UniFields fields, bool first)
{
string newValue = String.Format("{0:X6}", UniFields.GetInteger(fields, field, defaultValue));
tbColor.Text = ((!string.IsNullOrEmpty(tbColor.Text) && tbColor.Text != newValue) ? "" : newValue);
CheckColor();
blockevents = true;
string colorval = String.Format("{0:X6}", UniFields.GetInteger(fields, field, defaultvalue));
if(first)
{
tbColor.Text = colorval;
}
else if(!string.IsNullOrEmpty(tbColor.Text) && colorval != tbColor.Text)
{
blockupdate = true;
tbColor.Text = string.Empty;
cpColor.Color = PixelColor.FromInt(defaultvalue).WithAlpha(255);
blockupdate = false;
CheckColor();
}
blockevents = false;
}
public void ApplyTo(UniFields fields, int oldValue)
public void ApplyTo(UniFields fields, int oldvalue)
{
if(string.IsNullOrEmpty(tbColor.Text))
{
UniFields.SetInteger(fields, field, oldValue, defaultValue);
}
else
{
UniFields.SetInteger(fields, field, (cpColor.Color.ToInt() & 0x00ffffff), defaultValue);
}
int colorval = !string.IsNullOrEmpty(tbColor.Text) ? (cpColor.Color.ToInt() & 0x00FFFFFF) : oldvalue;
UniFields.SetInteger(fields, field, colorval, defaultvalue);
}
private void CheckColor()
{
bool changed = string.IsNullOrEmpty(tbColor.Text) || (cpColor.Color.ToInt() & 0x00ffffff) != defaultValue;
bool changed = string.IsNullOrEmpty(tbColor.Text) || (cpColor.Color.ToInt() & 0x00FFFFFF) != defaultvalue;
bReset.Visible = changed;
tbColor.ForeColor = changed ? SystemColors.WindowText : SystemColors.GrayText;
tbColor.ForeColor = (changed ? SystemColors.WindowText : SystemColors.GrayText);
}
#endregion
#region ================== Events
private void bReset_Click(object sender, EventArgs e)
{
cpColor.Color = PixelColor.FromInt(defaultValue).WithAlpha(255);
cpColor.Focus(); // Otherwise the focus will go to cpColor's textbox, which is not what we want
cpColor.Color = PixelColor.FromInt(defaultvalue).WithAlpha(255);
cpColor_ColorChanged(this, EventArgs.Empty);
}
private void cpColor_ColorChanged(object sender, EventArgs e)
{
if(blockUpdate) return;
if(blockupdate) return;
blockUpdate = true;
tbColor.Text = String.Format("{0:X6}", (cpColor.Color.ToInt() & 0x00ffffff));
blockUpdate = false;
blockupdate = true;
tbColor.Text = String.Format("{0:X6}", (cpColor.Color.ToInt() & 0x00FFFFFF));
blockupdate = false;
CheckColor();
if(OnValueChanged != null) OnValueChanged(this, EventArgs.Empty);
if(!blockevents && OnValueChanged != null) OnValueChanged(this, EventArgs.Empty);
}
private void tbColor_TextChanged(object sender, EventArgs e)
{
if(blockUpdate) return;
int colorVal;
if(int.TryParse(tbColor.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out colorVal))
if(blockupdate) return;
int colorval;
if(int.TryParse(tbColor.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out colorval))
{
colorVal = General.Clamp(colorVal, 0, 16777215);
blockUpdate = true;
cpColor.Color = PixelColor.FromInt(colorVal).WithAlpha(255);
blockUpdate = false;
colorval = General.Clamp(colorval, 0, 0xFFFFFF);
cpColor.Color = PixelColor.FromInt(colorval).WithAlpha(255);
}
CheckColor();
if(OnValueChanged != null) OnValueChanged(this, EventArgs.Empty);
if(!blockevents && OnValueChanged != null) OnValueChanged(this, EventArgs.Empty);
}
#endregion

View file

@ -854,17 +854,15 @@ namespace CodeImp.DoomBuilder.Rendering
world = CreateThingPositionMatrix(t);
//mxd. If current thing is light - set it's color to light color
Color4 litcolor;
if(Array.IndexOf(GZBuilder.GZGeneral.GZ_LIGHTS, t.Thing.SRB2Type) != -1 && !fullbrightness)
{
wantedshaderpass += 4; // Render using one of passes, which uses World3D.VertexColor
litcolor = t.LightColor;
vertexcolor = t.LightColor;
}
//mxd. Check if Thing is affected by dynamic lights and set color accordingly
else if(General.Settings.GZDrawLightsMode != LightRenderMode.NONE && !fullbrightness && lightthings.Count > 0)
{
litcolor = GetLitColorForThing(t);
Color4 litcolor = GetLitColorForThing(t);
if(litcolor.ToArgb() != 0)
{
wantedshaderpass += 4; // Render using one of passes, which uses World3D.VertexColor
@ -873,7 +871,6 @@ namespace CodeImp.DoomBuilder.Rendering
}
else
{
litcolor = new Color4();
vertexcolor = new Color4();
}
@ -889,8 +886,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(wantedshaderpass > 7)
{
graphics.Shaders.World3D.World = world;
float fogfactor = (litcolor.ToArgb() != 0 ? VisualThing.LIT_FOG_DENSITY_SCALER : t.FogFactor);
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, fogfactor);
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
}
// Set the colors to use
@ -1195,17 +1191,15 @@ namespace CodeImp.DoomBuilder.Rendering
world = CreateThingPositionMatrix(t);
//mxd. If current thing is light - set it's color to light color
Color4 litcolor;
if(Array.IndexOf(GZBuilder.GZGeneral.GZ_LIGHTS, t.Thing.SRB2Type) != -1 && !fullbrightness)
{
wantedshaderpass += 4; // Render using one of passes, which uses World3D.VertexColor
litcolor = t.LightColor;
vertexcolor = t.LightColor;
}
//mxd. Check if Thing is affected by dynamic lights and set color accordingly
else if(General.Settings.GZDrawLightsMode != LightRenderMode.NONE && !fullbrightness && lightthings.Count > 0)
{
litcolor = GetLitColorForThing(t);
Color4 litcolor = GetLitColorForThing(t);
if(litcolor.ToArgb() != 0)
{
wantedshaderpass += 4; // Render using one of passes, which uses World3D.VertexColor
@ -1214,7 +1208,6 @@ namespace CodeImp.DoomBuilder.Rendering
}
else
{
litcolor = new Color4();
vertexcolor = new Color4();
}
@ -1226,16 +1219,14 @@ namespace CodeImp.DoomBuilder.Rendering
currentshaderpass = wantedshaderpass;
}
//mxd. set variables for fog rendering?
//mxd. Set variables for fog rendering?
if(wantedshaderpass > 7)
{
graphics.Shaders.World3D.World = world;
float curfogfactor = (litcolor.ToArgb() != 0 ? VisualThing.LIT_FOG_DENSITY_SCALER : t.FogFactor);
if(curfogfactor != fogfactor)
if(t.FogFactor != fogfactor)
{
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, curfogfactor);
fogfactor = curfogfactor;
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
fogfactor = t.FogFactor;
}
}
@ -1428,18 +1419,11 @@ namespace CodeImp.DoomBuilder.Rendering
Color4 vertexcolor = new Color4(t.VertexColor);
//check if model is affected by dynamic lights and set color accordingly
Color4 litcolor;
// Check if model is affected by dynamic lights and set color accordingly
if(General.Settings.GZDrawLightsMode != LightRenderMode.NONE && !fullbrightness && lightthings.Count > 0)
{
litcolor = GetLitColorForThing(t);
graphics.Shaders.World3D.VertexColor = vertexcolor + litcolor;
}
graphics.Shaders.World3D.VertexColor = vertexcolor + GetLitColorForThing(t);
else
{
graphics.Shaders.World3D.VertexColor = vertexcolor;
litcolor = new Color4();
}
// Determine the shader pass we want to use for this object
int wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass);
@ -1469,13 +1453,12 @@ namespace CodeImp.DoomBuilder.Rendering
world = General.Map.Data.ModeldefEntries[t.Thing.SRB2Type].Transform * modelscale * modelrotation * t.Position;
ApplyMatrices3D();
//mxd. set variables for fog rendering
//mxd. Set variables for fog rendering
if(wantedshaderpass > 7)
{
graphics.Shaders.World3D.World = world;
if(t.Thing.Sector != null) graphics.Shaders.World3D.LightColor = t.Thing.Sector.FogColor;
float fogfactor = (litcolor.ToArgb() != 0 ? VisualThing.LIT_FOG_DENSITY_SCALER : t.FogFactor);
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, fogfactor);
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
}
for(int i = 0; i < group.Key.Model.Meshes.Count; i++)
@ -1545,18 +1528,11 @@ namespace CodeImp.DoomBuilder.Rendering
t.Update();
Color4 vertexcolor = new Color4(t.VertexColor);
//check if model is affected by dynamic lights and set color accordingly
Color4 litcolor;
// Check if model is affected by dynamic lights and set color accordingly
if(General.Settings.GZDrawLightsMode != LightRenderMode.NONE && !fullbrightness && lightthings.Count > 0)
{
litcolor = GetLitColorForThing(t);
graphics.Shaders.World3D.VertexColor = vertexcolor + litcolor;
}
graphics.Shaders.World3D.VertexColor = vertexcolor + GetLitColorForThing(t);
else
{
graphics.Shaders.World3D.VertexColor = vertexcolor;
litcolor = new Color4();
}
// Determine the shader pass we want to use for this object
int wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass);
@ -1586,13 +1562,12 @@ namespace CodeImp.DoomBuilder.Rendering
world = General.Map.Data.ModeldefEntries[t.Thing.SRB2Type].Transform * modelscale * modelrotation * t.Position;
ApplyMatrices3D();
//mxd. set variables for fog rendering
//mxd. Set variables for fog rendering
if(wantedshaderpass > 7)
{
graphics.Shaders.World3D.World = world;
if(t.Thing.Sector != null) graphics.Shaders.World3D.LightColor = t.Thing.Sector.FogColor;
float fogfactor = (litcolor.ToArgb() != 0 ? VisualThing.LIT_FOG_DENSITY_SCALER : t.FogFactor);
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, fogfactor);
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
}
GZModel model = General.Map.Data.ModeldefEntries[t.Thing.SRB2Type].Model;

View file

@ -33,7 +33,8 @@ namespace CodeImp.DoomBuilder.VisualModes
{
#region ================== Constants
public const float FOG_DENSITY_SCALER = -1.442692f / 256000f; //-1.442692f / 64000f; //mxd
private const float FOG_DENSITY_SCALER = -1.442692f / 512000f; //mxd. It's -1.442692f / 64000f in GZDoom...;
private const int FADE_MULTIPLIER = 4; //mxd
#endregion
@ -198,27 +199,27 @@ namespace CodeImp.DoomBuilder.VisualModes
boundingBox = BoundingBoxTools.CalculateBoundingPlane(bbs);
}
//mxd. Calculate fogdistance
//TODO: this doesn't match any GZDoom light mode...
//GZDoom: gl_renderstate.h, SetFog();
//GZDoom: gl_lightlevel.cpp gl_SetFog();
protected float CalculateFogFactor(int brightness) { return CalculateFogFactor(Sector.Sector.FogMode, brightness); }
public static float CalculateFogFactor(SectorFogMode mode, int brightness)
{
float density;
switch (mode)
{
case SectorFogMode.OUTSIDEFOGDENSITY:
density = General.Map.Data.MapInfo.OutsideFogDensity;
break;
//mxd. Calculate fogdistance
//TODO: this doesn't match any GZDoom light mode...
//GZDoom: gl_renderstate.h, SetFog();
//GZDoom: gl_lightlevel.cpp gl_SetFog();
protected float CalculateFogFactor(int brightness) { return CalculateFogFactor(Sector.Sector.FogMode, brightness); }
public static float CalculateFogFactor(SectorFogMode mode, int brightness)
{
float density;
switch(mode)
{
case SectorFogMode.OUTSIDEFOGDENSITY:
density = General.Map.Data.MapInfo.OutsideFogDensity * FADE_MULTIPLIER;
break;
case SectorFogMode.FOGDENSITY:
density = General.Map.Data.MapInfo.FogDensity;
break;
case SectorFogMode.FOGDENSITY:
density = General.Map.Data.MapInfo.FogDensity * FADE_MULTIPLIER;
break;
case SectorFogMode.FADE:
density = General.Clamp(255 - brightness, 30, 255) * 4;
break;
case SectorFogMode.FADE:
density = General.Clamp(255 - brightness, 30, 255) * FADE_MULTIPLIER;
break;
case SectorFogMode.CLASSIC:
density = General.Clamp(255 - brightness, 30, 255);

View file

@ -37,7 +37,6 @@ namespace CodeImp.DoomBuilder.VisualModes
#region ================== Constants
protected const int FIXED_RADIUS = 8; //mxd. Used to render things with zero width and radius
internal const float LIT_FOG_DENSITY_SCALER = 255 * VisualGeometry.FOG_DENSITY_SCALER; //mxd
#endregion

View file

@ -314,8 +314,8 @@ namespace CodeImp.DoomBuilder.Windows
desaturation.Text = General.Clamp(sc.Fields.GetValue("desaturation", 0.0f), 0f, 1f).ToString();
//Sector colors
fadeColor.SetValueFrom(sc.Fields);
lightColor.SetValueFrom(sc.Fields);
fadeColor.SetValueFrom(sc.Fields, true);
lightColor.SetValueFrom(sc.Fields, true);
//Slopes
SetupFloorSlope(sc, true);
@ -421,8 +421,8 @@ namespace CodeImp.DoomBuilder.Windows
if(s.Fields.GetValue("desaturation", 0.0f).ToString() != desaturation.Text) desaturation.Text = "";
//Sector colors
fadeColor.SetValueFrom(s.Fields);
lightColor.SetValueFrom(s.Fields);
fadeColor.SetValueFrom(s.Fields, false);
lightColor.SetValueFrom(s.Fields, false);
//Slopes
SetupFloorSlope(s, false);

View file

@ -213,7 +213,7 @@ namespace CodeImp.DoomBuilder.Windows
score.Text = ft.Fields.GetValue("score", 0).ToString();
health.Text = ft.Fields.GetValue("health", 1).ToString();
alpha.Text = ft.Fields.GetValue("alpha", 1.0f).ToString();
color.SetValueFrom(ft.Fields);
color.SetValueFrom(ft.Fields, true);
scale.SetValues(ft.ScaleX, ft.ScaleY, true);
pitch.Text = ft.Pitch.ToString();
roll.Text = ft.Roll.ToString();
@ -293,7 +293,7 @@ namespace CodeImp.DoomBuilder.Windows
if(t.Fields.GetValue("alpha", 1.0f).ToString() != alpha.Text) alpha.Text = "";
scale.SetValues(t.ScaleX, t.ScaleY, false);
color.SetValueFrom(t.Fields);
color.SetValueFrom(t.Fields, false);
if(t.Pitch.ToString() != pitch.Text) pitch.Text = "";
if(t.Roll.ToString() != roll.Text) roll.Text = "";