sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

antialias #71

Closed nilsbecker closed 5 years ago

nilsbecker commented 5 years ago

i am not seeing any improvement of the rendering of thin lines when i set antialiasing to any enabled value, like so:

...
        glfw.window_hint(glfw.SAMPLES, 8)
        self.window = glfw.create_window(width, height, title, None, None)
        if not self.window:
            glfw.terminate()
            print('could not create window?')
            return
        # needed _before_ any GL functions are called; otherwise segfault
        glfw.make_context_current(self.window)
        glEnable(GL_MULTISAMPLE)
        # nicer quality? does not seem to make any difference?!
        gr3.setquality(gr3.GR3_Quality.GR3_QUALITY_OPENGL_16X_SSAA)

...

am i doing this right? is this expected? this is on os x, on an imac which i think would have hardware support?

FlorianRhiem commented 5 years ago

GR3's setquality is unrelated to OpenGL multisampling settings. Setting the quality will change the way pixmaps are created, e.g. for gr3.getimage or gr3.export, either creating them via OpenGL or via POVRAY and with varying degrees of SSAA. These images will be created on an offscreen framebuffer object, possibly as tiles if the requested resolution is larger than the resolution of the underlying framebuffer (which can be set during gr3.init), so the multisampling settings of the default framebuffer do not influence this.

nilsbecker commented 5 years ago

ah! good to know. so for on-screen antialiasing, the only relevant setting is glfw.SAMPLES then?

FlorianRhiem commented 5 years ago

Yes, when rendering to OpenGL using the existing framebuffer, the multisampling settings (e.g. glfw.SAMPLES) will be used. Here are two screenshots which show the difference: image image

nilsbecker commented 5 years ago
screen shot 2019-01-03 at 15 28 50

i get this with glfw.SAMPLES set to 8 or 16 (it looks the same). with no multisampling hint it does look a bit worse. but the stripes on the grid are not desired; is this the best one can get?

FlorianRhiem commented 5 years ago

Those are very thin cylinders, right? I think these 'stripes' are a combination of the dark lower side and the lit upper side. You could try to make them slightly thicker (to move the two extremes further apart) or thinner (to let the antialiasing create mostly greys instead of sharp light and dark regions) to reduce this effect, or use a darker color to reduce the contrast between light and dark regions. For publications you can export the scene to a pov-file and adjust the lighting there, then use POVRay to create the image exactly the way you'd like it.

nilsbecker commented 5 years ago

yes, they are cylinders. actually, it's not such a big deal; i think stripes are preferable to thick cylinders. i just thought there might be an obvious setting i am missing. of course, with POVRay one could get something smoother if needed. thanks and happy new year!