Logo by tomot - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Support us via Flattr FLATTR Link
 
*
Welcome, Guest. Please login or register. March 29, 2024, 03:23:54 AM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: GL depthbuffer from GLSL fragment  (Read 6493 times)
Description: spline path object occlusion in Fragmentarium
0 Members and 1 Guest are viewing this topic.
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« on: April 18, 2015, 08:33:13 PM »

spline path object occlusion in Fragmentarium...
this is the bit of shader code that makes it work...
Code:
gl_FragDepth = ((1000.0 / (1000.0 - 0.00001)) +
(1000.0 * 0.00001 / (0.00001 - 1000.0)) /
clamp(Ray.Pos/length(Ray.Direction), 0.00001, 1000.0));
this is the C++ side...
Code:
void DisplayWidget::qMultMatrix(QMatrix4x4 mat) {
        if (sizeof(qreal) == sizeof(GLfloat))
            glMultMatrixf((GLfloat*)mat.constData());
#ifndef QT_OPENGL_ES
        else if (sizeof(qreal) == sizeof(GLdouble))
            glMultMatrixd((GLdouble*)mat.constData());
#endif
        else {
            GLfloat fmat[16];
#ifdef WIN32
            float const *r = mat.constData();
#else
            double const *r = mat.constData();
#endif
            for (int i = 0; i < 16; ++i)
                fmat[i] = r[i];

            glMultMatrixf(fmat);
        }
    }

 void DisplayWidget::qglPerspective(GLdouble fov, GLdouble aspect, GLdouble zNear, GLdouble zFar) {
        fov = 180.0 * ( 2.0 * atan2(1.0,(1.0/fov)) / 3.1415926535);
        QMatrix4x4 matrix;
        matrix.setToIdentity();
        matrix.perspective(fov, aspect, zNear, zFar);
        qMultMatrix(matrix);
}

first, draw with shader program onto quad...
Code:
   glDepthFunc(GL_ALWAYS);       // always passes test so we write color
   glEnable( GL_DEPTH_TEST );    // enable depth testing
   glDepthMask(GL_TRUE);         // enable depth buffer writing
...GL commands to render quad...

... before drawing the spline paths set perspective...
Code:
     qglPerspective(fov, aspect, 0.00001, 1000.0);
where aspect is the QGLWidget dimensions width() / height() and fov is the value from the FOV slider

then render splines with
Code:
   glDepthFunc(GL_LESS);       // closer to eye passes test
   glDepthMask(GL_FALSE);      // no Writing to depth buffer for splines
   glEnable( GL_DEPTH_TEST );  // only testing
...GL commands to render splines...
result: GL primitives respect GLSL depth values cheesy

only tested with Qt4.8.5/linux, curious to hear input input from others, after reading everything I could find and trying examples that just never worked right in this particular case I have settled on the above approach because it seems to do the trick.
(i thought this might be of interest to others and would be better up front rather than hidden at the end of a very loooong thread)

edit: using QMatrix means no more dependency on glu library for perspective
« Last Edit: April 18, 2015, 08:43:34 PM by 3dickulus, Reason: tip » Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #1 on: April 19, 2015, 12:50:50 PM »

Looks like you got it covered, but this blog post might still be of interest:
http://blog.hvidtfeldts.net/index.php/2014/01/combining-ray-tracing-and-polygons/
Logged
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #2 on: April 19, 2015, 08:56:36 PM »

tnx for the input smiley
I found your blog post to be very good with helping me understand the process...
Quote
Object Coords -> Model Matrix (World Space) -> View Matrix (Eye Space) -> Projection Matrix (Clip space) -> Perspective Divide (Normalized Device Coords) -> Viewport Transform (Window Coords)
I also found that GL is a bit counter intuitive wrt exactly how to accomplish this, at first I was mucking around in the GLSL code with modelviewmatrix and projectionmatix etc. but had the idea that we are projecting a scene via a specialized matrix onto a flat ortho surface in GLSL and then viewing that surface via a GL quad, which means the view spaces used for calculating can have little or no relationship to each other. I recall you mentioned, some time ago when I first attempted this, that getting this to work in Fragmentarium would be challenging because the GL matrices are not used in the standard way so that you can do things like equirectangular projection.

now the challenge has become: how to get this to work on W!n  huh?

this is a recording of the Fragmentarium screen on linux desktop 4.4M http://www.digilanti.org/fragmentarium/occ-2015-04-16_21.31.44.mp4
edit: recorded live in "progressive+stop" mode zoomed back a bit and looking around with "shift+LMB"

red path = camera
blue path = target
yellow line = current frame lookat vector
green dots = keyframe positions along paths
« Last Edit: April 19, 2015, 11:20:58 PM by 3dickulus, Reason: info » Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #3 on: April 20, 2015, 01:06:49 AM »

hmmm I think this might have something to do with W!n problem...
On Windows, Qt can be configured with the system OpenGL or with ANGLE. By default, configure uses ANGLE
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #4 on: April 20, 2015, 09:09:59 PM »

Yes, after I upgraded to Qt5, I also had to specify desktop GL for Fragmentarium to compile - but if I recall correctly, I don't think you can even compile on Windows with ANGLE.
Logged
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #5 on: April 21, 2015, 01:34:34 AM »

I compiled with Qt 5.3.2 but afaik from docs Qt will use ANGLE or OpenGL dynamically as of v5.5, but I'm not familiar with ANGLE so just speculating.
Qt has a bufferBlit() function for copying the special buffers like depth, the linux version shows that the depth buffer is being populated and used so I'm going to try copying it and draw the splines in the drawToFrameBufferObject() routine instead of drawFragmentProgram()
also, I note that of the three buffers preview, back and highres, preview and back can be RGBA8 RGBA16 or RGBA32F while highres is always RGBA8, should they all be the same? (all have depth)

edit:by "all the same" I mean in sync, when preview or back change to RGBA16 should highres be RGBA16 too?
« Last Edit: April 21, 2015, 08:00:35 AM by 3dickulus, Reason: clarity » Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #6 on: April 27, 2015, 05:49:31 AM »

ok, last one was a dumb question  bubble gum  I see what's up with the RGBAnn buffers
although I still haven't got occlusion working on W!n  hurt
maybe migrating all of the widgetry to Qt5 will help as the splines can easily be drawn with a shader prog instead.
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #7 on: May 01, 2015, 03:31:46 PM »

Ah Ha! it is not W!n that prevents occlusion, it is the switch to Qt5, it's doing something different wrt depth buffers, I will be digging into this over the weekend hopefully to find a fix.
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #8 on: May 07, 2015, 02:40:31 AM »

in this link re:QOpenGLWidget vs. QGLWidget I found this ...
Quote from: Agocs Laszlo Laszlo.Agocs at digia.com
Thu Jul 31 20:03:25 CEST 2014
Note that all this does not mean existing code has to migrate away from QGLWidget.
It is not going to disappear. If it works, just keep using it.
I have converted all calls & refs in Fragmentarium from QGL... to QOpenGL...  except QGLWidget, not a straight across conversion, a few minor adjustments were needed to accommodate the new stuff but the perspective (for spline paths) is whacked. It still renders primitives, point, line, poly, and fractals. tested with QOpenGLWidget too, same result, not rendering splines in perspective.
I finally got it working right in Qt4 and Qt5 blows it out of the water, most frustrating  fiery
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #9 on: May 10, 2015, 06:17:32 AM »

 Sponge Bob looney YAY!
now the challenge has become: how to get this to work on W!n  huh?
this is a recording of the Fragmentarium screen on linux desktop 4.4M http://www.digilanti.org/fragmentarium/occ-2015-04-16_21.31.44.mp4

Spline path occlusion works in Qt5 version of Fragmentarium for lin AND win !!!
the linked page has source code and win exe cheesy the GLSL code (above) remains the same (use bundled frags) the C++ was altered a little for GL 4.1 Compatibility profile.

this was bugging me for some time, now I feel like I can move on to Network rendering...
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
3dickulus
Global Moderator
Fractal Senior
******
Posts: 1558



WWW
« Reply #10 on: September 19, 2015, 08:54:41 PM »

see http://www.fractalforums.com/index.php?topic=21759.msg87183#msg87183 also wink
Logged

Resistance is fertile...
You will be illuminated!

                            #B^] https://en.wikibooks.org/wiki/Fractals/fragmentarium
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
fragment Mandelbulb3D Gallery micshac 0 950 Last post December 15, 2010, 07:06:21 PM
by micshac
Fragment from Spider web Mandelbulb3D Gallery mica.mala 0 699 Last post August 16, 2012, 06:13:47 PM
by mica.mala
Fragment Fragmentarium Gallery Frakkie 4 1059 Last post February 12, 2013, 04:16:41 PM
by knighty
A fragment for fragmenting into fragments in Fragmentarium :) Fragmentarium « 1 2 » Kali 23 5430 Last post March 12, 2013, 12:23:28 PM
by LMarkoya
Fragment archive 2012-2016 Fragmentarium Crist-JRoger 7 3726 Last post January 09, 2017, 07:38:43 PM
by Tim Emit

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.172 seconds with 27 queries. (Pretty URLs adds 0.009s, 2q)