View Full Version : Getting textures to always point at the screen?
Kirado
03-16-2008, 03:01 AM
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?
Lord crc
03-16-2008, 05:10 AM
Sounds to me like you want to read up on billboarding.
Random link: http://www.lighthouse3d.com/opengl/billboarding/
-NiCo-
03-16-2008, 05:17 AM
If you want to texture small particles you may also want to take a look at point sprites (http://www.opengl.org/registry/specs/ARB/point_sprite.txt).
Kirado
03-17-2008, 03:25 AM
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.
sqrt[-1]
03-17-2008, 04:42 AM
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)
Kirado
03-17-2008, 06:16 AM
wow thanks for your help! awesome.. will try it out ;-)
Kirado
03-26-2008, 09:36 AM
yeah that code worked really well thanks again
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.