OpenGL & Raytracing

Started by
16 comments, last by Neutrinohunter 16 years ago
thanks evil steve

so rendering to textures :) i'll read up and give it a go.

Result: using glTexSubImage2D every frame is slower than gldrawpixels

[Edited by - Dolf on March 23, 2008 2:15:11 PM]
Advertisement
If your really worried about performance then you shouldn't be using individual draws. The best idea would be to use FrameBufferObjects for this task, they should be a hell of a lot quicker and using render to texture rather than *fake* render to texture methods by using the gl...SubImages().

You might want to take a look at the Arauna Real Time Library source code which is available from a link off this website. Type it in the search bar and you should find a few results.

Also without a GeForce 8800 GTX equivalent or a Quad/Oct Core Processor its very unlikely that a drop from 1500-300FPS is going to be a problem.

Is VSync turned on? When you get numbers of FPS above 100, the measurement becomes quite irrelevant, at those numbers we can't see a difference.

Neutrinohunter
Well, looking at these f/s (also referred as fps) drops don't tell much about exact rendering times! It's much better to show rendering times in miliseconds. Take look at this - your drop was from 1500 f/s, so your frame was drawed every 0,666666... milisecond, to 300 f/s - means that you've rendered frame every 3,333333... miliseconds. So drawing your raytrace buffer onto screen took 2,666666... milisecond - that's not SO BIG drop.

Anyway I've done some research into combined rendering methods (rasterization and raytracing), which I use in a project that I'm working on - it's not just mine project - it's engine (can be used to create games, or just for rendering - it's still not completed). I succesfully use combined rendering to get F.e. Global Illumination, Nice soft shadows (using own PCML shadow mapping algo), etc. It's working pretty nice, framerates are realtime (Well - On lower resolutions - F.e. 800x600 or 1024x768 - even 40 or more f/s (sometimes more, sometimes less - it highly depends on complexity of scene, number of dynamic objects, etc.) on todays high-end hardware).

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Mister Vilem Otte,

I was wondering, what tasks do you do as a shader and which ones do you do on the CPU?
And am I right in assuming you are doing everything in rasterization, except: soft shadows, global illumination, reflections and refractions?

Mister Neutrinohunter,

V-sync isn't on.
I'll look into framebufferobjects and I dont think arauna will help me that much. Arauna renders in software. I'd like to create a hybrid.
Quote:Original post by Dolf
My point is, I've seen it with 1500 fps in some direct 3d application.

How do i get that same result in opengl? I'm not saying "it's too slow" , i am saying "it's slower than it can be".


It depends on the driver's behavior. So I cannot explain why you get 1500 in D3D and 300 in GL.
All I'm saying is that you need to render a lot of stuff on screen.
You might end up with GL at 70 FPS and D3D at 50 FPS.
It very much depends on the driver and all the GL commands you call.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
So, i'll describe F.e. Ambient occlusion (It's little simplier) - in short how ambient occlusion works - tracing rays in hemisphere over point - I'm getting some data and then computing visiblity factor from "some data" on that pixel. (Where some data = collision data from those rays emitted by point in random directions of hemisphere, the more rays in random direction I trace, the higher quality ambient occlusion would be) - I hope this short explanation is understandable.

1. I'm viewing scene from camera view point and tracing primary rays if I get collision, then I calculate ambent occlusion for that pixel.
- So now I have ambient occlusion in buffer (similar to texture buffer).

2. I generate texture from the raytracing buffer, there are two ways of how-to - using glTexImage2D (respectively glTexSubImage2D) or using glDrawPixels and glCopyTexImage2D (respectively glCopyTexSubImage2D, It might be possible to use frame buffers and P-buffers for this, but I haven't tested that yet)
- Now I have ambient occlusion in texture.

3. I rasterize whole scene with textures, lighting, normal mapping (sometimes with some kind of offset mapping - F.e. Parallax occlusion mapping), etc. from camera point and I have to render this into texture (I'm using frame buffer, but you can use F.e. glCopyTexSubImage2D).
- Now I have whole rasterised scene in texture.

4. I combine these two textures (for ambient occlusion is best to multiply them) and voilá I get....

5. Final scene with raytraced ambient occlusion

- I'm not using the same texture size for "raytrace buffers" and "rasterized buffers", raytrace buffers are smaller! (with bilinear filtering it looks smooth = nice)

Anyway ambient occlusion wouldn't make much sense in these days, because it'll give you similar result as screen-space ambient occlusion, but raytraced AO would be several times slower. And the last thing - raytracing speed depends very much on resolution of "scene" - so raytrace the smallest buffer you can (anyway you need to have at least some quality).
I'm not doing just reflections, refractions, GI and soft shadows using raytracing, I can render whole scene using raytracing, but it'd be slower, than combine it. Anyway reflections, refractions and GI can't be achieved correctly with rasterization (well, they can be done, but it's damn hard and damn slow - it has sense F.e. for plane).

EDIT:
#Neutrinohunter - You can't use framebuffers until you've got it in the textures or until you draw it onto screen using glDrawPixels. And "raytrace buffers" aren't textures, they're just field of floats or ints or doubles or ...

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Similar question with some answers:

http://ompf.org/forum/viewtopic.php?f=4&t=657

FYI, doing glTexSubImage2D is much faster than glDrawPixels, if you use it correctly. At least it was for me at 1920x1200x32 resolution, and seems to be the case for other people.
Vilem: The method I use is to render to my own image class, which allows me to perform sampling methods or blurring if wanted and then render that image as a texture to an FBO.

In his case, yes he may require to do a glDrawPixels, in the method I use I don't :)

This topic is closed to new replies.

Advertisement