3
$\begingroup$

I Recently posted this question on SO but didn't got any response so i thought to post it here since it's somewhat related to Raytracing.

I am making a real time ray tracer in OpenGL using Compute Shaders for my project and was following this link as a reference. The link tells to first draw a full screen quad, then store all the individual pixel colors gotten through intersections in a texture and render the texture to the quad.

However i was thinking can't we use Frame Buffer Objects to display the texture image instead of rendering the quad and save the over head?

Like I save all the colors using ImageStore and GlBindImageTexture in a texture, then attach it to a FBO to display it. And since I won't be using any rendering commands I won't be causing a Feedback loop as in writing and reading the same texture?

Here is the snippet

  void initialization() {
  int tex = create new texture object

  setup min/mag NEAR filtering for that texture
  initialize texture as 2D rgba32f FLOAT and some width/height

  int vao = create VertexArrayObject of full-screen-quad
  // This quad is used to render our
  // "framebuffer" texture onto the screen.

  int computeProgram = create-and-link program with single compute shader object

  int quadProgram = create-and-link simple full-screen quad vertex and fragment shader
  // The fragment shader would fetch
  // texels from our "tex" texture.

  Setup constant uniforms in quad program, such as "tex" texture unit = 0
}



 The rendering process to produce one frame will be as follows:

Bind the Compute Shader
Setup camera properties in compute shader uniforms
Bind level 0 of framebuffer texture to image binding point 0
Start/dispatch the compute shader to generate a frame in the framebuffer image
Unbind image binding point
Bind the written framebuffer texture in OpenGL to texture unit 0
Bind the full-screen shader program
Bind the full-screen-quad VAO
Draw the VAO
Release all bindings
$\endgroup$
2
$\begingroup$

So i searched a lot after this and I think it was my confusion on FrameBuffer Objects.

I thought you could use FBO's just like a default FrameBuffer and display the texture image attached to it but you can't. It's only used for offscreen rendering. So while you can use rendering commands to draw something to a "texture image" attached to it, you can't "display the image" by making it default framebuffer or something like that.

$\endgroup$
  • $\begingroup$ If I understand correctly what you are trying to do, then, it is possible to do with FBO. Just create rendertexture instead of renderbuffer for color attachment (and call appropriate bind function). Then you'll be able to use this render texture as shader input. $\endgroup$ – alariq Sep 18 '17 at 10:47
  • $\begingroup$ No i was thinking that i could use the FBO to display the texture image on the window. Like i was thinking if the texture image is already set in the compute shader, then the FBO it's attached to would just display it in the window if i make it default, but i don't think there's any command for that. $\endgroup$ – gallickgunner Sep 18 '17 at 13:10
  • $\begingroup$ I guess internally opengl keeps a texture buffer for the default framebuffer. It's just the API does not allow you to consider it as a texture, so a draw/copy operation is needed. $\endgroup$ – PaulHK Sep 19 '17 at 7:28
  • $\begingroup$ Yes that's what i was thinking. I thought opengl provided the functionality to use the FBO as a default one to display the texture directly attached but it doesn't i guess. They provided FBO for offscreen rendering only i guess for help with things like getting the reflection texture etc. $\endgroup$ – gallickgunner Sep 19 '17 at 19:07
1
$\begingroup$

The overhead on this is pretty miniscule anyway. Modern GPU raster and texture rates are on the order of tens of gigapixels per second. Compared to the cost of running a ray tracer, it's a rounding error.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.