Skip to content

Commit 825bfbf

Browse files
committed
make individual light path selection use opacity instead of soloing
1 parent c09120e commit 825bfbf

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

src/appleseed.studio/mainwindow/rendering/lightpathslayer.cpp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ void LightPathsLayer::slot_synchronize_camera()
190190

191191
void LightPathsLayer::load_light_paths_data()
192192
{
193-
m_index_offsets.clear();
193+
m_path_terminator_vertex_indices.clear();
194194
m_max_luminance = 0.0f;
195195
if (!m_light_paths.empty())
196196
{
197-
m_index_offsets.push_back(0);
197+
m_path_terminator_vertex_indices.push_back(0);
198198

199199
const auto& light_path_recorder = m_project.get_light_path_recorder();
200200

201-
GLsizei total_index_count = 0;
201+
m_total_triangle_count = 0;
202202

203203
// Vertex count * 4 since we will be adding two vertices for each point along the line and will
204204
// be adding each point twice for the beginning and end parts of each segment
@@ -301,10 +301,10 @@ void LightPathsLayer::load_light_paths_data()
301301
indices_scratch.begin(),
302302
indices_scratch.end());
303303

304-
total_index_count += 6;
304+
m_total_triangle_count += 6;
305305
prev = vert;
306306
}
307-
m_index_offsets.push_back(total_index_count);
307+
m_path_terminator_vertex_indices.push_back(static_cast<GLsizei>(others_buffer.size()));
308308
}
309309

310310
// Add an empty vertex at the end to serve as last 'next'
@@ -359,6 +359,8 @@ void LightPathsLayer::init_gl(QSurfaceFormat format)
359359
m_max_luminance_loc = m_gl->glGetUniformLocation(m_shader_program, "u_max_luminance");
360360
m_max_thickness_loc = m_gl->glGetUniformLocation(m_shader_program, "u_max_thickness");
361361
m_min_thickness_loc = m_gl->glGetUniformLocation(m_shader_program, "u_min_thickness");
362+
m_first_selected_loc = m_gl->glGetUniformLocation(m_shader_program, "u_first_selected");
363+
m_last_selected_loc = m_gl->glGetUniformLocation(m_shader_program, "u_last_selected");
362364

363365
const float z_near = 0.01f;
364366
const float z_far = 1000.0f;
@@ -510,8 +512,22 @@ void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const
510512
if (!m_gl_initialized)
511513
return;
512514

513-
if (m_index_offsets.size() > 1)
515+
if (m_total_triangle_count > 1)
514516
{
517+
GLint first_selected;
518+
GLint last_selected;
519+
assert(m_selected_light_path_index >= -1);
520+
if (m_selected_light_path_index == -1)
521+
{
522+
first_selected = 0;
523+
last_selected = static_cast<GLint>(m_path_terminator_vertex_indices[m_path_terminator_vertex_indices.size() - 1]);
524+
}
525+
else
526+
{
527+
first_selected = static_cast<GLint>(m_path_terminator_vertex_indices[m_selected_light_path_index + 1]);
528+
last_selected = static_cast<GLint>(m_path_terminator_vertex_indices[m_selected_light_path_index + 2]);
529+
}
530+
515531
m_gl->glUseProgram(m_shader_program);
516532

517533
m_gl->glUniformMatrix4fv(
@@ -537,24 +553,18 @@ void LightPathsLayer::render_scene(const GLfloat* gl_view_matrix) const
537553
m_res_loc,
538554
(GLfloat)m_width,
539555
(GLfloat)m_height);
556+
m_gl->glUniform1i(
557+
m_first_selected_loc,
558+
first_selected);
559+
m_gl->glUniform1i(
560+
m_last_selected_loc,
561+
last_selected);
540562

541563
m_gl->glBindVertexArray(m_light_paths_vao);
542564

543-
GLint first;
544-
GLsizei count;
545-
assert(m_selected_light_path_index >= -1);
546-
if (m_selected_light_path_index == -1)
547-
{
548-
first = 0;
549-
count = m_index_offsets[m_index_offsets.size() - 1] / 3;
550-
}
551-
else
552-
{
553-
first = static_cast<GLint>(m_index_offsets[m_selected_light_path_index]);
554-
count = m_index_offsets[m_selected_light_path_index + 1] - first;
555-
}
565+
556566
m_gl->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indices_ebo);
557-
m_gl->glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, reinterpret_cast<GLvoid*>(first * sizeof(unsigned int)));
567+
m_gl->glDrawElements(GL_TRIANGLES, m_total_triangle_count, GL_UNSIGNED_INT, static_cast<const GLvoid*>(0));
558568
m_gl->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
559569
}
560570
}

src/appleseed.studio/mainwindow/rendering/lightpathslayer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class LightPathsLayer: public QObject
129129
GLuint m_positions_vbo;
130130
GLuint m_others_vbo;
131131
GLuint m_indices_ebo;
132-
std::vector<GLsizei> m_index_offsets;
132+
std::vector<GLsizei> m_path_terminator_vertex_indices;
133+
GLsizei m_total_triangle_count;
133134
GLuint m_light_paths_vao;
134135
GLuint m_shader_program;
135136
GLint m_view_mat_loc;
@@ -138,6 +139,8 @@ class LightPathsLayer: public QObject
138139
GLint m_max_luminance_loc;
139140
GLint m_min_thickness_loc;
140141
GLint m_max_thickness_loc;
142+
GLint m_first_selected_loc;
143+
GLint m_last_selected_loc;
141144
foundation::Matrix4f m_gl_render_view_matrix;
142145
foundation::Matrix4f m_gl_view_matrix;
143146
foundation::Matrix4f m_gl_proj_matrix;

src/appleseed.studio/resources/shaders/lightpaths.frag

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#version 410
2929
#extension GL_ARB_separate_shader_objects : enable
3030

31-
flat in vec3 f_color;
31+
flat in vec4 f_color;
3232
in float f_aa_norm;
3333
flat in float f_thickness;
3434
flat in float f_total_thickness;
@@ -40,7 +40,7 @@ layout(location = 0) out vec4 accum_target;
4040
layout(location = 1) out float revealage_target;
4141

4242
void write_pixel(vec4 premultiplied_col, vec3 transmit) {
43-
// premultiplied_col.a *= 1.0 - clamp((transmit.r + transmit.g + transmit.b) * (1.0 / 3.0), 0, 1);
43+
premultiplied_col.a *= 1.0 - clamp((transmit.r + transmit.g + transmit.b) * (1.0 / 3.0), 0, 1);
4444

4545
float a = min(1.0, premultiplied_col.a) * 8.0 + 0.01;
4646
float b = -gl_FragCoord.z * 0.95 + 1.0;
@@ -55,7 +55,8 @@ void main()
5555
float dist = abs(f_aa_norm) * f_total_thickness - 0.5 / f_aspect_expansion_len;
5656
float eps = fwidth(dist);
5757
float a = 1.0 - smoothstep(f_thickness - eps, f_thickness + eps, dist);
58+
a *= f_color.a;
5859

59-
vec4 premult = vec4(f_color * a, a);
60-
write_pixel(premult, vec3(1.0));
60+
vec4 premult = vec4(f_color.rgb * a, a);
61+
write_pixel(premult, vec3(0.0));
6162
}

src/appleseed.studio/resources/shaders/lightpaths.vert

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ uniform float u_max_luminance;
4444
uniform float u_max_thickness;
4545
uniform float u_min_thickness;
4646

47-
flat out vec3 f_color;
47+
uniform int u_first_selected;
48+
uniform int u_last_selected;
49+
50+
flat out vec4 f_color;
4851
out float f_aa_norm;
4952
flat out float f_thickness;
5053
flat out float f_total_thickness;
@@ -105,5 +108,8 @@ void main() {
105108

106109
gl_Position = vec4((curr_screen + expansion) / aspect_vec, curr_proj.z / curr_proj.w, 1.0);
107110
f_aa_norm = orientation;
108-
f_color = v_color;
111+
112+
bool is_selected = gl_VertexID >= u_first_selected && gl_VertexID < u_last_selected;
113+
float a = is_selected ? 1.0 : 0.2;
114+
f_color = vec4(v_color, a);
109115
}

0 commit comments

Comments
 (0)