Jump to content
  • Advertisement
Sign in to follow this  
Relfos

OpenGL Tree billboards

This topic is 2950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the project I'm working, we're adding some trees, composed of a normal trunk mesh, and then the artists add lots of quads around the tree.
When loading the model, I search for all the quads, calculate the center point and size, and encode this in the vertex data that is send to OpenGL.
Note that every quad vertex is replaced by the center point and an index (from 0 to 3) that maps to a specific corner in the shader.


vec2 bbofs[4] = vec2[4]( vec2(0.5, -0.5),
vec2(-0.5, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5));
vec3 vAt = eyePos - (modelMatrix * gl_Vertex).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 = bbofs[int(gl_MultiTexCoord2.z)] * gl_MultiTexCoord2.xy;
vec3 vR = s.xxx * vRight;
vec3 vU = s.yyy * vUp;
position.xyz += vR;
position.xyz += vU;


This is the shader code I wrote after reading lots of topics about billboards here. It somehow works, but then, if we want to use the same tree model, but with a rotation added, to add some variation, this shader produces inccorect results (the billboards just vanish) and I cannot find why..

Share this post


Link to post
Share on other sites
Advertisement
is it possible that they are edge on?

Another possibility is that you have backface culling on and they are faced the wrong direction.

If i were you i'd try rotating by a very small amount (like 5-15 degrees) and seeing if you can still see them and see that they are rotated.

If backface culling or edge on quads aren't the problem, using a small rotation may give you some insight too into what's going wrong.

Share this post


Link to post
Share on other sites
Another possibility is that you're doing the rotation in the wrong order -- the trees aren't invisible, they're behind you...

Again, small rotation values should help with that. (Of course, turning round won't help -- the trees will ALWAYS be just behind you!!)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!