Jump to content
  • Advertisement
Sign in to follow this  
Yperloxas

Forest Trees Rendering

This topic is 4134 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

I am trying to insert some vegetation at my terrain demo.I use the trivial masked billboards for trees and grass. The common problem i encounter is that for correct rendering of the scene you have to enable the depth test,but i also need to do blending and the result is that the vegetation parts appears in pieces and ugly cut. I render the trees and grass after the rendering of the terrain mesh. Render_Terrain(); Render_Grass_As_Billboards(); I need to do some selecting depth cutting in order to achieve correct rendering like applying the depth test only to the non-transparent parts of the billboard. Is there any easy way to do this?

Share this post


Link to post
Share on other sites
Advertisement
I used the following render states in a 2 pass effect to achieve decent results. I found this technique on a Web site with XNA tutorials.

If you want to have a ton of trees in a group, it probably won't look great, but it worked a lot better for me than my original attempt.

pass P0
{
AlphaBlendEnable = false;

AlphaTestEnable = true;
AlphaFunc = Equal;
AlphaRef = 255;

ZEnable = true;
ZWriteEnable = true;

CullMode = None;
}

pass P1
{
AlphaBlendEnable = true;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;

AlphaTestEnable = true;
AlphaFunc = NotEqual;
AlphaRef = 255;

ZEnable = true;
ZWriteEnable = false;

CullMode = None;
}


Hope this helps.

~Matt

Share this post


Link to post
Share on other sites
Typically polys with transparent areas are rendered last, in depth order (furthest -> nearest). Are you doing this?

Share this post


Link to post
Share on other sites
For rendering blended grass try alpha-to-coverage. I don't have a documentation at hand right now and I didn't implement it yet but I read a very good article (in GPU Gems 2 IIRC) on vegetation rendering. There alpha-to-coverage was proposed to do grass rendering without having to sort the grass billboards depending on their distance to the camera.

Check this demo with sourcecode.

Share this post


Link to post
Share on other sites
Quote:
Original post by zppz
Typically polys with transparent areas are rendered last, in depth order (furthest -> nearest). Are you doing this?



It is too slow to bubble sort the bilboard list and calculate the distance of all trees grass from the viewer.

Maybe for the nearest part of the grass it may work,but for the faraway trees that can't be appear/disappear(for the realism of the scene) when you move it won't work.(If you have about 20% parts of the terrain quads filled with vegetation then it is a major problem doing it brute force)


Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
For rendering blended grass try alpha-to-coverage. I don't have a documentation at hand right now and I didn't implement it yet but I read a very good article (in GPU Gems 2 IIRC) on vegetation rendering. There alpha-to-coverage was proposed to do grass rendering without having to sort the grass billboards depending on their distance to the camera.

Check this demo with sourcecode.


This seems to work but only the main.cpp file is included at the project.I will research it a little more about alpha-to-coverage because i am not familliar with it right now.

Share this post


Link to post
Share on other sites
Try to avoid AlphaBlending. For trees and such AlphaTesting should suffice. Sorting transparent triangles is way too expensive, especially for grass with a triangle count of several thousands.

Share this post


Link to post
Share on other sites
As for the demo try the framework links on top of the page, there you should get the missing parts.

Like Schrompf said, alpha testing would be sufficient for rendering non-transparent but masked objects like grass quads. Alpha-to-coverage will help with aliasing issues when employing alpha testing.

Share this post


Link to post
Share on other sites
I am using the following code using the normal texture and a black&white mask.



glPushMatrix();

glEnable(GL_BLEND);

Set_Texture(masktex);

glDepthMask(GL_FALSE);

glTranslatef(pos[0],pos[1],pos[2]);

glBlendFunc(GL_DST_COLOR,GL_ZERO);

glBegin(GL_QUADS);
glTexCoord2f(1.0,0.0);
glVertex3f(1.0*sx,0.0,0.0*sy);

glTexCoord2f(1.0,1.0);
glVertex3f(1.0*sx,0.0,1.0*sy);

glTexCoord2f(0.0,1.0);
glVertex3f(-1.0*sx,0.0,1.0);

glTexCoord2f(0.0,0.0);
glVertex3f(-1.0*sx,0.0,0.0*sy);
glEnd();


glBlendFunc(GL_ONE, GL_ONE);

Set_Texture(tex);

glBegin(GL_QUADS);
glTexCoord2f(1.0,0.0);
glVertex3f(1.0*sx,0.0,0.0*sy);

glTexCoord2f(1.0,1.0);
glVertex3f(1.0*sx,0.0,1.0*sy);

glTexCoord2f(0.0,1.0);
glVertex3f(-1.0*sx,0.0,1.0);

glTexCoord2f(0.0,0.0);
glVertex3f(-1.0*sx,0.0,0.0*sy);
glEnd();


glTranslatef(-pos[0],-pos[1],-pos[2]);

glPopMatrix();




How shall i change the code to avoid sorting the billboards?

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!