Author Topic: ObjReader FBO & PP  (Read 28839 times)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
ObjReader FBO & PP
« on: March 31, 2019, 03:26:09 am »
Well, this is ObjReader's first ever render through a 16x MSAA FBO with a simple vignette PP shader. :D

(... at a full FPS rate that's twice lower than it would be without FBO and PP.  :( But as a bonus, we can now select the MSAA level in real time. 8) )
« Last Edit: May 03, 2019, 09:31:42 am by Patrice Terrier »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: ObReader FBO & PP
« Reply #1 on: March 31, 2019, 09:55:03 am »
Thank you my friend for your hard work!

A little WIKI definition about the meaning of MSAA, for the dummies like myself.

Multisampling, also known as multisample antialiasing (MSAA),
is one method for achieving full-screen antialiasing (FSAA). With multisampling, each pixel at the edge of a polygon is sampled multiple times. For each sample-pass, a slight offset is applied to all screen coordinates. This offset is smaller than the actual size of the pixels. By averaging all these samples, the result is a smoother transition of the colors at the edges. Unlike supersampling (SSAA) which can result in the same pixel being shaded multiple times per pixel, multisampling runs the fragment program just once per pixel rasterized. However with MSAA multiple depth/stencil comparisons are performed per sample, one for each of the subsamples, which gives you sub-pixel spatial precision on your geometry and nice, smoothed edges on your polygons.



History

Before GL_ARB_multisample extension, the edges of lines, polygons, and points could be selectively antialiased using using glEnable(GL_LINE_SMOOTH), glEnable(GL_POLYGON_SMOOTH), glEnable(GL_POINT_SMOOTH) respectively, combined with a blending function, such as glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Such features were typically not implemented in hardware in early consumer graphics cards at the time, and were done in software resulting in poor performance. More expensive "workstation" graphics cards from HP, Sun, and SGI at the time did implement these features in hardware. Modern programs should not make use of these features.

Rendering with Multisampling

There are two pieces to rendering with multisampling:
1.Allocating a multisample render target (window or FBO), and
2.Enabling multisample rasterization (i.e. glEnable( GL_MULTISAMPLE ))

While the second step is standardized across all render target types and platforms, the first is only standardized for FBOs (as it is totally internal to GL). When rendering to a window, the allocation method depends on the platform-specific GL integration layer in-use (e.g. WGL, GLX, AGL, etc.). GLUT provides a wrapper around some of these so you don't have to care.

More insight there:
https://www.khronos.org/opengl/wiki/Multisampling


« Last Edit: March 31, 2019, 10:06:38 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #2 on: March 31, 2019, 11:19:03 am »
That's perfectly correct, my friend! :)

Before, we had to select a proper MSAA-capable pixel format in a two-stage Mobj_choosePixelFormat() procedure at app start. Now, the screen rendering context may be left simple (without the MSAA selection loop) like in any simplest OpenGL example app.

The MSAA level (typically 16x) is selected and applied directly to the MSAA FBO when the FBOs are created in OR (actually, two of them: one MSAA'd for the actual frame renders, and one simple for screen quad texture creation). As FBOs must follow the gP.hGL size exactly but are non-resizable by design, they are to be re-created from scratch each time gP.hMain is resized for whatever reason. This is where a user-selectable MSAA level may be applied. 8)

Alternatively to MSAA, we may use an FXAA shader like here, which would be significantly more light-weight (hence faster) than full-scale MSAA.

Finally, nVidia (not ATi!) users may also optionally enjoy CSAA (Coverage Sampling Anti Aliasing), which is claimed to be as fast as 4x-only MSAA while yielding quality not worse than 16x MSAA.
______________________________________________

Here is a sample build of FBO OR for you to play with. Please report if it works OK under your W10.
Note: wireframe and point cloud modes are currently incompatible with the new code and produce a black screen!
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: ObReader FBO & PP
« Reply #3 on: March 31, 2019, 01:02:27 pm »
Quote
Please report if it works OK under your W10.
No, it doesn't, OR is not visible, nothing happen when trying to start the application.
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #4 on: March 31, 2019, 02:42:34 pm »
Try renaming it to ObjReader64.exe, please.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: ObReader FBO & PP
« Reply #5 on: March 31, 2019, 02:53:33 pm »
Sorry, but renaming to ObjReader64.exe, doesn't work either.
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #6 on: March 31, 2019, 03:32:31 pm »
I'll investigate the situation and inform you later.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #7 on: April 07, 2019, 10:34:26 am »
 :D :D :D :D

        8)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: ObReader FBO & PP
« Reply #8 on: April 07, 2019, 01:59:14 pm »
Bravo!
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #9 on: April 08, 2019, 10:27:29 am »
Thanks! :D

This is to inform you why I'm not rushing to supply you with the new toy that's now working flawlessly for both nVidia and ATi as well as W7 and W10.

The use of FBO doesn't affect our gl_DrawScene() and associated procs in any way as the code is 100% reusable. So, we're able to switch between direct and FBO rendering on the fly and thus basically turn post-processing off or on in real time. This requires appropriate menu switches and rock-solid initialization routines. That's what I'm working on now.

Further, we can also switch between direct and FBO MSAA in real time too. However, FBO MSAA requires a non-anti-aliased pixel format in gP.hGL while in the direct mode, the format should be 16x MSAA capable. So, I have to rework the pixel formatting routines accordingly.

Finally, such 3D editors like 3ds Max and Blender and some others can outline a selected mesh. Moreover, apart from the regular selection and mesh info tips, 3ds Max can outline dynamically the mesh that's currently under the cursor. And it does it depth independently so that the entire mesh is outlined not obscured by the other ones. (see the attached screenshots)

I am able to, and will, do the same in OR, and with a selectable color and thickness of the outline. It's gonna work in both direct and FBO modes of operation. 8)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: ObReader FBO & PP
« Reply #10 on: April 08, 2019, 11:16:23 am »
Thank you for your efforts!
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #11 on: April 10, 2019, 02:57:43 pm »
Well, how's your Royal Procrastinated Majesty feeling your precious self? :D

I remember I used to play truant from ObjReader for months. Sure you ain't gonna keep me alone that long, are you? :D

OK, here's the toy. It isn't yet complete or particularly stable (there may be some glitches with resizing and un-vsync'ed full-speed rendering) but it generally works for me on all my boxes, and promises to work still better in the future.

What it can do
  • It can run in direct or FBO modes (Inspect->Use framebuffers toggle).
  • It can use or not use a vignette PP shader (Renderer->Vignette toggle).
What it cannot do
  • It can't currently adjust its gP.hGL and FBO MSAA in real time yet (hardcoded at 16:8 samples, respectively, to satisfy both my nVidia and ATi video cards and direct or FBO modes of operation). So, its FPS rate is somewhat slower than it should be with just 1x MSAA in the viewport canvas when FBO is on.
  • It doesn't currently support wireframe or point cloud modes (the viewport goes black).
It's been compiled to my options, not yours, so I'm also including the 69.png FPS texture as I'm not sure if you still have one to be able to inspect the relative FPS rates. Please tell me if it works for you this time.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: ObReader FBO & PP
« Reply #12 on: April 10, 2019, 07:05:48 pm »
Thank you!

It seems to work fine by me on W10.

Quote
It's been compiled to my options, not yours, so I'm also including the 69.png FPS texture as I'm not sure if you still have one to be able to inspect the relative FPS rates.
Since at least the two last versions, i have been using the same FRAPS font (however smaller font size) to please you, as you can see on the attached screen shot.
« Last Edit: April 10, 2019, 07:25:08 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #13 on: April 10, 2019, 07:47:44 pm »
Quote
It seems to work fine by me on W10.

Wonderful! :)

Quote
... to please you, as you can see on the attached screen shot.

:D

Your monkey looks pretty BTW. (though mine is only 415KB large and loads in some 0.35 seconds. ;))
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: ObReader FBO & PP
« Reply #14 on: April 11, 2019, 12:42:13 pm »
Another simple single-pass PP shader -- "bloom".

No, this isn't "glow". Glow cannot be done in one pass because it involves texture re-scaling and gaussian blurs. Strictly speaking, bloom shouldn't be done in one pass either but it can still be (roughly) emulated in 2D screen space.

Bloom attempts to emphasize brightness of spot highlights in the screen quad. Due to the extreme simplicity of this shader it does currently generate certain sampling artifacts but they can be minimized by adding more elaborate screen texture sampling scenarios.

Also, this shader uses some rough gamma correction and is thus handy for making PBR-like albedo look more "juicy".
« Last Edit: April 11, 2019, 12:46:41 pm by Michael Lobko-Lobanovsky »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)