Skip to content

Commit

Permalink
added separate shader for drawing arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 15, 2023
1 parent db222f0 commit d3dc562
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
29 changes: 17 additions & 12 deletions Arrangement_on_surface_2/demo/earth/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void MainWidget::init_geometry()
void MainWidget::init_shader_programs()
{
init_sp_smooth();
init_sp_color_only();
init_sp_per_vertex_color();
}
void MainWidget::init_sp_smooth()
{
Expand All @@ -124,11 +124,11 @@ void MainWidget::init_sp_smooth()
m_sp_smooth.init(vs, "", fs);

}
void MainWidget::init_sp_color_only()
void MainWidget::init_sp_per_vertex_color()
{
const char* vs = "shaders/color_only_vs.glsl";
const char* fs = "shaders/color_only_fs.glsl";
m_sp_color_only.init(vs, "", fs);
m_sp_per_vertex_color.init(vs, "", fs);
}


Expand Down Expand Up @@ -169,13 +169,24 @@ void MainWidget::paintGL()
}

// WORLD COORDINATE AXES & GEODESIC ARCS
{
auto& sp = m_sp_per_vertex_color;
sp.use();
sp.set_uniform("u_mvp", mvp);

m_world_coord_axes->draw();

sp.unuse();
}

// GEODESIC ARCS
{
glDisable(GL_DEPTH_TEST);

auto& sp = m_sp_color_only;
auto& sp = m_sp_per_vertex_color;
sp.use();
sp.set_uniform("u_mvp", mvp);

// compute the cutting plane
auto c = m_camera.get_pos();
const auto d = c.length();
Expand All @@ -184,16 +195,10 @@ void MainWidget::paintGL()
const auto n = (c / d); // plane unit normal vector
const auto cos_beta = sin_alpha;
const auto p = (r * cos_beta) * n;
QVector4D plane(n.x(), n.y(), n.z(), -QVector3D::dotProduct(p,n));
std::cout << plane << std::endl;
QVector4D plane(n.x(), n.y(), n.z(), -QVector3D::dotProduct(p, n));
sp.set_uniform("u_plane", plane);
glEnable(GL_DEPTH_TEST);
m_geodesic_arcs->draw();

glEnable(GL_DEPTH_TEST);
sp.set_uniform("u_plane", QVector4D(0,0,0,0));// ad-hoc
m_world_coord_axes->draw();

sp.unuse();
}
}
5 changes: 3 additions & 2 deletions Arrangement_on_surface_2/demo/earth/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase

void init_shader_programs();
void init_sp_smooth();
void init_sp_color_only();
void init_sp_per_vertex_color();

private:
// Objects in the scene
Expand All @@ -55,7 +55,8 @@ class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase

// Shaders
Shader_program m_sp_smooth;
Shader_program m_sp_color_only;
Shader_program m_sp_per_vertex_color;
Shader_program m_sp_arc;

// Camera & controls
Camera m_camera;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

#version 330

uniform vec3 u_color;
uniform vec4 u_plane;

in vec3 v_color;

in vec3 v_pos;
out vec4 out_color;

Expand All @@ -13,5 +14,5 @@ void main()
if( dot(u_plane, vec4(v_pos, 1)) < 0 )
discard;

out_color = vec4(v_color, 1);
out_color = vec4(u_color, 1);
}
15 changes: 15 additions & 0 deletions Arrangement_on_surface_2/demo/earth/shaders/arc_vs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#version 330

layout (location = 0) in vec3 a_pos;

uniform mat4 u_mvp;

out vec3 v_pos;


void main()
{
v_pos = a_pos;
gl_Position = u_mvp * vec4(a_pos.xyz, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#version 330

uniform vec4 u_plane;

in vec3 v_color;
out vec4 out_color;


void main()
{
out_color = vec4(v_color, 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ layout (location = 1) in vec3 a_color;
uniform mat4 u_mvp;

out vec3 v_color;
out vec3 v_pos;


void main()
{
v_color = a_color;
v_pos = a_pos;
gl_Position = u_mvp * vec4(a_pos.xyz, 1);
}

0 comments on commit d3dc562

Please sign in to comment.