Hi,
I’m coding an instance-culling shader, which works in 2 passes.
In the first pass, I compute the instance position with the VertexID, perform a visibility test, and get the visible IDs back with Transform Feedback. So, I don’t need any vertex attribute data. The vertex Shader compiles fine and the program links. Now, how do I feed the pipeline from the client’s perspective ? Binding an empty VAO crashes the application, and I don’t want (unless I really have to) create a dummy VBO for the process… Any suggestions on how I could do this ?
Here’s the vertex-shader code
#version 400 core
// patch parameters
layout(std140) uniform PatchParams
{
int cst_patchCountSqrt; ///< Square root of the total number of patches
int cst_patchSize; ///< Patch Side Length
};
// camera view
layout(std140) uniform View
{
mat4 cst_view; ///< View Matrix
};
// projection matrix
uniform mat4 cst_projection;
// output
out vec4 var_pos;
flat out int var_isCulled;
void main()
{
// compute position in the grid
vec2 gridpos = vec2(gl_VertexID/cst_patchCountSqrt, gl_VertexID%cst_patchCountSqrt);
// mulitply offset by patch Size to get proper position
float offset = float(cst_patchCountSqrt)/2.0;
vec2 pos = (gridpos-vec2(offset))*vec2(cst_patchSize);
var_pos = vec4(pos,0.0,1.0);
// project
vec4 clipPos = cst_projection * (cst_view * var_pos);
// check visibility
if(clipPos.x < -clipPos.w) var_isCulled = 1;
else if(clipPos.x > clipPos.w) var_isCulled = 1;
else if(clipPos.y < -clipPos.w) var_isCulled = 1;
else if(clipPos.y > clipPos.w) var_isCulled = 1;
else if(clipPos.z < -clipPos.w) var_isCulled = 1;
else if(clipPos.z > clipPos.w) var_isCulled = 1;
else var_isCulled = 0;
}
And the draw call
glUseProgram(program[PROGRAM_FEEDBACK]);
glBindVertexArray(vertexArray[VERTEX_ARRAY_CULL]); // empty, crashes the app
glDrawArrays(GL_POINTS, 0, SAMPLE_PATCH_COUNT);