Forest Trees Rendering

Started by
17 comments, last by Yperloxas 17 years ago
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?
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
It doesn't work.
How Games like Serious Sam,Far Cry do they render so much grass? :)
Typically polys with transparent areas are rendered last, in depth order (furthest -> nearest). Are you doing this?
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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)


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.
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.
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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?

This topic is closed to new replies.

Advertisement