Added visible highlight for targeted object in Visual Mode

This commit is contained in:
codeimp 2009-04-15 22:16:30 +00:00
parent 2f512649a3
commit 6b347ad51d
5 changed files with 125 additions and 16 deletions

View file

@ -49,7 +49,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
#region ================== Constants #region ================== Constants
// Object picking // Object picking
private const double PICK_INTERVAL = 100.0d; private const double PICK_INTERVAL = 80.0d;
private const float PICK_RANGE = 0.98f; private const float PICK_RANGE = 0.98f;
// Gravity // Gravity
@ -266,6 +266,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Use fog! // Use fog!
renderer.SetFogMode(true); renderer.SetFogMode(true);
// Set target for highlighting
renderer.SetHighlightedObject(target.picked);
// Begin with geometry // Begin with geometry
renderer.StartGeometry(); renderer.StartGeometry();

View file

@ -56,6 +56,7 @@ namespace CodeImp.DoomBuilder.Rendering
void FinishGeometry(); void FinishGeometry();
// Rendering methods // Rendering methods
void SetHighlightedObject(IVisualPickable obj);
void AddSectorGeometry(VisualGeometry g); void AddSectorGeometry(VisualGeometry g);
void AddThingGeometry(VisualThing t); void AddThingGeometry(VisualThing t);
void RenderCrosshair(); void RenderCrosshair();

View file

@ -77,6 +77,10 @@ namespace CodeImp.DoomBuilder.Rendering
private FlatVertex[] crosshairverts; private FlatVertex[] crosshairverts;
private bool crosshairbusy; private bool crosshairbusy;
// Highlighting
private IVisualPickable highlighted;
private float highlightglow;
// Geometry to be rendered. // Geometry to be rendered.
// Each Dictionary in the array is a render pass. // Each Dictionary in the array is a render pass.
// Each BinaryHeap in the Dictionary contains all geometry that needs // Each BinaryHeap in the Dictionary contains all geometry that needs
@ -376,11 +380,16 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Device.SetRenderState(RenderState.RangeFogEnable, false); graphics.Device.SetRenderState(RenderState.RangeFogEnable, false);
graphics.Device.SetRenderState(RenderState.TextureFactor, -1); graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
graphics.Shaders.World3D.SetModulateColor(-1); graphics.Shaders.World3D.SetModulateColor(-1);
graphics.Shaders.World3D.SetHighlightColor(0);
// Matrices // Matrices
world = Matrix.Identity; world = Matrix.Identity;
ApplyMatrices3D(); ApplyMatrices3D();
// Highlight
double time = General.Clock.GetCurrentTime();
highlightglow = (float)Math.Sin(time / 100.0f) * 0.3f + 0.5f;
// Determine shader pass to use // Determine shader pass to use
if(fullbrightness) shaderpass = 1; else shaderpass = 0; if(fullbrightness) shaderpass = 1; else shaderpass = 0;
@ -427,17 +436,13 @@ namespace CodeImp.DoomBuilder.Rendering
// SOLID PASS // SOLID PASS
world = Matrix.Identity; world = Matrix.Identity;
ApplyMatrices3D(); ApplyMatrices3D();
graphics.Shaders.World3D.BeginPass(shaderpass);
RenderSinglePass((int)RenderPass.Solid); RenderSinglePass((int)RenderPass.Solid);
graphics.Shaders.World3D.EndPass();
// MASK PASS // MASK PASS
world = Matrix.Identity; world = Matrix.Identity;
ApplyMatrices3D(); ApplyMatrices3D();
graphics.Device.SetRenderState(RenderState.AlphaTestEnable, true); graphics.Device.SetRenderState(RenderState.AlphaTestEnable, true);
graphics.Shaders.World3D.BeginPass(shaderpass);
RenderSinglePass((int)RenderPass.Mask); RenderSinglePass((int)RenderPass.Mask);
graphics.Shaders.World3D.EndPass();
// ALPHA PASS // ALPHA PASS
world = Matrix.Identity; world = Matrix.Identity;
@ -447,9 +452,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Device.SetRenderState(RenderState.ZWriteEnable, false); graphics.Device.SetRenderState(RenderState.ZWriteEnable, false);
graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
graphics.Shaders.World3D.BeginPass(shaderpass);
RenderSinglePass((int)RenderPass.Alpha); RenderSinglePass((int)RenderPass.Alpha);
graphics.Shaders.World3D.EndPass();
// THINGS // THINGS
if(renderthingcages) RenderThingCages(); if(renderthingcages) RenderThingCages();
@ -458,9 +461,7 @@ namespace CodeImp.DoomBuilder.Rendering
world = Matrix.Identity; world = Matrix.Identity;
ApplyMatrices3D(); ApplyMatrices3D();
graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.One); graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.One);
graphics.Shaders.World3D.BeginPass(shaderpass);
RenderSinglePass((int)RenderPass.Additive); RenderSinglePass((int)RenderPass.Additive);
graphics.Shaders.World3D.EndPass();
// Remove references // Remove references
graphics.Shaders.World3D.Texture1 = null; graphics.Shaders.World3D.Texture1 = null;
@ -511,6 +512,9 @@ namespace CodeImp.DoomBuilder.Rendering
// Get geometry for this pass // Get geometry for this pass
Dictionary<ImageData, BinaryHeap<VisualGeometry>> geopass = geometry[pass]; Dictionary<ImageData, BinaryHeap<VisualGeometry>> geopass = geometry[pass];
// Begin rendering with this shader
graphics.Shaders.World3D.BeginPass(shaderpass);
// Render the geometry collected // Render the geometry collected
foreach(KeyValuePair<ImageData, BinaryHeap<VisualGeometry>> group in geopass) foreach(KeyValuePair<ImageData, BinaryHeap<VisualGeometry>> group in geopass)
{ {
@ -558,10 +562,29 @@ namespace CodeImp.DoomBuilder.Rendering
} }
} }
// Render!
if(sector != null) if(sector != null)
{ {
// Highlight this object?
if(g == highlighted)
{
// Temporarely switch shader and use a highlight color
graphics.Shaders.World3D.EndPass();
Color4 highlight = General.Colors.Highlight.ToColorValue();
highlight.Alpha = highlightglow;
graphics.Shaders.World3D.SetHighlightColor(highlight.ToArgb());
graphics.Shaders.World3D.BeginPass(shaderpass + 2);
}
// Render!
graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles); graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, g.VertexOffset, g.Triangles);
// Reset highlight settings
if(g == highlighted)
{
graphics.Shaders.World3D.EndPass();
graphics.Shaders.World3D.SetHighlightColor(0);
graphics.Shaders.World3D.BeginPass(shaderpass);
}
} }
} }
} }
@ -600,6 +623,17 @@ namespace CodeImp.DoomBuilder.Rendering
// Only do this sector when a vertexbuffer is created // Only do this sector when a vertexbuffer is created
if(t.GeometryBuffer != null) if(t.GeometryBuffer != null)
{ {
// Highlight this object?
if(t == highlighted)
{
// Temporarely switch shader and use a highlight color
graphics.Shaders.World3D.EndPass();
Color4 highlight = General.Colors.Highlight.ToColorValue();
highlight.Alpha = highlightglow;
graphics.Shaders.World3D.SetHighlightColor(highlight.ToArgb());
graphics.Shaders.World3D.BeginPass(shaderpass + 2);
}
// Create the matrix for positioning / rotation // Create the matrix for positioning / rotation
world = t.Orientation; world = t.Orientation;
if(t.Billboard) world = Matrix.Multiply(world, billboard); if(t.Billboard) world = Matrix.Multiply(world, billboard);
@ -612,24 +646,42 @@ namespace CodeImp.DoomBuilder.Rendering
// Render! // Render!
graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, t.Triangles); graphics.Device.DrawPrimitives(PrimitiveType.TriangleList, 0, t.Triangles);
// Reset highlight settings
if(t == highlighted)
{
graphics.Shaders.World3D.EndPass();
graphics.Shaders.World3D.SetHighlightColor(0);
graphics.Shaders.World3D.BeginPass(shaderpass);
} }
} }
} }
} }
} }
// Done rendering with this shader
graphics.Shaders.World3D.EndPass();
}
// This finishes rendering // This finishes rendering
public void Finish() public void Finish()
{ {
// Done // Done
graphics.FinishRendering(); graphics.FinishRendering();
graphics.Present(); graphics.Present();
highlighted = null;
} }
#endregion #endregion
#region ================== Rendering #region ================== Rendering
// This sets the highlighted object for the rendering
public void SetHighlightedObject(IVisualPickable obj)
{
highlighted = obj;
}
// This collects a visual sector's geometry for rendering // This collects a visual sector's geometry for rendering
public void AddSectorGeometry(VisualGeometry g) public void AddSectorGeometry(VisualGeometry g)
{ {

View file

@ -46,6 +46,7 @@ namespace CodeImp.DoomBuilder.Rendering
private EffectHandle minfiltersettings; private EffectHandle minfiltersettings;
private EffectHandle magfiltersettings; private EffectHandle magfiltersettings;
private EffectHandle modulatecolor; private EffectHandle modulatecolor;
private EffectHandle highlightcolor;
#endregion #endregion
@ -72,6 +73,7 @@ namespace CodeImp.DoomBuilder.Rendering
minfiltersettings = effect.GetParameter(null, "minfiltersettings"); minfiltersettings = effect.GetParameter(null, "minfiltersettings");
magfiltersettings = effect.GetParameter(null, "magfiltersettings"); magfiltersettings = effect.GetParameter(null, "magfiltersettings");
modulatecolor = effect.GetParameter(null, "modulatecolor"); modulatecolor = effect.GetParameter(null, "modulatecolor");
highlightcolor = effect.GetParameter(null, "highlightcolor");
} }
// Initialize world vertex declaration // Initialize world vertex declaration
@ -100,6 +102,7 @@ namespace CodeImp.DoomBuilder.Rendering
if(minfiltersettings != null) minfiltersettings.Dispose(); if(minfiltersettings != null) minfiltersettings.Dispose();
if(magfiltersettings != null) magfiltersettings.Dispose(); if(magfiltersettings != null) magfiltersettings.Dispose();
if(modulatecolor != null) modulatecolor.Dispose(); if(modulatecolor != null) modulatecolor.Dispose();
if(highlightcolor != null) highlightcolor.Dispose();
// Done // Done
base.Dispose(); base.Dispose();
@ -113,17 +116,17 @@ namespace CodeImp.DoomBuilder.Rendering
// This sets the constant settings // This sets the constant settings
public void SetConstants(bool bilinear, bool useanisotropic) public void SetConstants(bool bilinear, bool useanisotropic)
{ {
if(manager.Enabled) if(manager.Enabled && General.Settings.QualityDisplay)
{ {
if(bilinear) if(bilinear)
{ {
effect.SetValue<int>(magfiltersettings, (int)TextureFilter.Linear); effect.SetValue(magfiltersettings, (int)TextureFilter.Linear);
if(useanisotropic) effect.SetValue<int>(minfiltersettings, (int)TextureFilter.Anisotropic); if(useanisotropic) effect.SetValue<int>(minfiltersettings, (int)TextureFilter.Anisotropic);
} }
else else
{ {
effect.SetValue<int>(magfiltersettings, (int)TextureFilter.Point); effect.SetValue(magfiltersettings, (int)TextureFilter.Point);
effect.SetValue<int>(minfiltersettings, (int)TextureFilter.Point); effect.SetValue(minfiltersettings, (int)TextureFilter.Point);
} }
} }
} }
@ -131,9 +134,9 @@ namespace CodeImp.DoomBuilder.Rendering
// This sets the modulation color // This sets the modulation color
public void SetModulateColor(int modcolor) public void SetModulateColor(int modcolor)
{ {
if(manager.Enabled) if(manager.Enabled && General.Settings.QualityDisplay)
{ {
effect.SetValue<Color4>(modulatecolor, new Color4(modcolor)); effect.SetValue(modulatecolor, new Color4(modcolor));
} }
else else
{ {
@ -142,6 +145,15 @@ namespace CodeImp.DoomBuilder.Rendering
} }
} }
// This sets the highlight color
public void SetHighlightColor(int hicolor)
{
if(manager.Enabled && General.Settings.QualityDisplay)
{
effect.SetValue(highlightcolor, new Color4(hicolor));
}
}
// This sets up the render pipeline // This sets up the render pipeline
public override void BeginPass(int index) public override void BeginPass(int index)
{ {

View file

@ -20,6 +20,9 @@ struct PixelData
// Modulation color // Modulation color
float4 modulatecolor; float4 modulatecolor;
// Highlight color
float4 highlightcolor;
// Matrix for final transformation // Matrix for final transformation
float4x4 worldviewproj; float4x4 worldviewproj;
@ -74,6 +77,30 @@ float4 ps_fullbright(PixelData pd) : COLOR
return tcolor * modulatecolor; return tcolor * modulatecolor;
} }
// Normal pixel shader with highlight
float4 ps_main_highlight(PixelData pd) : COLOR
{
float4 tcolor = tex2D(texturesamp, pd.uv);
// Blend texture color, vertex color and modulation color
float4 ncolor = tcolor * pd.color * modulatecolor;
float4 hcolor = float4(highlightcolor.rgb, ncolor.a);
return ncolor + hcolor * highlightcolor.a;
}
// Full-bright pixel shader with highlight
float4 ps_fullbright_highlight(PixelData pd) : COLOR
{
float4 tcolor = tex2D(texturesamp, pd.uv);
// Blend texture color and modulation color
float4 ncolor = tcolor * modulatecolor;
float4 hcolor = float4(highlightcolor.rgb, ncolor.a);
return ncolor + hcolor * highlightcolor.a;
}
// Technique for shader model 2.0 // Technique for shader model 2.0
technique SM20 technique SM20
{ {
@ -90,4 +117,18 @@ technique SM20
VertexShader = compile vs_2_0 vs_main(); VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_fullbright(); PixelShader = compile ps_2_0 ps_fullbright();
} }
// Normal with highlight
pass p2
{
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main_highlight();
}
// Full brightness mode with highlight
pass p3
{
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_fullbright_highlight();
}
} }