Ray-caster: pass the sphere count as a uniform

In the process, start exploring array size limits of various kinds.
This commit is contained in:
Aaron Fenyes 2024-08-26 00:43:42 -07:00
parent c5fe725b1b
commit 85db7b9be0
2 changed files with 29 additions and 10 deletions

View file

@ -23,8 +23,10 @@ vecInv sphere(vec3 center, float radius) {
// --- uniforms ---
// construction
const int SPHERE_MAX = 256;
// construction. the SPHERE_MAX array size seems to affect frame rate a lot,
// even though we should only be using the first few elements of each array
const int SPHERE_MAX = 12;
uniform int sphere_cnt;
uniform vecInv sphere_list[SPHERE_MAX];
// view
@ -128,13 +130,11 @@ vec2 sphere_cast(vecInv v, vec3 dir) {
}
void main() {
const int sphere_cnt = 3;
vec2 scr = (2.*gl_FragCoord.xy - resolution) / shortdim;
vec3 dir = vec3(focal_slope * scr, -1.);
// initialize two spheres
vecInv sphere_list_internal [sphere_cnt];
vecInv sphere_list_internal [SPHERE_MAX];
if (use_test_construction) {
/* DEBUG */
// spheres 0 and 1 are identical in the test construction hard-coded
@ -149,14 +149,14 @@ void main() {
sphere_list_internal[i] = sphere_list[i];
}
}
vec3 color_list [sphere_cnt];
vec3 color_list [SPHERE_MAX];
color_list[0] = vec3(1., 0.25, 0.);
color_list[1] = vec3(0., 0.25, 1.);
color_list[2] = vec3(0.25, 0., 1.0);
// cast rays through the spheres
vec2 depth_pairs [sphere_cnt];
taggedFrag frags [2*sphere_cnt];
vec2 depth_pairs [SPHERE_MAX];
taggedFrag frags [2*SPHERE_MAX];
int frag_cnt = 0;
for (int i = 0; i < sphere_cnt; ++i) {
vec2 hit_depths = sphere_cast(sphere_list_internal[i], dir);