Archived

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

oeginc

Reflection Help & Slow texture mapping...

Recommended Posts

oeginc    122
-- This is my first OpenGL program, and the code is pretty sloppy, fair warning -- The idea I had was to have 2 playing cards (King & Queen) "Dance" around eachother over some marble flooring that was reflecting their images as they floated around. Problem #1 ========== My scene renders INCREDIBLY slow (15fps) on one of my computers, and viciously fast (60+fps) on another. The problem here is the machine that it renders slow on, I have been able to successfully run numerous other OpenGL programs that have MUCH more complex scene details, and many many more objects at framerates of 40+ fps easily. As a matter of fact, *MY* code appears to be the *ONLY* code I''ve seen that doesn''t run fast! If any optimization experts can take a look at the code and give me some suggestions, it''d be greatly appreciated (I know I''m doing a couple things here-n-there to speed it up slightly by 1 or 2 fps, but the visual impact wasn''t worth it... If you can find something to speed it up 20+ fps I''ll give ya a donut!) NOTE: Comment out the ENVMAPPING_CODE line to test w/o my hosed environment mapping code. Problem #2 ========== I am *TOTALLY* lost when it comes to environment mapping and/or reflections. I''d like the marble flooring to reflect the images from the playing cards, however, but looking at several environment mapping examples out there, the best I have been able to do is to get the cards to reflect an image of themselves on themselves (Yes, it *IS* a wierd effect and not even remotely close to what I wanted, LOL). If an environment mapping specialist could browse thru this code and give me some suggestions (or even fix it so I have an example based on code I''m familiar with) I would be eternally grateful. The idea behind this project was to create a neat looking effect with a cute concept that people could look at and learn from (it appears that I''m the one doing most of the learning). Download the code from: http://www.oeginc.com/downloads/RotateCard4.zip or click here.

Share this post


Link to post
Share on other sites
playworker    122
Real reflections are done using the stencil buffer - you need to search for a tutorial or have a browse through the OpenGL Red Book.

Environment mapping is a way of making something look as if it is reflecting it''s surroundings without the overheads of real reflections. The only way to do what you want with environment mapping is to render the scene to a texture and use that texture as an environment map - it''s probably faster doing the reflections with the stencil buffer

Share this post


Link to post
Share on other sites
oeginc    122
Yeah, I have tried stencil buffers as well, even more lost there.. Is it just me, or is there a lack of good information on these subjects? Perhaps I''m just not looking in the right places... Anyone able to solve these problems? =)

Share this post


Link to post
Share on other sites
Maximus    124
You can do proper reflections without the stencil buffer, and its not that hard (I coded up a test case pretty quickly).

1) Draw the reflected scene
2) Clear Z
3) Draw the mirror surface polygon(s)
4) Draw the rest of the scene normally

Works a charm, and is supported on all hardware.

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack

Share this post


Link to post
Share on other sites
davepermen    1047
http://developer.nvidia.com

right top..
perfect shadow volumes for every situation

hm..
demo with source
big paper explaining the whole approach

what else do we need?

(they have TONS of papers about any grafical subject..)

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

Share this post


Link to post
Share on other sites
ANSI2000    122
You frame rate problem can be related to vsync... Turn it off in the Display Properties of your OGL driver or do in code... I dont rember what the extension is...

Share this post


Link to post
Share on other sites
oeginc    122
Ok, I am getting significantly closer to realism now.. I finally got *SOMETHING* to appear, although:

1) It doesn''t look quite "right",

-and-

2) Frame rates have dropped to rediculously low levels...
I am now luck if I can get 2fps in 800x600 mode.

I''ve cleaned up the code quite a bit, and I am now doing the reflections by using the stencil buffers as someone has suggested...

If those OpenGL masters that have sent me some feedback on my code already wouldn''t mind downloading the latest version and see if you can spot some ways of making it faster and look a little more realistic, I''d appreciate it greatly!

(1 of the realism things I''m referring to is that you''ll notice when the card that is flipping head over heals flips, you can see the front/back of the card in the reflection before you would be able to in real life (Ie: the card hasn''t crossed the 1/2 way point yet, but you still see the reflection of the surface that would be facing up in RL)).

The new code is here.

Thanks a million for all the help!

Share this post


Link to post
Share on other sites
oeginc    122
quote:
Original post by ANSI2000
You frame rate problem can be related to vsync... Turn it off in the Display Properties of your OGL driver or do in code... I dont rember what the extension is...


I've tried that, didn't appear to make any difference... What I don't understand is that I'm able to view other peoples OpenGL demo's with scenes many times more complex than mine at 30+ fps...


quote:
Original post by davepermen
http://developer.nvidia.com

right top..
perfect shadow volumes for every situation

hm..
demo with source
big paper explaining the whole approach

what else do we need?

(they have TONS of papers about any grafical subject..)

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


I'm not a complete NEWB, I've been programming professionally since 1982. I have done quite a bit of extensive research on the subject, and there really aren't to many articles/examples I've been able to find that explains bit-by-bit what each line does, and why you need it (or don't need it as the case may be).

I've learned what I know now by trial and error, and what works in someone else's code, may not work in yours (as I've found out with this code). I've found SOME examples, but when I implemented them, nothing -- nadda... And since those examples didn't explain WHY they were doing something the way they were, it makes it difficult for me to even attempt to make changes to fix it.

P.S. Thanks to all of you who DID help, it's much appreciated!


[edited by - oeginc on May 7, 2002 1:55:26 PM]

Share this post


Link to post
Share on other sites
zin    110
Your version 5 file is unavailable, version 4 runs 450 fps on my 1 gig athlon w/ geforce2.

zin

zintel.com - 3d graphics & more or less

Share this post


Link to post
Share on other sites
Extrarius    1412
When running version 4 of the program w/o reflections on a machine that is approximately 500MHz, running NT, with a generic graphics card, I got 60 FPS _UNTIL_ it started drawing the FPS counter (the first time it drew the counter, it showed 60 FPS, then after that it showed <20 every update) so I would guess glDrawText is a ''little'' slow. IT would depend on the OS, card, and drivers, but it may be that its extremely slow on your problem PC.



"I believe; therefore, it is." -True Perception
"The Requested Information Is Unknown Or Classified" -Anonymous

Share this post


Link to post
Share on other sites
davepermen    1047
well

one thing..
you enable texgen for the spheremapping
you should disable it after drawing the floor
that way you don''t have those fancy "selfreflectmapping" cards

spheremaps are NOT for reflections, they are for environmental effects.. like looking like metall for example
they CAN be used for some reflection-effects but surely NOT for real reflections..
result:
DONT use envmaps for the planar reflection

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

Share this post


Link to post
Share on other sites
oeginc    122
quote:
Original post by zin
Your version 5 file is unavailable, version 4 runs 450 fps on my 1 gig athlon w/ geforce2.

zin

zintel.com - 3d graphics & more or less


This has been fixed now, sorry about that.. Version 5 does reflections using Stencil buffers.. I''m running this on a AMD Athlon 800mhz w/GeForce 2 and 1.5 Gigs of RAM and only getting about 2 frames per second... =(

quote:
Original post by davepermen
well

one thing..
you enable texgen for the spheremapping
you should disable it after drawing the floor
that way you don''t have those fancy "selfreflectmapping" cards

spheremaps are NOT for reflections, they are for environmental effects.. like looking like metall for example
they CAN be used for some reflection-effects but surely NOT for real reflections..
result:
DONT use envmaps for the planar reflection


I''ve completely changed the way this works to now use stencil buffers, the new code is available at:

http://www.oeginc.com/downloads/RotateCard5.zip

or you can click here.

But it runs incredibly slow on my machine (see above).

Share this post


Link to post
Share on other sites
_the_phantom_    11250
just gave the above code a test
got a sweeet rock soild 170fps from it

desktop running @ 1280*1024*32
vsync off
CPU : AMD Athlon T-bird 1.4Ghz
RAM : 768SD @ 140Mhz
GFX : Geforce 3 Ti200 64Meg DDR, o/c 220Mhz core, 503Mhz Mem
OS : Win2K

the fps held at 170fps and I did run it for a while
all was nice and smooth and it does look sweet

Share this post


Link to post
Share on other sites
Sivle    122
Well, I tried it out myself and I have bad news for you...

Less than 1 frame a second. Yes, you heard me right. 0.656 (average) frames a second. Presumably, I have the same problem that you do (except much worse, most likely due to my aging hardware).

Pentium III 650MhZ
256 MB RAM
TNT2 32MB

Share this post


Link to post
Share on other sites
davepermen    1047
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwLayerMask = PFD_MAIN_PLANE; // We want the standard mask (this is ignored anyway)
pfd.iPixelType = PFD_TYPE_RGBA; // We want RGB and Alpha pixel type
pfd.cColorBits = SCREEN_DEPTH; // Here we use our #define for the color bits
pfd.cDepthBits = SCREEN_DEPTH; // Depthbits is ignored for RGBA, but we do it anyway
pfd.cAccumBits = 0; // No special bitplanes needed
pfd.cStencilBits = 0; // We desire no stencil bits


you don''t ask for any stencil bits.. how do you except that there will be a stencil buffer awailable? set this to 1, or 8, depends on hardware..

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

Share this post


Link to post
Share on other sites
Maximus    124
Run your app in 32bit colour mode. If youre running in 16bit colour and trying to use stencil on your gf2/tnt2 cards, youre using software rendering which is why its so damn slow. Put it on 32bit and hardware stencilling is enabled and youll have hardware rendering.

Geez Im amazed nobody else pointed this out.

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack

Share this post


Link to post
Share on other sites
oeginc    122
quote:
Original post by davepermen
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwLayerMask = PFD_MAIN_PLANE; // We want the standard mask (this is ignored anyway)
pfd.iPixelType = PFD_TYPE_RGBA; // We want RGB and Alpha pixel type
pfd.cColorBits = SCREEN_DEPTH; // Here we use our #define for the color bits
pfd.cDepthBits = SCREEN_DEPTH; // Depthbits is ignored for RGBA, but we do it anyway
pfd.cAccumBits = 0; // No special bitplanes needed
pfd.cStencilBits = 0; // We desire no stencil bits


you don't ask for any stencil bits.. how do you except that there will be a stencil buffer awailable? set this to 1, or 8, depends on hardware..

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


That made all the difference in the world, on one of my machines... still only get 4fps on the other... (I can't believe I missed that, doh!)

--- EDITED ---

quote:
Original post by Maximus
Run your app in 32bit colour mode. If youre running in 16bit colour and trying to use stencil on your gf2/tnt2 cards, youre using software rendering which is why its so damn slow. Put it on 32bit and hardware stencilling is enabled and youll have hardware rendering.


Ding Ding Ding! We have a winner.. =) It now runs at 75fps! Thanks! I was unaware of this limitation... Now to throw some code in there to inform others if they aren't running in 32bit mode it may be slow...


[edited by - oeginc on May 8, 2002 9:24:01 AM]

Share this post


Link to post
Share on other sites
_the_phantom_    11250
ah yes, I've just looked at my tweeked OGL setup from NVMax :

Color depth 32bits
Fast Mipmaping one
Force S3TC v3 compression on
64tap texture filtering
Quincunx FSAA is on

the first one and 3rd one might well explain why I saw very good performance when I tested it.

Edit :
maybe not however got : 460fps with same settings as before, only changes are as follows :
FSAA off
16bit color depth
no texture compression
Bi or Trilinear filtering only

so I turned the Qunicunx FSAA back on and the fps dropped back to 190, this was still better than my last reading, so I'm starting to think that, on a gf3 at least, the color depth dont matter so much as it did on older hardware.

[edited by - _the_phantom_ on May 8, 2002 11:14:22 AM]

Share this post


Link to post
Share on other sites