Fix support for triangle fans on GL/Vulkan

This commit is contained in:
baldurk
2019-08-20 15:33:12 +01:00
parent 27dcb72b93
commit 07158ad24c
19 changed files with 629 additions and 158 deletions
+12 -11
View File
@@ -65,6 +65,9 @@ bool TriangleRayIntersect(vec3 A, vec3 B, vec3 C, vec3 RayPosition, vec3 RayDire
{
bool Result = false;
if(A == B || A == C || B == C)
return false;
vec3 v0v1 = B - A;
vec3 v0v2 = C - A;
vec3 pvec = cross(RayDirection, v0v2);
@@ -161,23 +164,21 @@ void trianglePath(uint threadID)
bool hit;
if(meshpick.unproject == 1u)
{
hit = TriangleRayIntersect(pos0.xyz / pos0.w, pos1.xyz / pos1.w, pos2.xyz / pos2.w,
meshpick.rayPos, meshpick.rayDir,
/*out*/ hitPosition);
}
else
{
hit = TriangleRayIntersect(pos0.xyz, pos1.xyz, pos2.xyz, meshpick.rayPos, meshpick.rayDir,
/*out*/ hitPosition);
pos0.xyz /= pos0.w;
pos1.xyz /= pos1.w;
pos2.xyz /= pos2.w;
}
hit = TriangleRayIntersect(pos0.xyz, pos1.xyz, pos2.xyz, meshpick.rayPos, meshpick.rayDir,
/*out*/ hitPosition);
// ray hit a triangle, so return the vertex that was closest
// to the triangle/ray intersection point
if(hit)
{
float dist0 = distance(pos0.xyz / pos0.w, hitPosition);
float dist1 = distance(pos1.xyz / pos1.w, hitPosition);
float dist2 = distance(pos2.xyz / pos2.w, hitPosition);
float dist0 = distance(pos0.xyz, hitPosition);
float dist1 = distance(pos1.xyz, hitPosition);
float dist2 = distance(pos2.xyz, hitPosition);
uint result_idx = atomicAdd(pickresult.counter, 1u);
+12 -11
View File
@@ -144,6 +144,9 @@ bool TriangleRayIntersect(float3 A, float3 B, float3 C, float3 RayPosition, floa
{
bool Result = false;
if(all(A == B) || all(A == C) || all(B == C))
return false;
float3 v0v1 = B - A;
float3 v0v2 = C - A;
float3 pvec = cross(RayDirection, v0v2);
@@ -224,23 +227,21 @@ void trianglePath(uint threadID)
bool hit;
if(PickUnproject == 1)
{
hit = TriangleRayIntersect(pos0.xyz / pos0.w, pos1.xyz / pos1.w, pos2.xyz / pos2.w, PickRayPos,
PickRayDir,
/*out*/ hitPosition);
}
else
{
hit = TriangleRayIntersect(pos0.xyz, pos1.xyz, pos2.xyz, PickRayPos, PickRayDir,
/*out*/ hitPosition);
pos0.xyz /= pos0.w;
pos1.xyz /= pos1.w;
pos2.xyz /= pos2.w;
}
hit = TriangleRayIntersect(pos0.xyz, pos1.xyz, pos2.xyz, PickRayPos, PickRayDir,
/*out*/ hitPosition);
// ray hit a triangle, so return the vertex that was closest
// to the triangle/ray intersection point
if(hit)
{
float dist0 = distance(pos0.xyz / pos0.w, hitPosition);
float dist1 = distance(pos1.xyz / pos1.w, hitPosition);
float dist2 = distance(pos2.xyz / pos2.w, hitPosition);
float dist0 = distance(pos0.xyz, hitPosition);
float dist1 = distance(pos1.xyz, hitPosition);
float dist2 = distance(pos2.xyz, hitPosition);
uint meshVert = vertid0;
if(dist1 < dist0 && dist1 < dist2)