Skip to content

Commit 6b417ad

Browse files
Optimize multipass texture binding and drop redundant sampler updates
1 parent 9dd34da commit 6b417ad

2 files changed

Lines changed: 42 additions & 54 deletions

File tree

src/OpenCOVER/plugins/hlrs/LamurePointCloud/LamureRenderer.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,23 @@ struct PointsDrawCallback : public virtual osg::Drawable::DrawCallback
844844
const float scale_radius_combined = s.scale_radius * s.scale_element;
845845
const float scale_proj_pass = opencover::cover->getScale() * static_cast<float>(vpHeight) * 0.5f * projection_matrix.data_array[5];
846846

847+
const auto bindTexture2DToUnit = [](GLuint unit, GLuint texture) {
848+
#if defined(GL_VERSION_4_5)
849+
if (GLEW_VERSION_4_5) {
850+
glBindTextureUnit(unit, texture);
851+
return;
852+
}
853+
#endif
854+
#if defined(GL_ARB_direct_state_access)
855+
if (GLEW_ARB_direct_state_access) {
856+
glBindTextureUnit(unit, texture);
857+
return;
858+
}
859+
#endif
860+
glActiveTexture(GL_TEXTURE0 + unit);
861+
glBindTexture(GL_TEXTURE_2D, texture);
862+
};
863+
847864
// --- PASS 1: Depth pre-pass (depth-only, kreisförmiges discard im FS)
848865
glBindFramebuffer(GL_FRAMEBUFFER, target.fbo);
849866
glViewport(0, 0, vpWidth, vpHeight);
@@ -918,10 +935,7 @@ struct PointsDrawCallback : public virtual osg::Drawable::DrawCallback
918935
glViewport(0, 0, vpWidth, vpHeight);
919936

920937
// Tiefe aus Pass 1
921-
glActiveTexture(GL_TEXTURE0);
922-
glBindTexture(GL_TEXTURE_2D, target.depth_texture);
923-
if (_renderer->getSurfelPass2Shader().depth_texture_loc >= 0)
924-
glUniform1i(_renderer->getSurfelPass2Shader().depth_texture_loc, 0);
938+
bindTexture2DToUnit(0, target.depth_texture);
925939

926940
// Globale Uniforms für VS/GS/FS
927941
if (_renderer->getSurfelPass2Shader().viewport_loc >= 0) glUniform2f(_renderer->getSurfelPass2Shader().viewport_loc, viewport.x, viewport.y);
@@ -994,25 +1008,10 @@ struct PointsDrawCallback : public virtual osg::Drawable::DrawCallback
9941008
glUseProgram(_renderer->getSurfelPass3Shader().program);
9951009

9961010
// G-Buffer
997-
glActiveTexture(GL_TEXTURE0);
998-
glBindTexture(GL_TEXTURE_2D, target.texture_color);
999-
if (_renderer->getSurfelPass3Shader().in_color_texture_loc >= 0)
1000-
glUniform1i(_renderer->getSurfelPass3Shader().in_color_texture_loc, 0);
1001-
1002-
glActiveTexture(GL_TEXTURE1);
1003-
glBindTexture(GL_TEXTURE_2D, target.texture_normal);
1004-
if (_renderer->getSurfelPass3Shader().in_normal_texture_loc >= 0)
1005-
glUniform1i(_renderer->getSurfelPass3Shader().in_normal_texture_loc, 1);
1006-
1007-
glActiveTexture(GL_TEXTURE2);
1008-
glBindTexture(GL_TEXTURE_2D, target.texture_position);
1009-
if (_renderer->getSurfelPass3Shader().in_vs_position_texture_loc >= 0)
1010-
glUniform1i(_renderer->getSurfelPass3Shader().in_vs_position_texture_loc, 2);
1011-
1012-
glActiveTexture(GL_TEXTURE3);
1013-
glBindTexture(GL_TEXTURE_2D, target.depth_texture);
1014-
if (_renderer->getSurfelPass3Shader().in_depth_texture_loc >= 0)
1015-
glUniform1i(_renderer->getSurfelPass3Shader().in_depth_texture_loc, 3);
1011+
bindTexture2DToUnit(0, target.texture_color);
1012+
bindTexture2DToUnit(1, target.texture_normal);
1013+
bindTexture2DToUnit(2, target.texture_position);
1014+
bindTexture2DToUnit(3, target.depth_texture);
10161015

10171016
// View-space lighting Setup
10181017
scm::math::mat4 viewMat = view_matrix;

src/OpenCOVER/plugins/hlrs/LamurePointCloud/shaders/vis/vis_surfel_util.glsl

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,20 @@ bool scale_anisotropic_pixels_depth(
144144

145145
float ru = length(su - s0);
146146
float rv = length(sv - s0);
147-
float d_pxC = clamp(2.0 * max(ru, rv), min_screen_size, max_screen_size);
148-
if (d_pxC <= UTIL_EPS) return false;
149-
150-
float R = 0.5 * d_pxC;
151-
float m = max(ru, rv);
152-
float iso = (m > UTIL_EPS) ? (R / m) : 1.0;
153-
float su_s = (ru > UTIL_EPS) ? (R / ru) : 1.0;
154-
float sv_s = (rv > UTIL_EPS) ? (R / rv) : 1.0;
155-
156-
// Smoothly cap extreme anisotropy to avoid popping near degeneracies
157-
const float Amax = 3.0; // desired max anisotropy ratio
158-
float ratio = (ru > rv) ? (ru / max(rv, UTIL_EPS)) : (rv / max(ru, UTIL_EPS));
159-
float t = clamp((ratio - Amax) / (Amax * 0.5), 0.0, 1.0); // blend towards isotropic when exceeding cap
160-
su_s = mix(su_s, iso, t);
161-
sv_s = mix(sv_s, iso, t);
147+
148+
float du = clamp(2.0 * ru, min_screen_size, max_screen_size);
149+
float dv = clamp(2.0 * rv, min_screen_size, max_screen_size);
150+
float r_u = 0.5f * du;
151+
float r_v = 0.5f * dv;
152+
153+
float su_s = (ru > UTIL_EPS) ? (r_u / ru) : 0.0f;
154+
float sv_s = (rv > UTIL_EPS) ? (r_v / rv) : 0.0f;
162155

163156
step_u_ws *= su_s;
164157
step_v_ws *= sv_s;
165-
out_pixel_diameter = d_pxC;
166-
return true;
158+
159+
out_pixel_diameter = max(du, dv);
160+
return (du > UTIL_EPS) || (dv > UTIL_EPS);
167161
}
168162

169163
// Anisotropic pixel-scaling (no depth): same as above, but does not report NDC depth
@@ -187,25 +181,20 @@ bool scale_anisotropic_pixels(
187181

188182
float ru = length(su - s0);
189183
float rv = length(sv - s0);
190-
float d_pxC = clamp(2.0 * max(ru, rv), min_screen_size, max_screen_size);
191-
if (d_pxC <= UTIL_EPS) return false;
192184

193-
float R = 0.5 * d_pxC;
194-
float m = max(ru, rv);
195-
float iso = (m > UTIL_EPS) ? (R / m) : 1.0;
196-
float su_s = (ru > UTIL_EPS) ? (R / ru) : 1.0;
197-
float sv_s = (rv > UTIL_EPS) ? (R / rv) : 1.0;
185+
float du = clamp(2.0 * ru, min_screen_size, max_screen_size);
186+
float dv = clamp(2.0 * rv, min_screen_size, max_screen_size);
187+
float r_u = 0.5f * du;
188+
float r_v = 0.5f * dv;
198189

199-
const float Amax = 3.0;
200-
float ratio = (ru > rv) ? (ru / max(rv, UTIL_EPS)) : (rv / max(ru, UTIL_EPS));
201-
float t = clamp((ratio - Amax) / (Amax * 0.5), 0.0, 1.0);
202-
su_s = mix(su_s, iso, t);
203-
sv_s = mix(sv_s, iso, t);
190+
float su_s = (ru > UTIL_EPS) ? (r_u / ru) : 0.0f;
191+
float sv_s = (rv > UTIL_EPS) ? (r_v / rv) : 0.0f;
204192

205193
step_u_ws *= su_s;
206194
step_v_ws *= sv_s;
207-
out_pixel_diameter = d_pxC;
208-
return true;
195+
196+
out_pixel_diameter = max(du, dv);
197+
return (du > UTIL_EPS) || (dv > UTIL_EPS);
209198
}
210199

211200
// Isotropic scaling with depth reporting (compat variant for other shaders)

0 commit comments

Comments
 (0)