mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-23 15:06:32 +00:00
triangle lists pick correctly
This commit is contained in:
@@ -130,12 +130,18 @@ BINDING(0) uniform FontUBOData
|
||||
}
|
||||
INST_NAME(general);
|
||||
|
||||
#define MESH_TRIANGLE_LIST 0
|
||||
#define MESH_TRIANGLE_STRIP 1
|
||||
BINDING(0) uniform MeshPickUBOData
|
||||
{
|
||||
vec3 rayPos;
|
||||
uint use_indices;
|
||||
|
||||
vec3 rayDir;
|
||||
uint numVerts;
|
||||
|
||||
int meshMode;//triangles, triangle strip, fan, etc...
|
||||
vec3 padding;
|
||||
}
|
||||
INST_NAME(meshpick);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ bool TriangleRayIntersect(vec3 A, vec3 B, vec3 C,
|
||||
vec3 pvec = cross(RayDirection, v0v2);
|
||||
float det = dot(v0v1, pvec);
|
||||
|
||||
// if the determinant is negative the triangle is backfacing
|
||||
// if the determinant is negative the triangle is backfacing, but we still take those!
|
||||
// if the determinant is close to 0, the ray misses the triangle
|
||||
if (abs(det) > 0.000001f)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ void main()
|
||||
{
|
||||
uvec3 tid = gl_GlobalInvocationID;
|
||||
|
||||
uint vertid = tid.x * 3;
|
||||
uint vertid = tid.x;
|
||||
|
||||
// NOTE(james): when I turn on following early out the shader doesn't do anything.
|
||||
// so I end up with a lot of duplicated work on smaller meshes
|
||||
@@ -87,11 +87,25 @@ void main()
|
||||
// return;
|
||||
vertid = uint(mod(float(vertid), float(meshpick.numVerts)));
|
||||
|
||||
|
||||
|
||||
uint idx0 = meshpick.use_indices != 0u ? ib.data[vertid ] : vertid;
|
||||
uint idx1 = meshpick.use_indices != 0u ? ib.data[vertid+1] : vertid+1;
|
||||
uint idx2 = meshpick.use_indices != 0u ? ib.data[vertid+2] : vertid+2;
|
||||
uint idx0 = 0;
|
||||
uint idx1 = 0;
|
||||
uint idx2 = 0;
|
||||
switch (meshpick.meshMode)
|
||||
{
|
||||
case MESH_TRIANGLE_LIST:{
|
||||
vertid *= 3;
|
||||
idx0 = meshpick.use_indices != 0u ? ib.data[vertid ] : vertid;
|
||||
idx1 = meshpick.use_indices != 0u ? ib.data[vertid+1] : vertid+1;
|
||||
idx2 = meshpick.use_indices != 0u ? ib.data[vertid+2] : vertid+2;
|
||||
break;
|
||||
}
|
||||
case MESH_TRIANGLE_STRIP:{
|
||||
idx0 = meshpick.use_indices != 0u ? ib.data[vertid ] : vertid;
|
||||
idx1 = meshpick.use_indices != 0u ? ib.data[vertid+1] : vertid+1;
|
||||
idx2 = meshpick.use_indices != 0u ? ib.data[vertid+2] : vertid+2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vec4 pos0 = vb.data[idx0];
|
||||
vec4 pos1 = vb.data[idx1];
|
||||
|
||||
@@ -1076,8 +1076,24 @@ uint32_t GLReplay::PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t
|
||||
cdata->rayDir = rayDir;
|
||||
cdata->use_indices = cfg.position.idxByteWidth ? 1U : 0U;
|
||||
cdata->numVerts = cfg.position.numVerts;
|
||||
// cdata->unproject = cfg.position.unproject;
|
||||
// cdata->mvp = PickMVP;
|
||||
switch(cfg.position.topo)
|
||||
{
|
||||
case eTopology_TriangleList:
|
||||
{
|
||||
cdata->meshMode = MESH_TRIANGLE_LIST;
|
||||
break;
|
||||
};
|
||||
case eTopology_TriangleStrip:
|
||||
{
|
||||
cdata->meshMode = MESH_TRIANGLE_STRIP;
|
||||
break;
|
||||
};
|
||||
default:
|
||||
{
|
||||
cdata->meshMode = -1;
|
||||
RDCWARN("Mesh type unsupported by picking");
|
||||
};
|
||||
}
|
||||
|
||||
gl.glUnmapBuffer(eGL_UNIFORM_BUFFER);
|
||||
|
||||
@@ -1187,8 +1203,7 @@ uint32_t GLReplay::PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t
|
||||
(GLsizeiptr)(cfg.position.idxoffs + cfg.position.idxByteWidth * cfg.position.numVerts));
|
||||
gl.glBindBufferBase(eGL_SHADER_STORAGE_BUFFER, 3, DebugData.pickResultBuf);
|
||||
|
||||
gl.glDispatchCompute(GLuint((cfg.position.numVerts / 3) / 128 + 1), 1,
|
||||
1); // launch one thread per triangle
|
||||
gl.glDispatchCompute(GLuint((cfg.position.numVerts) / 128 + 1), 1, 1);
|
||||
gl.glMemoryBarrier(GL_ATOMIC_COUNTER_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT);
|
||||
|
||||
uint32_t numResults = 0;
|
||||
|
||||
Reference in New Issue
Block a user