Improved rendering for nav poly selection, path shader now batches selection lines and tris

This commit is contained in:
dexyfex 2018-05-01 18:03:20 +10:00
parent a56e87d64a
commit 4c46a850f4
3 changed files with 113 additions and 82 deletions

View File

@ -757,7 +757,7 @@ namespace CodeWalker.Rendering
public void RenderSelectionNavPoly(YnvPoly poly) public void RenderSelectionNavPoly(YnvPoly poly)
{ {
////draw poly triangles ////draw poly triangles
var pcolour = new Color4(0.6f, 0.95f, 0.6f, 1.0f); var pcolour = new Color4(1.0f, 1.0f, 1.0f, 0.2f);
var colourval = (uint)pcolour.ToRgba(); var colourval = (uint)pcolour.ToRgba();
var ynv = poly.Ynv; var ynv = poly.Ynv;
var ic = poly._RawData.IndexCount; var ic = poly._RawData.IndexCount;
@ -792,6 +792,71 @@ namespace CodeWalker.Rendering
} }
} }
public void RenderSelectionNavPolyOutline(YnvPoly poly, uint colourval)
{
//var colourval = (uint)colour.ToRgba();
var ynv = poly.Ynv;
var ic = poly._RawData.IndexCount;
var startid = poly._RawData.IndexID;
var endid = startid + ic;
var lastid = endid - 1;
var vc = ynv.Vertices.Count;
var startind = ynv.Indices[startid];
////draw poly outline
VertexTypePC v = new VertexTypePC();
v.Colour = colourval;
VertexTypePC v0 = new VertexTypePC();
for (int id = startid; id < endid; id++)
{
var ind = ynv.Indices[id];
if (ind >= vc)
{ continue; }
v.Position = ynv.Vertices[ind];
SelectionLineVerts.Add(v);
if (id == startid)
{
v0 = v;
}
else
{
SelectionLineVerts.Add(v);
}
if (id == lastid)
{
SelectionLineVerts.Add(v0);
}
}
////draw poly triangles
//VertexTypePC v0 = new VertexTypePC();
//VertexTypePC v1 = new VertexTypePC();
//VertexTypePC v2 = new VertexTypePC();
//v0.Position = ynv.Vertices[startind];
//v0.Colour = colourval;
//v1.Colour = colourval;
//v2.Colour = colourval;
//int tricount = ic - 2;
//for (int t = 0; t < tricount; t++)
//{
// int tid = startid + t;
// int ind1 = ynv.Indices[tid + 1];
// int ind2 = ynv.Indices[tid + 2];
// if ((ind1 >= vc) || (ind2 >= vc))
// { continue; }
// v1.Position = ynv.Vertices[ind1];
// v2.Position = ynv.Vertices[ind2];
// Renderer.SelectionTriVerts.Add(v0);
// Renderer.SelectionTriVerts.Add(v1);
// Renderer.SelectionTriVerts.Add(v2);
// Renderer.SelectionTriVerts.Add(v0);
// Renderer.SelectionTriVerts.Add(v2);
// Renderer.SelectionTriVerts.Add(v1);
//}
}
public void RenderSelectionGeometry(MapSelectionMode mode) public void RenderSelectionGeometry(MapSelectionMode mode)
{ {

View File

@ -178,16 +178,31 @@ namespace CodeWalker.Rendering
SetInputLayout(context, VertexType.PC); SetInputLayout(context, VertexType.PC);
SetSceneVars(context, camera, null, lights); SetSceneVars(context, camera, null, lights);
vertices.Clear(); int drawn = 0;
foreach (var vert in verts) int tricount = verts.Count / 3;
int maxcount = vertices.StructCount / 3;
while (drawn < tricount)
{ {
vertices.Add(vert); vertices.Clear();
}
vertices.Update(context); int offset = drawn*3;
vertices.SetVSResource(context, 0); int bcount = Math.Min(tricount - drawn, maxcount);
for (int i = 0; i < bcount; i++)
{
int t = offset + (i * 3);
vertices.Add(verts[t + 0]);
vertices.Add(verts[t + 1]);
vertices.Add(verts[t + 2]);
}
drawn += bcount;
vertices.Update(context);
vertices.SetVSResource(context, 0);
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
context.Draw(vertices.CurrentCount, 0);
}
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
context.Draw(vertices.CurrentCount, 0);
} }
public void RenderLines(DeviceContext context, List<VertexTypePC> verts, Camera camera, ShaderGlobalLights lights) public void RenderLines(DeviceContext context, List<VertexTypePC> verts, Camera camera, ShaderGlobalLights lights)
@ -197,16 +212,29 @@ namespace CodeWalker.Rendering
SetInputLayout(context, VertexType.PC); SetInputLayout(context, VertexType.PC);
SetSceneVars(context, camera, null, lights); SetSceneVars(context, camera, null, lights);
vertices.Clear(); int drawn = 0;
foreach (var vert in verts) int linecount = verts.Count / 2;
int maxcount = vertices.StructCount / 2;
while (drawn < linecount)
{ {
vertices.Add(vert); vertices.Clear();
}
vertices.Update(context);
vertices.SetVSResource(context, 0);
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList; int offset = drawn * 2;
context.Draw(vertices.CurrentCount, 0); int bcount = Math.Min(linecount - drawn, maxcount);
for (int i = 0; i < bcount; i++)
{
int t = offset + (i * 2);
vertices.Add(verts[t + 0]);
vertices.Add(verts[t + 1]);
}
drawn += bcount;
vertices.Update(context);
vertices.SetVSResource(context, 0);
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList;
context.Draw(vertices.CurrentCount, 0);
}
} }

View File

@ -1435,7 +1435,8 @@ namespace CodeWalker
if (selectionItem.NavPoly != null) if (selectionItem.NavPoly != null)
{ {
Renderer.RenderSelectionNavPoly(selectionItem.NavPoly); Renderer.RenderSelectionNavPoly(selectionItem.NavPoly);
//return;//don't render a selection box for nav mesh? Renderer.RenderSelectionNavPolyOutline(selectionItem.NavPoly, cgrn);
return;//don't render a selection box for nav poly
} }
if (selectionItem.NavPoint != null) if (selectionItem.NavPoint != null)
{ {
@ -2717,70 +2718,7 @@ namespace CodeWalker
if ((CurMouseHit.NavPoly != null) && MouseSelectEnabled) if ((CurMouseHit.NavPoly != null) && MouseSelectEnabled)
{ {
var colour = Color4.White; Renderer.RenderSelectionNavPolyOutline(CurMouseHit.NavPoly, 0xFFFFFFFF);
var colourval = (uint)colour.ToRgba();
var poly = CurMouseHit.NavPoly;
var ynv = poly.Ynv;
var ic = poly._RawData.IndexCount;
var startid = poly._RawData.IndexID;
var endid = startid + ic;
var lastid = endid - 1;
var vc = ynv.Vertices.Count;
var startind = ynv.Indices[startid];
////draw poly outline
VertexTypePC v = new VertexTypePC();
v.Colour = colourval;
VertexTypePC v0 = new VertexTypePC();
for (int id = startid; id < endid; id++)
{
var ind = ynv.Indices[id];
if (ind >= vc)
{ continue; }
v.Position = ynv.Vertices[ind];
Renderer.SelectionLineVerts.Add(v);
if (id == startid)
{
v0 = v;
}
else
{
Renderer.SelectionLineVerts.Add(v);
}
if (id == lastid)
{
Renderer.SelectionLineVerts.Add(v0);
}
}
////draw poly triangles
//VertexTypePC v0 = new VertexTypePC();
//VertexTypePC v1 = new VertexTypePC();
//VertexTypePC v2 = new VertexTypePC();
//v0.Position = ynv.Vertices[startind];
//v0.Colour = colourval;
//v1.Colour = colourval;
//v2.Colour = colourval;
//int tricount = ic - 2;
//for (int t = 0; t < tricount; t++)
//{
// int tid = startid + t;
// int ind1 = ynv.Indices[tid + 1];
// int ind2 = ynv.Indices[tid + 2];
// if ((ind1 >= vc) || (ind2 >= vc))
// { continue; }
// v1.Position = ynv.Vertices[ind1];
// v2.Position = ynv.Vertices[ind2];
// Renderer.SelectionTriVerts.Add(v0);
// Renderer.SelectionTriVerts.Add(v1);
// Renderer.SelectionTriVerts.Add(v2);
// Renderer.SelectionTriVerts.Add(v0);
// Renderer.SelectionTriVerts.Add(v2);
// Renderer.SelectionTriVerts.Add(v1);
//}
} }
} }