Ray-caster: pass colors in through uniforms
This commit is contained in:
parent
b9370ceb41
commit
cbec31f5df
2 changed files with 27 additions and 10 deletions
|
|
@ -28,6 +28,7 @@ vecInv sphere(vec3 center, float radius) {
|
|||
const int SPHERE_MAX = 12;
|
||||
uniform int sphere_cnt;
|
||||
uniform vecInv sphere_list[SPHERE_MAX];
|
||||
uniform vec3 color_list[SPHERE_MAX];
|
||||
|
||||
// view
|
||||
uniform vec2 resolution;
|
||||
|
|
@ -135,6 +136,7 @@ void main() {
|
|||
|
||||
// initialize two spheres
|
||||
vecInv sphere_list_internal [SPHERE_MAX];
|
||||
vec3 color_list_internal [SPHERE_MAX];
|
||||
if (use_test_construction) {
|
||||
/* DEBUG */
|
||||
// spheres 0 and 1 are identical in the test construction hard-coded
|
||||
|
|
@ -144,15 +146,15 @@ void main() {
|
|||
sphere_list_internal[0] = sphere(vec3(0.5, 0.5, -5. + ctrl.x), radius.x);
|
||||
sphere_list_internal[1] = sphere(vec3(-0.5, -0.5, -5. + ctrl.y), radius.y);
|
||||
sphere_list_internal[2] = sphere(vec3(-0.5, 0.5, -5.), 0.5);
|
||||
color_list_internal[0] = vec3(1., 0.25, 0.);
|
||||
color_list_internal[1] = vec3(0., 0.25, 1.);
|
||||
color_list_internal[2] = vec3(0.25, 0., 1.0);
|
||||
} else {
|
||||
for (int i = 0; i < sphere_cnt; ++i) {
|
||||
sphere_list_internal[i] = sphere_list[i];
|
||||
color_list_internal[i] = color_list[i];
|
||||
}
|
||||
}
|
||||
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_MAX];
|
||||
|
|
@ -161,11 +163,11 @@ void main() {
|
|||
for (int i = 0; i < sphere_cnt; ++i) {
|
||||
vec2 hit_depths = sphere_cast(sphere_list_internal[i], dir);
|
||||
if (!isnan(hit_depths[0])) {
|
||||
frags[frag_cnt] = sphere_shading(sphere_list_internal[i], hit_depths[0] * dir, color_list[i], i);
|
||||
frags[frag_cnt] = sphere_shading(sphere_list_internal[i], hit_depths[0] * dir, color_list_internal[i], i);
|
||||
++frag_cnt;
|
||||
}
|
||||
if (!isnan(hit_depths[1])) {
|
||||
frags[frag_cnt] = sphere_shading(sphere_list_internal[i], hit_depths[1] * dir, color_list[i], i);
|
||||
frags[frag_cnt] = sphere_shading(sphere_list_internal[i], hit_depths[1] * dir, color_list_internal[i], i);
|
||||
++frag_cnt;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue