Loading ...
Sorry, an error occurred while loading the content.

GLSL Vertex Shader for Fulldome Fisheye?

Expand Messages
  • nada_cloo
    Can anyone point me to (or share) a working example of a GLSL vertex shader to generate a 180 degree fulldome fisheye? I d prefer seeing both the GLSL and the
    Message 1 of 13 , Oct 3, 2012
    • 0 Attachment
      Can anyone point me to (or share) a working example of a GLSL vertex shader to generate a 180 degree fulldome fisheye? I'd prefer seeing both the GLSL and the host-side OpenGL setup code (Java, Cpp, C, Python, etc.) to give me a full understanding.

      My current shader is based on this (http://pixelsorcery.wordpress.com/2010/07/13/fisheye-vertex-shader/), but I'm not happy with it. Frankly, I don't understand it (in spite of the great diagrams), and the field of view is less than 180 degrees.

      Regards,

      Ken Scott
      Digital Chaotics
      http://www.DigitalChaotics.com
    • asaf yurdakul
      Hi Ken You can find vertex shader code is here https://github.com/mphasize/FullDome/downloads. FulldomeTemplate codes may help you. Asaf Yurdakul
      Message 2 of 13 , Oct 3, 2012
      • 0 Attachment
        Hi Ken
        You can find vertex shader code is here
        https://github.com/mphasize/FullDome/downloads.
        FulldomeTemplate codes may help you.
        Asaf Yurdakul
        www.sureyyasoft.com

        From: nada_cloo
        Sent: Wednesday, October 03, 2012 6:42 PM
        To: fulldome@yahoogroups.com
        Subject: [fulldome] GLSL Vertex Shader for Fulldome Fisheye?

        Can anyone point me to (or share) a working example of a GLSL vertex shader to generate a 180 degree fulldome fisheye? I'd prefer seeing both the GLSL and the host-side OpenGL setup code (Java, Cpp, C, Python, etc.) to give me a full understanding.

        My current shader is based on this (http://pixelsorcery.wordpress.com/2010/07/13/fisheye-vertex-shader/), but I'm not happy with it. Frankly, I don't understand it (in spite of the great diagrams), and the field of view is less than 180 degrees.

        Regards,

        Ken Scott
        Digital Chaotics
        http://www.DigitalChaotics.com
      • Videometry
        I recently battled with this in Away3D (AS3), though the same issues arise for any platform, and the same solution can probably be applied.
        Message 3 of 13 , Oct 4, 2012
        • 0 Attachment
          I recently battled with this in Away3D (AS3), though the same issues arise for any platform, and the same solution can probably be applied.

          <http://www.videometry.net/Fisheye/>



          If you want to warp your actual geometry, it may need to be�tessellated.

          Consider a flat plane. Normally it would have a minimum of 4 vertices, and yet no matter how these are transformed, you won't achieve the desired curve, that an optical fisheye lens produces.

          So, you could just add thousands of vertices, say a grid 1000 x 1000 depending on the size and desired output quality. But therein lies an issue, which the article you refer to also mentions. Suddenly you have 1,000,000 vertices to represent a flat plane!

          I realise that this might not apply to your particular 3D scene, but it illustrates the point.

          There is an alternative approach that doesn't require any alterations to
          geometry, or special lighting shaders. The technique is described in this
          thread<http://away3d.com/forum/viewthread/3198/>

          but here's the short and general version...

          1. Render a reflection map at the point where the camera is.

          2. Point your camera at a sphere that uses the reflection map (and preferably in reverse...)

          3. That's it! You might want to attach the sphere to the camera so they follow each other round.

          As the reflection shader works at pixel level rather than with geometry, you get nice flowing curves.

          This technique can be used to create all kinds of "lenses", and gives you the curves without the vertex count. Admittedly creating the reflection map for every frame does require some processor/GPU power, but generally not as much, and with no special requirements for geometry/lighting in your scene.

          I hope that will be useful to someone.

          As I'm only a "wannabe" full dome content creator I rarely get to chip in on this forum ;)


          Good Luck!



          Peter Strømberg (aka. theMightyAtom)


          --
          Peter Strømberg
          Skovvej 11
          8382 Hinnerup
          DENMARK

          mobil: (+45) 60 44 08 80

          On Oct 3, 2012 17:42 "nada_cloo" <ken.scott@...> wrote:

          Can anyone point me to (or share) a working example of a GLSL vertex shader to generate a 180 degree fulldome fisheye? I'd prefer seeing both the GLSL and the host-side OpenGL setup code (Java, Cpp, C, Python, etc.) to give me a full understanding.

          My current shader is based on this (http://pixelsorcery.wordpress.com/2010/07/13/fisheye-vertex-shader/), but I'm not happy with it. Frankly, I don't understand it (in spite of the great diagrams), and the field of view is less than 180 degrees.

          Regards,

          Ken Scott
          Digital Chaotics
          http://www.DigitalChaotics.com
        • Jonathan Cremieux
          Hi, You could check out the fisheye shader example that comes with the latest release of processing : http://processing.org It is inspired by Paul Bourke s
          Message 4 of 13 , Oct 4, 2012
          • 0 Attachment
            Hi,
            You could check out the fisheye shader example that comes with the latest
            release of processing : http://processing.org
            It is inspired by Paul Bourke's article on the angular fisheye lens.

            Regards.
            -
            Jonathan Cremieux
          • nada_cloo
            Thanks to all who replied. While the answers and suggestions were helpful, they re not quite what I m looking for. I just need the core of the vertex shader
            Message 5 of 13 , Oct 4, 2012
            • 0 Attachment
              Thanks to all who replied.

              While the answers and suggestions were helpful, they're not quite what I'm looking for. I just need the core of the vertex shader that shifts the vertices around as needed to create the illusion of a fisheye lens.

              - I'm aware of the need for tessellation to prevent straight lines from remaining straight.

              - Screen-space solutions won't work. Warped pixels are icky.

              - Cube rendering slightly better, but it's still a radical brute force solution that doesn't produce the quality I'm looking for. I may have to go there someday, but I'm hoping to avoid super-mega-sampled rendering of the scene five times for each frame.

              Really I just want a function that, given an original vertex location, an eye position, and an eye direction vector, will return a new vertex location. Actually, my ideal generalized solution would be an algorithm that maps vertices onto an arbitrary 3D grid surface (for example, a hemisphere). (Not all domes are perfect hemispheres, y'know.)

              This function is the final stage in a series of functions that nudge vertices around according to a variety of rules. Some are just surface tweaks (bumps), but this one's the biggie.

              Thanks,

              Ken Scott
            • J-Walt
              Ken, Here s a quick explanation of how to do it. First, transform vertices into camera-space. The next step is projecting with some sort of perspective.
              Message 6 of 13 , Oct 4, 2012
              • 0 Attachment
                Ken,
                Here's a quick explanation of how to do it.

                First, transform vertices into camera-space. The next step is projecting
                with some sort of perspective. Typically, CGI divides the XY
                (left-right/up-down) position by the Z(forward-back) position:

                screenx = x/z
                screeny = y/z
                screenz = z

                This is not what you want for the nice fish-eye distortion, because a
                point at (10,10,15) will appear to be the same distance away as a point at
                (0,0,15). In your case, you want to divide the XY by the distance of the
                point:

                d = sqrt(x*x + y*y + z*z)
                screenx = x/d
                screeny = y/d
                screenz = z

                Scaling your screenx and screeny by some factor will get you your
                field-of-view. Sorry to be vague here, but it's been decades since I
                worked out this distortion, and I don't want to get into more detail,
                because...

                You really don't want to do this!

                You won't be saving time or render speed. This technique works fine for
                wireframes (sometimes), but it won't work well for textures or polygons
                unless you subdivide them highly. Plus, you need to tessellate based on
                distance, and good luck with that.

                Rendering large frames and distorting them works fine, and it's compatible
                with everything else you can get your GPU to do. We do it in real-time all
                the time. You saw me doing it at DomeFest at 60 fps. (Sure, it was running
                in parallel, but whatever). Just render your frames large, distort, and
                join them. It looks great! Here's an example from a few years ago:

                http://spontaneousfantasia.com/DomePortraits/slides/JWalt_Dome_021.html


                nada_cloo wrote:
                Thanks to all who replied.

                While the answers and suggestions were helpful, they're not quite what I'm looking for. I just need the core of the vertex shader that shifts the vertices around as needed to create the illusion of a fisheye lens.

                - I'm aware of the need for tessellation to prevent straight lines from remaining straight.

                - Screen-space solutions won't work. Warped pixels are icky.

                - Cube rendering slightly better, but it's still a radical brute force solution that doesn't produce the quality I'm looking for. I may have to go there someday, but I'm hoping to avoid super-mega-sampled rendering of the scene five times for each frame.

                Really I just want a function that, given an original vertex location, an eye position, and an eye direction vector, will return a new vertex location. Actually, my ideal generalized solution would be an algorithm that maps vertices onto an arbitrary 3D grid surface (for example, a hemisphere). (Not all domes are perfect hemispheres, y'know.)

                This function is the final stage in a series of functions that nudge vertices around according to a variety of rules. Some are just surface tweaks (bumps), but this one's the biggie.

                Thanks,

                Ken Scott
              • Videometry
                Listen to Walt :) Actually, my ideal generalized solution would be an algorithm that maps vertices onto an arbitrary 3D grid surface (for example, a
                Message 7 of 13 , Oct 5, 2012
                • 0 Attachment
                  Listen to Walt :)

                  "Actually, my ideal generalized solution would be an algorithm that maps
                  vertices onto an arbitrary 3D grid surface (for example, a hemisphere"

                  That's precisely what you get when you map the cubic map onto some
                  geometry. You can tweak the mesh shape to fit the dome,or any arbitrary
                  shaped environment. I'm confident that if Flash can do it realtime at
                  60fps, lower level shading languages should cope just fine.

                  Btw, I was in error when I said the shader works at pixel level, it is
                  of course still a fragment shader, with curve quality being controlled
                  by the vertex densityof your "lens" mesh.


                  Cheers!


                  --
                  Peter Strømberg
                  Skovvej 11
                  8382 Hinnerup
                  DENMARK

                  mobil: (+45) 60 44 08 80

                  On Oct 5, 2012 07:28 "J-Walt" <jwalt@...> wrote:

                  Ken,
                  Here's a quick explanation of how to do it.

                  First, transform vertices into camera-space. The next step is projecting
                  with some sort of perspective. Typically, CGI divides the XY
                  (left-right/up-down) position by the Z(forward-back) position:

                  screenx = x/z
                  screeny = y/z
                  screenz = z

                  This is not what you want for the nice fish-eye distortion, because a
                  point at (10,10,15) will appear to be the same distance away as a point at
                  (0,0,15). In your case, you want to divide the XY by the distance of the
                  point:

                  d = sqrt(x*x + y*y + z*z)
                  screenx = x/d
                  screeny = y/d
                  screenz = z

                  Scaling your screenx and screeny by some factor will get you your
                  field-of-view. Sorry to be vague here, but it's been decades since I
                  worked out this distortion, and I don't want to get into more detail,
                  because...

                  You really don't want to do this!

                  You won't be saving time or render speed. This technique works fine for
                  wireframes (sometimes), but it won't work well for textures or polygons
                  unless you subdivide them highly. Plus, you need to tessellate based on
                  distance, and good luck with that.

                  Rendering large frames and distorting them works fine, and it's compatible
                  with everything else you can get your GPU to do. We do it in real-time all
                  the time. You saw me doing it at DomeFest at 60 fps. (Sure, it was running
                  in parallel, but whatever). Just render your frames large, distort, and
                  join them. It looks great! Here's an example from a few years ago:

                  http://spontaneousfantasia.com/DomePortraits/slides/JWalt_Dome_021.html


                  nada_cloo wrote:
                  Thanks to all who replied.

                  While the answers and suggestions were helpful, they're not quite what I'm looking for. I just need the core of the vertex shader that shifts the vertices around as needed to create the illusion of a fisheye lens.

                  - I'm aware of the need for tessellation to prevent straight lines from remaining straight.

                  - Screen-space solutions won't work. Warped pixels are icky.

                  - Cube rendering slightly better, but it's still a radical brute force solution that doesn't produce the quality I'm looking for. I may have to go there someday, but I'm hoping to avoid super-mega-sampled rendering of the scene five times for each frame.

                  Really I just want a function that, given an original vertex location, an eye position, and an eye direction vector, will return a new vertex location. Actually, my ideal generalized solution would be an algorithm that maps vertices onto an arbitrary 3D grid surface (for example, a hemisphere). (Not all domes are perfect hemispheres, y'know.)

                  This function is the final stage in a series of functions that nudge vertices around according to a variety of rules. Some are just surface tweaks (bumps), but this one's the biggie.

                  Thanks,

                  Ken Scott
                • Robert Spearman
                  This fisheye vertex shader from the real time simulator Nightshade 12 might be an example of what you are looking for:
                  Message 8 of 13 , Oct 5, 2012
                  • 0 Attachment
                    This fisheye vertex shader from the real time simulator Nightshade 12
                    might be an example of what you are looking for:

                    http://bazaar.launchpad.net/~nightshade-dev/nightshade12/ns12-main/view/head:/src/GLSL/transform.vert.glsl

                    [Or http://tinyurl.com/8kxgwg9 --Moderator]

                    Main site: http://NightshadeSoftware.org (new site launching next week)

                    Rob

                    --
                    Digitalis Education Solutions, Inc. 360.616-8915
                    817 Pacific Ave fax 360.616.8917
                    Bremerton, WA 98337 http://digitaliseducation.com
                  • nada_cloo
                    Thank you, J-Walt! Thank you, Peter! Thank you, Rob! Three excellent answers. So, J-Walt, you re saying I should render five sides of a cube and then map the
                    Message 9 of 13 , Oct 5, 2012
                    • 0 Attachment
                      Thank you, J-Walt! Thank you, Peter! Thank you, Rob!

                      Three excellent answers.

                      So, J-Walt, you're saying I should render five sides of a cube and then map the pixels to the final warped image? I do get your point about variable tessellation based upon distance. I saw that one coming, and knew it wouldn't be pretty. I already have dumb brute-force code to deal with it (fortunately, not in too many places).

                      And Rob! That is EXACTLY the code I was seeking. I've tried that method before (from Bourke?), but it didn't work right away so I set it aside. I will pick it back up now that I've received your confirmation that it does work.

                      Long-term, however, I clearly need to shift to J-Walt's method.

                      Regards,

                      Ken Scott
                    • nada_cloo
                      Rob - The shader you sent me is The One - at least for now. I plugged it in, it didn t work, and then I realized I had OpenGL doing a perspective projection.
                      Message 10 of 13 , Oct 5, 2012
                      • 0 Attachment
                        Rob -

                        The shader you sent me is The One - at least for now.

                        I plugged it in, it didn't work, and then I realized I had OpenGL doing a perspective projection. That was effectively double-transforming each vertex.

                        Switch to 'glOrtho(-1, 1, -1, 1, 1, 1000000)' and voila!

                        Thanks, all.

                        I will eventually be faced with the need to do the cube mapping method, but this will be fine for now.

                        Ken
                      • pauldavidbourke
                        ... Remembering of course that 5 faces is a waste, you only need 4. Consider the camera pointing towards an edge of the cube rather than the centre of a face.
                        Message 11 of 13 , Oct 6, 2012
                        • 0 Attachment
                          > So, J-Walt, you're saying I should render five sides of a cube and then map the pixels to the final warped image?

                          Remembering of course that 5 faces is a waste, you only need 4.
                          Consider the camera pointing towards an edge of the cube rather than the centre of a face.
                        • Ken Scott @ Digital Chaotics
                          Ahh! Good point. Thanks, Paul. ... Remembering of course that 5 faces is a waste, you only need 4. Consider the camera pointing towards an edge of the cube
                          Message 12 of 13 , Oct 8, 2012
                          • 0 Attachment
                            Ahh! Good point. Thanks, Paul.


                            On 10/6/2012 5:17 AM, pauldavidbourke wrote:

                            > So, J-Walt, you're saying I should render five sides of a cube and then map the pixels to the final warped image?

                            Remembering of course that 5 faces is a waste, you only need 4. Consider the camera pointing towards an edge of the cube rather than the centre of a face.

                            --
                            Ken Scott (VJ Chaotic)
                            Founder and CEO of Digital Chaotics
                            http://www.DigitalChaotics.com
                          • Robert Spearman
                            Ken, glad the GLSL code example helped. The development team originally started down the (partial) cube map route and found it completely unworkable for
                            Message 13 of 13 , Oct 9, 2012
                            • 0 Attachment
                              Ken, glad the GLSL code example helped.

                              The development team originally started down the (partial) cube map
                              route and found it completely unworkable for Nightshade 12. Either
                              approach can work but there are trade offs to each. Which one works
                              best will depend entirely on your particular situation.

                              Rob

                              --
                              Digitalis Education Solutions, Inc. 360.616.8915
                              817 Pacific Ave fax 360.616.8917
                              Bremerton, WA 98337 http://digitaliseducation.com
                            Your message has been successfully submitted and would be delivered to recipients shortly.