Extending Functionality of Shader Programs

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Extending Functionality of Shader Programs

ElvJOGL
Hi everyone, specially to @Elect who responded to my first jogamp forum post.

I am a college student. A professor at my school has asked me to help her on her research. Her work entails investigating the area of the boundary of polygon geometry when subject to subtraction. For instance taking the subtracting the geometrical region of a polygon by the same shape polygon only toned down in scale. Like subtracting a small triangle out of a larger triangle. The professor's interests is to investigate the relation between the region the is left inside the larger polygon, because that translates into a variable which might link to Ehrhart's Polynomial coefficients. I am not saying in fact that Ehrhart's Polynomial coefficients are involved, but they might, only if I knew the entire work of what my professor is working.

However, my role into this as a program is to write a program that can visually represent all these geometrical shapes to make it possible to do count the number of pixels that are in the polygonal region.

Anyways, the problem that I ran into in java is that Heap memory is too small, even in 64Bit java version. The problem here is that storing that many pixels into an array is somehow IMPOSSIBLE, because the number of pixels that one derives out of the H Fold Sum Set Algorithm that I am working on outputs a number of an integer number like 49 digits long. You for a fact that the number is huge, it will take virtual about 32GygaBytes or more to store that many vectors in a file. I have tried it, but because the look is so slow as the number of vectors (vertices) approach 1 billion pixels, it just to overwhelming.

Anyhow, I was just looking into OpenGL technology (I mean programming) and I am wondering whether one can write multiple shader programs with hard coded vectors to draw the geometry that I am looking?

Anyone is particularly capable or understand GLSL Shader programming, do you think this type of work is possible with JOGL Shader? I prefer JOGL Java because I have been working with java for quite some time and the research opportunity that my professor has offered me is something that I have not expect and it is putting me to the test.

Any help will be greatly appreciated.

If you guys need more explanation about lattice points geometry, let me know.

I will definitely come around this forum to share my questions in how to solve this Tabaco.

thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
Hey ElvJOGL,

let me first give you some links

JCSG is a java program about constructive solid geometry, it may be interesting for you.

Now, to represent all these geometrical shapes you can use jogl, if you have the geometric data, you load them on the gpu and you render them.

Counting the number of pixels is another story. You should take in account that those pixels are just a representation that we see after we loaded the geometry on the graphic card, set up a couple of matrices and the gpu rasterizer has done its job. And the pixels we see represent the outmost geometry.

So it is not really clear to me what you mean by counting the number of pixels.

Do you mean maybe about representing the geometry in small units, such as small cubes, and then counting them?

Anyway, modern OpenGL offers huge potential, you can load your data on the gpu and then perform any algorithm you want with compute shaders (that has nothing to do with rendering at all) and then render the geometry you created/modified
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
This post was updated on .
This is what I mean about counting the pixels inside a polygon.

In mathematics there is a person that created a theorem, his name is Pick and his theorem is called Pick's Theorem.

A = i + b/2 - 1

if you go by the equation above, counting the number of pixels that make up the boundary in this case variable {b} in the equation, and then counting the number of pixels in the interior in this case variable {i} in this equation, then as you apply the equation you will get the exact Area of a Triangle. Pick's Theorem applies to triangles because triangles are the most simple polygon there is.

You can prove this in a graphing paper, you draw a triangle and trace the points that are in the boundary and inside the interior then you apply that equation and you get the exact Area of the triangle. This does not work in plain blank paper. It has to be on graphing paper because when you drawing something in graphing paper like a triangle, then you are drawing it to exact scale.

Now that I have said much about that, lets go into what is called Higher Dimensions of the Pick's Theorem.

If instead of a triangle you have a Quad (such as a rectangle), then you looking not at a polygon to which you can apply Pick's Theorem, but you looking at a Polynomial, in which case you have apply Ehrhart's Polynomial to get the Area.

That is why it is important for me to count the pixels inside the polygons, because with that information, I can deduce whether 1). I might be doing Pick's Theorem correctly, and 2). whether I can also calculate Ehrhart's Polynomial out of whatever polygon you throw at the program. (That also includes geometry subtraction, which I will do at some point later once I get a good example working.)

You all your life you have gone thinking that the only way you get the area of triangle is by calculating the height and the base length and divide by 2. That seams reasonable. So you might think that both Pick's Theorem and the way they teach you in school how to find the area of a triangle should yield the same result. It all depends, in whether both equations are referring to the same scaled up triangle. (That is why I said, not to draw the triangle in the a plain blank paper, because that will not be accurate.)


Now to re-reference the question that I asked in this post: http://forum.jogamp.org/I-am-New-To-GLSL-C-OpenGL-Shader-program-tp4036135.html

Well you didn't quite answer my question when I asked it.

So I will ask again here if you get to see @elect.

Ok, does the Shader program bellow if you were to implemented in JOGL, will it change syntax? Or the Shader language in C or in JOGL are the same syntax?

//-------------------------------------------------------------------- //
#version 430 core

//"offset" is an input vertex attribute
layout (location = 0) in vec4 offset;

void main(void){
         const vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),
                             vec4(-0.25, -0.25, 0.5, 1.0),
                             vec4( 0.25, 0.25, 0.5, 1.0));

         //add "offset" to our hard-coded vertex position
         gl_Position = vertices[gl_VertexID] + offset;
}

//--------------------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
Ok, I got it by looking at the wiki sample

So, it seems you really need to count the pixels inside, I can already tell you this should be a pretty easy task.

What can be hard, instead, is calculating the boundary points.. since this involves some trick and approximations errors can play a big role here..

Anyway, to come back to the interior points calculation, what you can do is:

- clearing with a blank color
- find a way to understand if you are inside the geometry, you can do that by playing with depth values. You can achieve that by doing something similar to the depth peeling algorithm. I don't have clear in mind right now the steps you have to do, but it should be pretty feasible
- run a compute shader that for each pixel matching your geometry color (or != blank color) will increase an atomic counter
- retrieving all the counters (one for slice) and then sum up

Speaking about bottlenecks:

- atomic counter can only be unsigned int, so you have 2^32
- max texture size is 16k on recent hw, so you should have up to 2^14 * 2^14 = 2^28 bytes/pixels

About the shader syntax, sorry, I forgot to answer you on that part, it is exactly the same, except a little bug about including additional shaders with double quotes

this in C

#include "light.glsl"

must be written in jogl as

#include light.glsl

For the rest everything the same, the compiler is the same, so..
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
Wow you seem very much interested in my project.

Thank you for all the opinions you have provide.

Another question is: is possible to write a shaders by fragments. Because as you know, as the geometry lets say from my professor terms, H Fold 100, and because for a 3 vertices polygon such as a triangle produces 3^100 a integer number of 48 to 49 digits long, that is the number of vertices that she wants to work with.

For instance, in java I am able to do this project, but only for a small H Fold (I will explain what the H Fold algorithm that we have is all about and how it produces the pixels that lie inside the polygon).

And because I can only do it for a small H Fold like (10), once I push the program (java) to compute something larger then H Fold 10, there is a memory barrier. So my other professor who is not involved in this project, but who is the chair of the Math and Comp Science department said, that this project is virtually impossible. So they both are not giving me much hope. However, I have been asked to solve this issue. As the Chair said, you don't need computer programming skill to solve the issue, you need mathematical skill to produce mathematical shortcut to solve the issue.

That's one of my problems.

I have a vague Idea, but I don't know whether it will work. (I don't want to discuss it until I come up with a working example of the program that I need to build.

Now to explain to you what the H Fold is all about.

The H Fold is an algorithm (in mathematics) which takes the 3 vertices of a triangle and adds them to each other, which produces are larger triangle. For example you have vertices of the initial triangle such as {{-1,1}, {-1, -1}, {1, 1}}.

So this is how the algorithm goes: You take {-1, 1} which is the first vertex and added {-1, 1}, {-1, -1}, {1, 1}, which produces {-2, 2}, {-2, 0}, {0, 2}, then the following set is from vertex {-1, -1}, which are {-2, 0}, {-2, -2}, {0, 0}, and the last set follows as {0, 2}, {0, 0}, {2, 2}.

So what is call the Sum Set you have {{{-2, 2}, {-2, 0}, {0, 2}}, {{-2, 0}, {-2, -2}, {0, 0}}, {{0, 2}, {0, 0}, {2, 2}}}

That is a sum set.

Now the H Fold Sum Set is just the loop which will repeat the same process now to the 9 vertices triangle that you ended up with, which will produce a sum set of vertices of 27, then 81, and so on. This because it is a triangle starting with 3 vertices all the expansions of the sum set are multiples of 3, that is why when you produce an H Fold Sum Set of 100, you are actually calculating a number of vertices of 3 to the power of 100.

I hope this interest you much.

The problem itself is not complicated since I already did it in Java for a small H Fold. But my professor who is doing the research on this has asked me to do it for H Fold 100 and above, which is a huge mathematical problem all over the world as she says, that has not been solved.

Now why would a professor asked a simple student to try to handle a problem that requires super computers, I have no idea. But I like the idea that she personally asked me to help her, so I am trying my best to learn what ever it takes to solve this issue.

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

gouessej
Administrator
There is an example of depth peeling in jogl-demos provided by the maintainer of Jzy3d.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
I have a question:

When rendering geometry (I mean polygon geometry dealing with vertices) I have noticed that in all JOGL examples I have come across, when you resize the viewport frame (the window showing the canvas), the shape itself resizes.

Is there a way to avoid this, when rendering large scenes, and you want everything to remain at the scale size that you programmed them to be?

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
In reply to this post by ElvJOGL
ElvJOGL wrote
Wow you seem very much interested in my project.
It's a non-conventional request and it is particularly stimulating :p

ElvJOGL wrote
is possible to write a shaders by fragments
What do you mean? Can you elaborate?

Anyway, let me get one thing.. you said you got problem with H Fold > 10, if we take 11, this mean 3^11 = 177'147, if you store it in integers (4 bytes) you end up with a rough amount of 708'588 Bytes, this is not at all a barrier, so I guess I lost some piece..

Moreover, I'd like to know what your prof wants to achieve.. does she want the final Sum Set of H Fold 100?


glWindow.setResizable(false); should avoid any resize, although I can still go fullscreen.. maybe gouessej can help you better on this
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
Ok,

Let me give you an example of what 3 to the power of 100 is, this number is exactly this:

3^100 = 515377520732011331036461129765621272702107522001

Well you know there is no possible storage with a programming language that can hold that many vertices in an array.

So my professor wants to produce polygons using the H Fold Algorithm that explained in the previous post.

As is, this is not feasible in Java, I need mathematical shortcuts (which I don't know).

100 is just an example, my professor's goal is to ultimately represent larger geometry of H Fold greater than 100. What the relation of that is, I don't know but she wants me to write the program that is able to produce these geometrical phenomenon.

To begin with, these examples are on in 2D (dimensions). Once I am done with 2D, I will have the ground work to start a framework for 3D.

That's where this whole Tabaco gets extremely more complicated.

Let me know if you want me to share the Ehrhart's polynomial documentation that my professor has provided to me.

Maybe you can help me understand it.

Because the equations of ehrhart's polynomial have a more feasible when to break the computation problem if we know how to solve the Ehrhart's polynomial equation.

Let me know if you want the pdf, so I can link it for you @elect?
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
I don't feel myself really in the mood to dig papers particularly complex by a mathematical point of view right now if I have to be honest ^^


Anyway, let's take the example you gave me before, what does she want is something like that?



She wants you to be able to draw the outmost polygon for H Fold x?
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
You probably did something wrong with adding the points to each other, and one should use Integer points, not floating points.

I should've have mentioned that you needed to use integer points.

now I am at school. And I don't have a scanner readily available that I could use, so when I get home tonight, I will post an image of an example of what I mean (or what my professor means).

Your example is be out of place, but if you were to count the dots that are on the boundary (on the lines that connect of the polygon) then you count the dots inside of the region that are not in the same coordinates of the dots that are in the boundary, and you apply this equation : A = B + I/2 - 1, gives you the exact Area.

I will show it with a bit more complicated geometry than a triangle so that you can see how the next polygon looks like derived out of the previous polygon. Because in your example, your triangle looks a bit out of place.

But yes, that's what my professor wants to do.

The idea is, that when you do the H Fold algorithm properly you end up with a blown up image of the previous one (and by blown up, I am scaled up image).

So in your example you didn't really follow the right idea because your connected lines don't form a triangle bigger than the previous one, it forms some odd Quad shape, in which case you would use Ehrhart's Polynomial to solve the area not pick's theorem.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
I draw first the triangle {-1, 1}, {-1, -1}, {1, 1}

then:
- {-2, 2}, {-2, 0}, {0, 2}
- {-2, 0}, {-2, -2}, {0, 0}
- {0, 2}, {0, 0}, {2, 2}

and finally I underlined the outmost shape

look the image at the center, not the one at the bottom
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
Ah ok.

Well, when I run my java program it shows a triangle that is around the previous one.

Instead of doing it by hand, I will run my java version and show you how it looks like.

It will be much simpler.

But be wear that this java version cannot handle H Fold larger than 10 or 15, either one. But I know it just runs out of memory.

I will show you a screen shut of it.

Another thing that I didn't mention is that once I have a running example, I will need to make it so that one can Zoom In and Zoom Out Without affecting the pixel size, but at the same time separating the pixels from each other to sort of look closer into the image.

I can do it in my java program so instead of a showing you an image, I will post a video. (If in the case that this website does not allow posting videos, then I will use some other means to post a link to the video. I can probably uploaded to my Youtube.com account and you can see it there.)

Just bear in mind, that program might seem a bit mundane for the fact that I didn't improve on it because I had to stop working on it because of the memory problem. Since I got disappointed on that, I figure, I need to upgrade my program by learning or using some other means, like learning OpenGL (JOGL). And the reason I seem very much confused as to where to start is because I just started learning. It like since last week. I should've learned OpenGL a long time ago, but I was in the military. Now I am a veteran just trying to finish school, but along the line a professor has given me this problem to solve so I can help her on her research studies.

thanks
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
This post was updated on .
With Not Much further a due, here is the example I promised you @elect

I hope you don't mind the quarky [sound] of my voice.

But I tried to explain what is it that I am trying to do, and what I am trying to achieve in JOGL.

Sorry for the delay, but making the [video] and editing (compressing it) to a manageable size took some time.

I hope you can understand my example.

here is the YouTube.com video: https://youtu.be/24Ckwu7H4OU

There is a slight problem with the youtube video.  The video quality when you upload to youtube does not show the BLUE colors...and that's is why if you run the video in regular mode, you will not see them.

In other words, just run the video in FULL SCREEN MODE....so you can see the other triangle and so the blue dots.


Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
Thanks, the voice is totally fine, really understandable, only the volume is crap (also the blue color, even in fullscreen it's hard to see), I had to max it out and it is still barely enough, but I guess making video is not that easy, so don't mind ;)

Don't worry about the delay, I can image it takes its time


Anyway, one thing I don't get

if we start by:

(5, 5), (10, 5), (10, 10)

we end up with 3 new triangles

(10, 10), (15, 10), (15, 15)     (15, 10), (20, 10), (20, 15)   (15, 15), (20, 15), (20, 20)

and if you draw them, an empty space, big as the original triangle (just inverted on the hypotenuse), will be at the center of the new shape, that is (15,10), (20, 15), (15, 15)

Your program instead doesn not render that empty space..

Moreover, its area, using the old-school way, should be 5 * 5 / 2=12.5 you get 15 + 6 / 2 - 1 = 17 instead.. how do you explain this discrepancy?
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
elect wrote
Thanks, the voice is totally fine, really understandable, only the volume is crap (also the blue color, even in fullscreen it's hard to see), I had to max it out and it is still barely enough, but I guess making video is not that easy, so don't mind ;)

Don't worry about the delay, I can image it takes its time


Anyway, one thing I don't get

if we start by:

(5, 5), (10, 5), (10, 10)

we end up with 3 new triangles

(10, 10), (15, 10), (15, 15)     (15, 10), (20, 10), (20, 15)   (15, 15), (20, 15), (20, 20)

and if you draw them, an empty space, big as the original triangle (just inverted on the hypotenuse), will be at the center of the new shape, that is (15,10), (20, 15), (15, 15)

Your program instead doesn not render that empty space..

Moreover, its area, using the old-school way, should be 5 * 5 / 2=12.5 you get 15 + 6 / 2 - 1 = 17 instead.. how do you explain this discrepancy?
To answer your question by parts I will say this.

1). when you do the points {5, 5}, {10, 5}, {10, 10}, you are still missing what's inside the region, that is something I fill in using a barycentric interpolation equation I get from Real Time Collision textbook my video game programming professor referred to me. So you don't get tree triangles, what you are seeing is a permutation of points that lie at each end of the corners or the vertices, and the points that lie inside of the triangle. You right, logically they should look like 3 triangles, but infact they are not, is just the scale more of the next polygon.

2) you asked explain the discrepancy from 5 * 5 / 2 = 12.5 and [I] get 15 + 6/2 - 1 = 17 instead. All I can say is that both equations are correct. However when you take your equation (which I will refer to the equation they teach in preschool and highschool the area of the triangle) and the difference between Pickt's Theorem equation is that Your Equation deals with NOT TO SCALE triangle drawings. And pick's Theorem deals with TO SCALE Triangle models. That is hard to grasp at first, but my math professor who assigned this task to me said it to me at of times, that both equations are correct, but both are not referring to same scale or the same size of the model. (And by model I mean the polygon such as the triangle).

But tell me do you understand the basic idea of where I am trying to get to.

I figure that Shader technology can help me with and I was hope I can get some insight.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
Ok

Yep, you can definitely subtract 2d geometry, don't worry about that
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
I will continue reading opengl literature until I can grasp a valid idea put to work.

Once I do that, I will post the example here to get some opinions.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

elect
ElvJOGL wrote
I will continue reading opengl literature until I can grasp a valid idea put to work.

Once I do that, I will post the example here to get some opinions.

Thanks.
You'r welcome, in the meanwhile, which graphic card/OpenGL version do you have access to?
Reply | Threaded
Open this post in threaded view
|

Re: Extending Functionality of Shader Programs

ElvJOGL
I got myself a hold of a Titan Z 12GBs NVIDIA gpu with my Alienware Aurora R4 desktop (that was when it first came out, dell alienware no longer sells Aurora desktops, but now with the new Titan X alienware has a triple GPU setup which is a monster of a video card system, and all Titan X NVidia cards have 12GBs of GPU RAM that makes it 36GBs of GPU RAM that you can have in your alienware Area 51 Desktop, I think it is Area 51, but you won't miss it, the design looks like a diamond out of Area 51, kind of cool).

On my laptop runs a NVIDIA GTX 960M (integrated) 4GBs gpu.

The jogl version that I have available right now is GL4 or I think the latest that jogamp has released.

Anyhow, yeah that's my setup.

Thanks.
12