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
|
2017-03-25 03:19:42 +00:00
|
|
|
private readonly EffectHandle vertexColorHandle;
|
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;
|
2017-07-26 15:35:22 +00:00
|
|
|
private readonly EffectHandle ignoreNormalsHandle;
|
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
|
2017-03-25 03:19:42 +00:00
|
|
|
|
|
|
|
// [ZZ]
|
|
|
|
private readonly EffectHandle stencilColorHandle;
|
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
|
|
|
{
|
2017-03-25 03:19:42 +00:00
|
|
|
effect.SetValue(vertexColorHandle, value);
|
2015-10-02 14:47:34 +00:00
|
|
|
vertexcolor = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 03:19:42 +00:00
|
|
|
|
|
|
|
// [ZZ]
|
|
|
|
private Color4 stencilcolor;
|
|
|
|
public Color4 StencilColor
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (stencilcolor != value)
|
|
|
|
{
|
|
|
|
effect.SetValue(stencilColorHandle, value);
|
|
|
|
stencilcolor = 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 15:35:22 +00:00
|
|
|
// [ZZ] emulating broken gz lights
|
|
|
|
private bool ignorenormals;
|
|
|
|
public bool IgnoreNormals
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (ignorenormals != value)
|
|
|
|
{
|
|
|
|
effect.SetValue(ignoreNormalsHandle, value ? 1f : 0f);
|
|
|
|
ignorenormals = value;
|
|
|
|
settingschanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 14:47:34 +00:00
|
|
|
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
|
2017-03-25 03:19:42 +00:00
|
|
|
vertexColorHandle = effect.GetParameter(null, "vertexColor");
|
2013-09-11 09:47:53 +00:00
|
|
|
//lights
|
|
|
|
lightPositionAndRadiusHandle = effect.GetParameter(null, "lightPosAndRadius");
|
|
|
|
lightColorHandle = effect.GetParameter(null, "lightColor");
|
2017-07-26 15:35:22 +00:00
|
|
|
ignoreNormalsHandle = effect.GetParameter(null, "ignoreNormals");
|
2013-09-11 09:47:53 +00:00
|
|
|
//fog
|
2016-01-11 13:00:52 +00:00
|
|
|
camPosHandle = effect.GetParameter(null, "campos");
|
2012-05-20 00:56:59 +00:00
|
|
|
|
2017-03-25 03:19:42 +00:00
|
|
|
// [ZZ]
|
|
|
|
stencilColorHandle = effect.GetParameter(null, "stencilColor");
|
|
|
|
|
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-03-25 14:06:00 +00:00
|
|
|
VertexElement[] ve = {
|
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
|
2017-03-25 03:19:42 +00:00
|
|
|
if(vertexColorHandle != null) vertexColorHandle.Dispose();
|
2015-09-27 21:09:14 +00:00
|
|
|
if(lightColorHandle != null) lightColorHandle.Dispose();
|
2017-07-26 15:35:22 +00:00
|
|
|
if (ignoreNormalsHandle != null) ignoreNormalsHandle.Dispose();
|
2015-09-27 21:09:14 +00:00
|
|
|
if(lightPositionAndRadiusHandle != null) lightPositionAndRadiusHandle.Dispose();
|
|
|
|
if(camPosHandle != null) camPosHandle.Dispose();
|
2017-03-25 03:19:42 +00:00
|
|
|
if (stencilColorHandle != null) stencilColorHandle.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-03-25 14:06:00 +00:00
|
|
|
//mxd. It's still nice to have anisotropic filtering when texture filtering is disabled
|
2016-03-29 14:38:07 +00:00
|
|
|
TextureFilter magminfilter = (bilinear ? TextureFilter.Linear : TextureFilter.Point);
|
|
|
|
effect.SetValue(magfiltersettings, magminfilter);
|
|
|
|
effect.SetValue(minfiltersettings, (maxanisotropy > 1.0f ? TextureFilter.Anisotropic : magminfilter));
|
2017-04-29 13:52:12 +00:00
|
|
|
effect.SetValue(mipfiltersettings, (bilinear ? TextureFilter.Linear : TextureFilter.None)); // [SB] use None, otherwise textures are still filtered
|
2016-03-25 14:06:00 +00:00
|
|
|
effect.SetValue(maxanisotropysetting, maxanisotropy);
|
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
|
|
|
|
}
|
|
|
|
}
|