LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-22-2004, 09:36 AM   #1
cjp
Member
 
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Rep: Reputation: 15
Making fast reflections in openGL


I'm making a racing game with openGL, but real-time updated reflections make it really slow. On the same computer, NFS underground seems to do exactly the same thing much faster. I don't think it can be the difference between directX and openGL, because ATI also provides good openGL support for my Radeon 9200 card, and DirectX 8+ and openGL aren't that much different. Of course it could be my code that's inefficient, but I don't think that that is the case, because of this:

Reflections are done by applying a texture to an object that describes its environment (the "environment map"). To update the environment map, you need to render the scene from the point of view of the object 6 times (left, right, top etc.), and put the results in the environment map. So after every rendering step you need at least one glCopyTexImage2D call to put the result in a texture. I've measured that these calls take approximately 2 ms, so it takes at least 6x2 = 12 ms to update a reflection.

Let's say that 25 fps is reasonable. That gives us 1/25 = 0.04 s = 40 ms for every frame. So with 12 ms per reflection, you can only update 3 reflections per frame. In reality it will be even worse, because you also need to render the scene 1 time + 6 times per reflection. But in a game like NFS underground I can see many cars and even the road having reflections, while the frame rate is still good. So how is that possible?
 
Old 10-22-2004, 01:08 PM   #2
avarus
Member
 
Registered: Apr 2004
Location: Oxford, UK
Distribution: Ubuntu, Debian, various
Posts: 230
Blog Entries: 5

Rep: Reputation: 32
Hi,

It's been a while since I did OpenGL at university, but I remeber the way that we were told to do reflections is as described here:

http://www.opengl.org/resources/code...s/Reflect.html

I won't say any more since this guy puts it much better than I can.

TIM
 
Old 10-22-2004, 01:30 PM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
I haven't done much with cubical environment maps, which is what I am assuming you are using since you said you render the scene 6 times from different view, but there are a couple things you might be able to try.

First, you could try to use glCopyTexSubImage2D instead of glCopyTexImage2D. I believe that glCopyTExSubImage2D is generally a bit faster.

Second, when rendering for your environment map, you can try to use some tricks to make those renders go faster. Maybe turn off lighting for those, render into as small an area as possible, etc...

Third, if that none of that works, you could try and fall back to normal environment mapping, which only uses a single distorted texture instead of 6 textures from different directions...

Edit:
I briefly looked at the link that was posted. If you just are just reflecting off of a plane (like a mirror), that method should work pretty well. If you are trying to make an irregularly shaped object reflect its environment, environment mapping will probably give you a better result.

Last edited by deiussum; 10-22-2004 at 02:30 PM.
 
Old 10-26-2004, 03:31 AM   #4
cjp
Member
 
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Original Poster
Rep: Reputation: 15
I already did a lot of these things. Turn out lighting, depth testing, blending etc.

BTW currently I'm using sphere mapping, but for updating your sphere map you still need several rendering steps. In the future, when I'm going to support cube mapping, I'll be able to skip the final compilation of the sphere map, but that's not the thing that takes most of the time.

I know about the option to use a "static" environment map, but that's not what I'm talking about. I know that environment maps in NFS are dynamic (at least for cars close to the camera).

Thanks for the glCopyTexSubImage2D hint, I'll try it. Why would it be faster than glCopyTexImage2D?
 
Old 10-26-2004, 06:02 AM   #5
worldmagic
Member
 
Registered: Oct 2003
Location: Europe/Sweden
Distribution: RedHat
Posts: 78

Rep: Reputation: 15
I know very little about OpenGL, so I guess my words are light on the subject. But maybe you can change the Field Of View to render all sides of your "box" at one time? And then develop a static alorithm that transforms the result image into 6 images (abit streched and such, but might work?). Im thinking of gluPerspective. Im guessing you already do this when you use Spheric mapping, but from what I see you only need one render.
 
Old 10-26-2004, 08:29 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
Quote:
Originally posted by cjp
Thanks for the glCopyTexSubImage2D hint, I'll try it. Why would it be faster than glCopyTexImage2D?
That I'm not exactly sure of myself. I seem to remember people recommending that on the OpenGL forums a lot, though. BTW, if you don't get a satisfactory answer here, there are a lot of very knowledgeable people over at the opengl.org forums.
 
Old 10-28-2004, 04:58 PM   #7
cjp
Member
 
Registered: Dec 2003
Location: the Netherlands
Distribution: SuSE 9.0
Posts: 54

Original Poster
Rep: Reputation: 15
I tried glCopyTexSubImage2D, and it really works. On my system, it takes 0,41 ms on average, compared to 2 ms for glCopyTexImage2D. Now I should only optimise the rendering of the scene, which is still 1,5 ms, but that's my problem
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAST (Mega fast Mirror) SUSE 10 beta 4 download 1kyle Suse/Novell 2 09-07-2005 10:13 AM
Making a fast system jedediah Linux - General 6 09-16-2004 11:15 AM
making slack fast as sourcemage Abe_the_Man Slackware 3 12-28-2003 03:07 PM
Reflections 6.0 XtremeDawg Linux - Newbie 0 12-15-2003 03:34 PM
Making linux super fast! Mwahahaha! Abe_the_Man Linux - Newbie 4 08-16-2003 02:34 PM


All times are GMT -5. The time now is 11:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration