Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vec3 ray_march(in vec3 ro, in vec3 rd)
- {
- float total_distance_traveled = 0.0;
- const int NUMBER_OF_STEPS = 32;
- const float MINIMUM_HIT_DISTANCE = 0.001;
- const float MAXIMUM_TRACE_DISTANCE = 1000.0;
- for (int i = 0; i < NUMBER_OF_STEPS; ++i)
- {
- // Calculate our current position along the ray
- vec3 current_position = ro + total_distance_traveled * rd;
- // We wrote this function earlier in the tutorial -
- // assume that the sphere is centered at the origin
- // and has unit radius
- float distance_to_closest = distance_from_sphere(current_position, vec3(0.0), 1.0);
- if (distance_to_closest < MINIMUM_HIT_DISTANCE) // hit
- {
- // We hit something! Return red for now
- return vec3(1.0, 0.0, 0.0);
- }
- if (total_distance_traveled > MAXIMUM_TRACE_DISTANCE) // miss
- {
- break;
- }
- // accumulate the distance traveled thus far
- total_distance_traveled += distance_to_closest;
- }
- // If we get here, we didn't hit anything so just
- // return a background color (black)
- return vec3(0.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement