Commit 82f1e07f authored by Sabrina Templeton's avatar Sabrina Templeton
Browse files

works up to 1e5 points, still problem with more than that

parent c98a6e14
......@@ -7,6 +7,8 @@ layout( location = 0 ) out vec4 fragColor;
in vec3 v_Position;
in vec3 v_Normal;
in vec3 v_Parameter;
flat in int v_Index;
const int ncolor = 256;
uniform float u_umin;
......@@ -44,7 +46,7 @@ void main() {
vec3 color = vec3(.8, .8, .8);//vec3(0.8,0.8,0.2);
int idx = gl_PrimitiveID;
int idx = v_Index;//gl_PrimitiveID;
float f = idx;
......
......@@ -39,6 +39,11 @@ const int MAX_VERTS = 30;
// out vec3 v_Position;
// out vec3 v_Normal;
// out vec3 v_Parameter;
flat in int[] instance_ID;
flat out int v_Index; //this might not need to be flat but doesnt seem to work otherwise
//out vec3 v_Ind;
layout (triangle_strip, max_vertices = 100) out; // this was 40, upped it for debugging purposes
......@@ -68,7 +73,7 @@ void render_poly(vec3[MAX_VERTS] poly, vec3 center, int space){
EmitVertex();
gl_Position = u_ModelViewProjectionMatrix*vec4(center, 1.0);
gl_PrimitiveID = gl_PrimitiveIDIn;
gl_PrimitiveID = instance_ID[0];
EmitVertex();
EndPrimitive();
......@@ -97,7 +102,7 @@ void render_square(vec3 pt, float size) {
//EmitVertex();
gl_PrimitiveID = gl_PrimitiveIDIn;
gl_PrimitiveID = instance_ID[0];
EmitVertex();
EndPrimitive();
......@@ -113,7 +118,7 @@ void render_square(vec3 pt, float size) {
gl_Position = u_ModelViewProjectionMatrix*vec4(br, 1.0);
//EmitVertex();
gl_PrimitiveID = gl_PrimitiveIDIn;
gl_PrimitiveID = instance_ID[0];
EmitVertex();
EndPrimitive();
......@@ -245,10 +250,13 @@ void calc_poly(vec3 zi, vec3 zj, inout vec3[MAX_VERTS] curr_poly, inout int cspa
void
main() {
// lookup the seed points, taking in glPrimitiveIDIn
vec3 p0 = vec3(texelFetch( seeds , gl_PrimitiveIDIn ).xy, 0);
int site_idx = instance_ID[0];
v_Index = instance_ID[0];
//v_Ind = vec3(instance_ID[0], instance_ID[0], instance_ID[0])
vec3 p0 = vec3(texelFetch( seeds , site_idx ).xy, 0);
//vec3 p1 = vec3(texelFetch( seeds , 0 ).xy, 0);
//if (gl_PrimitiveIDIn == 0){ // this is for debugging purposes: REMOVE ONCE WE WANT TO EXPAND TO ACTUALLY COMPUTE FOR MORE THAN ONE SEED
//if (site_idx == 0){ // this is for debugging purposes: REMOVE ONCE WE WANT TO EXPAND TO ACTUALLY COMPUTE FOR MORE THAN ONE SEED
// but also when we do that we will need to fix the nearest neighbors which right now are hardcoded in
//this is the initial poly
vec3 curr_poly1 = vec3(0, 0, 0);
......@@ -309,10 +317,10 @@ main() {
for (int i = 1; i < u_nb_neighbors; i ++){
//works when i < 2 but not otherwise
//vec3 nn0 = vec3(texelFetch( seeds, i).xy, 0);
int nn0 = int(texelFetch( nn, i + (gl_PrimitiveIDIn * u_nb_neighbors)).x); // i + (gl_PrimitiveIDIn * 7)
int nn0 = int(texelFetch( nn, i + (site_idx * u_nb_neighbors)).x); // i + (site_idx * 7)
//int nn0 = neighbor_hardcoded[i + (gl_PrimitiveIDIn * 7)];//int(texelFetch( nn, i + (gl_PrimitiveIDIn * 7)).x); // i + (gl_PrimitiveIDIn * 7) // remember that this is just the index, we have to use this to lookup in seeds
//int nn0 = neighbor_hardcoded[i + (site_idx * 7)];//int(texelFetch( nn, i + (site_idx * 7)).x); // i + (site_idx * 7) // remember that this is just the index, we have to use this to lookup in seeds
vec3 nearest_neighbor = vec3(texelFetch( seeds, nn0).xy, 0);
float d1 = d;
d = distance(nearest_neighbor, p0);
......@@ -338,7 +346,7 @@ main() {
}
}
//render_square(furthest_pt, .02);
// if (gl_PrimitiveIDIn == 0){
// if (site_idx == 0){
// render_square(furthest_pt, i * .001);
// }
......@@ -351,7 +359,7 @@ main() {
break;
}
}
//if (gl_PrimitiveIDIn == 0) {
//if (site_idx == 0) {
render_poly(curr_poly, p0, space);
//}
......
......@@ -2,12 +2,13 @@
// e.g. #version 410 or #version 330
#version 410
// this code taken from example of tetrahedron/volume toy by Philip
flat out int instance_ID;
layout (location = 0 ) in vec3 a_Position;
// nothing is done here because the geometry shader produces and processes the actual vertices
// but we still need to set gl_Position
void main() {
gl_Position = vec4(0.0,0.0,0.0,0.0);
instance_ID = gl_VertexID;
}
......@@ -18,6 +18,8 @@
#include <geogram/nn_search.h>
#include <time.h>
using namespace avro;
UT_TEST_SUITE( voronoi_toy )
......@@ -77,7 +79,7 @@ UT_TEST_CASE( test1 )
GL_CALL( glBindVertexArray(vertex_array) );
//generate random seeds desired times 3
int num_points = 100000.;
int num_points = 2e5;
int size = num_points*3;
......@@ -129,6 +131,9 @@ UT_TEST_CASE( test1 )
std::vector<real_t> seeds_d( seeds.begin() , seeds.end() ); //convert the seeds to double
//compute the nearest neighbors here
// start the nearest neighbor timer around here,
clock_t TIME0 = clock();
GEO::NearestNeighborSearch* nns = GEO::NearestNeighborSearch::create(3,"BNN"); // number of dimensions is really 2, but we have been using three
// index_t nb_points = 7;
......@@ -149,7 +154,6 @@ UT_TEST_CASE( test1 )
std::vector<index_t> total_neighbors(nb_neighbors * num_points); // i don't know if this is the correct number if, for example, nb points and nb neighbors are not the same (which they usually will not be)
std::vector<double> neighbors_sq_dist(nb_neighbors);
index_t i = 0;
for (index_t k=0;k<num_points;k++)
......@@ -172,6 +176,8 @@ UT_TEST_CASE( test1 )
}
}
clock_t TIME1 = clock();
printf("--> nearest neighbor calculation time = %g seconds\n",real_t(TIME1-TIME0)/real_t(CLOCKS_PER_SEC));
// std::vector<graphics::gl_float> seeds = {
......@@ -265,9 +271,8 @@ UT_TEST_CASE( test1 )
glfwSetCursorPos(window, width/2, height/2);
glDisable(GL_DEPTH_TEST);
while (true) {
shader.use();
// grey-ish (almost white) background color
......@@ -298,18 +303,42 @@ UT_TEST_CASE( test1 )
glUniform1i(nn_location, 2);
// draw
clock_t TIME2 = clock();
GL_CALL( glBindBuffer(GL_ARRAY_BUFFER, points_buffer ) ); // it doesn't really matter which buffer we bind here since it isn't used
int points_remaining = num_points;
int first_point_to_draw = 0;
while (points_remaining > 0){
std::cout << "one iteration" << std::endl;
std::cout << points_remaining << std::endl;
// std::cout << first_point_to_draw << std::endl;
if (points_remaining < 1e4){
// std::cout << "if statement" << std::endl;
// std::cout << first_point_to_draw << std::endl;
// std::cout << first_point_to_draw + points_remaining << std::endl;
GL_CALL( glDrawArrays(GL_POINTS, first_point_to_draw , points_remaining ) );
points_remaining = 0;
}
else{
//std::cout << "test" << std::endl;
GL_CALL( glDrawArrays(GL_POINTS, first_point_to_draw , 1e4 ) );
points_remaining -= 1e4;
first_point_to_draw += 1e4;
}
}
GL_CALL( glDrawArrays(GL_POINTS, 0 , num_points ) );
clock_t TIME3 = clock();
printf("--> GPU run time = %g seconds\n",real_t(TIME3-TIME2)/real_t(CLOCKS_PER_SEC));
glfwSwapBuffers(window);
while (true) {
// swap buffers and wait for user input
glfwSwapBuffers(window);
//glfwSwapBuffers(window);
glfwPollEvents();
// determine if we should exit the render loop
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment