Archived

This topic is now archived and is closed to further replies.

VanKurt

Trees+billboards+crossfading+imposors = lots of trouble

Recommended Posts

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

Share this post


Link to post
Share on other sites
(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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ;-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
AP is right in a way, and wrong in a way.

If you only have 1 tree in a scene to worry about, AP''s approach will work since there are no other conflicting translucency issues.

If you disable depth writing for multiple trees, you will still have visual artefacts when you move around the other side of 2 trees ... Since depth information (if you disable depth writing) is not written and if you draw in a particular order, one tree will always be on top of the other tree (no matter which direction you are facing them from) since the second drawn tree will always be drawn on top of the first drawn tree. This is all very well and good if you can guarantee that you''re only going to view it from a particular direction, but it will look kinda funny to have a tree in the distance being drawn over one in the foreground. Hence, the need for depth sorting.

On a per-individual tree basis go for AP''s approach: render the tree (depth-testing & (depth-writing or none)), render the billboard (no depth-testing and no depth-writing). But lots of individual trees will have to be depth-sorted - unfortunate, but true.

Share this post


Link to post
Share on other sites
AP is also right if the billboarded tree fits snugly on top of the rendered tree, since the pieces that aren''t written to the depth buffer will be overwritten by the pieces that do get written to the depth buffer. But this also means that any mismatch between the billboard and the model will show as depth artifacts when viewed from the wrong direction.

There might be another way though. It''s the same method used by the SpeedTree lib I mentioned above. They do not blend the billboard into the tree, they alphatest it. When the tree is about to change LOD, they vary the alpha test value. If the tree goes from model to billboard, the alpha test starts at 1.0f (showing almost no billboard) to 0.5 or so (showing the entire billboard) as you move further away.
quote:

That looks amazing! But 6000€??? Huh!


Yes, it''s a lot. We are going to try to negotiate a more limited license for less money. The SpeedTreeRT SDK comes with a huge amount of stuff we do not need at all, such as special CAD programs, plugings, lots and lots of models, etcetera. We also do not need the source, just the .lib and the .h.


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

Share this post


Link to post
Share on other sites
Hey, thanks!

Terrain:
Big color-texture, three layers of detailtextures at different resolutions on a 16bit heightfield.

Water:
Scene rendered to texture then applied to the water plane. Added animated dot3 bumpmaps to do bumpmapping and tex-coord-distortion.

Nothing extremely special... ;-D Check out my Website for more pics and details... (www.ecoengine.tk)

PS: I had a thread going on here not long ago about my water...

Share this post


Link to post
Share on other sites
WOW looks really nice.

How did you get the animated bumpmaps? Did you use precreated ones or do you generate them on the fly? Did you use shaders?


[ My Site ]
''I wish life was not so short,'' he thought. ''Languages take such a time, and so do all the things one wants to know about.'' - J.R.R Tolkien
/*ilici*/

Share this post


Link to post
Share on other sites
Yep. I use shaders (CG).

animating the bumpmap was really tricky at first... ;-)

I tried to create an animation of e.g. 30 frames (=30 maps) and cycle through them...but that looked like SHXX.

Then I found out that the solution is really simple: Create two or three different maps. Scroll them in different directions. Use a shader to merge these maps into a single one. Use that map for whatever you like.

It''s simple, fast and looks good!

Share this post


Link to post
Share on other sites