use triangle fan for top and bottom of pudding model

This commit is contained in:
frank 2021-09-10 15:02:53 -04:00
parent eb391b911a
commit 9271ba9226
5 changed files with 42 additions and 30 deletions

View File

@ -46,7 +46,7 @@
"enabled": true, "enabled": true,
"json-save": true, "json-save": true,
"json-save-directory": "local/scans", "json-save-directory": "local/scans",
"barcode": "", "barcode": "1703543090000",
"capture-device": "/dev/video0" "capture-device": "/dev/video0"
}, },
"api": "api":

2
lib/sb

@ -1 +1 @@
Subproject commit 87b1fa735c5d663052995177c6d2f639eeac713b Subproject commit 1f8de2f5f1b6a83a6c235d65030a709441f3cd37

View File

@ -113,33 +113,39 @@ void Pudding::set_pudding_model(
ring_start_vertex_u += u_step; ring_start_vertex_u += u_step;
} }
} }
pudding_triangle_vertex_count = pudding_vertices.size();
/* process the top and bottom of pudding, filling each face with a triangle fan */ /* process the top and bottom of pudding, filling each face with a triangle fan */
layer_top_ring.clear();
float y = max_y; float y = max_y;
const glm::vec3* face_color = &PUDDING_BROWN; const glm::vec3* face_color = &PUDDING_BROWN;
Box texture_box = Box({0, 0}, {1, 1}); Box texture_box = Box({0, 0}, {1, 1});
for (float radius : {top_radius, base_radius}) for (float radius : {top_radius, base_radius})
{ {
/* first point in a GL_TRIANGLE_FAN is the center */
pudding_vertices.push_back({0, y, 0});
pudding_uv.push_back({0, 0});
layer_top_ring.clear();
sb::points_on_circle(layer_top_ring, ring_vertex_count, radius); sb::points_on_circle(layer_top_ring, ring_vertex_count, radius);
/* loop through points on the face */ /* loop through points on the face */
for (ii = 0; ii < layer_top_ring.size(); ii++) for (ii = 0; ii < layer_top_ring.size(); ii++)
{ {
start_vertex = &layer_top_ring[ii]; start_vertex = &layer_top_ring[ii];
end_vertex = &layer_top_ring[(ii + 1) % layer_top_ring.size()]; /* for GL_TRIANGLE_FAN we just need to add an outer vertex */
/* triangle from the center of the layer_top_ring to the edge */
pudding_vertices.push_back({start_vertex->x, y, start_vertex->y}); pudding_vertices.push_back({start_vertex->x, y, start_vertex->y});
pudding_vertices.push_back({end_vertex->x, y, end_vertex->y});
pudding_vertices.push_back({0, y, 0});
/* map circle points to UV points of the texture */
pudding_uv.push_back(*start_vertex); pudding_uv.push_back(*start_vertex);
pudding_uv.push_back(*end_vertex); /* connect the ring on the last vertex */
pudding_uv.push_back({0, 0}); if (ii == layer_top_ring.size() - 1)
{
end_vertex = &layer_top_ring[(ii + 1) % layer_top_ring.size()];
pudding_vertices.push_back({end_vertex->x, y, end_vertex->y});
pudding_uv.push_back(*end_vertex);
}
} }
/* single color for the entire layer_top_ring */ /* single color for the entire layer_top_ring */
pudding_colors.insert(pudding_colors.end(), 3 * layer_top_ring.size(), *face_color); pudding_colors.insert(pudding_colors.end(), layer_top_ring.size() + 2, *face_color);
y = min_y; y = min_y;
face_color = &PUDDING_YELLOW; face_color = &PUDDING_YELLOW;
} }
pudding_fan_vertex_count = (pudding_vertices.size() - pudding_triangle_vertex_count) / 2;
} }
/* Create GL context via super class and load vertices, UV data, and shaders */ /* Create GL context via super class and load vertices, UV data, and shaders */
@ -756,7 +762,7 @@ void Pudding::update()
/* set blend to modify white part of background, color passed is in HSV format */ /* set blend to modify white part of background, color passed is in HSV format */
GLint blend_min_hsv_location = glGetUniformLocation(flat_program, "blend_min_hsv"); GLint blend_min_hsv_location = glGetUniformLocation(flat_program, "blend_min_hsv");
float hue = std::abs(std::abs(model[0][0]) - 0.5) * 2; float hue = std::abs(std::abs(model[0][0]) - 0.5) * 2;
glUniform3f(blend_min_hsv_location, hue, 0.9, 1); glUniform3f(blend_min_hsv_location, 0, 0, 0);
/* draws rectangle vertices and rectangle texture using UV coords */ /* draws rectangle vertices and rectangle texture using UV coords */
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
/* draw pudding model using MVP shader */ /* draw pudding model using MVP shader */
@ -781,6 +787,7 @@ void Pudding::update()
else else
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4); glEnableVertexAttribArray(4);
GLuint pudding_texture_location = glGetUniformLocation(mvp_program, "pudding_texture"); GLuint pudding_texture_location = glGetUniformLocation(mvp_program, "pudding_texture");
glUniform1i(pudding_texture_location, 0); glUniform1i(pudding_texture_location, 0);
@ -789,7 +796,9 @@ void Pudding::update()
} }
/* draw pudding model */ /* draw pudding model */
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDrawArrays(GL_TRIANGLES, 0, pudding_vertices.size()); glDrawArrays(GL_TRIANGLES, 0, pudding_triangle_vertex_count);
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count, pudding_fan_vertex_count);
glDrawArrays(GL_TRIANGLE_FAN, pudding_triangle_vertex_count + pudding_fan_vertex_count, pudding_fan_vertex_count);
/* regular fill mode enabled for all other drawing */ /* regular fill mode enabled for all other drawing */
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
/* only do more drawing if items are downloaded or camera is enabled */ /* only do more drawing if items are downloaded or camera is enabled */

View File

@ -54,7 +54,7 @@ private:
const glm::vec3 PUDDING_YELLOW = glm::vec3(0.878f, 0.859f, 0.122f); const glm::vec3 PUDDING_YELLOW = glm::vec3(0.878f, 0.859f, 0.122f);
std::string current_barcode, previous_barcode, current_config_barcode, current_camera_barcode; std::string current_barcode, previous_barcode, current_config_barcode, current_camera_barcode;
std::vector<Item> items; std::vector<Item> items;
int current_item_index = 0; int current_item_index = 0, effect_id = Effect::NONE, pudding_triangle_vertex_count = 0, pudding_fan_vertex_count = 0;
cv::VideoCapture capture; cv::VideoCapture capture;
zbar::ImageScanner image_scanner; zbar::ImageScanner image_scanner;
GLuint flat_program, mvp_program, capture_texture_front_buffer_id, capture_texture_back_buffer_id, capture_texture_id, GLuint flat_program, mvp_program, capture_texture_front_buffer_id, capture_texture_back_buffer_id, capture_texture_id,
@ -63,7 +63,6 @@ private:
std::vector<glm::vec3> pudding_vertices, pudding_colors; std::vector<glm::vec3> pudding_vertices, pudding_colors;
std::vector<glm::vec2> pudding_uv; std::vector<glm::vec2> pudding_uv;
bool show_item = false, reading_capture_frame = false; bool show_item = false, reading_capture_frame = false;
int effect_id = Effect::NONE;
SDL_GLContext capture_frame_thread_context = nullptr; SDL_GLContext capture_frame_thread_context = nullptr;
void set_pudding_model(float, float, int, int = 1, float = -1, float = 1, float = 0.3f); void set_pudding_model(float, float, int, int = 1, float = -1, float = 1, float = 0.3f);

View File

@ -5,21 +5,25 @@ in float x;
in vec2 uv; in vec2 uv;
uniform sampler2D pudding_texture; uniform sampler2D pudding_texture;
void main(void) void color()
{
vec3 shadowed = min(ex_color, 1.0);
float dx = abs(floor(gl_FragCoord[0]) - 480) / 480.0;
if (int(floor(gl_FragCoord[0] / 2) + floor(gl_FragCoord[1]) / 2) % 2 == 0)
{
gl_FragColor = vec4(shadowed * 1.2, 1);
}
else
{
gl_FragColor = vec4(shadowed * 0.7, 1);
}
gl_FragColor[0] = int(gl_FragColor[0] * 4) / 4.0;
gl_FragColor[1] = int(gl_FragColor[1] * 4) / 4.0;
gl_FragColor[2] = int(gl_FragColor[2] * 4) / 4.0;
gl_FragColor *= x;
}
void main()
{ {
// vec3 shadowed = min(ex_color, 1.0);
// float dx = abs(floor(gl_FragCoord[0]) - 480) / 480.0;
// if (int(floor(gl_FragCoord[0] / 3) + floor(gl_FragCoord[1]) / 3) % 2 == 0)
// {
// gl_FragColor = vec4(shadowed * 1.3, 1);
// }
// else
// {
// gl_FragColor = vec4(shadowed * 0.6, 1);
// }
// gl_FragColor[0] = int(gl_FragColor[0] * 4) / 4.0;
// gl_FragColor[1] = int(gl_FragColor[1] * 4) / 4.0;
// gl_FragColor[2] = int(gl_FragColor[2] * 4) / 4.0;
// gl_FragColor *= x;
gl_FragColor = texture(pudding_texture, uv); gl_FragColor = texture(pudding_texture, uv);
} }