Skip to main content
GameDev.net gamedev.net
🔒 Locked

rendering 2-sided planes

Started by generic user Jun 27, 2007 at 9:55 AM 2 replies 600+ views
Original Post
generic user
generic user
hi, I'm looking for a way to render small vegetation objects like bushes. I've decided to use planes which get a bush or grass texture. The problem is that all these planes are single-sided so that the bushes disappear when looked from behind. I've solved this by creating 2 planes from the vertices but using a different order of the vertices so that the surface normals point in other directions:


	glBegin(GL_QUADS);
	{
		glTexCoord2f(1.0, 1.0);
		glVertex3f( -0.5, 1.0, 0.0);
		
		glTexCoord2f(0.0, 1.0);
		glVertex3f(+0.5, +1.0, 0.0);
		
		glTexCoord2f(0.0, 0.0);
		glVertex3f(0.5, 0.0, 0.0);
		
		glTexCoord2f(1.0, 0.0);
		glVertex3f(-0.5, 0.0, 0.0);
	}
	glEnd();

	glBegin(GL_QUADS);
	{
		glTexCoord2f(0.0, 1.0);
		glVertex3f(+0.5, +1.0, 0.0);
		
		glTexCoord2f(1.0, 1.0);
		glVertex3f( -0.5, 1.0, 0.0);
		
		glTexCoord2f(1.0, 0.0);
		glVertex3f(-0.5, 0.0, 0.0);

		glTexCoord2f(0.0, 0.0);
		glVertex3f(0.5, 0.0, 0.0);
	}
Then I store the planes in a display list (a bush consists of 4-8 planes). Is there a way to optimize this? Maybe have the normal always facing the camera so that I don't need that 2nd plane or use a different storage method for the data such as VBOs? I've been reading some articles about VBOs and I'm not sure whether they would be useful/faster in my case.
silvermace
silvermace
sounds like you need to disable culling when rendering the faces and possibly take into account the view-direction when shading them.

either push-attrib:
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_CULL_FACE);
renderVegetationPlane();
glPopAttrib();


or you can just toggle it manually:
glDisable(GL_CULL_FACE);
renderVegetationPlane();
glEnable(GL_CULL_FACE);


if you are using alpha blending, you may also need to disable Z-buffer writes, but this will create a few new issues (have a look into Z order and Alpha blending)
generic user
generic user
Thanks a lot, this solved the problem.

Would it speed up the rendering if I stored the vertice data in a vertex buffer object instead of a display list? I'm not sure if this is the right way as there are only a few quads to render and I also do not have any vertices that are used multiple times. If this is important: In my scene I will probably have >1000 bushes, each composed of 5 planes or so.
zedz
zedz
performance is the last thing to worry about.

in your case glBegin()..glEnd() is gonna be about the same speed as DL/vbos (it may even be quicker), dls/vbo's benifit when u have lots of vertices in one call.
thus in your case group all the bushes together + draw them in one call (in saying that u prolly wont see much of a performance increase if any)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.