Hi, I’ve been investiguating on ways to billboard thousands batched QUAD geometries in a shader so that Y rotation always aims at the camera, but the position of the geometry remains untouched in world coordinates. Basically, I batched those thousands of quads using GeometryBatchFactory and every frame, I want the GPU to adjust the rotation of those quads to aim at the camera via a shader (vertex probably). I couldn’t find ANY shader code that left the geometry position alone and only rotated it. The closest I’ve got is this:
vec3 vAt = g_CameraPosition - pos.xyz;
vAt = normalize( vAt );
vec3 vRight = cross( vec3( 0.0, 1.0, 0.0 ), vAt );
vec3 vUp = cross( vAt, vRight );
vRight = normalize( vRight );
vUp = normalize( vUp );
vec2 s = inTexCoord * vec2( 5.0, 2.0 ); // NOTICE THIS LINE
vec3 vR = s.xxx * vRight;
vec3 vU = s.yyy * vUp;
vec4 dir = vec4( vR + vU, 0.0 );
gl_Position = g_WorldViewProjectionMatrix * (pos + dir);
You’ll notice that line with the TexCoord XY multiplier… if this value is not high like this, it doesn’t work: the geometry looks THIN on some angles just as it would normally. The problem with this GLSL code is that it looks like it’s working (kind of) but the quads have to be very tall for this billboarding method to work. I tried to send halfed sized quads to the shader in hope that it would compensate, but it does exactly as if I had low TexCoord multiplier values, which cancels the billboarding effect.
I also noticed with the above GLSL code that if the camera is near, sometimes the quad is deformed or if the camera looks a little down we can see that by going around the quad, it moves in the world space. Like if it were not rotating from the center of itself or something.
I am looking for your help on this matter guys, I know somebody has a solution to this somewhat /simple/ billboarding problem that I could not figure out. PLEASE KEEP IN MIND that I can’t rotate individual geometries on simpleUpdate() loop because they are batched, so it means I would have to lose the batching and this would degrade considerably the performance. I have thousands of those quads to update every frame (to aim at the camera) so I would much more prefer if the GPU adjusted their orientation via a shader of some sort, but I’m open to every single solution you might have.