Trees+billboards+crossfading+imposors = lots of trouble

Started by
16 comments, last by VanKurt 20 years, 6 months ago
Hi there! I''ve ignored this problem for quite a while now but today I started working on my happy little trees again... ;-) First of all here are three images that show the tree system in action: The first image shows a tree from far away (billboard). The second image shows how the billboard and the 3D-model are crossfaded when you come closer. On the third image you can see the tree from near as a model only. The first problem I''m having is to render the billboard correctly. As you can see (image 1) it is somehow semi-translucent, although the model is NOT. I have tried to use a leaf texture with custom (selfmade) mipmaps, where I scaled the image down without blurring it but obviously that didn''t help... Second, the billboard and model don''t have the same dimensions as image two shows. The billboards size is chosen as the size of the tree''s bounding box. The camera is positioned like this: glTranslatef( 0, -mQuadSizeY*0.5f, -(mQuadSizeY*0.5f / 0.424475f) ); (I''ve forgotten how I got that formula...somehow with sin/cos/tan stuff...) Third: When crossfading there is an incredibly ugly blending problem (image2). No matter which of the two I draw first (tree or billboard), the problem remains the same. Really don''t know how to fix that :-( I''m really glad of any help! Thanks a lot in advance... :-D
Advertisement
disable depth write?
http://www.8ung.at/basiror/theironcross.html
(1) The transpareny looks okay to me, but if you want to fix it, allright. BTW: It looks like only the leaves are somewhat transparent. Not the trunk itself. Anyway, to fix it, you need to disable mipmapping. You can scale down the image yourself without blending the Alpha value, but OpenGL will still interpolate around the edges of the leaves if you render the texture. That's what you get even with regular GL_LINEAR textures (PS: Have you tried another texture setting? There is one that doesn't interpolate the pixels at all. Pretty ugly on normal textures, but this could work for you because you use a custom mipmap routine with custom blending. I don't know what the setting is called though. Look it up).

You could also change the depth values at which you switch mipmap textures. Keep the high-res textures for longer.

There is one other way aound it but thats ugly: Alpha testing. It works, but you'll get borders. Maybe you could combine them though:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glAlphaTest(GL_GREATER, 0.9f);

Don't know if that would work. It could blend the ugly alphatest borders.

for (2):
It looks like you use additive blending: GL_SRC_APLHA, GL_ONE. Try to use the blendfunc from (1) with GL_ONE_MINUS_SRC_ALPHA.


Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


[edited by - sander on October 7, 2003 6:13:33 AM]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

I just stumbled upon this. You might find it usefull. Especially the second half of the page: how to deal with alpha values in tree billboards.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Problem 1:
you will have to check the texture that you are rendering to, and find out whether the alpha values in that texture are wrong or not. This could be several problems:
* when rendering to the texture, you may have a residual glColor4f(x,y,z, interpolatealpha) still lying around. Before rendering to the texture try glColor4f(1,1,1,1) first.
* when rendering the imposter you could be doing the same thing
Try a glColor4f(1,1,1,1) first.
* or it may be mipmapping. Not sure, I don''t have much experience with this.

Problem 2:
Are you sure your tree''s bounding box is the correct size?
That 0.424475f looks too much like a scaling factor to me, which may account for the ''squashing effect'' in the pictures. I might be wrong though.

Problem 3:
For rendering any transparent objects (especially if you''re interpolating alpha), you HAVE to depth sort the objects. .
If you draw a mildy opaque object first and then draw a semi-translucent object, it won''t be drawn because the first object was written into the depth-buffer and thus occludes the second object (the phenomenon you see there). If you merely arbitrarily draw the tree model then the billboard it may render fine from one angle, but not from another angle.
Rather, calculate the depth of each translucent object (from the camera) and draw all of them in back to front order. This will eliminate the problem you see in picture 2.
do unto others... and then run like hell.
Frey is correct about (3). Ignore my advice on additive blending....

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Whoohoo! So many replies! Got a lot to read and test now! :-D

Thanks for your support, you''re great guys!
Good luck! Keep us posted. I''m pretty curious. My team is looking into SpeedTreeRT but that''s sooooo expensive ($6000,-) so we may need to do our own LOD trees after all.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

That looks amazing! But 6000€??? Huh!
Well, I almost got it working...the last thing is that the billboard''s size isn''t exacly the model''s one. But I guess I''ll have that fixed soon ;-)
The answer is NOT always to depth sort alpha blended stuff, often (as in this case) disabling depth write (here only for the first of [billboard, tree] that you render) will be sufficient

This topic is closed to new replies.

Advertisement