I want to create simple impostors for low-resolution distant objects. Each impostor is a set of faces, each with a texture representing the object as seen from a different direction. Only the face most directly facing the camera should be rendered.
Can such face selection be done in a shader? If so, how?
(This seems so basic that an answer should be online, but I’m not finding it.)
Envision the object a axis-aligned cube centered around its own local origin. Construct a vector from that origin to the eyepoint. The signs of the vector components identify which face you want to render.
For other objects, just adapt this. The face with the maximum dot( eye_vector, face_normal ) wins.
Yes, I know that the biggest dot product indicates the face to render. But I don’t know how to do that in shader language, or even if it’s possible. The idea is to do this on the graphics card, for large numbers of background impostors.
It’s certainly possible. It’s really just a question of whether to do it in the vertex shader (which requires performing the same calculations for each vertex of a quad) or a geometry shader (which requires using a geometry shader), or whether to do it in a separate pass using either a compute shader or a vertex shader with transform-feedback. And also whether to pass per-impostor data by duplicating it for each vertex, or using instancing, or using fake instancing (uniform arrays, SSBO array or textures, indexed using gl_VertexID).