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 Things2DShader : D3DShader
|
|
|
|
{
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Property handlers
|
|
|
|
private EffectHandle texture1;
|
|
|
|
private EffectHandle rendersettings;
|
|
|
|
private EffectHandle transformsettings;
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
private EffectHandle fillColorHandle;
|
2012-04-17 19:13:47 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public Texture Texture1 { set { if(manager.Enabled) effect.SetTexture(texture1, value); } }
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
public Color4 FillColor { set { if (manager.Enabled) effect.SetValue<Color4>(fillColorHandle, value); } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public Things2DShader(ShaderManager manager) : base(manager)
|
|
|
|
{
|
|
|
|
// Load effect from file
|
|
|
|
effect = LoadEffect("things2d.fx");
|
|
|
|
|
|
|
|
// Get the property handlers from effect
|
|
|
|
if(effect != null)
|
|
|
|
{
|
|
|
|
texture1 = effect.GetParameter(null, "texture1");
|
|
|
|
rendersettings = effect.GetParameter(null, "rendersettings");
|
|
|
|
transformsettings = effect.GetParameter(null, "transformsettings");
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
fillColorHandle = effect.GetParameter(null, "fillColor");
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize world vertex declaration
|
|
|
|
VertexElement[] elements = new VertexElement[]
|
|
|
|
{
|
|
|
|
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),
|
|
|
|
VertexElement.VertexDeclarationEnd
|
|
|
|
};
|
|
|
|
vertexdecl = new VertexDeclaration(General.Map.Graphics.Device, elements);
|
|
|
|
|
|
|
|
// 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(rendersettings != null) rendersettings.Dispose();
|
|
|
|
if(transformsettings != null) transformsettings.Dispose();
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd
|
|
|
|
if (fillColorHandle != null) fillColorHandle.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This sets the settings
|
|
|
|
public void SetSettings(float alpha)
|
|
|
|
{
|
|
|
|
if(manager.Enabled)
|
|
|
|
{
|
|
|
|
Vector4 values = new Vector4(0.0f, 0.0f, 1.0f, alpha);
|
|
|
|
effect.SetValue(rendersettings, values);
|
|
|
|
Matrix world = manager.D3DDevice.Device.GetTransform(TransformState.World);
|
|
|
|
Matrix view = manager.D3DDevice.Device.GetTransform(TransformState.View);
|
2015-10-02 14:47:34 +00:00
|
|
|
effect.SetValue(transformsettings, world * view);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-17 19:13:47 +00:00
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
//mxd. Used to render models
|
2014-05-03 14:44:59 +00:00
|
|
|
public void SetTransformSettings(Matrix world)
|
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
|
|
|
{
|
2015-10-02 14:47:34 +00:00
|
|
|
if(manager.Enabled)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
Matrix view = manager.D3DDevice.Device.GetTransform(TransformState.View);
|
2015-10-02 14:47:34 +00:00
|
|
|
effect.SetValue(transformsettings, world * view);
|
|
|
|
settingschanged = true;
|
2013-09-11 09:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This sets up the render pipeline
|
|
|
|
public override void BeginPass(int index)
|
|
|
|
{
|
|
|
|
Device device = manager.D3DDevice.Device;
|
|
|
|
|
2009-05-03 20:21:52 +00:00
|
|
|
if(!manager.Enabled)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Sampler settings
|
|
|
|
if(General.Settings.ClassicBilinear)
|
|
|
|
{
|
|
|
|
device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
|
|
|
|
device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
|
|
|
|
device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);
|
|
|
|
device.SetSamplerState(0, SamplerState.MipMapLodBias, 0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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.MipMapLodBias, 0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Texture addressing
|
|
|
|
device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Wrap);
|
|
|
|
device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Wrap);
|
|
|
|
device.SetSamplerState(0, SamplerState.AddressW, TextureAddress.Wrap);
|
|
|
|
|
|
|
|
// First texture stage
|
|
|
|
device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.Modulate);
|
|
|
|
device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
|
|
|
|
device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Diffuse);
|
|
|
|
device.SetTextureStageState(0, TextureStage.ResultArg, TextureArgument.Current);
|
|
|
|
device.SetTextureStageState(0, TextureStage.TexCoordIndex, 0);
|
|
|
|
|
|
|
|
// Second texture stage
|
|
|
|
device.SetTextureStageState(1, TextureStage.ColorOperation, TextureOperation.Modulate);
|
|
|
|
device.SetTextureStageState(1, TextureStage.ColorArg1, TextureArgument.Current);
|
|
|
|
device.SetTextureStageState(1, TextureStage.ColorArg2, TextureArgument.TFactor);
|
|
|
|
device.SetTextureStageState(1, TextureStage.ResultArg, TextureArgument.Current);
|
|
|
|
device.SetTextureStageState(1, TextureStage.TexCoordIndex, 0);
|
|
|
|
|
|
|
|
// No more further stages
|
|
|
|
device.SetTextureStageState(2, TextureStage.ColorOperation, TextureOperation.Disable);
|
|
|
|
|
|
|
|
// First alpha stage
|
|
|
|
device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate);
|
|
|
|
device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture);
|
|
|
|
device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse);
|
|
|
|
|
|
|
|
// Second alpha stage
|
|
|
|
device.SetTextureStageState(1, TextureStage.AlphaOperation, TextureOperation.Modulate);
|
|
|
|
device.SetTextureStageState(1, TextureStage.AlphaArg1, TextureArgument.Current);
|
|
|
|
device.SetTextureStageState(1, TextureStage.AlphaArg2, TextureArgument.TFactor);
|
|
|
|
|
|
|
|
// No more further stages
|
|
|
|
device.SetTextureStageState(2, TextureStage.AlphaOperation, TextureOperation.Disable);
|
|
|
|
}
|
|
|
|
|
|
|
|
base.BeginPass(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|