Skip to content

Commit 3585c68

Browse files
🐛 gaps in volumetric data happened for certain shapes of data
This happened when we had for instance 7 columns, because mod(7, 7) == 7 See also: https://stackoverflow.com/questions/33908644/get-accurate-integer-modulo-in-webgl-shader/48909461 This might depend on the video card, since I also found mod(8, 8) == 8. We now avoid mod, and use floor instead.
1 parent 285d0b1 commit 3585c68

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

js/glsl/volr-fragment.glsl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ uniform int steps;
8989

9090

9191
vec2 compute_slice_offset(float slice, float columns, vec2 uv_slice_spacing) {
92-
return uv_slice_spacing * vec2(mod(slice, columns), floor(slice / columns));
92+
float column = floor((slice+0.5) / (columns));
93+
float row = slice - column * columns;
94+
return uv_slice_spacing * vec2(row, column);
9395
}
9496
vec4 sample_as_3d_texture(sampler2D tex, vec2 tex_size, vec3 texCoord, vec2 slice_size, float slices, float rows, float columns) {
9597
float slice = texCoord.z*slices*(slices-1.)/slices ;
@@ -370,12 +372,30 @@ void main(void) {
370372
#else
371373
gl_FragColor = color;
372374
#endif
373-
//gl_FragColor = vec4(ray_begin.xyz, 0.1) * brightness;
375+
// code below is used for debugging purposes
376+
// float x = floor((pixel.x *500. / 10.));
377+
// float y = floor((pixel.y *500. / 10.));
378+
// // gl_FragColor = vec4(x / 10., 0.0, 0.0, 1.0);
379+
// // gl_FragColor = vec4(y / 10., 0.0, 0.0, 1.0);
380+
// vec2 result;
381+
// float eps = 1. - 1e-4;
382+
// float modulo = mod(x, y * eps);
383+
// float offset = x - modulo * y;
384+
// offset = floor(x / y);
385+
// gl_FragColor = vec4(mod(x, x) > 0. ? 1.0 : 0., 0.0, 0.0, 1.0);
386+
// gl_FragColor = vec4(modulo >= x ? 1.0 : 0., 0.0, 0.0, 1.0);
387+
// gl_FragColor = vec4(offset >= 0.5 ? 1.0 : 0., 0.0, 0.0, 1.0);
388+
// gl_FragColor = vec4(offset/x, 0.0, 0.0, 1.0);
389+
// eps = 0.;
390+
// gl_FragColor = vec4(float(int(x / (y - eps))) / 1., 0.0, 0.0, 1.0);
391+
// gl_FragColor = vec4(texture2D(data[0], pixel).a * 140., 0., 0., 1.0);
392+
// gl_FragColor = vec4(ray_begin.xyz, 1.);
393+
// gl_FragColor = vec4(ray_begin.xyz, 0.1) * brightness;
374394
//gl_FragColor = vec4(rotation[0], 1) * brightness;
375-
//gl_FragColor = vec4(alpha_total, 0., 0., 1.);
395+
// gl_FragColor = vec4(alpha_total, 0., 0., 1.);
376396
//gl_FragColor = texture2D(volume, vec2(ray_begin.x, ray_begin.y));
377-
// gl_FragColor = vec4(ray_pos.x, ray_pos.y, ray_pos.z, 1);
378-
//gl_FragColor = texture2D(transfer_function, vec2(pixel.x, 0.5));
397+
// gl_FragColor = vec4(ray_begin.x, ray_begin.y, ray_begin.z, 1.);
398+
// gl_FragColor = texture2D(transfer_function, vec2(pixel.x, 0.5));
379399
//gl_FragColor = vec4(texture2D(volume, vec2(pixel.x, pixel.y)).rgb, 1.0);
380400
// gl_FragColor = vec4(pixel.x, pixel.y, 0, 1);
381401
// gl_FragColor = vec4(ray_end, 1.);

0 commit comments

Comments
 (0)