Ray-caster: only draw the top few fragments
This seems to increase graphics pipe use from 50--60% to 55--65%.
This commit is contained in:
parent
6db9f5be6c
commit
f148552964
@ -25,10 +25,10 @@ vecInv sphere(vec3 center, float radius) {
|
|||||||
|
|
||||||
// construction. the SPHERE_MAX array size seems to affect frame rate a lot,
|
// 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
|
// even though we should only be using the first few elements of each array
|
||||||
const int SPHERE_MAX_UNIFORM = 200;
|
const int SPHERE_MAX = 200;
|
||||||
uniform int sphere_cnt;
|
uniform int sphere_cnt;
|
||||||
uniform vecInv sphere_list[SPHERE_MAX_UNIFORM];
|
uniform vecInv sphere_list[SPHERE_MAX];
|
||||||
uniform vec3 color_list[SPHERE_MAX_UNIFORM];
|
uniform vec3 color_list[SPHERE_MAX];
|
||||||
|
|
||||||
// view
|
// view
|
||||||
uniform vec2 resolution;
|
uniform vec2 resolution;
|
||||||
@ -135,8 +135,8 @@ void main() {
|
|||||||
vec3 dir = vec3(focal_slope * scr, -1.);
|
vec3 dir = vec3(focal_slope * scr, -1.);
|
||||||
|
|
||||||
// cast rays through the spheres
|
// cast rays through the spheres
|
||||||
const int SPHERE_MAX_INTERNAL = 6;
|
const int LAYER_MAX = 12;
|
||||||
taggedFrag frags [2*SPHERE_MAX_INTERNAL];
|
taggedFrag frags [LAYER_MAX];
|
||||||
int layer_cnt = 0;
|
int layer_cnt = 0;
|
||||||
for (int id = 0; id < sphere_cnt; ++id) {
|
for (int id = 0; id < sphere_cnt; ++id) {
|
||||||
// find out where the ray hits the sphere
|
// find out where the ray hits the sphere
|
||||||
@ -144,17 +144,20 @@ void main() {
|
|||||||
|
|
||||||
// insertion-sort the fragments we hit into the fragment list
|
// insertion-sort the fragments we hit into the fragment list
|
||||||
for (int side = 0; side < 2; ++side) {
|
for (int side = 0; side < 2; ++side) {
|
||||||
if (hit_depths[side] > 0.) {
|
float hit_z = -hit_depths[side];
|
||||||
|
if (0. > hit_z) {
|
||||||
for (int layer = layer_cnt; layer >= 0; --layer) {
|
for (int layer = layer_cnt; layer >= 0; --layer) {
|
||||||
if (layer < 1 || frags[layer-1].pt.z >= -hit_depths[side]) {
|
if (layer < 1 || frags[layer-1].pt.z >= hit_z) {
|
||||||
// we're not as close to the screen as the fragment
|
// we're not as close to the screen as the fragment
|
||||||
// before the empty slot, so insert here
|
// before the empty slot, so insert here
|
||||||
frags[layer] = sphere_shading(
|
if (layer < LAYER_MAX) {
|
||||||
sphere_list[id],
|
frags[layer] = sphere_shading(
|
||||||
hit_depths[side] * dir,
|
sphere_list[id],
|
||||||
color_list[id],
|
hit_depths[side] * dir,
|
||||||
id
|
color_list[id],
|
||||||
);
|
id
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// we're closer to the screen than the fragment before
|
// we're closer to the screen than the fragment before
|
||||||
@ -163,7 +166,7 @@ void main() {
|
|||||||
frags[layer] = frags[layer-1];
|
frags[layer] = frags[layer-1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++layer_cnt;
|
layer_cnt = min(layer_cnt + 1, LAYER_MAX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user