Getting textures to always point at the screen?

Hi, is it possible to get a texture to point/face the screen at all times using a GLSL shader? Any advice on how I would go about doing this?

Sounds to me like you want to read up on billboarding.

Random link: http://www.lighthouse3d.com/opengl/billboarding/

If you want to texture small particles you may also want to take a look at point sprites.

thanks for the replies. I want to have the texture map use screen co-orindates. ie. the texture bill boards but not the the 3d object.

Then do this in the vertex shader



varying vec4 projectSpace;

void main(){

  // Calculate the output position and projection space lookup
  projectSpace = gl_ModelViewProjectionMatrix * gl_Vertex;  
  gl_Position = projectSpace;
  projectSpace.xy = (projectSpace.xy + vec2(projectSpace.w)) * 0.5;


And this in the fragment shader:


varying vec4 projectSpace;
uniform sampler2D TextureBitmap;

void main(){

  // Look texture in screen space
  vec4 tex = texture2DProj(TextureBitmap, projectSpace);


You can scale the texture coordinates in the vertex shader to suit your needs. (by default the texture will be stretched over the screen)

wow thanks for your help! awesome… will try it out :wink:

yeah that code worked really well thanks again

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.