   GLSL gl_Vertex multiply by scalar weirdness
  I've just come across some very odd behavior while trying to multiply the built-in gl_Vertex input with a single scalar in a GLSL vertex shader. To be precise, I'm writing a shader to automatically orient billboards towards the camera. I've defined two uniforms to supply the necessary info I need: camera_matrix (self-explanatory) and scale (to make the billboard bigger or smaller). The translation component of the billboard is supplied via glTranslatef, and is therefore already present in gl_ModelViewProjectionMatrix. Here's my initial stab:uniform mat4 camera_matrix;uniform float scale;void main (){gl_Position = gl_ModelViewProjectionMatrix * camera_matrix *(gl_Vertex * scale);gl_TexCoord[0] = gl_MultiTexCoord0;gl_FrontColor = gl_Color;}No matter what value I supply for scale, my billboard stays exactly the same size. Other than the size issue, everything else works perfectly--it is positioned correctly, rotates to face the camera correctly, and is textured correctly. My shader info log is empty.I next tried something like this:uniform mat4 camera_matrix;uniform float scale;void main (){gl_Position = gl_ModelViewProjectionMatrix * camera_matrix *vec4(gl_Vertex.x * scale, gl_Vertex.y * scale, 0.0, 0.0);gl_TexCoord[0] = gl_MultiTexCoord0;gl_FrontColor = gl_Color;}This causes all kinds of freaky artifacts, usually some sort of polygon covering half of my viewport (it shifts depending on the camera angle).Frustrated, I tried the following:uniform mat4 camera_matrix;uniform float scale;void main (){vec4 foo = gl_Vertex;foo.x *= scale;foo.y *= scale;gl_Position = gl_ModelViewProjectionMatrix * camera_matrix * foo;gl_TexCoord[0] = gl_MultiTexCoord0;gl_FrontColor = gl_Color;}SUCCESS! It works! Positioned properly, scaled properly, textured properly, and faces the camera always. I really don't see why this way should work while the others above would cause really odd behavior. Then again, I'm relatively new to GLSL and shaders in general, so maybe there's something I'm missing. Additionally, having no output in my info log leads me to believe my first attempts are not illegal.Anyone have any clues that could help me explain the failure of the first 2 programs above?In case it matters, I'm running on a GeForce 8800 GTS with the very latest drivers installed (as of yesterday).   
  The w component of the vertex needs to be 1.0 for "normal" behavior.   ;  Or to be more precise, as everything is going to be divided by w, scaling all components can't work, as you end up with:x*scale/w*scale = x/w, etc.The second one simply blows up because division by zero is never a good idea.I'd also try to avoid the need for the camera matrix by not multiplying with the view matrix in the first place, because right now it seems like you got something like:Proj*Model*View*InvertedView*scaledVertex which should be the same as Proj*Model*Scale*Vertex. Easily reduced to a single multiplication with modelviewprojection by glLoadIdentity, glTransform, glScale before rendering your billboards. Unless I missed the obvious somewhere, which I love to do.   ;  D'oh! Thanks to both of you guys. I knew I was doing something stupid! Thanks for helping me get that sorted out.Trienco,I don't think I can reduce the multiplications in this instance because camera_matrix is actually just the camera rotation matrix (i.e. it doesn't contain the camera translation to account for camera position). This means that what I really have is Proj * CameraInverseRotation * CameraTranslation * BillboardTranslation * CameraRotation * ScaledVertex (where gl_ModelViewProjectionMatrix contains everything up to and including BillboardTranslation), which as far as I know makes it impossible to do as you suggest. It sure would be nice though, and if there is a better way to render billboards, I'd love to hear it!;  Hmmm... you could still try to apply the camera matrix and scaling to the modelview. Unless I'm still missing one the current shader should do scale, multmatrix(cam), multMatrix(invCam), translate, draw. But if every billboard gets a separate render call it pretty much doesn't matter anyway. I guess geometry shaders open up a whole new bunch of possibilities to optimize.   