Sign in to follow this  
Dolf

OpenGL OpenGL & Raytracing

Recommended Posts

Dolf    100
Hello, I was wondering, if I'd build a raytracing in software, what would be the fastest way to get my image across? glDrawPixels on the entire screen drops my application to 300 fps. And I still want to be able to use opengl commands, because I want to offload the CPU with stuff that can be done on the GPU (primairy ray intersection for instance, and shading). My ultimate goal would be to combine software and hardware. So is there any extension that would allow me proper pixel manipulation? or should I dive into shaders? Regards, Dolf

Share this post


Link to post
Share on other sites
V-man    813
Yes, you ca use glDrawPixels and it should be good enough and fast on todays hw.

Quote:
So is there any extension that would allow me proper pixel manipulation? or should I dive into shaders?

If you want to do raytracing in the shader, then yes it is possible. There are some demoes out there.

http://www.geocities.com/vmelkon/glsl_raytracing.html
I don't have the source anymore.

http://www.humus.ca/index.php?page=3D&&start=16
Raytraced shadows

Share this post


Link to post
Share on other sites
Dolf    100
"Yes, you ca use glDrawPixels and it should be good enough and fast on todays hw."
I didn't like the speed of that.

Thanks for the links!

Do i have to raytrace in shaders? or can i raytrace on the cpu and give it to the gpu? using a shader instead of drawpixels?

I was thinking of a hybrid between cpu and gpu, but you recommend doing all the tracing on gpu using shaders?

Share this post


Link to post
Share on other sites
V-man    813
Yes, raytracing can be done in shaders and there was some other guys who had done it. They were able to do more complex models instead of just planes and spheres.

What hybrid model do you have? Because glDrawPixels just renders a ready made image.

Share this post


Link to post
Share on other sites
Moomin    332
Quote:
Original post by SiCrane
Why on earth are you complaining about 300fps?


I believe birds such as pigeons(who see somewhere between the range of 60-200 fps), who may be viewing his material may see only a slightly blurred slide show instead of the animation he requires. Wait no they wouldn't.

Share this post


Link to post
Share on other sites
Dolf    100
Without any ray tracing done, just the pure act of sending glDrawPixels, slows me down to 300 fps.
With nothing but an empty screen I was expecting 1500, I've seen that.

About glDrawPixels:
Well, if you render in software to an array of bytes, and then send it to the GPU just to blend it in with the rasterized image.

About my model:
I'm not sure what kind of hybrid I want yet, but I will be going for a real-time implementation.

I think I'd like to leave all the things that rasterization is good at in there for the GPU, and the things the GPU sucks at (like reflections, refractions, soft shadows and maybe global illumination) I'd like to raytrace those.
And with "raytracing" I mean either on the CPU or on the GPU, whatever turns out to be the best.

Edit: I just found out about "render to texture", maybe that would be faster than drawpixels?
Edit again: Or maybe there is a way to get direct access to the framebuffer?

[Edited by - Dolf on March 23, 2008 2:40:54 PM]

Share this post


Link to post
Share on other sites
V-man    813
The GL driver is tuned to execute a certain amount of commands and in the general area of 60 to 100FPS.
300 FPS is meaningless.

Someone needs to write an article on this so that people understand that they must render a lot of stuff and then worry about benchmarking.

Share this post


Link to post
Share on other sites
Dolf    100
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".

Share this post


Link to post
Share on other sites
Evil Steve    2017
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".
I'm not an OpenGL person, so this won't be that helpful, but drawing individual pixels is bound to be slow. For a 320x200 screen, you'd be drawing 64,000 individual pixels. In D3D, you'd fill a texture with pixel data, then upload that in one go to the graphics card.

I imagine doing something similar in OGL would give you better performance.

Share this post


Link to post
Share on other sites
Dolf    100
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]

Share this post


Link to post
Share on other sites
Neutrinohunter    158
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

Share this post


Link to post
Share on other sites
Vilem Otte    2938
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).

Share this post


Link to post
Share on other sites
Dolf    100
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.

Share this post


Link to post
Share on other sites
V-man    813
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.

Share this post


Link to post
Share on other sites
Vilem Otte    2938
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 ...

Share this post


Link to post
Share on other sites
Neutrinohunter    158
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now