Archived

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

LongJohn

stencil buffer performs bad.

Recommended Posts

i posted something similar some time ago..but the problem was not solved and the search function...ok,here we go: i´m using the stencil buffer to mirror a scene with spheres. it looks just fine but performs VERY slow.i now have a FPS counter: the scene:about 400 FPS the scene twice ,via translatef:220 FPS now even if i draw it 4 times i get 120 FPS ! if i turn on my mirror:25 FPS.Pfffffffffff. i "outsourced" the mirror (including what´s seen in the mirror). i´m using linux/SDL. i put a glClearStencil(0); in the initGL function. i start with:glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); the drawing part. finally i call Spiegelung(); //the mirror wich looks like: please excuse the german comments. kugelding(),is the objects including 7 spheres. spiegel(),is just a single GLquad wich was outsurced so i can place it at different place to get a feeling how the scene will look. please notice that it doesn´t change anything to put the code in the drawing section directly !
   


void Spiegelung()
   {
        double eqr[] = {0.0f,0.0f, -1.0f, 0.0f};   //Welcher seit geclippt(abgeschnitten) wird !

        glColorMask(0,0,0,0);			   //Es können keine farben in den stencil buffer !

        glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_ALWAYS, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); // 1 schreiben wo gezeichnet werden soll



	glDisable(GL_DEPTH_TEST);		   // kein tiefentest notwendig/verwirrung/2D

	Spiegel();				   // zeichnet 1 in den puffer,die "SPIEGELFLAECHE" !!

	glEnable(GL_DEPTH_TEST);
	glColorMask(1,1,1,1);			   //alles wieder an

	glStencilFunc(GL_EQUAL, 1, 1);             //wo die einsen stehen,wird gezeichnet !

	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);	   //alles bleibt beim altem(spiegel)

	glEnable(GL_CLIP_PLANE0);		   //hier wird das cliping loch angemacht

	glClipPlane(GL_CLIP_PLANE0, eqr);          //und hier angegeben

	glPushMatrix();				   //initialisieren deer matrix auf 0,0,0


	glScalef(1.0f, 1.0f,- 1.0f);	           //wo ist die symetrieachse ? bei Z !


	//glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);  //licht im spiegel..

	glTranslatef(0.0f, 2.0f, 9.0f);		   //wo im spiegel soll gezechnet werden ?

	KugelDing();				   //hier wird gespiegelt !!

	glPopMatrix();				   //und zurück mit der matrix !!


	glDisable(GL_CLIP_PLANE0);		   //damit wir auserhalb zeichnen duerfen !

	glDisable(GL_STENCIL_TEST);		   //damit wir wieder überall zeichnen dürfen

	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);//Licht setzen

	glEnable(GL_BLEND);			   // die alpha textur vorbereiten

	glDisable(GL_LIGHTING);			   // dafür braucht man kein licht

	glColor4f(1.0f, 1.0f, 1.0f, 0.5f);	   //weiss,50 prozent nicht-durchlässig

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);// alpha-modus


	Spiegel();				   // is klar ne,diesmal der echte

	glEnable(GL_LIGHTING);			   //licht an,nach alpha

	glDisable(GL_BLEND);			   //kein blending mehr

	glFlush();											// Flush The GL Pipeline


   }





  

Share this post


Link to post
Share on other sites
It''s late and I''m tired so I''ll just tell something you might want to know:
stencil has never been fast, except on PowerVR hardware.

That might be your problem (but the hit you take seems too big even with a slow stencil buffer)

other thing possible : lack of hardware stencil buffer ?

it''s too late for me to think properly.

Share this post


Link to post
Share on other sites
The stencil buffer may or may not be hardware accelerated. To give a more concrete example: on my GF2, I only get hardware stencil buffer in fullscreen mode and 32bit colour. I''m reasonably sure that this is a common requirement for most nVidia cards. Try 32bit colour, 16bit depth and 8bit stencil for your display mode - in fullscreen that should be almost guranteed to get accelerated stencil buffer if its avalible.

Share this post


Link to post
Share on other sites
If you ask questions about performance problems, please always post a short hardware description, esp. the type of 3D card used.

I don''t think that the stencil buffer is your problem. I think that this is: glClipPlane(GL_CLIP_PLANE0, eqr). At least, if you have an Nvidia card. If you have an ATI, then ignore this. Nvidia cards do not correctly handle clipplanes. Sometimes, you get hardware acceleration (or better: pseudo-acceleration, as it will burn a texture unit for it, I consider this as a major design flaw on the GeForce architecture), sometimes you don''t. It seems to depend on hardware and driver revision. nVidia strongly discourages the use glClipPlane. You should either do the culling through alpha-test, or by using the texkill pixelshader instruction (supported on GF3+).

Share this post


Link to post
Share on other sites
i have a gf4/4400 128MB from MSI
with athlon 1800+
with 512 MB ddr ram,
slackware linux,nvidia drivers about 3 months old.
Q3A performs with 1024*767*32*32 everything on/max/trilinear
250-500 FPS, in Front of the F#*:;#g mirror at the beginning still 150 FPS.maybe i write an e-mail to mr C.
while i´m waiting,does anybody have a nice link/piece of code with a workaround ?

Share this post


Link to post
Share on other sites
Hmm. Now that you mention it i''ve noticed that with my application too. IT uses stencil shadows, and it runs over 200 on my ATI radeon 8500 but it runs rediculously slow on my NVIDIA TNT2(like 2 fps). How to you get rid of the GlClipPlane?

Share this post


Link to post
Share on other sites
quote:
Original post by Reverse_Gecko
Hmm. Now that you mention it i''ve noticed that with my application too. IT uses stencil shadows, and it runs over 200 on my ATI radeon 8500 but it runs rediculously slow on my NVIDIA TNT2(like 2 fps). How to you get rid of the GlClipPlane?

That''s a different problem. The glClipPlane problem only occurs on T&L hardware. The TNT2 performs all vertex transformations in software, so a glClipPlane won''t change very much here. Even on a GForce, the only thing glClipPlane could do, is disabling T&L, the system will not revert back to software rendering mode (only software vertex transforms). That''s why thee is a performance drop, but it''s not that drastic. In your case (drop to 2fps) show a fallback to SW rendering. This is due to the fact, that the TNT only accelerates stencil buffer in certain screenmodes (IIRC, only in 32bit colour, with 24bit zbuffer, and 8bit stencil. All other modes are not accelerated).

Share this post


Link to post
Share on other sites
I have a cliping plane for my water reflections (I turn it off after I finish drawing the reflections), and there is absolutely no penalty...
And I have a Vanta TNT 2. I tested it on my brother''s computer, who has a GF2, and no penality either...

Height Map Editor | Eternal lands

Share this post


Link to post
Share on other sites