intersection working, outlines wrong

This commit is contained in:
2018-04-10 14:02:18 -04:00
parent dd5f05a12f
commit f3bfaf021e
2 changed files with 53 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Data.Common;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics.OpenGL;
@@ -22,6 +23,13 @@ namespace Platformer
public static ViewMats Identity => new ViewMats {Model = Matrix4.Identity, View = Matrix4.Identity};
}
public struct PlaneMats
{
public Matrix4 Tform;
public static PlaneMats Identity => new PlaneMats {Tform = Matrix4.Identity};
}
public class PlatformWindow : GameWindow
{
private Program _render;
@@ -29,16 +37,22 @@ namespace Platformer
private Buffer<Vector4> _tVerts;
private Buffer<uint> _tFaces;
private Buffer<uint> _tEdges;
private Buffer<ViewMats> _ubo;
private Buffer<ViewMats> _viewBuf;
private Buffer<PlaneMats> _tformBuf;
private VertexArray _tetraVao;
private ViewMats _view;
private PlaneMats _tform;
private Buffer<uint> _tInds;
private Buffer<Vector4> _pVerts;
private Program _compute;
private Buffer<uint> _pEdges;
private Buffer<uint> _pAreas;
private VertexArray _polyVao;
protected override void OnLoad(EventArgs e)
@@ -75,12 +89,18 @@ namespace Platformer
_pEdges = new Buffer<uint>(_tInds.Count / 4 * 8);
_pAreas = new Buffer<uint>(_tInds.Count / 4 * 6);
_ubo = new Buffer<ViewMats>();
_viewBuf = new Buffer<ViewMats>();
_view = ViewMats.Identity;
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, _ubo);
_tformBuf = new Buffer<PlaneMats>();
_tform = PlaneMats.Identity;
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, _viewBuf);
GL.UniformBlockBinding(_render, _render.UnifBlockInd("ViewMats"), 0);
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 1, _tformBuf);
GL.UniformBlockBinding(_compute, _compute.UnifBlockInd("PlaneMats"), 1);
_tetraVao = new VertexArray();
_tetraVao.VertexPointer(_tVerts, index: _render.AttrLoc("pos"), size: 4);
@@ -126,10 +146,10 @@ namespace Platformer
_view.Proj = Matrix4.CreateOrthographic(5, 5f * Height / Width, -2.5f, 2.5f);
_view.View = Matrix4.LookAt(Vector3.Zero, -Vector3.One, Vector3.UnitZ);
_tform.Tform = _view.Model *= Matrix4.CreateRotationZ((float) e.Time);
_view.Model *= Matrix4.CreateRotationZ((float) e.Time);
_ubo.SetData(ref _view);
_viewBuf.SetData(ref _view);
_tformBuf.SetData(ref _tform);
GL.UseProgram(_compute);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 0, _tVerts);

View File

@@ -28,28 +28,35 @@ uniform PlaneMats
layout(local_size_x = 128, local_size_y = 1, local_size_z = 1) in;
void main () {
uint ti0 = gl_GlobalInvocationID.x * 4;
uint pv0 = gl_GlobalInvocationID.x * 4;
uint pe0 = gl_GlobalInvocationID.x * 8;
int ti0 = int(gl_GlobalInvocationID.x * 4);
int pv0 = int(gl_GlobalInvocationID.x * 4);
int pe0 = int(gl_GlobalInvocationID.x * 8);
uint ii = 0;
uint vv = 0;
int ii = 0;
int vv = 0;
// polyVerts[pv0 + vv++] = vec4(-1,0,0,1);
// polyVerts[pv0 + vv++] = vec4(1,0,0,1);
//
// polyEdges[pe0 + ii++] = pv0 + 0;
// polyEdges[pe0 + ii++] = pv0 + 1;
for(uint i = 1; i < 4; i++)
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++)
{
polyVerts[pv0 + vv++] = (tetraVerts[ti0] + tetraVerts[ti0 + i]) / 2;
}
vec4 a = tetraVerts[tetraInds[ti0 + i]];
vec4 a_ = tform * a;
vec4 b = tetraVerts[tetraInds[ti0 + j]];
vec4 b_ = tform * b;
polyEdges[pe0 + ii++] = pv0 + 0;
polyEdges[pe0 + ii++] = pv0 + 1;
polyEdges[pe0 + ii++] = pv0 + 1;
polyEdges[pe0 + ii++] = pv0 + 2;
polyEdges[pe0 + ii++] = pv0 + 2;
polyEdges[pe0 + ii++] = pv0 + 0;
if (a_.x * b_.x < 0)
{
vec4 p = (b-a) / (a_.x - b_.x) * b_.x + b;
polyVerts[pv0 + vv++] = p;
}
}
for (int i = 0; i < vv; i++)
{
polyEdges[pe0 + ii++] = pv0 + i;
polyEdges[pe0 + ii++] = pv0 + (i + 1) % vv;
}
while (vv < 4) polyVerts[pv0 + vv++] = vec4(0);
while (ii < 8) polyEdges[pe0 + ii++] = 0;
}