Compare commits

4 Commits

Author SHA1 Message Date
f254facb85 edges working but intermittent 2018-04-06 20:42:00 -04:00
4a25ae992f faces working properly 2018-04-06 19:35:47 -04:00
94775b73cf better but still broken 2018-04-06 17:01:17 -04:00
93cd1c767f cleanup and refactoring 2018-04-06 12:01:52 -04:00
7 changed files with 337 additions and 221 deletions

View File

@@ -0,0 +1,24 @@
using System.Runtime.InteropServices;
using OpenTK;
namespace Tetrahedrons
{
public struct PenTransform
{
public Matrix4 Rotate; // want this to be a bivector somehow
public Vector4 Pivot;
public static PenTransform Identity => new PenTransform() {Rotate = Matrix4.Identity, Pivot = Vector4.Zero};
public static readonly int SizeInBytes = Marshal.SizeOf(typeof(PenTransform));
}
public struct ViewTransform
{
public Matrix4 Model;
public Matrix4 View;
public Matrix4 Projection;
public static ViewTransform Identity => new ViewTransform() {Model = Matrix4.Identity, View = Matrix4.Identity, Projection = Matrix4.Identity};
public static readonly int SizeInBytes = Marshal.SizeOf(typeof(ViewTransform));
}
}

View File

@@ -1,224 +1,254 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform.Windows;
namespace Tetrahedrons
{
struct MatrixBlock
{
public Matrix4 Model;
public Matrix4 View;
public Matrix4 Projection;
internal class Gl4Window : GameWindow
{
private float _t;
public static MatrixBlock Identity => new MatrixBlock() {Model = Matrix4.Identity, View = Matrix4.Identity, Projection = Matrix4.Identity};
public static readonly int SizeInBytes = Marshal.SizeOf(typeof(MatrixBlock));
}
private int _pgmRend;
struct TransformMats
{
public Matrix4 Rotate;
public Vector4 Pivot;
private int _shVert;
private int _shFrag;
public static TransformMats Identity => new TransformMats() {Rotate = Matrix4.Identity, Pivot = Vector4.Zero};
public static readonly int SizeInBytes = Marshal.SizeOf(typeof(TransformMats));
}
private int _bufPentVerts;
private int _bufPentInds;
internal class Gl4Window : GameWindow
{
private float _t;
private int _bufHullEdgeInds;
private int _bufHullFaceInds;
private int _bufHullVerts;
private int _pgmRend;
private int _bufTransView;
private int _bufTransPent;
private int _shVert;
private int _shFrag;
private Vector4[] _datPentVerts;
private uint[] _datPentInds;
private int _bufPentVerts;
private int _bufPentInds;
private int _bufUniform;
private int _bufPenMats;
private ViewTransform _transView;
private PenTransform _transPent;
private Vector4[] _datPentVerts;
private uint[] _datPentInds;
private int _shComp;
private int _pgmComp;
private MatrixBlock _datMats;
private TransformMats _datPenMats;
private int _hullFaceIndsCount;
private int _hullEdgeIndsCount;
private int _hullVertsCount;
private int _bufHullVerts;
private int _bufHullInds;
private int _penIndsCount;
private int _penVertsCount;
private int _shComp;
private int _pgmComp;
private int _invocationCount;
private int _hullIndsCount;
private int _hullVertsCount;
private int _penIndsCount;
private int _penVertsCount;
private int _invocationCount;
private float _w = 6;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
X = (DisplayDevice.Default.Width - Width) / 2;
Y = (DisplayDevice.Default.Height - Height) / 2;
X = (DisplayDevice.Default.Width - Width) / 2;
Y = (DisplayDevice.Default.Height - Height) / 2;
#region Shaders
#region Shaders
_pgmRend = GL.CreateProgram();
_pgmRend = GL.CreateProgram();
_shVert = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource(_shVert, File.ReadAllText("Shaders/simple.vert"));
GL.CompileShader(_shVert);
GL.AttachShader(_pgmRend, _shVert);
Console.WriteLine(GL.GetShaderInfoLog(_shVert));
_shVert = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource(_shVert, File.ReadAllText("Shaders/simple.vert"));
GL.CompileShader(_shVert);
GL.AttachShader(_pgmRend, _shVert);
Console.WriteLine(GL.GetShaderInfoLog(_shVert));
_shFrag = GL.CreateShader(ShaderType.FragmentShader);
GL.ShaderSource(_shFrag, File.ReadAllText("Shaders/simple.frag"));
GL.CompileShader(_shFrag);
GL.AttachShader(_pgmRend, _shFrag);
Console.WriteLine(GL.GetShaderInfoLog(_shFrag));
_shFrag = GL.CreateShader(ShaderType.FragmentShader);
GL.ShaderSource(_shFrag, File.ReadAllText("Shaders/simple.frag"));
GL.CompileShader(_shFrag);
GL.AttachShader(_pgmRend, _shFrag);
Console.WriteLine(GL.GetShaderInfoLog(_shFrag));
GL.LinkProgram(_pgmRend);
Console.WriteLine(GL.GetProgramInfoLog(_pgmRend));
GL.LinkProgram(_pgmRend);
Console.WriteLine(GL.GetProgramInfoLog(_pgmRend));
_pgmComp = GL.CreateProgram();
_shComp = GL.CreateShader(ShaderType.ComputeShader);
GL.ShaderSource(_shComp, File.ReadAllText("Shaders/intersect.comp"));
GL.CompileShader(_shComp);
GL.AttachShader(_pgmComp, _shComp);
Console.Out.WriteLine(GL.GetShaderInfoLog(_shComp));
GL.LinkProgram(_pgmComp);
Console.Out.WriteLine(GL.GetProgramInfoLog(_pgmComp));
#endregion
_w = 10;
var n = 5;
var vlst = new List<Vector4>();
var ilst = new List<uint>();
for (var x = 0; x < n; x++)
for (var y = 0; y < n; y++)
for (var z = 0; z < n; z++)
for (var w = 0; w < n; w++)
{
vlst.Add(new Vector4(x + 1, y - 0, z - 0, w - 0) - new Vector4(n) / 2);
vlst.Add(new Vector4(x - 0, y + 1, z - 0, w - 0) - new Vector4(n) / 2);
vlst.Add(new Vector4(x - 0, y - 0, z + 1, w - 0) - new Vector4(n) / 2);
vlst.Add(new Vector4(x - 0, y - 0, z - 0, w + 1) - new Vector4(n) / 2);
vlst.Add(new Vector4(x + 1, y + 1, z + 1, w + 1) - new Vector4(n) / 2);
ilst.Add((uint) ilst.Count);
ilst.Add((uint) ilst.Count);
ilst.Add((uint) ilst.Count);
ilst.Add((uint) ilst.Count);
ilst.Add((uint) ilst.Count);
}
_datPentVerts = vlst.ToArray();
_datPentInds = ilst.ToArray();
// _datPentVerts = new[]
// {
// new Vector4(-1, -1, -1, -1) / 2,
// new Vector4(+1, +1, -1, -1) / 2,
// new Vector4(-1, +1, +1, -1) / 2,
// new Vector4(+1, -1, +1, -1) / 2,
// new Vector4(+0, +0, +0, +1) / 2,
// };
// _datPentInds = new uint[]
// {
// 0, 1, 2, 3, 4
// };
_transView = ViewTransform.Identity;
_transPent = PenTransform.Identity;
_penVertsCount = _datPentVerts.Length;
_penIndsCount = _datPentInds.Length;
_invocationCount = _penIndsCount / 5;
_hullVertsCount = _invocationCount * 6; // 6 hull verts per pent
_hullFaceIndsCount = _invocationCount * 24; // 24 hull inds per pent
_hullEdgeIndsCount = _invocationCount * 18;
_bufPentVerts = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufPentVerts);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_penVertsCount * Vector4.SizeInBytes), _datPentVerts, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufPentInds = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufPentInds);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_penIndsCount * sizeof(int)), _datPentInds, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufHullVerts = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufHullVerts);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_hullVertsCount * Vector4.SizeInBytes), IntPtr.Zero, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufHullFaceInds = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufHullFaceInds);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_hullFaceIndsCount * sizeof(int)), IntPtr.Zero, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufHullEdgeInds = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufHullEdgeInds);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_hullEdgeIndsCount * sizeof(int)), IntPtr.Zero, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufTransView = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufTransView);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) ViewTransform.SizeInBytes, ref _transView, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufTransPent = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufTransPent);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) ViewTransform.SizeInBytes, ref _transPent, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
GL.UniformBlockBinding(_pgmRend, 0, 0);
}
_pgmComp = GL.CreateProgram();
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Viewport(0, 0, Width, Height);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Enable(EnableCap.DepthTest);
_shComp = GL.CreateShader(ShaderType.ComputeShader);
GL.ShaderSource(_shComp, File.ReadAllText("Shaders/intersect.comp"));
GL.CompileShader(_shComp);
GL.AttachShader(_pgmComp, _shComp);
Console.Out.WriteLine(GL.GetShaderInfoLog(_shComp));
GL.UseProgram(_pgmComp);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 1, _bufPentVerts);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 2, _bufPentInds);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 3, _bufHullVerts);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 4, _bufHullFaceInds);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 5, _bufHullEdgeInds);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 6, _bufTransPent);
GL.DispatchCompute(_invocationCount, 1, 1);
GL.MemoryBarrier(MemoryBarrierFlags.ShaderStorageBarrierBit);
GL.LinkProgram(_pgmComp);
Console.Out.WriteLine(GL.GetProgramInfoLog(_pgmComp));
#endregion
_datPentVerts = new[]
{
new Vector4(-1, -1, -1, +1) / 2,
new Vector4(+1, -1, -1, -1) / 2,
new Vector4(-1, +1, -1, -1) / 2,
new Vector4(-1, -1, +1, -1) / 2,
new Vector4(+1, +1, +1, +1) / 2,
};
_datPentInds = new uint[]
{
0, 1, 2, 3, 4,
// 0, 1, 2, 3, 5,
};
_datMats = MatrixBlock.Identity;
_datPenMats = TransformMats.Identity;
_penVertsCount = _datPentVerts.Length;
_penIndsCount = _datPentInds.Length;
_invocationCount = _penIndsCount / 5;
_hullVertsCount = _invocationCount * 6; // 6 hull verts per pent
_hullIndsCount = _invocationCount * 24; // 24 hull inds per pent
Console.Out.WriteLine("_hullIndsCount = {0}", _hullIndsCount);
_bufPentVerts = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufPentVerts);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_penVertsCount * Vector4.SizeInBytes), _datPentVerts, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufPentInds = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufPentInds);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_penIndsCount * sizeof(int)), _datPentInds, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufHullVerts = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufHullVerts);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_hullVertsCount * Vector4.SizeInBytes), IntPtr.Zero, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufHullInds = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufHullInds);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) (_hullIndsCount * sizeof(int)), IntPtr.Zero, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufUniform = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufUniform);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) MatrixBlock.SizeInBytes, ref _datMats, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
_bufPenMats = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufPenMats);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) MatrixBlock.SizeInBytes, ref _datPenMats, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
GL.UniformBlockBinding(_pgmRend, 0, 0);
}
GL.UseProgram(_pgmRend);
GL.PointSize(10f);
GL.LineWidth(4f);
GL.BindBuffer(BufferTarget.ArrayBuffer, _bufHullVerts);
GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.EnableVertexAttribArray(0);
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Viewport(0, 0, Width, Height);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.DepthTest);
GL.Uniform4(3, new Vector4(1, 1, 1, 1));
GL.BindBuffer(BufferTarget.ElementArrayBuffer, _bufHullFaceInds);
GL.DrawElements(BeginMode.Triangles, _hullFaceIndsCount, DrawElementsType.UnsignedInt, 0);
GL.Disable(EnableCap.DepthTest);
GL.UseProgram(_pgmComp);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 1, _bufPentVerts);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 2, _bufPentInds);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 3, _bufHullVerts);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 4, _bufHullInds);
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 5, _bufPenMats);
GL.DispatchCompute(_invocationCount, 1, 1);
GL.MemoryBarrier(MemoryBarrierFlags.ShaderStorageBarrierBit);
GL.Uniform4(3, new Vector4(0, 0, 0, 1));
GL.BindBuffer(BufferTarget.ElementArrayBuffer, _bufHullEdgeInds);
GL.DrawElements(BeginMode.Lines, _hullEdgeIndsCount, DrawElementsType.UnsignedInt, 0);
GL.UseProgram(_pgmRend);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, _bufHullInds);
GL.BindBuffer(BufferTarget.ArrayBuffer, _bufHullVerts);
GL.VertexAttribPointer(0, 4, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.Enable(EnableCap.DepthTest);
GL.EnableVertexAttribArray(0);
GL.DrawElements(BeginMode.Triangles, _hullIndsCount, DrawElementsType.UnsignedInt, 0);
GL.DisableVertexAttribArray(0);
GL.Disable(EnableCap.DepthTest);
GL.Flush();
SwapBuffers();
}
GL.DisableVertexAttribArray(0);
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
_t += (float) e.Time;
GL.Flush();
SwapBuffers();
}
float w = 3;
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);
_t += (float) e.Time;
_datMats.Projection = Matrix4.CreateOrthographic(w, w * Height / Width, -w, w);
_datMats.View = Matrix4.LookAt(Vector3.Zero, -new Vector3(1, -1, 1), Vector3.UnitZ);
_datMats.Model = Matrix4.CreateRotationZ(_t / 10);
_transView.Projection = Matrix4.CreateOrthographic(_w, _w * Height / Width, -_w, _w);
_transView.View = Matrix4.LookAt(Vector3.Zero, -new Vector3(1, -1, 1), Vector3.UnitZ);
_transView.Model = Matrix4.CreateRotationZ(_t / 10);
_bufUniform = GL.GenBuffer();
GL.BindBuffer(BufferTarget.UniformBuffer, _bufUniform);
GL.BufferData(BufferTarget.UniformBuffer, (IntPtr) MatrixBlock.SizeInBytes, ref _datMats, BufferUsageHint.StaticDraw);
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, _bufUniform);
GL.BindBuffer(BufferTarget.UniformBuffer, 0);
_bufTransView = GL.GenBuffer();
GL.BindBuffer(BufferTarget.UniformBuffer, _bufTransView);
GL.BufferData(BufferTarget.UniformBuffer, (IntPtr) ViewTransform.SizeInBytes, ref _transView, BufferUsageHint.StaticDraw);
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, _bufTransView);
GL.BindBuffer(BufferTarget.UniformBuffer, 0);
_datPenMats.Pivot.W = (float) (Math.Sin(_t) * .6);
_datPenMats.Rotate = new Matrix4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, (float)Math.Sin(_t/2), (float)-Math.Cos(_t/2),
0, 0, (float)Math.Cos(_t/2), (float)Math.Sin(_t/2));
// _transPent.Pivot.W = .3f;
// _transPent.Pivot.W = (float) (Math.Sin(_t*.5) * .6);
var a = 1f;
a = _t;
_transPent.Rotate = new Matrix4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, (float) Math.Cos(a / 5), (float) Math.Sin(a / 5),
0, 0, (float) -Math.Sin(a / 5), (float) Math.Cos(a / 5));
_bufPenMats = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufPenMats);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) MatrixBlock.SizeInBytes, ref _datPenMats, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
}
}
_bufTransPent = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, _bufTransPent);
GL.BufferData(BufferTarget.ShaderStorageBuffer, (IntPtr) ViewTransform.SizeInBytes, ref _transPent, BufferUsageHint.DynamicDraw);
GL.BindBuffer(BufferTarget.ShaderStorageBuffer, 0);
}
}
}

View File

@@ -9,9 +9,6 @@ namespace Tetrahedrons
{
using (var p = new Gl4Window())
p.Run();
// using (var p = new TetrahedronWindow())
// p.Run();
}
}
}

View File

@@ -7,7 +7,7 @@ layout(std430, binding=1) buffer PentVerts
layout(std430, binding=2) buffer PentInds
{
uint pentInds[];
int pentInds[];
};
layout(std430, binding=3) buffer HullVerts
@@ -15,74 +15,134 @@ layout(std430, binding=3) buffer HullVerts
vec4 hullVerts[];
};
layout(std430, binding=4) buffer HullInds
layout(std430, binding=4) buffer HullFaceInds
{
uint hullInds[];
int hullFaceInds[];
};
layout(std430, binding=5) buffer Transform
layout(std430, binding=5) buffer HullEgdeInds
{
int hullEdgeInds[];
};
layout(std430, binding=6) buffer Transform
{
mat4 rotate;
vec4 pivot;
};
layout(local_size_x = 128, local_size_y = 1, local_size_z = 1) in;
layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
void main() {
uint pentInd0 = gl_GlobalInvocationID.x * 5;
uint hullVrt0 = gl_GlobalInvocationID.x * 6;
uint hullInd0 = gl_GlobalInvocationID.x * 24;
int iid = int(gl_GlobalInvocationID.x);
int k = 0;
int pi0 = iid * 5;
int hv0 = iid * 6;
int hi0 = iid * 24;
int he0 = iid * 18;
for(int i = 0; i < 24; i++)
hullFaceInds[hi0 + i] = 0;
for(int i = 0; i < 18; i++)
hullEdgeInds[he0 + i] = 0;
int vi = 0; // vert index
int fi = 0; // face inds index
int ei = 0; // edge inds index
for(int i = 0; i < 5; i++)
for(int j = i + 1; j < 5; j++)
{
vec4 a = (pentVerts[pentInds[pentInd0 + i]] - pivot) * rotate;
vec4 b = (pentVerts[pentInds[pentInd0 + j]] - pivot) * rotate;
vec4 a = (pentVerts[pentInds[pi0 + i]] - pivot) * rotate;
vec4 b = (pentVerts[pentInds[pi0 + j]] - pivot) * rotate;
if (a.w * b.w < 0) // different sides
{
float alph = a.w / (a.w - b.w);
vec4 p = a + alph * (b - a);
hullVerts[hullVrt0 + k++] = p + pivot;
hullVerts[hv0 + vi] = p + pivot;
hullFaceInds[hi0 + 23 - 2 * vi] = i;
hullFaceInds[hi0 + 22 - 2 * vi] = j;
vi++;
}
}
for (int i = 0; i < 24; i++)
hullInds[hullInd0 + i] = 0;
int v = 0;
if (k == 4)
if (vi == 4) // points form a tetrahedron
{
for(int i = 0; i < 4; i++)
for(int i = 0; i < 4; i++)
for(int j = i + 1; j < 4; j++)
for(int k = j + 1; k < 4; k++)
{
hullInds[hullInd0 + v++] = hullVrt0 + i;
hullInds[hullInd0 + v++] = hullVrt0 + j;
hullInds[hullInd0 + v++] = hullVrt0 + k;
hullFaceInds[hi0 + fi++] = hv0 + i;
hullFaceInds[hi0 + fi++] = hv0 + j;
hullFaceInds[hi0 + fi++] = hv0 + k;
}
for(int i = 0; i < 4; i++)
for(int j = i + 1; j < 4; j++)
{
hullEdgeInds[hi0 + ei++] = hv0 + i;
hullEdgeInds[hi0 + ei++] = hv0 + j;
}
}
else if (k == 6)
{
for (int i = 0; i < 6; i++)
hullInds[hullInd0 + v++] = hullVrt0 + i;
else if (vi == 6) { // points form a triangular prism
for(int f = 0; f < 5; f++)
{
for(int i = 0; i < 4; i++)
for(int j = i + 1; j < 5; j++)
for(int k = j + 1; k < 6; k++)
if (
(hullFaceInds[hi0 + 23 - 2 * i] == f ||
hullFaceInds[hi0 + 22 - 2 * i] == f) &&
(hullFaceInds[hi0 + 23 - 2 * j] == f ||
hullFaceInds[hi0 + 22 - 2 * j] == f) &&
(hullFaceInds[hi0 + 23 - 2 * k] == f ||
hullFaceInds[hi0 + 22 - 2 * k] == f))
{
hullFaceInds[hi0 + fi++] = hv0 + i;
hullFaceInds[hi0 + fi++] = hv0 + j;
hullFaceInds[hi0 + fi++] = hv0 + k;
hullEdgeInds[he0 + ei++] = hv0 + i;
hullEdgeInds[he0 + ei++] = hv0 + j;
hullEdgeInds[he0 + ei++] = hv0 + j;
hullEdgeInds[he0 + ei++] = hv0 + k;
hullEdgeInds[he0 + ei++] = hv0 + k;
hullEdgeInds[he0 + ei++] = hv0 + i;
}
}
for (int i = 0; i < 3; i++)
{
int a = i;
int b = (1 + i) % 3;
int c = 3 + i;
int d = 3 + (1 + i) % 3;
int a = hullFaceInds[hi0 + i];
int b = hullFaceInds[hi0 + (1 + i) % 3];
int c = hullFaceInds[hi0 + 3 + i];
int d = hullFaceInds[hi0 + 3 + (1 + i) % 3];
hullInds[hullInd0 + v++] = hullVrt0 + c;
hullInds[hullInd0 + v++] = hullVrt0 + a;
hullInds[hullInd0 + v++] = hullVrt0 + b;
hullInds[hullInd0 + v++] = hullVrt0 + b;
hullInds[hullInd0 + v++] = hullVrt0 + d;
hullInds[hullInd0 + v++] = hullVrt0 + c;
hullFaceInds[hi0 + fi++] = c;
hullFaceInds[hi0 + fi++] = a;
hullFaceInds[hi0 + fi++] = b;
hullFaceInds[hi0 + fi++] = b;
hullFaceInds[hi0 + fi++] = d;
hullFaceInds[hi0 + fi++] = c;
hullEdgeInds[he0 + ei++] = a;
hullEdgeInds[he0 + ei++] = c;
}
}
while (vi < 6)
hullVerts[hv0 + vi++] = vec4(0);
while (fi < 24)
hullFaceInds[hi0 + fi++] = 0;
while (ei < 18)
hullEdgeInds[he0 + ei++] = 0;
}

View File

@@ -1,6 +1,10 @@
in vec4 color;
#version 430 compatibility
uniform vec4 color;
in vec4 scol;
void main()
{
gl_FragColor = color;
gl_FragColor = color * scol;
}

View File

@@ -9,10 +9,10 @@ layout(row_major) uniform Matrices
in vec4 pos;
out vec4 color;
out vec4 scol;
void main()
{
gl_Position = vec4(pos.xyz, 1) * model * view * proj;
color = vec4(gl_Position.xyz + vec3(.5), 1);
scol = vec4(pos.xyz / 5 + .5, 1);
}

View File

@@ -43,6 +43,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Gl4Window.cs" />
<Compile Include="BlockStructs.cs" />
<Compile Include="MVec4D.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />