Archived

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

stencil buffer - is it worth it?

This topic is 5649 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 tried using stencil buffer for my 2d top-down shooter game to limit how much you can see, and it worked great. on my system, at least. another person tried it, and it worked fine too. but after the next one tried it, it froze his computer. i am wondering, if the stencil buffer really worth it? is it faster to render a triangle to stencil, or instead render a black triangle where one in stencil was not. so basically instead of marking the zone where to render, cover the zone you dont want to be rendered with black triangles or quads. in my case, i can do both ways, so i'm wondering what should i do. because of stencil being inconsistent on all systems, i don't know what's a better choise. is the stencil buffer a lot faster, if at all? or should i have an option allowing you to choose? is it possible to detect if stencil is a better alternative on a certain system? meanwhile, please try this on your system, and tell me if it works (or crashes/freezes), as well as your video card name. download a newer version in one of my posts below. thanks. --- shurcool my project [edited by - shurcool on June 27, 2002 12:28:40 PM]

Share this post


Link to post
Share on other sites
Works fine for me.

Nice way of doing the player''s line of sight! But the CPU''s too difficult (I think), he kills me before I even see him!

GFX: ATI Rage Xpert 2000 Pro

Share this post


Link to post
Share on other sites
yeah, i made the bot extra tough in this version, because some found him too easy. now he doesn''t shoot aimlessly at walls, instead he waits till you''re in his line of sight, and shoots at you (with high precision) only then. and when (if, very unlikely, since a few bullets kill you very fast) he runs out of ammo, he backs off, until he''s done reloading.

there''s still one exploit, a way to kill him. he will stop whenever he''s really close to you, so if you come close to a corner you know he''ll come out of, he''ll stop, and won''t shoot, since the center of your player is behind a wall. and you, being a smart human and everything, will be able to shoot his "side" or whatever part of him you can see/shoot. a bit more shots are required, but will result in a very safe elimination of the bot.

ps. when finished, this will be a multi-player game, so no bots will be so hard/hacking-thru-walls/dumb/etc.

---
shurcool
my project

Share this post


Link to post
Share on other sites
Scissor testing is perfect for what you are tryng to do, and you can support older cards this way, with Stencil well.., not all cards support it in hardware.

Share this post


Link to post
Share on other sites
nice effect. shame though, you realise how it''s done really quick it doesn''t look anywhere near as convincing (and it doesn''t need stencil buffering at all)..

what would be nice, is after you draw the verticle walls, draw the map again, with reversed depth testing, but make it red. that''d look quite nice, and complete the effect.

Share this post


Link to post
Share on other sites
you totally mis-understood the purpose of what i used stencil buffer for here. but i absolutely undertstand you, because it is an optical illusion and i experienced it as well. it looks like there are vertical walls going up, blocking your view. it really does. however, the whole game is in ortho view, and the purpose of those black "walls going up", making the cross polygon look like some sky scraper, is to block your view, and limit your line of sight only to what you would see if you look from your character's 1st perspetive.

do you see what i'm trying to explain here? so that you wouldn't see through walls, and enemies would only be visible to you if there are no walls between them and you.

now that it causes visual illusions, i don't know what i should do. i want it to be realistic as a 1st person shooter, so you wouldn't see ppl thro walls, and enemies could sneak up to you from behind.

maybe if you knew that, it'd be better (less confuzion)?

so how should i do it? any ideas?

i came up with one possible solution: only clip away enemies behind walls, not the map. what do you think?

---
shurcool
my project

[edited by - shurcool on June 26, 2002 8:58:03 AM]

Share this post


Link to post
Share on other sites
You have to ditch the stencil buffer. A neat effect, but the performance becomes unbearable for the complexity of the game you are doing. I am getting ~0.85 fps.

Pentium II @ 450 MHz
16 MB card with Riva TNT chipset
512 MB RAM

Share this post


Link to post
Share on other sites
5.6fps with softwaregl.
i don^t its too slow or so, i just think people here in don''t know what it requires to run an app with stencil buffer.
i bet you all who have it slow do have 16bit color mode on screen, right?

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
quote:
Original post by Bruno
Scissor testing is perfect for what you are tryng to do, and you can support older cards this way, with Stencil well.., not all cards support it in hardware.


actually, i can''t use scissor testing here. and i guess that you''re right about stencil buffer, older card probably don''t support it or something.

please try this newer version, i made some changes to bit depths and hoping it might work better. please try both windowed and full-screen modes. thank you.

download it here.

---
shurcool
my project

Share this post


Link to post
Share on other sites
Well, it was almost too fast on my Duron 800 with GF2...

Anyway, stencil tests are "free" if you do depth testing, and if you don''t use depth testing, well... It "costs" as much as a normal depth test. I.e. stencil buffering is _not_ slow. The only thing slow about it is that you often have to draw more geometry (since you often first draw some geometry setting the stencil buffer, and then some other geometry to mask against the stencil buffer). Anyway, for what you''ve done here, it''s perfect. The only backside of it is that it''s not supported on all hardware. There are ways of doing pretty much the same thing with destination alpha though, which is supported on almost all hardware. Don''t know exactly how though.

Share this post


Link to post
Share on other sites
Dentoid, thanks for your reply. it was very useful. i''ll have to sort things out with the guy who''s making glfw, which is the window creation library i''m using (to achieve muti-platform support). gotta make sure that his library does a good job, and if i don''t get better consistency, i guess i''ll have an option to toggle it. but users with stencil buffer enabled will have an advantage over those whose is not, since thoses without stencil support will only see other players whose ceter is not blocked by a wall, whereas someone with stencil buffer enabled will see just a tiny part of a player in the same situation. and without it, you can''t tell (well, it''s harder to) where you can see, and where you can''t, to make sure no one sneaks up behind you.

---
shurcool
my project

Share this post


Link to post
Share on other sites
Hi!

About 140 FPS, the enemy finds and kills me in one sec.
AMD 800 MHz, GeForce 2, Windows XP

Max FPS = 176.4


[edited by - axodoss on June 26, 2002 11:52:06 AM]

Share this post


Link to post
Share on other sites
Looks pretty good, can''t wait to see the end result.....

~20 fps windowed, but around 1-2 fps in fullscreen mode.
Don''t know what could cause the big difference between windowed and fullscreen mode..... maybe the TNT2 ??

AMD 750mhz
64mb ram
NVidia TNT2 32mb

Share this post


Link to post
Share on other sites
yep, i've looked around and found out that stencil buffer is free if you use depth testing, so it's cost is no more than depth testing. which isn't bad actually. the problems arise with older video cards, so like i said, i will probably have an option to toggle it. but weird things like difference in fps in windowed and full-screen mode (most of the time full-screen gets (and should get) better fps!), i'm worrying that it might be glfw's (window creation library) fault. i will look into that. thanks to all for testing this demo. (and more fps scores are welcome)

ps. i made the bot walk, instead of run, giving you an advantage, and making things easier. i also made it display the fps in-game, instead of in window title, letting you know what your fps is in full-screen mode. i might update it with more minor fixes, so try it again sometime.

---
shurcool
my project

[edited by - shurcool on June 26, 2002 12:43:55 PM]

Share this post


Link to post
Share on other sites
yeah. I realise what you were saying. what I meant was that if you drew the map again (not enimies) in a different colour (eg, red) to fill in the black, it''d look a lot better. so you''d be able to see the map, but not the enimies.

Share this post


Link to post
Share on other sites
>>~20 fps windowed, but around 1-2 fps in fullscreen mode.
Don''t know what could cause the big difference between windowed and fullscreen mode..... maybe the TNT2 ??<<

as davepermen saiz u need to be in 32bit colour for hardware stencil to work (obviously when its fullscreen u have 16bit colour)
this is for practically all cards (including tnt2)

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
quote:
Original post by RipTorn
yeah. I realise what you were saying. what I meant was that if you drew the map again (not enimies) in a different colour (eg, red) to fill in the black, it''d look a lot better. so you''d be able to see the map, but not the enimies.


riptorn!
that''s exactly what i did in eX0_4; u haven''t tried it, have you? well, here''s a shot:


zedzeek,
i''m working on that problem, it seems to me that (from the specification for nvidia riva tnt2 vid card) tnt2 cars (and many more) do support stencilling, so it must be something wrong w/ what i''m doing. anyway, i read that most card (including tnt2) have a 32 bit z-buffer (depth buffer) w/ 8 bit stencil buffer. in eX0_4, i allocated 0 bits to z-buffer (since i don''t need depth - it''s 2d), and 1 bit to the stencil buffer. in this executable, i changed that to 32 bits z-buffer w/ 8 bits stencil buffer, just like the specification says. please try it, and tell me if it works for you (never mind the name, cuz tnt2 and matrox g400 max are very similar):
download the executable here. (if you have matrox g400 max or tnt2, please give it a try)

thanks to all.

---
shurcool
my project

Share this post


Link to post
Share on other sites
nice. thats exactly what I meant

you still don't need stencil for that though.
people seem to have problems in fullscreen, are you setting a 32bit colour mode?

now. make the bullets bounce

[edited by - RipTorn on June 27, 2002 10:37:12 AM]

Share this post


Link to post
Share on other sites
I still get the low framerate in fullscreen....... in 16 and 32 bit mode.....

[edited by - Crawl on June 27, 2002 10:43:53 AM]

Share this post


Link to post
Share on other sites
Um... am I just stupid but... how do you run it in fullscreen mode!?

I get about 390fps in windowed mode (P4 1.4, Radeon8500) which is entirely unplayable... I die before I can do anything. Is it possible to time scale the game a bit?

Share this post


Link to post
Share on other sites
damn it people, you're downloading the wrong version. you should be getting eX0_4, not eX0_3. that's why u can't select full-screen mode: there isn't any in eX0_3. i guess this is sort of my fault, because i forgot to edit my original post, and people don't read replies.

well, anyway, you can download a new version here .

please give that a try. and if it works way too slowly (less than 5 fps) in both full-screen and windowed modes, try replacing it with an executable, which you can find here (don't mind the name).

quote:
Posted by RipTorn
you still don't need stencil for that though.


how else would i do it?

AndyTX, i have exactly the same video card, which is why such great fps! but the bot moves too fast because you probably got eX0_3, the older verions. in eX0_4 (download above) the bot moves a lot slower than you, but if you don't press anything for to long, he'll still find you and kill you. so as soon as you start, move back a little bit.

and just to remind the controls:
wasd - control your player
mouse horizontal movement - look around
left mouse button - shoot
r - reload
b - buy more clips (ammo)
hold shift - stealth mode (you walk slowly)

---
shurcool
my project

[edited by - shurcool on June 27, 2002 12:41:47 PM]

Share this post


Link to post
Share on other sites