• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# The ray tracer function....

a guest Dec 10th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. For David M.
2.
3. float ct_trace(glm::vec3 from, glm::vec3 direction) {
4.     float distance_total = 0.0;
5.     int steps;
6.     for (steps = 0; steps < 64; steps++) {
7.         glm::vec3 p = from + distance_total * direction;
8.         float distance_sum = 9999.;
9.
10.         glm::vec3 p_0 = p + glm::vec3(-3., 0., 0.);
11.         glm::vec3 p_1 = p + glm::vec3(3., 0., 0.);
12.         glm::vec3 p_2 = p + glm::vec3(0., 3., 0.);
13.         glm::vec3 p_3 = p + glm::vec3(0., -3., 0.);
14.         glm::vec3 p_4 = p + glm::vec3(0., .0, -3.);
15.         glm::vec3 p_5 = p + glm::vec3(0., .0, 3.);
16.
17.         //float color_0 = ct_box(p_1, glm::vec3(1., 1., 1.));
18.         //float color_1 = ct_box(p_1, glm::vec3(1., 1., 1.));
19.         //float color_2 = ct_box(p_2, glm::vec3(1., 1., 1.));
20.         //float color_3 = ct_box(p_3, glm::vec3(1., 1., 1.));
21.         // float color_4 = ct_box(p_4, glm::vec3(1., 1., 1.));
22.         //float color_5 = ct_box(p_5, glm::vec3(1., 1., 1.));
23.
24.         float color_0 = ct_torus(p_0, glm::vec2(1., 1.));
25.         float color_1 = ct_torus(p_1, glm::vec2(1., 1.));
26.         float color_2 = ct_torus(p_2, glm::vec2(1., 1.));
27.         float color_3 = ct_torus(p_3, glm::vec2(1., 1.));
28.         float color_4 = ct_torus(p_4, glm::vec2(1., 1.));
29.         float color_5 = ct_torus(p_4, glm::vec2(1., 1.));
30.
31.         float color_6 = ct_box(p, glm::vec3(2., 2., 2.)); //ct_sphere_distance(p, 2.);
32.         float color_7 = ct_sphere_distance(p, 1.0);
33.
34.         distance_sum = glm::min(distance_sum, color_0);
35.         distance_sum = glm::min(distance_sum, color_1);
36.         distance_sum = glm::min(distance_sum, color_2);
37.         distance_sum = glm::min(distance_sum, color_3);
38.         distance_sum = glm::min(distance_sum, color_4);
39.         distance_sum = glm::min(distance_sum, color_5);
40.         distance_sum = glm::min(distance_sum, color_6);
41.         //distance_sum = glm::min(distance_sum, color_7);
42.
43.         distance_total += distance_sum;
44.         if (distance_sum < .001)
45.         {
46.             break;
47.         }
48.     }
49.     return 1.0 - float(steps) / float(64);
50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top