Repository: yt-project/yt_idv (language: python)

Issue:
BUG: slicing shader does not compile
The test appears to pass, but the test report log shows an error. Can reproduce with:

```python
import yt

import yt_idv

ds = yt.load_sample("IsolatedGalaxy")

rc = yt_idv.render_context(height=800, width=800, gui=True)
sg = rc.add_scene(ds, "density", no_ghost=True)

rc.scene.components[0].render_method = "slice"
rc.scene.components[0].slice_normal = (1.0, 1.0, 0.0)
rc.scene.components[0].slice_position = (0.5, 0.25, 0.5)
rc.run()
```

```
---------------------------- Captured stderr setup -----------------------------
yt : [INFO     ] 2024-06-27 19:41:45,265 Parameters: current_time              = 0.0
yt : [INFO     ] 2024-06-27 19:41:45,265 Parameters: domain_dimensions         = [32 32 32]
yt : [INFO     ] 2024-06-27 19:41:45,265 Parameters: domain_left_edge          = [0. 0. 0.]
yt : [INFO     ] 2024-06-27 19:41:45,265 Parameters: domain_right_edge         = [1. 1. 1.]
yt : [INFO     ] 2024-06-27 19:41:45,265 Parameters: cosmological_simulation   = 0

----------------------------- Captured stdout call -----------------------------
b"0:134(17): error: no matching function for call to `texture(sampler3D[6], vec3)'; candidates are:\n0:134(17): error:    vec4 texture(sampler1D, float)\n0:134(17): error:    ivec4 texture(isampler1D, float)\n0:134(17): error:    uvec4 texture(usampler1D, float)\n0:134(17): error:    vec4 texture(sampler2D, vec2)\n0:134(17): error:    ivec4 texture(isampler2D, vec2)\n0:134(17): error:    uvec4 texture(usampler2D, vec2)\n0:134(17): error:    vec4 texture(sampler3D, vec3)\n0:134(17): error:    ivec4 texture(isampler3D, vec3)\n0:134(17): error:    uvec4 texture(usampler3D, vec3)\n0:134(17): error:    vec4 texture(samplerCube, vec3)\n0:134(17): error:    ivec4 texture(isamplerCube, vec3)\n0:134(17): error:    uvec4 texture(usamplerCube, vec3)\n0:134(17): error:    float texture(sampler1DShadow, vec3)\n0:134(17): error:    float texture(sampler2DShadow, vec3)\n0:134(17): error:    float texture(samplerCubeShadow, vec4)\n0:134(17): error:    vec4 texture(sampler1DArray, vec2)\n0:134(17): error:    ivec4 texture(isampler1DArray, vec2)\n0:134(17): error:    uvec4 texture(usampler1DArray, vec2)\n0:134(17): error:    vec4 texture(sampler2DArray, vec3)\n0:134(17): error:    ivec4 texture(isampler2DArray, vec3)\n0:134(17): error:    uvec4 texture(usampler2DArray, vec3)\n0:134(17): error:    float texture(sampler1DArrayShadow, vec3)\n0:134(17): error:    float texture(sampler2DArrayShadow, vec4)\n0:134(17): error:    vec4 texture(sampler2DRect, vec2)\n0:134(17): error:    ivec4 texture(isampler2DRect, vec2)\n0:134(17): error:    uvec4 texture(usampler2DRect, vec2)\n0:134(17): error:    float texture(sampler2DRectShadow, vec3)\n0:134(17): error:    vec4 texture(sampler1D, float, float)\n0:134(17): error:    ivec4 texture(isampler1D, float, float)\n0:134(17): error:    uvec4 texture(usampler1D, float, float)\n0:134(17): error:    vec4 texture(sampler2D, vec2, float)\n0:134(17): error:    ivec4 texture(isampler2D, vec2, float)\n0:134(17): error:    uvec4 texture(usampler2D, vec2, float)\n0:134(17): error:    vec4 texture(sampler3D, vec3, float)\n0:134(17): error:    ivec4 texture(isampler3D, vec3, float)\n0:134(17): error:    uvec4 texture(usampler3D, vec3, float)\n0:134(17): error:    vec4 texture(samplerCube, vec3, float)\n0:134(17): error:    ivec4 texture(isamplerCube, vec3, float)\n0:134(17): error:    uvec4 texture(usamplerCube, vec3, float)\n0:134(17): error:    float texture(sampler1DShadow, vec3, float)\n0:134(17): error:    float texture(sampler2DShadow, vec3, float)\n0:134(17): error:    float texture(samplerCubeShadow, vec4, float)\n0:134(17): error:    vec4 texture(sampler1DArray, vec2, float)\n0:134(17): error:    ivec4 texture(isampler1DArray, vec2, float)\n0:134(17): error:    uvec4 texture(usampler1DArray, vec2, float)\n0:134(17): error:    vec4 texture(sampler2DArray, vec3, float)\n0:134(17): error:    ivec4 texture(isampler2DArray, vec3, float)\n0:134(17): error:    uvec4 texture(usampler2DArray, vec3, float)\n0:134(17): error:    float texture(sampler1DArrayShadow, vec3, float)\n"
00001: #version 330 core
00002: 
00003: 
00004: // Box annotation control
00005: uniform float box_alpha;
00006: uniform float box_width;
00007: uniform vec3 box_color;
00008: 
00009: // Colormap control
00010: uniform float cmap_log;
00011: uniform float cmap_max;
00012: uniform float cmap_min;
00013: 
00014: // Text and particle control
00015: uniform float scale;
00016: uniform float max_particle_size;
00017: uniform float x_offset;
00018: uniform float x_origin;
00019: uniform float y_offset;
00020: uniform float y_origin;
00021: 
00022: // Transfer function control
00023: uniform float tf_log;
00024: uniform float tf_max;
00025: uniform float tf_min;
00026: 
00027: // Control of RGB channel information
00028: uniform int channel;
00029: 
00030: // Mesh rendering
00031: uniform mat4 model_to_clip;
00032: 
00033: // Slicing
00034: uniform vec3 slice_position;
00035: uniform vec3 slice_normal;
00036: 
00037: // Matrices for projection and positions
00038: uniform mat4 modelview;
00039: uniform mat4 projection;
00040: uniform vec3 camera_pos;
00041: uniform vec4 viewport; // (offset_x, offset_y, 1 / screen_x, 1 / screen_y)
00042: uniform mat4 inv_pmvm;
00043: uniform float near_plane;
00044: uniform float far_plane;
00045: 
00046: // textures we tend to use
00047: uniform sampler1D cm_tex;
00048: uniform sampler2D db_tex;
00049: uniform sampler2D fb_tex;
00050: uniform sampler2D tf_tex;
00051: uniform sampler3D bitmap_tex;
00052: uniform sampler3D ds_tex[6];
00053: 
00054: // ray tracing control
00055: uniform float sample_factor;
00056: 
00057: // depth buffer control
00058: uniform bool use_db;
00059: 
00060: // curve drawing control
00061: uniform vec4 curve_rgba;
00062: 
00063: // isocontour control
00064: uniform int iso_num_layers;
00065: uniform float iso_layers[32];
00066: uniform float iso_layer_tol[32];
00067: uniform float iso_alphas[32];
00068: 
00069: 
00070: in vec4 v_model;
00071: flat in vec3 dx;
00072: flat in vec3 left_edge;
00073: flat in vec3 right_edge;
00074: flat in mat4 inverse_proj;
00075: flat in mat4 inverse_mvm;
00076: flat in mat4 inverse_pmvm;
00077: out vec4 output_color;
00078: 
00079: bool within_bb(vec3 pos)
00080: {
00081:     bvec3 left =  greaterThanEqual(pos, left_edge);
00082:     bvec3 right = lessThanEqual(pos, right_edge);
00083:     return all(left) && all(right);
00084: }
00085: 
00086: bool sample_texture(vec3 tex_curr_pos, inout vec4 curr_color, float tdelta,
00087:                     float t, vec3 dir);
00088: vec4 cleanup_phase(in vec4 curr_color, in vec3 dir, in float t0, in float t1);
00089: 
00090: // This main() function will call a function called sample_texture at every
00091: // step along the ray.  It must be of the form
00092: //   void (vec3 tex_curr_pos, inout vec4 curr_color, float tdelta, float t,
00093: //         vec3 direction);
00094: 
00095: void main()
00096: {
00097:     // Obtain screen coordinates
00098:     // https://www.opengl.org/wiki/Compute_eye_space_from_window_space#From_gl_FragCoord
00099:     vec4 ndcPos;
00100:     ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1;
00101:     ndcPos.z = (2.0 * gl_FragCoord.z - 1.0);
00102:     ndcPos.w = 1.0;
00103: 
00104:     vec4 clipPos = ndcPos / gl_FragCoord.w;
00105:     vec4 eyePos = inverse_proj * clipPos;
00106:     eyePos /= eyePos.w;
00107: 
00108:     vec3 ray_position = (inverse_pmvm * clipPos).xyz;
00109: 
00110:     // Five samples
00111:     vec3 dir = normalize(camera_pos.xyz - ray_position);
00112:     dir = max(abs(dir), 0.0001) * sign(dir);
00113:     vec4 curr_color = vec4(0.0);
00114: 
00115:     // We'll compute the t at which this ray intersects the slice. If that t
00116:     // results in a position that is within this box, we'll sample and return.
00117:     // For a nice, rust-y walkthrough: https://samsymons.com/blog/math-notes-ray-plane-intersection/
00118:     float t_intersect = dot((slice_position - ray_position), slice_normal) / dot(dir, slice_normal);
00119:     if (abs(t_intersect) < 1e-5) discard;
00120:     ray_position += t_intersect * dir;
00121:     if (!within_bb(ray_position)) discard;
00122: 
00123:     vec3 range = (right_edge + dx/2.0) - (left_edge - dx/2.0);
00124:     vec3 nzones = range / dx;
00125:     vec3 ndx = 1.0/nzones;
00126: 
00127:     vec3 tex_curr_pos = (ray_position - left_edge) / range;  // Scale from 0 .. 1
00128:     // But, we actually need it to be 0 + normalized dx/2 to 1 - normalized dx/2
00129:     tex_curr_pos = (tex_curr_pos * (1.0 - ndx)) + ndx/2.0;
00130: 
00131:     float map_sample = texture(bitmap_tex, tex_curr_pos).r;
00132:     if (!(map_sample > 0.0)) discard;
00133: 
00134:     output_color = texture(ds_tex, tex_curr_pos);
00135: }
00136: 
Computed new cmap values 134.5 - 889.5
```


Discussion / hints:
oh, got a fix i think... will push

Fix patch:
diff --git a/yt_idv/shaders/slice_sample.frag.glsl b/yt_idv/shaders/slice_sample.frag.glsl
index 84bbbb1b..99d25681 100644
--- a/yt_idv/shaders/slice_sample.frag.glsl
+++ b/yt_idv/shaders/slice_sample.frag.glsl
@@ -62,5 +62,5 @@ void main()
     float map_sample = texture(bitmap_tex, tex_curr_pos).r;
     if (!(map_sample > 0.0)) discard;
 
-    output_color = texture(ds_tex, tex_curr_pos);
+    output_color = texture(ds_tex[0], tex_curr_pos);
 }


Test patch:
diff --git a/yt_idv/tests/test_yt_idv.py b/yt_idv/tests/test_yt_idv.py
index 66b46b5a..9ebce3fb 100644
--- a/yt_idv/tests/test_yt_idv.py
+++ b/yt_idv/tests/test_yt_idv.py
@@ -68,7 +68,12 @@ def test_snapshots(osmesa_fake_amr, image_store):
 
 def test_slice(osmesa_fake_amr, image_store):
     osmesa_fake_amr.scene.components[0].render_method = "slice"
-    image_store(osmesa_fake_amr)
+    osmesa_fake_amr.scene.components[0].slice_position = (0.5, 0.5, 0.5)
+    for ax in [0, 1, 2]:
+        normal = [0.0, 0.0, 0.0]
+        normal[ax] = 1.0
+        osmesa_fake_amr.scene.components[0].slice_normal = tuple(normal)
+        image_store(osmesa_fake_amr)
     osmesa_fake_amr.scene.components[0].slice_normal = (1.0, 1.0, 0.0)
     osmesa_fake_amr.scene.components[0].slice_position = (0.5, 0.25, 0.5)
     image_store(osmesa_fake_amr)