Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: glDrawElements - Tetrahedron

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    7

    glDrawElements - Tetrahedron

    Hello!
    We have functionality to draw points (1 vertex), lines (2 vertices), triangles (3 vertices).
    Why don't we have a possibility to draw tetrahedron (4 vertices)?

    4 vertices can be projected to screen as usual. And then in the zone inside of them (in screen space) the device can check if _the existing values in depth buffer_ are located inside tetrahedron (in 3D). If they are inside -> the fragment shader will run. With interpolated values from tetrahedron vertices (volume interpolation).

    This will add possibility to approximate 3D functions with vertices (not in regular grid). Now we have 3D textures for that.

    For example, we can create volumetric light sources and dimming sources, which interact with existing geometry via depth buffer. We can take a mesh and create extruded faces using normals, this crust can be filled with tetrahedrons (base mesh and extruded mesh). Then some values can be interpolated based on distance from the surface of the mesh (light intensity for example).

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264

    Re: glDrawElements - Tetrahedron

    It sounds like you are asking for a special case to be implemented in hardware : if the depth value from the depth buffer is inside the tetrahedron, then run the fragment shader. If it is not inside, then don't run the fragment shader.

    Therefore, the GPU needs to evaluate 2 points on the tetrahedron and then compare if the value from the depth buffer is inside.

    Also, why is this suggestion limited to a terahedron? Light volumes aren't always tetrahedrons : I have used cylinders.

    Your suggestion doesn't fit with the rest of the graphics pipeline and it is limited to a tetrahedron.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    7

    Re: glDrawElements - Tetrahedron

    Yes, the depth test for volumetric object can be INSIDE, not only LESS or GREATER. Or even OUTSIDE, if it is needed.

    You can create any shape with tetrahedrons by putting them together just like the surface is formed with triangles. Tetrahedron is a simplex which supports interpolation with barycentric coordinates just like triangle.
    I'm just moving to the next dimension and not taking shapes like cylinder.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: glDrawElements - Tetrahedron

    Why don't we have a possibility to draw tetrahedron (4 vertices)?
    We use triangles because they're fast to rasterize. They are fast to rasterize because they're flat objects. They're guaranteed planar, and they require nothing more than 4D homogenous math and well-known rasterization algorithms.

    Rasterizing a tetrahedron requires a lot more work.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    7

    Re: glDrawElements - Tetrahedron

    I don't think that it requires a lot of work as it is a convex shape. It's just a rasterization of back and front sides at the same time and getting depths.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jan 2011
    Location
    Paris, France
    Posts
    248
    The idea seem fine


    I see another problem about the selection of the back and front sides, since a tetrahedron has 4 faces, not only one as triangles or planar quads

    But this can perhaps to be handled via the use of two temporally depth buffers that can store the back sides on the first depth buffer and the front sides on the second depth buffer ?
    (and at a second pass, we can use the content of the "back sides" and "front sides" depth buffers for to see if the current voxel is inside or outside this volume)

    Note that this can too add anothers volumetric effects such as things like clouds and smoke or a fast emulation of semi-transparents glass windows between the eye and drawed objects for example (but without reflexions and refractions effects of course)

    Something, this can to be see such as something more or less near to the inverse of dual paraboloid maps, no ?
    Last edited by The Little Body; 04-25-2012 at 04:40 PM.
    @+
    Yannoo

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    Why you don't do that already?

    You could use a geometry shader to generate the tetrahedron slices and output gl_Layer so that your fragment shader outputs go to the appropriate slice of the 3D texture.

    This may not be exactly what you want to do as I didn't 100% understand your original request but I'm pretty sure you can achieve what you want using the existing toolset. The only question may be performance.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    7
    Quote Originally Posted by aqnuep View Post
    Why you don't do that already?

    You could use a geometry shader to generate the tetrahedron slices and output gl_Layer so that your fragment shader outputs go to the appropriate slice of the 3D texture.

    This may not be exactly what you want to do as I didn't 100% understand your original request but I'm pretty sure you can achieve what you want using the existing toolset. The only question may be performance.
    No, I'm not talking about rendering to 3D texture.
    My idea is more similar to rendering lights in deferred shading.
    When the scene is drawn we have a depth buffer to work with.
    So for each pixel we have a 3d position. We can do lookup in 3d texture, which stores some value distributed in volume.
    Or we can lookup in a mesh of tetrahedrons -> far more efficient approach without a regular grid of 3d texture.

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    7
    For example the point light can be done like this: we take a polygonal sphere and fill it with tetrahedrons - all sharing the vertex in the center of the sphere. Other 3 vertices of tetrahedrons are faces of the sphere. The center vertex can have color value 1 and surface vertices can have value 0. So when we render this mesh of tetrahedrons existing depth buffer will get interpolated value based on position from center to surface.
    But we can model any light source shape this way.
    Of course the traditional way of doing point light in DS (by passing center position and drawing sphere triangles) is better.

    We can also render a transparent mesh which gets opaque in the middle (made of colored glass, liquid, etc.). We must get the distance between front side and back side of tetrahedrons. Or front side and depth buffer - if depth value is inside tetrahedron. We get the density based on this distance and determine the color.

    There are lots of things we can do

  10. #10
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Quote Originally Posted by MakKlaski View Post
    Of course the traditional way of doing point light in DS (by passing center position and drawing sphere triangles) is better.
    Then shouldn't your suggestion actually be "glDrawElements should support GL_SPHERE"?

    Anyway, the depth test stage is designed to test the depth value of an incoming fragment with the depth value of the depth buffer.
    In your case, you want it to have 2 fragments from different faces of your tetrahedron to be the incoming fragments. How exactly is that suppose to happen?
    Imagine this, you have a fragment from face 1 with position XYZ.
    Which fragment is behind that face? Which face is behind that face? Is there even a face behind that face?
    Is it face 2 or face 3 or face 4?
    The GPU would have to go into a series of calculations to figure out what that second fragment is. It would actually need access to the primitive assembly stage information.

    And the final question. Is that going to be faster than a 2 pass approach?
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •