mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 22:41:46 +00:00
- remove Things2DShader, World3DShader, Effect and EffectShader
This commit is contained in:
parent
0b3725e2fa
commit
14fd3c96e1
12 changed files with 266 additions and 1076 deletions
|
@ -222,8 +222,6 @@
|
|||
</Compile>
|
||||
<Compile Include="Rendering\Color3.cs" />
|
||||
<Compile Include="Rendering\Color4.cs" />
|
||||
<Compile Include="Rendering\Effect.cs" />
|
||||
<Compile Include="Rendering\EffectShader.cs" />
|
||||
<Compile Include="Rendering\IndexBuffer.cs" />
|
||||
<Compile Include="Rendering\IRenderResource.cs" />
|
||||
<Compile Include="Rendering\Matrix.cs" />
|
||||
|
@ -576,9 +574,7 @@
|
|||
<Compile Include="Rendering\Renderer2D.cs" />
|
||||
<Compile Include="Rendering\Renderer3D.cs" />
|
||||
<Compile Include="Rendering\ShaderManager.cs" />
|
||||
<Compile Include="Rendering\Things2DShader.cs" />
|
||||
<Compile Include="VisualModes\VisualSector.cs" />
|
||||
<Compile Include="Rendering\World3DShader.cs" />
|
||||
<Compile Include="Rendering\WorldVertex.cs" />
|
||||
<Compile Include="ZDoom\DecorateActorStructure.cs" />
|
||||
<Compile Include="ZDoom\DecorateStateGoto.cs" />
|
||||
|
|
|
@ -3419,9 +3419,6 @@ namespace CodeImp.DoomBuilder.Data
|
|||
skyimage = ResizeImage(skyimage, (int)Math.Round(skyimage.Width * scaler), (int)Math.Round(skyimage.Height * scaler));
|
||||
}
|
||||
|
||||
// Get Device and shader...
|
||||
World3DShader effect = General.Map.Graphics.Shaders.World3D;
|
||||
|
||||
// Make custom rendertarget
|
||||
const int cubemaptexsize = 1024;
|
||||
Texture rendertarget = new Texture(cubemaptexsize, cubemaptexsize);
|
||||
|
@ -3464,18 +3461,18 @@ namespace CodeImp.DoomBuilder.Data
|
|||
Matrix mworld = Matrix.Multiply(Matrix.Identity, Matrix.Translation(offset) * Matrix.Scaling(1.0f, 1.0f, yscale));
|
||||
Matrix mprojection = Matrix.PerspectiveFovLH(Angle2D.PIHALF, 1.0f, 0.5f, 100.0f);
|
||||
|
||||
// Place camera at origin
|
||||
effect.CameraPosition = new Vector4();
|
||||
// Place camera at origin
|
||||
General.Map.Graphics.SetUniform(Uniform.campos, new Vector4());
|
||||
|
||||
// Begin fullbright shaderpass
|
||||
effect.Begin();
|
||||
effect.BeginPass(1);
|
||||
// Begin fullbright shaderpass
|
||||
General.Map.Graphics.SetVertexDeclaration(General.Map.Graphics.Shaders.WorldVertexDecl);
|
||||
General.Map.Graphics.SetShader(Shader.world3d_fullbright);
|
||||
|
||||
// Render to the six faces of the cube map
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
Matrix faceview = GetCubeMapViewMatrix((CubeMapFace)i);
|
||||
effect.WorldViewProj = mworld * faceview * mprojection;
|
||||
General.Map.Graphics.SetUniform(Uniform.worldviewproj, mworld * faceview * mprojection);
|
||||
|
||||
// Render the skysphere meshes
|
||||
for(int j = 0; j < meshes.Meshes.Count; j++)
|
||||
|
@ -3483,25 +3480,20 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// Set appropriate texture
|
||||
switch(meshes.Skins[j])
|
||||
{
|
||||
case "top.png": effect.Texture1 = textop; break;
|
||||
case "bottom.png": effect.Texture1 = texbottom; break;
|
||||
case "side.png": effect.Texture1 = texside; break;
|
||||
case "top.png": General.Map.Graphics.SetUniform(Uniform.texture1, textop); break;
|
||||
case "bottom.png": General.Map.Graphics.SetUniform(Uniform.texture1, texbottom); break;
|
||||
case "side.png": General.Map.Graphics.SetUniform(Uniform.texture1, texside); break;
|
||||
default: throw new Exception("Unexpected skin!");
|
||||
}
|
||||
|
||||
// Commit changes
|
||||
effect.ApplySettings();
|
||||
|
||||
// Render mesh
|
||||
meshes.Meshes[j].DrawSubset(0);
|
||||
meshes.Meshes[j].Draw(General.Map.Graphics);
|
||||
}
|
||||
|
||||
General.Map.Graphics.CopyTexture(rendertarget, cubemap, (CubeMapFace)i);
|
||||
}
|
||||
|
||||
// End rendering
|
||||
effect.EndPass();
|
||||
effect.End();
|
||||
General.Map.Graphics.FinishRendering();
|
||||
|
||||
// Dispose unneeded stuff
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
public enum ShaderFlags { None, Debug }
|
||||
|
||||
public class Effect
|
||||
{
|
||||
public static Effect FromStream(Stream stream, ShaderFlags flags, out string errors)
|
||||
{
|
||||
errors = "";
|
||||
return new Effect();
|
||||
}
|
||||
|
||||
public void SetTexture(EffectHandle handle, BaseTexture texture)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetValue<T>(EffectHandle handle, T value) where T : struct
|
||||
{
|
||||
}
|
||||
|
||||
public EffectHandle GetParameter(EffectHandle parameter, string name)
|
||||
{
|
||||
if (!Parameters.ContainsKey(name))
|
||||
{
|
||||
Parameters[name] = new EffectHandle();
|
||||
}
|
||||
return Parameters[name];
|
||||
}
|
||||
|
||||
public void CommitChanges()
|
||||
{
|
||||
}
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
}
|
||||
|
||||
public void BeginPass(int index)
|
||||
{
|
||||
}
|
||||
|
||||
public void EndPass()
|
||||
{
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
Dictionary<string, EffectHandle> Parameters = new Dictionary<string, EffectHandle>();
|
||||
}
|
||||
|
||||
public class EffectHandle
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
|
||||
#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 System.IO;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
internal abstract class EffectShader : IDisposable
|
||||
{
|
||||
#region ================== Constants
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
||||
// The manager
|
||||
protected ShaderManager manager;
|
||||
|
||||
// The effect
|
||||
protected Effect effect;
|
||||
|
||||
// The vertex declaration
|
||||
protected VertexDeclaration vertexdecl;
|
||||
|
||||
// Disposing
|
||||
protected bool isdisposed;
|
||||
|
||||
//mxd. Settings changes
|
||||
protected bool settingschanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
// Disposing
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
protected EffectShader(ShaderManager manager)
|
||||
{
|
||||
// Initialize
|
||||
this.manager = manager;
|
||||
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// Disposer
|
||||
public virtual void Dispose()
|
||||
{
|
||||
// Not already disposed?
|
||||
if(!isdisposed)
|
||||
{
|
||||
// Clean up
|
||||
manager = null;
|
||||
if(effect != null) effect.Dispose();
|
||||
vertexdecl.Dispose();
|
||||
|
||||
// Done
|
||||
isdisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This loads an effect
|
||||
protected Effect LoadEffect(string fxfile)
|
||||
{
|
||||
Effect fx;
|
||||
string errors = string.Empty;
|
||||
|
||||
// Load the resource
|
||||
Stream fxdata = General.ThisAssembly.GetManifestResourceStream("CodeImp.DoomBuilder.Resources." + fxfile);
|
||||
fxdata.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
try
|
||||
{
|
||||
// Compile effect
|
||||
fx = Effect.FromStream(fxdata, ShaderFlags.None, out errors);
|
||||
if(!string.IsNullOrEmpty(errors))
|
||||
{
|
||||
throw new Exception("Errors in effect file " + fxfile + ": " + errors);
|
||||
}
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
string debugerrors = string.Empty; //mxd
|
||||
|
||||
// Compiling failed, try with debug information
|
||||
try
|
||||
{
|
||||
//mxd. Rewind before use!
|
||||
fxdata.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Compile effect
|
||||
fx = Effect.FromStream(fxdata, ShaderFlags.Debug, out debugerrors);
|
||||
if(!string.IsNullOrEmpty(debugerrors))
|
||||
{
|
||||
throw new Exception("Errors in effect file " + fxfile + ": " + debugerrors);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//mxd. Try to get something. Anything!
|
||||
string message;
|
||||
if(!string.IsNullOrEmpty(debugerrors))
|
||||
message = e.Message + "\nInitial message (debug mode): \"" + debugerrors + "\"";
|
||||
else if(!string.IsNullOrEmpty(errors))
|
||||
message = e.Message + "\nInitial message: \"" + errors + "\"";
|
||||
else
|
||||
message = e.ToString();
|
||||
|
||||
if(string.IsNullOrEmpty(message)) message = "No initial message...";
|
||||
|
||||
// No debug information, just crash
|
||||
throw new Exception(e.GetType().Name + " while loading effect " + fxfile + ": " + message);
|
||||
}
|
||||
}
|
||||
|
||||
fxdata.Dispose();
|
||||
|
||||
// Return result
|
||||
return fx;
|
||||
}
|
||||
|
||||
// This applies the shader
|
||||
public void Begin()
|
||||
{
|
||||
// Set vertex declaration
|
||||
General.Map.Graphics.SetVertexDeclaration(vertexdecl);
|
||||
|
||||
// Set effect
|
||||
effect.Begin();
|
||||
}
|
||||
|
||||
// This begins a pass
|
||||
public virtual void BeginPass(int index)
|
||||
{
|
||||
effect.BeginPass(index);
|
||||
}
|
||||
|
||||
// This ends a pass
|
||||
public void EndPass()
|
||||
{
|
||||
effect.EndPass();
|
||||
}
|
||||
|
||||
// This ends te shader
|
||||
public void End()
|
||||
{
|
||||
effect.End();
|
||||
}
|
||||
|
||||
// This applies properties during a pass
|
||||
public void ApplySettings()
|
||||
{
|
||||
if(settingschanged)
|
||||
{
|
||||
effect.CommitChanges();
|
||||
settingschanged = false; //mxd
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
public class Mesh : IDisposable
|
||||
internal class Mesh : IDisposable
|
||||
{
|
||||
public Mesh(VertexElement[] vertexDecl, WorldVertex[] vertexData, int[] indexData)
|
||||
{
|
||||
|
@ -15,6 +15,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
Vertices.SetBufferData(vertexData);
|
||||
Indices = new IndexBuffer(sizeof(int) * indexData.Length);
|
||||
Indices.SetBufferData(indexData);
|
||||
Count = indexData.Length;
|
||||
}
|
||||
|
||||
~Mesh()
|
||||
|
@ -22,8 +23,17 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
Dispose();
|
||||
}
|
||||
|
||||
public void DrawSubset(int index)
|
||||
internal void Draw(RenderDevice device)
|
||||
{
|
||||
/*
|
||||
device.SetVertexDeclaration(VertexDecl);
|
||||
device.SetVertexBuffer(0, Vertices, 0, WorldVertex.Stride);
|
||||
device.SetIndexBuffer(Indices);
|
||||
device.DrawElements(0, Count);
|
||||
device.SetIndexBuffer(null);
|
||||
device.SetVertexBuffer(0, null, 0, 0);
|
||||
device.SetVertexDeclaration(null);
|
||||
*/
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -35,5 +45,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
VertexDeclaration VertexDecl;
|
||||
VertexBuffer Vertices;
|
||||
IndexBuffer Indices;
|
||||
int Count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
SetSamplerState(0, TextureAddress.Wrap);
|
||||
|
||||
// Shader settings
|
||||
Shaders.World3D.SetConstants(General.Settings.VisualBilinear, General.Settings.FilterAnisotropy);
|
||||
Shaders.SetWorld3DConstants(General.Settings.VisualBilinear, General.Settings.FilterAnisotropy);
|
||||
|
||||
// Initialize presentations
|
||||
Presentation.Initialize();
|
||||
|
@ -391,12 +391,15 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
|
||||
public void SetShader(Shader shader) { }
|
||||
public void SetUniform(Uniform uniform, bool value) { }
|
||||
public void SetUniform(Uniform uniform, float value) { }
|
||||
public void SetUniform(Uniform uniform, Vector2 value) { }
|
||||
public void SetUniform(Uniform uniform, Vector3 value) { }
|
||||
public void SetUniform(Uniform uniform, Vector4 value) { }
|
||||
public void SetUniform(Uniform uniform, Color4 value) { }
|
||||
public void SetUniform(Uniform uniform, Matrix value) { }
|
||||
public void SetUniform(Uniform uniform, Texture value) { }
|
||||
public void SetUniform(Uniform uniform, BaseTexture value) { }
|
||||
public void SetUniform(Uniform uniform, TextureFilter value) { }
|
||||
}
|
||||
|
||||
public enum Shader : int
|
||||
|
@ -408,20 +411,24 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
things2d_thing,
|
||||
things2d_sprite,
|
||||
things2d_fill,
|
||||
world3d_main,
|
||||
world3d_fullbright,
|
||||
world3d_main_highlight,
|
||||
world3d_fullbright_highlight,
|
||||
world3d_main_vertexcolor,
|
||||
world3d_skybox,
|
||||
world3d_main_highlight_vertexcolor,
|
||||
world3d_main_fog,
|
||||
world3d_main_highlight_fog,
|
||||
world3d_main_fog_vertexcolor,
|
||||
world3d_main_highlight_fog_vertexcolor,
|
||||
world3d_vertex_color,
|
||||
world3d_constant_color,
|
||||
world3d_lightpass // AlphaBlendEnable = true
|
||||
world3d_main, // 0
|
||||
world3d_fullbright, // 1
|
||||
world3d_main_highlight, // 2
|
||||
world3d_fullbright_highlight, // 3
|
||||
world3d_main_vertexcolor, // 4
|
||||
world3d_skybox, // 5
|
||||
world3d_main_highlight_vertexcolor, // 6
|
||||
world3d_p7,
|
||||
world3d_main_fog, // 8
|
||||
world3d_p9,
|
||||
world3d_main_highlight_fog, // 10
|
||||
world3d_p11,
|
||||
world3d_main_fog_vertexcolor, // 12
|
||||
world3d_p13,
|
||||
world3d_main_highlight_fog_vertexcolor, // 14
|
||||
world3d_vertex_color, // 15
|
||||
world3d_constant_color, // 16
|
||||
world3d_lightpass // 17 // AlphaBlendEnable = true
|
||||
}
|
||||
|
||||
public enum Uniform : int
|
||||
|
@ -435,6 +442,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
worldviewproj,
|
||||
world,
|
||||
modelnormal,
|
||||
FillColor,
|
||||
vertexColor,
|
||||
stencilColor,
|
||||
lightPosAndRadius,
|
||||
|
@ -444,6 +452,10 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
ignoreNormals,
|
||||
spotLight,
|
||||
campos,
|
||||
magfiltersettings,
|
||||
minfiltersettings,
|
||||
mipfiltersettings,
|
||||
maxanisotropysetting
|
||||
}
|
||||
|
||||
public enum Cull : int { None, Counterclockwise }
|
||||
|
|
|
@ -1209,14 +1209,12 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetVertexBuffer(0, thingsvertices, 0, FlatVertex.Stride);
|
||||
|
||||
// Set things texture
|
||||
graphics.Shaders.Things2D.Texture1 = General.Map.Data.ThingTexture.Texture; //mxd
|
||||
graphics.SetUniform(Uniform.texture1, General.Map.Data.ThingTexture.Texture); //mxd
|
||||
SetWorldTransformation(false);
|
||||
graphics.Shaders.Things2D.SetSettings(alpha);
|
||||
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
|
||||
graphics.SetShader(Shader.things2d_thing);
|
||||
graphics.Shaders.SetThings2DSettings(alpha);
|
||||
|
||||
// Begin drawing
|
||||
graphics.Shaders.Things2D.Begin();
|
||||
graphics.Shaders.Things2D.BeginPass(0);
|
||||
|
||||
// Determine next lock size
|
||||
int locksize = (things.Count > THING_BUFFER_SIZE) ? THING_BUFFER_SIZE : things.Count;
|
||||
FlatVertex[] verts = new FlatVertex[THING_BUFFER_SIZE * 6];
|
||||
|
@ -1278,12 +1276,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if(buffercount > 0)
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, buffercount * 2);
|
||||
|
||||
// Done
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
|
||||
//mxd. Render sprites
|
||||
int selectionColor = General.Colors.Selection.ToInt();
|
||||
graphics.Shaders.Things2D.BeginPass(1);
|
||||
graphics.SetShader(Shader.things2d_sprite);
|
||||
|
||||
foreach(KeyValuePair<int, List<Thing>> group in thingsByType)
|
||||
{
|
||||
|
@ -1328,8 +1323,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
if(sprite.Texture == null) sprite.CreateTexture();
|
||||
|
||||
graphics.Shaders.Things2D.Texture1 = sprite.Texture;
|
||||
graphics.Shaders.Things2D.ApplySettings();
|
||||
graphics.SetUniform(Uniform.texture1, sprite.Texture);
|
||||
|
||||
// Determine next lock size
|
||||
locksize = (framegroup.Value.Count > THING_BUFFER_SIZE) ? THING_BUFFER_SIZE : framegroup.Value.Count;
|
||||
|
@ -1423,12 +1417,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
}
|
||||
|
||||
// Done
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
|
||||
//mxd. Render thing arrows
|
||||
graphics.Shaders.Things2D.Texture1 = General.Map.Data.ThingTexture.Texture;
|
||||
graphics.Shaders.Things2D.BeginPass(0);
|
||||
graphics.SetUniform(Uniform.texture1, General.Map.Data.ThingTexture.Texture);
|
||||
graphics.SetShader(Shader.things2d_thing);
|
||||
|
||||
// Determine next lock size
|
||||
locksize = (thingsByPosition.Count > THING_BUFFER_SIZE) ? THING_BUFFER_SIZE : thingsByPosition.Count;
|
||||
|
@ -1468,9 +1459,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if(buffercount > 0)
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, 0, buffercount * 2);
|
||||
|
||||
//Done with this pass
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
|
||||
//mxd. Render models
|
||||
if(General.Settings.GZDrawModelsMode != ModelRenderMode.NONE)
|
||||
{
|
||||
|
@ -1479,7 +1467,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetTextureFactor(-1);
|
||||
graphics.SetFillMode(FillMode.Wireframe);
|
||||
|
||||
graphics.Shaders.Things2D.BeginPass(2);
|
||||
graphics.SetShader(Shader.things2d_fill);
|
||||
|
||||
Color4 cSelection = General.Colors.Selection.ToColorValue();
|
||||
Color4 cWire = ((c.ToInt() == General.Colors.Highlight.ToInt()) ? General.Colors.Highlight.ToColorValue() : General.Colors.ModelWireframe.ToColorValue());
|
||||
|
@ -1503,7 +1491,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
((screenpos.y + mde.Model.Radius * modelScale) <= 0.0f) || ((screenpos.y - mde.Model.Radius * modelScale) >= windowsize.Height))
|
||||
continue;
|
||||
|
||||
graphics.Shaders.Things2D.FillColor = (t.Selected ? cSelection : cWire);
|
||||
graphics.SetUniform(Uniform.FillColor, (t.Selected ? cSelection : cWire));
|
||||
|
||||
// Set transform settings
|
||||
float sx = t.ScaleX * t.ActorScale.Width;
|
||||
|
@ -1514,21 +1502,17 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
Matrix position = Matrix.Translation(screenpos.x, screenpos.y, 0.0f);
|
||||
Matrix world = General.Map.Data.ModeldefEntries[t.Type].Transform * modelscale * rotation * viewscale * position;
|
||||
|
||||
graphics.Shaders.Things2D.SetTransformSettings(world);
|
||||
graphics.Shaders.Things2D.ApplySettings();
|
||||
graphics.Shaders.SetThings2DTransformSettings(world);
|
||||
|
||||
// Draw
|
||||
foreach(Mesh mesh in mde.Model.Meshes) mesh.DrawSubset(0);
|
||||
foreach(Mesh mesh in mde.Model.Meshes) mesh.Draw(graphics);
|
||||
}
|
||||
}
|
||||
|
||||
//Done with this pass
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
graphics.SetFillMode(FillMode.Solid);
|
||||
}
|
||||
|
||||
graphics.Shaders.Things2D.End();
|
||||
|
||||
//mxd. Render thing boxes
|
||||
RenderArrows(bboxes, false);
|
||||
}
|
||||
|
@ -1661,15 +1645,13 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetFogEnable(false);
|
||||
|
||||
SetWorldTransformation(true);
|
||||
graphics.Shaders.Things2D.FillColor = new Color4(color);
|
||||
graphics.Shaders.Things2D.SetSettings(1.0f);
|
||||
graphics.SetUniform(Uniform.FillColor, new Color4(color));
|
||||
graphics.Shaders.SetThings2DSettings(1.0f);
|
||||
|
||||
// Draw
|
||||
graphics.Shaders.Things2D.Begin();
|
||||
graphics.Shaders.Things2D.BeginPass(2);
|
||||
// Draw
|
||||
graphics.SetVertexDeclaration(graphics.Shaders.FlatVertexDecl);
|
||||
graphics.SetShader(Shader.things2d_fill);
|
||||
graphics.DrawUserPrimitives(PrimitiveType.TriangleList, 0, vertices.Length / 3, vertices);
|
||||
graphics.Shaders.Things2D.EndPass();
|
||||
graphics.Shaders.Things2D.End();
|
||||
}
|
||||
|
||||
//mxd. This renders text (DB2 compatibility)
|
||||
|
|
|
@ -38,9 +38,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
private const float PROJ_NEAR_PLANE = 1f;
|
||||
private const float FOG_RANGE = 0.9f;
|
||||
|
||||
private const int SHADERPASS_LIGHT = 17; //mxd
|
||||
private const int SHADERPASS_SKYBOX = 5; //mxd
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Variables
|
||||
|
@ -54,7 +51,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
private Matrix world;
|
||||
private Vector3D cameraposition;
|
||||
private Vector3D cameravector;
|
||||
private int shaderpass;
|
||||
private Shader shaderpass;
|
||||
|
||||
// Window size
|
||||
private Size windowsize;
|
||||
|
@ -284,7 +281,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// This applies the matrices
|
||||
private void ApplyMatrices3D()
|
||||
{
|
||||
graphics.Shaders.World3D.WorldViewProj = world * viewproj; //mxd. Multiplication is ~2x faster than "world * view3d * projection";
|
||||
graphics.SetUniform(Uniform.worldviewproj, world * viewproj); //mxd. Multiplication is ~2x faster than "world * view3d * projection";
|
||||
}
|
||||
|
||||
// This sets the appropriate view matrix
|
||||
|
@ -317,7 +314,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetFogStart(General.Settings.ViewDistance * FOG_RANGE);
|
||||
graphics.SetFogEnd(General.Settings.ViewDistance);
|
||||
graphics.SetTextureFactor(-1);
|
||||
graphics.Shaders.World3D.HighlightColor = new Color4(); //mxd
|
||||
graphics.SetUniform(Uniform.highlightcolor, new Color4()); //mxd
|
||||
|
||||
// Texture addressing
|
||||
graphics.SetSamplerState(0, TextureAddress.Wrap);
|
||||
|
@ -339,7 +336,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
|
||||
// Determine shader pass to use
|
||||
shaderpass = (fullbrightness ? 1 : 0);
|
||||
shaderpass = (fullbrightness ? Shader.world3d_fullbright : Shader.world3d_main);
|
||||
|
||||
// Create crosshair vertices
|
||||
if(crosshairverts == null)
|
||||
|
@ -385,7 +382,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetAlphaBlendEnable(false);
|
||||
graphics.SetAlphaTestEnable(false);
|
||||
graphics.SetTextureFactor(-1);
|
||||
graphics.Shaders.World3D.Begin();
|
||||
graphics.SetVertexDeclaration(graphics.Shaders.WorldVertexDecl);
|
||||
|
||||
//mxd. SKY PASS
|
||||
if(skygeo.Count > 0)
|
||||
|
@ -435,9 +432,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
graphics.SetAlphaTestEnable(true);
|
||||
graphics.SetCullMode(Cull.None);
|
||||
graphics.Shaders.World3D.IgnoreNormals = true;
|
||||
graphics.SetUniform(Uniform.ignoreNormals, true);
|
||||
RenderModels(true, false);
|
||||
graphics.Shaders.World3D.IgnoreNormals = false;
|
||||
graphics.SetUniform(Uniform.ignoreNormals, false);
|
||||
graphics.SetCullMode(Cull.Counterclockwise);
|
||||
}
|
||||
}
|
||||
|
@ -480,9 +477,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if (General.Settings.GZDrawLightsMode != LightRenderMode.NONE && !fullbrightness && lightthings.Count > 0 && translucentmodelthings.Count > 0)
|
||||
{
|
||||
graphics.SetAlphaTestEnable(true);
|
||||
graphics.Shaders.World3D.IgnoreNormals = true;
|
||||
graphics.SetUniform(Uniform.ignoreNormals, true);
|
||||
RenderModels(true, true);
|
||||
graphics.Shaders.World3D.IgnoreNormals = false;
|
||||
graphics.SetUniform(Uniform.ignoreNormals, false);
|
||||
}
|
||||
|
||||
// THING CAGES
|
||||
|
@ -500,11 +497,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if(General.Settings.GZShowEventLines) RenderArrows(eventlines);
|
||||
|
||||
// Remove references
|
||||
graphics.Shaders.World3D.Texture1 = null;
|
||||
graphics.SetUniform(Uniform.texture1, null);
|
||||
|
||||
// Done
|
||||
graphics.Shaders.World3D.End();
|
||||
|
||||
//mxd. Trash collections
|
||||
solidgeo = null;
|
||||
maskedgeo = null;
|
||||
|
@ -592,7 +586,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetSourceBlend(Blend.SourceAlpha);
|
||||
graphics.SetDestinationBlend(Blend.SourceAlpha);
|
||||
|
||||
graphics.Shaders.World3D.BeginPass(16);
|
||||
graphics.SetShader(Shader.world3d_constant_color);
|
||||
|
||||
foreach(VisualThing t in allthings)
|
||||
{
|
||||
|
@ -607,16 +601,14 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
thingcolor = t.CageColor;
|
||||
if(t != highlighted) thingcolor.Alpha = 0.6f;
|
||||
}
|
||||
graphics.Shaders.World3D.VertexColor = thingcolor;
|
||||
graphics.SetUniform(Uniform.vertexColor, thingcolor);
|
||||
|
||||
//Render cage
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
graphics.SetVertexBuffer(0, t.CageBuffer, 0, WorldVertex.Stride);
|
||||
graphics.DrawPrimitives(PrimitiveType.LineList, 0, t.CageLength);
|
||||
}
|
||||
|
||||
// Done
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.SetTextureFactor(-1);
|
||||
}
|
||||
|
||||
|
@ -631,7 +623,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetSourceBlend(Blend.SourceAlpha);
|
||||
graphics.SetDestinationBlend(Blend.SourceAlpha);
|
||||
|
||||
graphics.Shaders.World3D.BeginPass(16);
|
||||
graphics.SetShader(Shader.world3d_constant_color);
|
||||
|
||||
foreach(VisualVertex v in visualvertices)
|
||||
{
|
||||
|
@ -649,16 +641,14 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
color = v.HaveHeightOffset ? General.Colors.InfoLine.ToColorValue() : General.Colors.Vertices.ToColorValue();
|
||||
if(v != highlighted) color.Alpha = 0.6f;
|
||||
}
|
||||
graphics.Shaders.World3D.VertexColor = color;
|
||||
graphics.SetUniform(Uniform.vertexColor, color);
|
||||
|
||||
//Commence drawing!!11
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
graphics.SetVertexBuffer(0, v.CeilingVertex ? vertexhandle.Upper : vertexhandle.Lower, 0, WorldVertex.Stride);
|
||||
graphics.DrawPrimitives(PrimitiveType.LineList, 0, 8);
|
||||
}
|
||||
|
||||
// Done
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.SetTextureFactor(-1);
|
||||
}
|
||||
|
||||
|
@ -727,18 +717,16 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.SetSourceBlend(Blend.SourceAlpha);
|
||||
graphics.SetDestinationBlend(Blend.SourceAlpha);
|
||||
|
||||
graphics.Shaders.World3D.BeginPass(15);
|
||||
graphics.SetShader(Shader.world3d_vertex_color);
|
||||
|
||||
world = Matrix.Identity;
|
||||
ApplyMatrices3D();
|
||||
|
||||
//render
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
graphics.SetVertexBuffer(0, vb, 0, WorldVertex.Stride);
|
||||
graphics.DrawPrimitives(PrimitiveType.LineList, 0, pointscount / 2);
|
||||
|
||||
// Done
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.SetTextureFactor(-1);
|
||||
vb.Dispose();
|
||||
}
|
||||
|
@ -747,11 +735,11 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
private void RenderSinglePass(Dictionary<ImageData, List<VisualGeometry>> geopass, Dictionary<ImageData, List<VisualThing>> thingspass)
|
||||
{
|
||||
ImageData curtexture;
|
||||
int currentshaderpass = shaderpass;
|
||||
int highshaderpass = shaderpass + 2;
|
||||
Shader currentshaderpass = shaderpass;
|
||||
Shader highshaderpass = (Shader)(shaderpass + 2);
|
||||
|
||||
// Begin rendering with this shader
|
||||
graphics.Shaders.World3D.BeginPass(shaderpass);
|
||||
graphics.SetShader(shaderpass);
|
||||
|
||||
// Render the geometry collected
|
||||
foreach(KeyValuePair<ImageData, List<VisualGeometry>> group in geopass)
|
||||
|
@ -768,8 +756,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if((curtexture.Texture == null) || curtexture.Texture.Disposed)
|
||||
curtexture.CreateTexture();
|
||||
|
||||
// Apply texture
|
||||
graphics.Shaders.World3D.Texture1 = curtexture.Texture;
|
||||
// Apply texture
|
||||
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
|
||||
|
||||
//mxd. Sort geometry by sector index
|
||||
group.Value.Sort((g1, g2) => g1.Sector.Sector.FixedIndex - g2.Sector.Sector.FixedIndex);
|
||||
|
@ -801,11 +789,11 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
}
|
||||
|
||||
graphics.Shaders.World3D.Desaturation = 0;
|
||||
graphics.SetUniform(Uniform.desaturation, 0.0f);
|
||||
if (sector != null)
|
||||
{
|
||||
// Determine the shader pass we want to use for this object
|
||||
int wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
Shader wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
|
||||
//mxd. Render fog?
|
||||
if(General.Settings.GZDrawFog && !fullbrightness && sector.Sector.FogMode != SectorFogMode.NONE)
|
||||
|
@ -814,34 +802,30 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Switch shader pass?
|
||||
if(currentshaderpass != wantedshaderpass)
|
||||
{
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.Shaders.World3D.BeginPass(wantedshaderpass);
|
||||
graphics.SetShader(wantedshaderpass);
|
||||
currentshaderpass = wantedshaderpass;
|
||||
|
||||
//mxd. Set variables for fog rendering?
|
||||
if(wantedshaderpass > 7)
|
||||
if(wantedshaderpass > Shader.world3d_p7)
|
||||
{
|
||||
graphics.Shaders.World3D.World = world;
|
||||
graphics.Shaders.World3D.ModelNormal = Matrix.Identity;
|
||||
graphics.SetUniform(Uniform.world, world);
|
||||
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
//mxd. Set variables for fog rendering?
|
||||
if(wantedshaderpass > 7)
|
||||
if(wantedshaderpass > Shader.world3d_p7)
|
||||
{
|
||||
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor);
|
||||
graphics.Shaders.World3D.LightColor = sector.Sector.FogColor;
|
||||
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor));
|
||||
graphics.SetUniform(Uniform.lightColor, sector.Sector.FogColor);
|
||||
}
|
||||
|
||||
// Set the colors to use
|
||||
graphics.Shaders.World3D.HighlightColor = CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection));
|
||||
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
|
||||
|
||||
// [ZZ] include desaturation factor
|
||||
graphics.Shaders.World3D.Desaturation = sector.Sector.Desaturation;
|
||||
graphics.SetUniform(Uniform.desaturation, sector.Sector.Desaturation);
|
||||
|
||||
// Apply changes
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
|
||||
// Render!
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
|
@ -872,8 +856,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if((curtexture.Texture == null) || curtexture.Texture.Disposed)
|
||||
curtexture.CreateTexture();
|
||||
|
||||
// Apply texture
|
||||
graphics.Shaders.World3D.Texture1 = curtexture.Texture;
|
||||
// Apply texture
|
||||
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
|
||||
|
||||
// Render all things with this texture
|
||||
foreach(VisualThing t in group.Value)
|
||||
|
@ -889,7 +873,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if(t.GeometryBuffer != null)
|
||||
{
|
||||
// Determine the shader pass we want to use for this object
|
||||
int wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
Shader wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
|
||||
//mxd. If fog is enagled, switch to shader, which calculates it
|
||||
if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE)
|
||||
|
@ -922,35 +906,33 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Switch shader pass?
|
||||
if(currentshaderpass != wantedshaderpass)
|
||||
{
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.Shaders.World3D.BeginPass(wantedshaderpass);
|
||||
graphics.SetShader(wantedshaderpass);
|
||||
currentshaderpass = wantedshaderpass;
|
||||
}
|
||||
|
||||
//mxd. Set variables for fog rendering?
|
||||
if(wantedshaderpass > 7)
|
||||
if(wantedshaderpass > Shader.world3d_p7)
|
||||
{
|
||||
graphics.Shaders.World3D.World = world;
|
||||
graphics.Shaders.World3D.ModelNormal = Matrix.Identity;
|
||||
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
|
||||
graphics.SetUniform(Uniform.world, world);
|
||||
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
|
||||
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
|
||||
}
|
||||
|
||||
// Set the colors to use
|
||||
if(t.Thing.Sector != null) graphics.Shaders.World3D.LightColor = t.Thing.Sector.FogColor;
|
||||
graphics.Shaders.World3D.VertexColor = vertexcolor;
|
||||
graphics.Shaders.World3D.HighlightColor = CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection));
|
||||
if(t.Thing.Sector != null) graphics.SetUniform(Uniform.lightColor, t.Thing.Sector.FogColor);
|
||||
graphics.SetUniform(Uniform.vertexColor, vertexcolor);
|
||||
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
|
||||
|
||||
// [ZZ] check if we want stencil
|
||||
graphics.Shaders.World3D.StencilColor = t.StencilColor.ToColorValue();
|
||||
graphics.SetUniform(Uniform.stencilColor, t.StencilColor.ToColorValue());
|
||||
|
||||
// [ZZ] apply desaturation
|
||||
if (t.Thing.Sector != null)
|
||||
graphics.Shaders.World3D.Desaturation = t.Thing.Sector.Desaturation;
|
||||
else graphics.Shaders.World3D.Desaturation = 0;
|
||||
graphics.SetUniform(Uniform.desaturation, t.Thing.Sector.Desaturation);
|
||||
else graphics.SetUniform(Uniform.desaturation, 0.0f);
|
||||
|
||||
// Apply changes
|
||||
ApplyMatrices3D();
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
|
||||
// Apply buffer
|
||||
graphics.SetVertexBuffer(0, t.GeometryBuffer, 0, WorldVertex.Stride);
|
||||
|
@ -961,23 +943,20 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
|
||||
// [ZZ]
|
||||
graphics.Shaders.World3D.StencilColor = new Color4(0f, 1f, 1f, 1f);
|
||||
graphics.SetUniform(Uniform.stencilColor, new Color4(0f, 1f, 1f, 1f));
|
||||
}
|
||||
|
||||
// Texture addressing
|
||||
graphics.SetSamplerState(0, TextureAddress.Wrap);
|
||||
graphics.SetCullMode(Cull.Counterclockwise); //mxd
|
||||
}
|
||||
|
||||
// Done rendering with this shader
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
}
|
||||
|
||||
//mxd
|
||||
private void RenderTranslucentPass(List<VisualGeometry> geopass, List<VisualThing> thingspass)
|
||||
{
|
||||
int currentshaderpass = shaderpass;
|
||||
int highshaderpass = shaderpass + 2;
|
||||
Shader currentshaderpass = shaderpass;
|
||||
Shader highshaderpass = (Shader)(shaderpass + 2);
|
||||
|
||||
// Sort geometry by camera distance. First vertex of the BoundingBox is it's center
|
||||
geopass.Sort(delegate(VisualGeometry vg1, VisualGeometry vg2)
|
||||
|
@ -1020,7 +999,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
float fogfactor = -1;
|
||||
|
||||
// Begin rendering with this shader
|
||||
graphics.Shaders.World3D.BeginPass(shaderpass);
|
||||
graphics.SetShader(shaderpass);
|
||||
|
||||
// Go for all geometry
|
||||
foreach(VisualGeometry g in geopass)
|
||||
|
@ -1057,8 +1036,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if((curtexture.Texture == null) || curtexture.Texture.Disposed)
|
||||
curtexture.CreateTexture();
|
||||
|
||||
// Apply texture
|
||||
graphics.Shaders.World3D.Texture1 = curtexture.Texture;
|
||||
// Apply texture
|
||||
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
|
||||
curtexturename = g.Texture.LongName;
|
||||
}
|
||||
|
||||
|
@ -1087,7 +1066,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if (sector != null)
|
||||
{
|
||||
// Determine the shader pass we want to use for this object
|
||||
int wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
Shader wantedshaderpass = (((g == highlighted) && showhighlight) || (g.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
|
||||
//mxd. Render fog?
|
||||
if (General.Settings.GZDrawFog && !fullbrightness && sector.Sector.FogMode != SectorFogMode.NONE)
|
||||
|
@ -1096,39 +1075,35 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Switch shader pass?
|
||||
if (currentshaderpass != wantedshaderpass)
|
||||
{
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.Shaders.World3D.BeginPass(wantedshaderpass);
|
||||
graphics.SetShader(wantedshaderpass);
|
||||
currentshaderpass = wantedshaderpass;
|
||||
|
||||
//mxd. Set variables for fog rendering?
|
||||
if (wantedshaderpass > 7)
|
||||
if (wantedshaderpass > Shader.world3d_p7)
|
||||
{
|
||||
graphics.Shaders.World3D.World = world;
|
||||
graphics.Shaders.World3D.ModelNormal = Matrix.Identity;
|
||||
graphics.SetUniform(Uniform.world, world);
|
||||
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
// Set variables for fog rendering?
|
||||
if (wantedshaderpass > 7 && g.FogFactor != fogfactor)
|
||||
if (wantedshaderpass > Shader.world3d_p7 && g.FogFactor != fogfactor)
|
||||
{
|
||||
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor);
|
||||
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, g.FogFactor));
|
||||
fogfactor = g.FogFactor;
|
||||
}
|
||||
|
||||
//
|
||||
graphics.Shaders.World3D.Desaturation = sector.Sector.Desaturation;
|
||||
graphics.SetUniform(Uniform.desaturation, sector.Sector.Desaturation);
|
||||
|
||||
// Set the colors to use
|
||||
graphics.Shaders.World3D.LightColor = sector.Sector.FogColor;
|
||||
graphics.Shaders.World3D.HighlightColor = CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection));
|
||||
|
||||
// Apply changes
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
graphics.SetUniform(Uniform.lightColor, sector.Sector.FogColor);
|
||||
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
|
||||
|
||||
// Render!
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
else graphics.Shaders.World3D.Desaturation = 0f;
|
||||
else graphics.SetUniform(Uniform.desaturation, 0.0f);
|
||||
}
|
||||
|
||||
// Get things for this pass
|
||||
|
@ -1195,8 +1170,8 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if((curtexture.Texture == null) || curtexture.Texture.Disposed)
|
||||
curtexture.CreateTexture();
|
||||
|
||||
// Apply texture
|
||||
graphics.Shaders.World3D.Texture1 = curtexture.Texture;
|
||||
// Apply texture
|
||||
graphics.SetUniform(Uniform.texture1, curtexture.Texture);
|
||||
curtexturename = t.Texture.LongName;
|
||||
}
|
||||
|
||||
|
@ -1204,7 +1179,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
if(t.GeometryBuffer != null)
|
||||
{
|
||||
// Determine the shader pass we want to use for this object
|
||||
int wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
Shader wantedshaderpass = (((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass;
|
||||
|
||||
//mxd. if fog is enagled, switch to shader, which calculates it
|
||||
if(General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE)
|
||||
|
@ -1237,37 +1212,35 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Switch shader pass?
|
||||
if(currentshaderpass != wantedshaderpass)
|
||||
{
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.Shaders.World3D.BeginPass(wantedshaderpass);
|
||||
graphics.SetShader(wantedshaderpass);
|
||||
currentshaderpass = wantedshaderpass;
|
||||
}
|
||||
|
||||
//mxd. Set variables for fog rendering?
|
||||
if(wantedshaderpass > 7)
|
||||
if(wantedshaderpass > Shader.world3d_p7)
|
||||
{
|
||||
graphics.Shaders.World3D.World = world;
|
||||
graphics.Shaders.World3D.ModelNormal = Matrix.Identity;
|
||||
graphics.SetUniform(Uniform.world, world);
|
||||
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
|
||||
if (t.FogFactor != fogfactor)
|
||||
{
|
||||
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
|
||||
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
|
||||
fogfactor = t.FogFactor;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the colors to use
|
||||
graphics.Shaders.World3D.LightColor = t.Thing.Sector.FogColor;
|
||||
graphics.Shaders.World3D.VertexColor = vertexcolor;
|
||||
graphics.Shaders.World3D.HighlightColor = CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection));
|
||||
// Set the colors to use
|
||||
graphics.SetUniform(Uniform.lightColor, t.Thing.Sector.FogColor);
|
||||
graphics.SetUniform(Uniform.vertexColor, vertexcolor);
|
||||
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
|
||||
|
||||
// [ZZ] check if we want stencil
|
||||
graphics.Shaders.World3D.StencilColor = t.StencilColor.ToColorValue();
|
||||
graphics.SetUniform(Uniform.stencilColor, t.StencilColor.ToColorValue());
|
||||
|
||||
//
|
||||
graphics.Shaders.World3D.Desaturation = t.Thing.Sector.Desaturation;
|
||||
graphics.SetUniform(Uniform.desaturation, t.Thing.Sector.Desaturation);
|
||||
|
||||
// Apply changes
|
||||
ApplyMatrices3D();
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
|
||||
// Apply buffer
|
||||
graphics.SetVertexBuffer(0, t.GeometryBuffer, 0, WorldVertex.Stride);
|
||||
|
@ -1278,15 +1251,12 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
|
||||
// [ZZ] check if we want stencil
|
||||
graphics.Shaders.World3D.StencilColor = new Color4(0f, 1f, 1f, 1f);
|
||||
graphics.SetUniform(Uniform.stencilColor, new Color4(0f, 1f, 1f, 1f));
|
||||
|
||||
// Texture addressing
|
||||
graphics.SetSamplerState(0, TextureAddress.Wrap);
|
||||
graphics.SetCullMode(Cull.Counterclockwise); //mxd
|
||||
}
|
||||
|
||||
// Done rendering with this shader
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
}
|
||||
|
||||
//mxd
|
||||
|
@ -1356,14 +1326,14 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
if (sector == null) continue;
|
||||
|
||||
graphics.Shaders.World3D.Desaturation = sector.Sector.Desaturation;
|
||||
graphics.SetUniform(Uniform.desaturation, sector.Sector.Desaturation);
|
||||
|
||||
// note: additive geometry doesn't receive lighting
|
||||
if (g.RenderPass == RenderPass.Additive)
|
||||
continue;
|
||||
|
||||
if (settexture)
|
||||
graphics.Shaders.World3D.Texture1 = g.Texture.Texture;
|
||||
graphics.SetUniform(Uniform.texture1, g.Texture.Texture);
|
||||
|
||||
//normal lights
|
||||
int count = lightOffsets[0];
|
||||
|
@ -1378,17 +1348,16 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
graphics.Shaders.World3D.LightColor = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
}
|
||||
|
@ -1406,17 +1375,16 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
graphics.Shaders.World3D.LightColor = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
}
|
||||
|
@ -1434,17 +1402,16 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
graphics.Shaders.World3D.LightColor = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
}
|
||||
|
@ -1463,17 +1430,16 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
Color4 lc = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightColor = new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2);
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2));
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
}
|
||||
|
@ -1488,9 +1454,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
if (geometrytolit.Count == 0) return;
|
||||
|
||||
graphics.Shaders.World3D.World = Matrix.Identity;
|
||||
graphics.Shaders.World3D.ModelNormal = Matrix.Identity;
|
||||
graphics.Shaders.World3D.BeginPass(SHADERPASS_LIGHT);
|
||||
graphics.SetUniform(Uniform.world, Matrix.Identity);
|
||||
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
|
||||
graphics.SetShader(Shader.world3d_lightpass);
|
||||
|
||||
VisualSector sector = null;
|
||||
|
||||
|
@ -1501,7 +1467,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
RenderLightsFromGeometryList(geometrytolit, lights, sector, true);
|
||||
|
||||
//
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.SetBlendOperation(BlendOperation.Add);
|
||||
}
|
||||
|
||||
|
@ -1511,9 +1476,9 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Anything to do?
|
||||
if (geometrytolit.Count == 0) return;
|
||||
|
||||
graphics.Shaders.World3D.World = Matrix.Identity;
|
||||
graphics.Shaders.World3D.ModelNormal = Matrix.Identity;
|
||||
graphics.Shaders.World3D.BeginPass(SHADERPASS_LIGHT);
|
||||
graphics.SetUniform(Uniform.world, Matrix.Identity);
|
||||
graphics.SetUniform(Uniform.modelnormal, Matrix.Identity);
|
||||
graphics.SetShader(Shader.world3d_lightpass);
|
||||
|
||||
VisualSector sector = null;
|
||||
|
||||
|
@ -1523,32 +1488,31 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
foreach (KeyValuePair<ImageData, List<VisualGeometry>> group in geometrytolit)
|
||||
{
|
||||
if (group.Key.Texture == null) continue;
|
||||
graphics.Shaders.World3D.Texture1 = group.Key.Texture;
|
||||
graphics.SetUniform(Uniform.texture1, group.Key.Texture);
|
||||
|
||||
sector = RenderLightsFromGeometryList(group.Value, lights, sector, false);
|
||||
}
|
||||
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.SetBlendOperation(BlendOperation.Add);
|
||||
}
|
||||
|
||||
//mxd. Render models
|
||||
private void RenderModels(bool lightpass, bool trans)
|
||||
{
|
||||
int shaderpass = (fullbrightness ? 1 : 4);
|
||||
int currentshaderpass = shaderpass;
|
||||
int highshaderpass = shaderpass + 2;
|
||||
Shader shaderpass = (fullbrightness ? Shader.world3d_fullbright : Shader.world3d_main_vertexcolor);
|
||||
Shader currentshaderpass = shaderpass;
|
||||
Shader highshaderpass = (Shader)(shaderpass + 2);
|
||||
|
||||
RenderPass currentpass = RenderPass.Solid;
|
||||
|
||||
// Begin rendering with this shader
|
||||
if (!lightpass)
|
||||
{
|
||||
graphics.Shaders.World3D.BeginPass(currentshaderpass);
|
||||
graphics.SetShader(currentshaderpass);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.Shaders.World3D.BeginPass(SHADERPASS_LIGHT);
|
||||
graphics.SetShader(Shader.world3d_lightpass);
|
||||
}
|
||||
|
||||
List<VisualThing> things;
|
||||
|
@ -1599,10 +1563,10 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
Color4 vertexcolor = new Color4(t.VertexColor);
|
||||
|
||||
// Check if model is affected by dynamic lights and set color accordingly
|
||||
graphics.Shaders.World3D.VertexColor = vertexcolor;
|
||||
graphics.SetUniform(Uniform.vertexColor, vertexcolor);
|
||||
|
||||
// Determine the shader pass we want to use for this object
|
||||
int wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass);
|
||||
Shader wantedshaderpass = ((((t == highlighted) && showhighlight) || (t.Selected && showselection)) ? highshaderpass : shaderpass);
|
||||
|
||||
// If fog is enagled, switch to shader, which calculates it
|
||||
if (General.Settings.GZDrawFog && !fullbrightness && t.Thing.Sector != null && t.Thing.Sector.FogMode != SectorFogMode.NONE)
|
||||
|
@ -1611,13 +1575,12 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
// Switch shader pass?
|
||||
if (!lightpass && currentshaderpass != wantedshaderpass)
|
||||
{
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
graphics.Shaders.World3D.BeginPass(wantedshaderpass);
|
||||
graphics.SetShader(wantedshaderpass);
|
||||
currentshaderpass = wantedshaderpass;
|
||||
}
|
||||
|
||||
// Set the colors to use
|
||||
graphics.Shaders.World3D.HighlightColor = CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection));
|
||||
// Set the colors to use
|
||||
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((t == highlighted) && showhighlight, (t.Selected && showselection)));
|
||||
|
||||
// Create the matrix for positioning / rotation
|
||||
float sx = t.Thing.ScaleX * t.Thing.ActorScale.Width;
|
||||
|
@ -1630,29 +1593,28 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
ApplyMatrices3D();
|
||||
|
||||
// Set variables for fog rendering
|
||||
if(wantedshaderpass > 7)
|
||||
if(wantedshaderpass > Shader.world3d_p7)
|
||||
{
|
||||
graphics.Shaders.World3D.World = world;
|
||||
graphics.SetUniform(Uniform.world, world);
|
||||
// this is not right...
|
||||
graphics.Shaders.World3D.ModelNormal = General.Map.Data.ModeldefEntries[t.Thing.Type].TransformRotation * modelrotation;
|
||||
if (t.Thing.Sector != null) graphics.Shaders.World3D.LightColor = t.Thing.Sector.FogColor;
|
||||
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor);
|
||||
graphics.SetUniform(Uniform.modelnormal, General.Map.Data.ModeldefEntries[t.Thing.Type].TransformRotation * modelrotation);
|
||||
if (t.Thing.Sector != null) graphics.SetUniform(Uniform.lightColor, t.Thing.Sector.FogColor);
|
||||
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
|
||||
}
|
||||
|
||||
if (t.Thing.Sector != null)
|
||||
graphics.Shaders.World3D.Desaturation = t.Thing.Sector.Desaturation;
|
||||
else graphics.Shaders.World3D.Desaturation = 0;
|
||||
graphics.SetUniform(Uniform.desaturation, t.Thing.Sector.Desaturation);
|
||||
else graphics.SetUniform(Uniform.desaturation, 0.0f);
|
||||
|
||||
GZModel model = General.Map.Data.ModeldefEntries[t.Thing.Type].Model;
|
||||
for (int j = 0; j < model.Meshes.Count; j++)
|
||||
{
|
||||
graphics.Shaders.World3D.Texture1 = model.Textures[j];
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
graphics.SetUniform(Uniform.texture1, model.Textures[j]);
|
||||
|
||||
if (!lightpass)
|
||||
{
|
||||
// Render!
|
||||
model.Meshes[j].DrawSubset(0);
|
||||
model.Meshes[j].Draw(graphics);
|
||||
}
|
||||
else if (lightpass && t.RenderPass != RenderPass.Additive) // additive stuff does not get any lighting
|
||||
{
|
||||
|
@ -1672,18 +1634,17 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
graphics.Shaders.World3D.LightColor = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
model.Meshes[j].DrawSubset(0);
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
model.Meshes[j].Draw(graphics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1700,18 +1661,17 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
graphics.Shaders.World3D.LightColor = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
model.Meshes[j].DrawSubset(0);
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
model.Meshes[j].Draw(graphics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1728,18 +1688,17 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
{
|
||||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
graphics.Shaders.World3D.LightColor = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, lights[i].LightColor);
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
model.Meshes[j].DrawSubset(0);
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
model.Meshes[j].Draw(graphics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1757,18 +1716,17 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
lpr = new Vector4(lights[i].Center, lights[i].LightRadius);
|
||||
if (lpr.W == 0) continue;
|
||||
Color4 lc = lights[i].LightColor;
|
||||
graphics.Shaders.World3D.LightColor = new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2);
|
||||
graphics.Shaders.World3D.LightPositionAndRadius = lpr;
|
||||
graphics.SetUniform(Uniform.lightColor, new Color4(lc.Alpha, (lc.Green + lc.Blue) / 2, (lc.Red + lc.Blue) / 2, (lc.Green + lc.Red) / 2));
|
||||
graphics.SetUniform(Uniform.lightPosAndRadius, lpr);
|
||||
GZGeneral.LightData ld = lights[i].LightType;
|
||||
if (ld.LightType == GZGeneral.LightType.SPOT)
|
||||
{
|
||||
graphics.Shaders.World3D.SpotLight = true;
|
||||
graphics.Shaders.World3D.LightOrientation = lights[i].VectorLookAt;
|
||||
graphics.Shaders.World3D.Light2Radius = new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2));
|
||||
graphics.SetUniform(Uniform.spotLight, true);
|
||||
graphics.SetUniform(Uniform.lightOrientation, lights[i].VectorLookAt);
|
||||
graphics.SetUniform(Uniform.light2Radius, new Vector2(CosDeg(lights[i].LightSpotRadius1), CosDeg(lights[i].LightSpotRadius2)));
|
||||
}
|
||||
else graphics.Shaders.World3D.SpotLight = false;
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
model.Meshes[j].DrawSubset(0);
|
||||
else graphics.SetUniform(Uniform.spotLight, false);
|
||||
model.Meshes[j].Draw(graphics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1776,7 +1734,6 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
}
|
||||
}
|
||||
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
if (lightpass) graphics.SetBlendOperation(BlendOperation.Add);
|
||||
}
|
||||
|
||||
|
@ -1786,10 +1743,10 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
VisualSector sector = null;
|
||||
|
||||
// Set render settings
|
||||
graphics.Shaders.World3D.BeginPass(SHADERPASS_SKYBOX);
|
||||
graphics.Shaders.World3D.Texture1 = General.Map.Data.SkyBox;
|
||||
graphics.Shaders.World3D.World = world;
|
||||
graphics.Shaders.World3D.CameraPosition = new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, 0f);
|
||||
graphics.SetShader(Shader.world3d_skybox);
|
||||
graphics.SetUniform(Uniform.texture1, General.Map.Data.SkyBox);
|
||||
graphics.SetUniform(Uniform.world, world);
|
||||
graphics.SetUniform(Uniform.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, 0f));
|
||||
|
||||
foreach(VisualGeometry g in geo)
|
||||
{
|
||||
|
@ -1817,18 +1774,10 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
if(sector != null)
|
||||
{
|
||||
// Set the colors to use
|
||||
graphics.Shaders.World3D.HighlightColor = CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection));
|
||||
|
||||
// Apply changes
|
||||
graphics.Shaders.World3D.ApplySettings();
|
||||
|
||||
// Render!
|
||||
graphics.SetUniform(Uniform.highlightcolor, CalculateHighlightColor((g == highlighted) && showhighlight, (g.Selected && showselection)));
|
||||
graphics.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
|
||||
}
|
||||
}
|
||||
|
||||
graphics.Shaders.World3D.EndPass();
|
||||
}
|
||||
|
||||
// [ZZ] this is copied from GZDoom
|
||||
|
|
|
@ -32,8 +32,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
|
||||
// Shaders
|
||||
private VertexDeclaration flatvertexdecl;
|
||||
private Things2DShader things2dshader;
|
||||
private World3DShader world3dshader;
|
||||
private VertexDeclaration worldvertexdecl;
|
||||
|
||||
// Device
|
||||
private RenderDevice device;
|
||||
|
@ -46,8 +45,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
#region ================== Properties
|
||||
|
||||
public VertexDeclaration FlatVertexDecl { get { return flatvertexdecl; } }
|
||||
public Things2DShader Things2D { get { return things2dshader; } }
|
||||
public World3DShader World3D { get { return world3dshader; } }
|
||||
public VertexDeclaration WorldVertexDecl { get { return worldvertexdecl; } }
|
||||
public bool IsDisposed { get { return isdisposed; } }
|
||||
internal RenderDevice D3DDevice { get { return device; } }
|
||||
|
||||
|
@ -97,8 +95,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
public void UnloadResource()
|
||||
{
|
||||
flatvertexdecl.Dispose();
|
||||
things2dshader.Dispose();
|
||||
world3dshader.Dispose();
|
||||
worldvertexdecl.Dispose();
|
||||
}
|
||||
|
||||
// Load resources
|
||||
|
@ -110,9 +107,13 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
new VertexElement(0, 16, DeclarationType.Float2, DeclarationUsage.TextureCoordinate)
|
||||
});
|
||||
|
||||
things2dshader = new Things2DShader(this);
|
||||
world3dshader = new World3DShader(this);
|
||||
}
|
||||
worldvertexdecl = new VertexDeclaration(new VertexElement[] {
|
||||
new VertexElement(0, 0, DeclarationType.Float3, DeclarationUsage.Position),
|
||||
new VertexElement(0, 12, DeclarationType.Color, DeclarationUsage.Color),
|
||||
new VertexElement(0, 16, DeclarationType.Float2, DeclarationUsage.TextureCoordinate),
|
||||
new VertexElement(0, 24, DeclarationType.Float3, DeclarationUsage.Normal)
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -127,5 +128,30 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
D3DDevice.SetUniform(Uniform.filtersettings, (int)filter);
|
||||
}
|
||||
|
||||
public void SetThings2DSettings(float alpha)
|
||||
{
|
||||
Vector4 values = new Vector4(0.0f, 0.0f, 1.0f, alpha);
|
||||
D3DDevice.SetUniform(Uniform.rendersettings, values);
|
||||
Matrix world = D3DDevice.GetTransform(TransformState.World);
|
||||
Matrix view = D3DDevice.GetTransform(TransformState.View);
|
||||
D3DDevice.SetUniform(Uniform.transformsettings, world * view);
|
||||
}
|
||||
|
||||
//mxd. Used to render models
|
||||
public void SetThings2DTransformSettings(Matrix world)
|
||||
{
|
||||
Matrix view = D3DDevice.GetTransform(TransformState.View);
|
||||
D3DDevice.SetUniform(Uniform.transformsettings, world * view);
|
||||
}
|
||||
|
||||
public void SetWorld3DConstants(bool bilinear, float maxanisotropy)
|
||||
{
|
||||
//mxd. It's still nice to have anisotropic filtering when texture filtering is disabled
|
||||
TextureFilter magminfilter = (bilinear ? TextureFilter.Linear : TextureFilter.Point);
|
||||
D3DDevice.SetUniform(Uniform.magfiltersettings, magminfilter);
|
||||
D3DDevice.SetUniform(Uniform.minfiltersettings, (maxanisotropy > 1.0f ? TextureFilter.Anisotropic : magminfilter));
|
||||
D3DDevice.SetUniform(Uniform.mipfiltersettings, (bilinear ? TextureFilter.Linear : TextureFilter.None)); // [SB] use None, otherwise textures are still filtered
|
||||
D3DDevice.SetUniform(Uniform.maxanisotropysetting, maxanisotropy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -632,7 +632,7 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
graphics.DrawPrimitives(PrimitiveType.TriangleList, entry.vertexoffset + (entry.numvertices * surfacevertexoffsetmul), entry.numvertices / 3);
|
||||
}
|
||||
}
|
||||
graphics.SetUniform(Uniform.desaturation, 0);
|
||||
graphics.SetUniform(Uniform.desaturation, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
|
||||
#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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
internal sealed class Things2DShader : EffectShader
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
// Property handlers
|
||||
private readonly EffectHandle texture1;
|
||||
private readonly EffectHandle rendersettings;
|
||||
private readonly EffectHandle transformsettings;
|
||||
private readonly EffectHandle fillcolor; //mxd
|
||||
private readonly EffectHandle desaturationHandle; // [ZZ]
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
public Texture Texture1 { set { effect.SetTexture(texture1, value); settingschanged = true; } }
|
||||
|
||||
//mxd
|
||||
private Color4 fc;
|
||||
public Color4 FillColor
|
||||
{
|
||||
set
|
||||
{
|
||||
if(fc != value)
|
||||
{
|
||||
effect.SetValue(fillcolor, value);
|
||||
fc = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [ZZ]
|
||||
private float desaturation;
|
||||
public float Desaturation
|
||||
{
|
||||
set
|
||||
{
|
||||
if (desaturation != value)
|
||||
{
|
||||
effect.SetValue(desaturationHandle, value);
|
||||
desaturation = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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");
|
||||
fillcolor = effect.GetParameter(null, "fillColor"); //mxd
|
||||
desaturationHandle = effect.GetParameter(null, "desaturation"); // [ZZ]
|
||||
}
|
||||
|
||||
// Initialize world vertex declaration
|
||||
VertexElement[] elements = new[]
|
||||
{
|
||||
new VertexElement(0, 0, DeclarationType.Float3, DeclarationUsage.Position),
|
||||
new VertexElement(0, 12, DeclarationType.Color, DeclarationUsage.Color),
|
||||
new VertexElement(0, 16, DeclarationType.Float2, DeclarationUsage.TextureCoordinate)
|
||||
};
|
||||
vertexdecl = new VertexDeclaration(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();
|
||||
if(fillcolor != null) fillcolor.Dispose(); //mxd
|
||||
if(desaturationHandle != null) desaturationHandle.Dispose();
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This sets the settings
|
||||
public void SetSettings(float alpha)
|
||||
{
|
||||
Vector4 values = new Vector4(0.0f, 0.0f, 1.0f, alpha);
|
||||
effect.SetValue(rendersettings, values);
|
||||
Matrix world = manager.D3DDevice.GetTransform(TransformState.World);
|
||||
Matrix view = manager.D3DDevice.GetTransform(TransformState.View);
|
||||
effect.SetValue(transformsettings, world * view);
|
||||
settingschanged = true; //mxd
|
||||
}
|
||||
|
||||
//mxd. Used to render models
|
||||
public void SetTransformSettings(Matrix world)
|
||||
{
|
||||
Matrix view = manager.D3DDevice.GetTransform(TransformState.View);
|
||||
effect.SetValue(transformsettings, world * view);
|
||||
settingschanged = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,370 +0,0 @@
|
|||
|
||||
#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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace CodeImp.DoomBuilder.Rendering
|
||||
{
|
||||
internal sealed class World3DShader : EffectShader
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
// Property handlers
|
||||
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;
|
||||
|
||||
//mxd
|
||||
private readonly EffectHandle vertexColorHandle;
|
||||
private readonly EffectHandle lightPositionAndRadiusHandle; //lights
|
||||
private readonly EffectHandle lightOrientationHandle;
|
||||
private readonly EffectHandle light2RadiusHandle;
|
||||
private readonly EffectHandle lightColorHandle;
|
||||
private readonly EffectHandle desaturationHandle;
|
||||
private readonly EffectHandle ignoreNormalsHandle;
|
||||
private readonly EffectHandle spotLightHandle;
|
||||
private readonly EffectHandle world;
|
||||
private readonly EffectHandle modelnormal;
|
||||
private readonly EffectHandle camPosHandle; //used for fog rendering
|
||||
|
||||
// [ZZ]
|
||||
private readonly EffectHandle stencilColorHandle;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Properties
|
||||
|
||||
private Matrix wwp;
|
||||
public Matrix WorldViewProj
|
||||
{
|
||||
set
|
||||
{
|
||||
if(wwp != value)
|
||||
{
|
||||
effect.SetValue(worldviewproj, value);
|
||||
wwp = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseTexture Texture1 { set { effect.SetTexture(texture1, value); settingschanged = true; } }
|
||||
|
||||
//mxd
|
||||
private Color4 vertexcolor;
|
||||
public Color4 VertexColor
|
||||
{
|
||||
set
|
||||
{
|
||||
if(vertexcolor != value)
|
||||
{
|
||||
effect.SetValue(vertexColorHandle, value);
|
||||
vertexcolor = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [ZZ]
|
||||
private Color4 stencilcolor;
|
||||
public Color4 StencilColor
|
||||
{
|
||||
set
|
||||
{
|
||||
if (stencilcolor != value)
|
||||
{
|
||||
effect.SetValue(stencilColorHandle, value);
|
||||
stencilcolor = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//lights
|
||||
private Color4 lightcolor;
|
||||
public Color4 LightColor
|
||||
{
|
||||
set
|
||||
{
|
||||
if(lightcolor != value)
|
||||
{
|
||||
effect.SetValue(lightColorHandle, value);
|
||||
lightcolor = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [ZZ] desaturation!
|
||||
private float desaturation;
|
||||
public float Desaturation
|
||||
{
|
||||
set
|
||||
{
|
||||
if (desaturation != value)
|
||||
{
|
||||
effect.SetValue(desaturationHandle, value);
|
||||
desaturation = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool spotlight;
|
||||
public bool SpotLight
|
||||
{
|
||||
set
|
||||
{
|
||||
if (spotlight != value)
|
||||
{
|
||||
effect.SetValue(spotLightHandle, value ? 1f : 0f);
|
||||
spotlight = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector4 lightpos;
|
||||
public Vector4 LightPositionAndRadius
|
||||
{
|
||||
set
|
||||
{
|
||||
if(lightpos != value)
|
||||
{
|
||||
effect.SetValue(lightPositionAndRadiusHandle, value);
|
||||
lightpos = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 lightori;
|
||||
public Vector3 LightOrientation
|
||||
{
|
||||
set
|
||||
{
|
||||
if (lightori != value)
|
||||
{
|
||||
effect.SetValue(lightOrientationHandle, value);
|
||||
lightori = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 light2rad;
|
||||
public Vector2 Light2Radius
|
||||
{
|
||||
set
|
||||
{
|
||||
if (light2rad != value)
|
||||
{
|
||||
effect.SetValue(light2RadiusHandle, value);
|
||||
light2rad = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//fog
|
||||
private Vector4 campos;
|
||||
public Vector4 CameraPosition
|
||||
{
|
||||
set
|
||||
{
|
||||
if(campos != value)
|
||||
{
|
||||
effect.SetValue(camPosHandle, value);
|
||||
campos = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Matrix mworld;
|
||||
public Matrix World
|
||||
{
|
||||
set
|
||||
{
|
||||
if(mworld != value)
|
||||
{
|
||||
effect.SetValue(world, value);
|
||||
mworld = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Matrix mmodelnormal;
|
||||
public Matrix ModelNormal
|
||||
{
|
||||
set
|
||||
{
|
||||
if (mmodelnormal != value)
|
||||
{
|
||||
effect.SetValue(modelnormal, value);
|
||||
mmodelnormal = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//mxd. This sets the highlight color
|
||||
private Color4 hicolor;
|
||||
public Color4 HighlightColor
|
||||
{
|
||||
set
|
||||
{
|
||||
if(hicolor != value)
|
||||
{
|
||||
effect.SetValue(highlightcolor, value);
|
||||
hicolor = value;
|
||||
settingschanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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");
|
||||
mipfiltersettings = effect.GetParameter(null, "mipfiltersettings");
|
||||
highlightcolor = effect.GetParameter(null, "highlightcolor");
|
||||
maxanisotropysetting = effect.GetParameter(null, "maxanisotropysetting");
|
||||
|
||||
//mxd
|
||||
vertexColorHandle = effect.GetParameter(null, "vertexColor");
|
||||
//lights
|
||||
lightPositionAndRadiusHandle = effect.GetParameter(null, "lightPosAndRadius");
|
||||
lightOrientationHandle = effect.GetParameter(null, "lightOrientation");
|
||||
light2RadiusHandle = effect.GetParameter(null, "light2Radius");
|
||||
lightColorHandle = effect.GetParameter(null, "lightColor");
|
||||
desaturationHandle = effect.GetParameter(null, "desaturation");
|
||||
ignoreNormalsHandle = effect.GetParameter(null, "ignoreNormals");
|
||||
spotLightHandle = effect.GetParameter(null, "spotLight");
|
||||
//fog
|
||||
camPosHandle = effect.GetParameter(null, "campos");
|
||||
|
||||
// [ZZ]
|
||||
stencilColorHandle = effect.GetParameter(null, "stencilColor");
|
||||
|
||||
world = effect.GetParameter(null, "world");
|
||||
modelnormal = effect.GetParameter(null, "modelnormal");
|
||||
}
|
||||
|
||||
// Initialize world vertex declaration
|
||||
VertexElement[] ve = {
|
||||
new VertexElement(0, 0, DeclarationType.Float3, DeclarationUsage.Position),
|
||||
new VertexElement(0, 12, DeclarationType.Color, DeclarationUsage.Color),
|
||||
new VertexElement(0, 16, DeclarationType.Float2, DeclarationUsage.TextureCoordinate),
|
||||
new VertexElement(0, 24, DeclarationType.Float3, DeclarationUsage.Normal)
|
||||
};
|
||||
|
||||
vertexdecl = new VertexDeclaration(ve);
|
||||
|
||||
// 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();
|
||||
if(mipfiltersettings != null) mipfiltersettings.Dispose();
|
||||
if(highlightcolor != null) highlightcolor.Dispose();
|
||||
if(maxanisotropysetting != null) maxanisotropysetting.Dispose();
|
||||
|
||||
//mxd
|
||||
if(vertexColorHandle != null) vertexColorHandle.Dispose();
|
||||
if(lightColorHandle != null) lightColorHandle.Dispose();
|
||||
if(desaturationHandle != null) desaturationHandle.Dispose();
|
||||
if(ignoreNormalsHandle != null) ignoreNormalsHandle.Dispose();
|
||||
if(light2RadiusHandle != null) light2RadiusHandle.Dispose();
|
||||
if(lightOrientationHandle != null) lightOrientationHandle.Dispose();
|
||||
if(lightPositionAndRadiusHandle != null) lightPositionAndRadiusHandle.Dispose();
|
||||
if(camPosHandle != null) camPosHandle.Dispose();
|
||||
if(stencilColorHandle != null) stencilColorHandle.Dispose();
|
||||
if(world != null) world.Dispose();
|
||||
if(modelnormal != null) modelnormal.Dispose();
|
||||
|
||||
// Done
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// This sets the constant settings
|
||||
public void SetConstants(bool bilinear, float maxanisotropy)
|
||||
{
|
||||
//mxd. It's still nice to have anisotropic filtering when texture filtering is disabled
|
||||
TextureFilter magminfilter = (bilinear ? TextureFilter.Linear : TextureFilter.Point);
|
||||
effect.SetValue(magfiltersettings, magminfilter);
|
||||
effect.SetValue(minfiltersettings, (maxanisotropy > 1.0f ? TextureFilter.Anisotropic : magminfilter));
|
||||
effect.SetValue(mipfiltersettings, (bilinear ? TextureFilter.Linear : TextureFilter.None)); // [SB] use None, otherwise textures are still filtered
|
||||
effect.SetValue(maxanisotropysetting, maxanisotropy);
|
||||
|
||||
settingschanged = true; //mxd
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue