2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using SlimDX.Direct3D9;
|
|
|
|
using SlimDX;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
|
|
|
internal sealed class World3DShader : D3DShader
|
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Property handlers
|
2015-09-27 21:09:14 +00:00
|
|
|
private readonly EffectHandle texture1;
|
|
|
|
private readonly EffectHandle worldviewproj;
|
|
|
|
private readonly EffectHandle minfiltersettings;
|
|
|
|
private readonly EffectHandle magfiltersettings;
|
|
|
|
private readonly EffectHandle mipfiltersettings;
|
|
|
|
private readonly EffectHandle maxanisotropysetting;
|
|
|
|
private readonly EffectHandle highlightcolor;
|
2012-04-17 19:13:47 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2015-09-27 21:09:14 +00:00
|
|
|
private readonly EffectHandle vertexColorHadle;
|
2016-02-01 22:04:00 +00:00
|
|
|
private readonly EffectHandle lightPositionAndRadiusHandle; //lights
|
2015-09-27 21:09:14 +00:00
|
|
|
private readonly EffectHandle lightColorHandle;
|
2015-10-02 14:47:34 +00:00
|
|
|
private readonly EffectHandle world;
|
2016-02-01 22:04:00 +00:00
|
|
|
private readonly EffectHandle camPosHandle; //used for fog rendering
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
Cosmetic, actions: renamed "Lower Floor/Ceiling by 8 mp" to "Lower Floor/Ceiling/Thing by 8 mp", "Raise Floor/Ceiling by 8 mp" to "Raise Floor/Ceiling/Thing by 8 mp", "Lower Floor/Ceiling by 1 mp" to "Lower Floor/Ceiling/Thing by 1 mp", "Raise Floor/Ceiling by 1 mp" to "Raise Floor/Ceiling/Thing by 1 mp", "Lower Floor/Ceiling to adjacent sector" to "Lower Floor/Ceiling/Thing to adjacent Sector/Thing", "Raise Floor/Ceiling to adjacent sector" to "Raise Floor/Ceiling/Thing to adjacent Sector/Thing".
Updated, Visual mode, "Raise Floor/Ceiling/Thing to adjacent Sector/Thing" / "Lower Floor/Ceiling/Thing to adjacent Sector/Thing" actions: sectors across targeted sectors are now taken into account when determining target height.
Updated, Visual mode, "Raise Floor/Ceiling/Thing to adjacent Sector/Thing" / "Lower Floor/Ceiling/Thing to adjacent Sector/Thing" actions: the actions can now stack things on top of other things when their bounding boxes intersect.
Internal: cosmetic changes to shader update logic.
Internal: thing bounding box is now used when adding a thing to VisualBlockMap.
2015-12-10 14:34:34 +00:00
|
|
|
private Matrix wwp;
|
|
|
|
public Matrix WorldViewProj
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(wwp != value)
|
Cosmetic, actions: renamed "Lower Floor/Ceiling by 8 mp" to "Lower Floor/Ceiling/Thing by 8 mp", "Raise Floor/Ceiling by 8 mp" to "Raise Floor/Ceiling/Thing by 8 mp", "Lower Floor/Ceiling by 1 mp" to "Lower Floor/Ceiling/Thing by 1 mp", "Raise Floor/Ceiling by 1 mp" to "Raise Floor/Ceiling/Thing by 1 mp", "Lower Floor/Ceiling to adjacent sector" to "Lower Floor/Ceiling/Thing to adjacent Sector/Thing", "Raise Floor/Ceiling to adjacent sector" to "Raise Floor/Ceiling/Thing to adjacent Sector/Thing".
Updated, Visual mode, "Raise Floor/Ceiling/Thing to adjacent Sector/Thing" / "Lower Floor/Ceiling/Thing to adjacent Sector/Thing" actions: sectors across targeted sectors are now taken into account when determining target height.
Updated, Visual mode, "Raise Floor/Ceiling/Thing to adjacent Sector/Thing" / "Lower Floor/Ceiling/Thing to adjacent Sector/Thing" actions: the actions can now stack things on top of other things when their bounding boxes intersect.
Internal: cosmetic changes to shader update logic.
Internal: thing bounding box is now used when adding a thing to VisualBlockMap.
2015-12-10 14:34:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(worldviewproj, value);
|
|
|
|
wwp = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:15:54 +00:00
|
|
|
public BaseTexture Texture1 { set { effect.SetTexture(texture1, value); settingschanged = true; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2015-10-02 14:47:34 +00:00
|
|
|
private Color4 vertexcolor;
|
|
|
|
public Color4 VertexColor
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(vertexcolor != value)
|
2015-10-02 14:47:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(vertexColorHadle, value);
|
|
|
|
vertexcolor = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
|
|
//lights
|
2015-10-02 14:47:34 +00:00
|
|
|
private Color4 lightcolor;
|
|
|
|
public Color4 LightColor
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(lightcolor != value)
|
2015-10-02 14:47:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(lightColorHandle, value);
|
|
|
|
lightcolor = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Vector4 lightpos;
|
|
|
|
public Vector4 LightPositionAndRadius
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(lightpos != value)
|
2015-10-02 14:47:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(lightPositionAndRadiusHandle, value);
|
|
|
|
lightpos = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
|
|
//fog
|
2015-10-02 14:47:34 +00:00
|
|
|
private Vector4 campos;
|
|
|
|
public Vector4 CameraPosition
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(campos != value)
|
2015-10-02 14:47:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(camPosHandle, value);
|
|
|
|
campos = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-20 00:56:59 +00:00
|
|
|
|
2015-10-02 14:47:34 +00:00
|
|
|
private Matrix mworld;
|
|
|
|
public Matrix World
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(mworld != value)
|
2015-10-02 14:47:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(world, value);
|
|
|
|
mworld = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. This sets the highlight color
|
|
|
|
private Color4 hicolor;
|
|
|
|
public Color4 HighlightColor
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(hicolor != value)
|
2015-10-02 14:47:34 +00:00
|
|
|
{
|
|
|
|
effect.SetValue(highlightcolor, value);
|
|
|
|
hicolor = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 19:13:47 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public World3DShader(ShaderManager manager) : base(manager)
|
|
|
|
{
|
|
|
|
// Load effect from file
|
|
|
|
effect = LoadEffect("world3d.fx");
|
|
|
|
|
|
|
|
// Get the property handlers from effect
|
|
|
|
if(effect != null)
|
|
|
|
{
|
|
|
|
worldviewproj = effect.GetParameter(null, "worldviewproj");
|
|
|
|
texture1 = effect.GetParameter(null, "texture1");
|
|
|
|
minfiltersettings = effect.GetParameter(null, "minfiltersettings");
|
|
|
|
magfiltersettings = effect.GetParameter(null, "magfiltersettings");
|
2010-10-03 11:51:38 +00:00
|
|
|
mipfiltersettings = effect.GetParameter(null, "mipfiltersettings");
|
2009-04-19 18:07:22 +00:00
|
|
|
highlightcolor = effect.GetParameter(null, "highlightcolor");
|
2010-10-03 11:51:38 +00:00
|
|
|
maxanisotropysetting = effect.GetParameter(null, "maxanisotropysetting");
|
2012-04-17 19:13:47 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
vertexColorHadle = effect.GetParameter(null, "vertexColor");
|
|
|
|
//lights
|
|
|
|
lightPositionAndRadiusHandle = effect.GetParameter(null, "lightPosAndRadius");
|
|
|
|
lightColorHandle = effect.GetParameter(null, "lightColor");
|
|
|
|
//fog
|
2016-01-11 13:00:52 +00:00
|
|
|
camPosHandle = effect.GetParameter(null, "campos");
|
2012-05-20 00:56:59 +00:00
|
|
|
|
2015-10-02 14:47:34 +00:00
|
|
|
world = effect.GetParameter(null, "world");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize world vertex declaration
|
2016-02-01 22:04:00 +00:00
|
|
|
VertexElement[] ve = new[]
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
|
|
|
|
new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
|
|
|
|
new VertexElement(0, 16, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
|
|
|
|
new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0), //mxd
|
|
|
|
VertexElement.VertexDeclarationEnd
|
|
|
|
};
|
|
|
|
|
2016-02-01 22:04:00 +00:00
|
|
|
vertexdecl = new VertexDeclaration(General.Map.Graphics.Device, ve);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
if(texture1 != null) texture1.Dispose();
|
|
|
|
if(worldviewproj != null) worldviewproj.Dispose();
|
|
|
|
if(minfiltersettings != null) minfiltersettings.Dispose();
|
|
|
|
if(magfiltersettings != null) magfiltersettings.Dispose();
|
2010-10-03 11:51:38 +00:00
|
|
|
if(mipfiltersettings != null) mipfiltersettings.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
if(highlightcolor != null) highlightcolor.Dispose();
|
2010-10-03 11:51:38 +00:00
|
|
|
if(maxanisotropysetting != null) maxanisotropysetting.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
2015-09-27 21:09:14 +00:00
|
|
|
if(vertexColorHadle != null) vertexColorHadle.Dispose();
|
|
|
|
if(lightColorHandle != null) lightColorHandle.Dispose();
|
|
|
|
if(lightPositionAndRadiusHandle != null) lightPositionAndRadiusHandle.Dispose();
|
|
|
|
if(camPosHandle != null) camPosHandle.Dispose();
|
2015-10-02 14:47:34 +00:00
|
|
|
if(world != null) world.Dispose();
|
2012-05-20 00:56:59 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This sets the constant settings
|
2016-01-14 22:15:54 +00:00
|
|
|
public void SetConstants(bool bilinear, float maxanisotropy)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
if(bilinear)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
effect.SetValue(magfiltersettings, (int)TextureFilter.Linear);
|
|
|
|
effect.SetValue(minfiltersettings, (int)TextureFilter.Anisotropic);
|
|
|
|
effect.SetValue(mipfiltersettings, (int)TextureFilter.Linear);
|
|
|
|
effect.SetValue(maxanisotropysetting, maxanisotropy);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2016-01-14 22:15:54 +00:00
|
|
|
else
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-01-14 22:15:54 +00:00
|
|
|
effect.SetValue(magfiltersettings, (int)TextureFilter.Point);
|
|
|
|
effect.SetValue(minfiltersettings, (int)TextureFilter.Point);
|
|
|
|
effect.SetValue(mipfiltersettings, (int)TextureFilter.Linear);
|
|
|
|
effect.SetValue(maxanisotropysetting, 1.0f);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 22:15:54 +00:00
|
|
|
settingschanged = true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|