Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float distanceFunction(vec3 p) {
  2.     return length(p) - 1.0; // This is the distance to a sphere at (0,0,0), radius 1.0
  3. }
  4.  
  5. vec3 rgb = vec3(0.0); // start with black pixel
  6.  
  7. vec3 camPos = vec3(0, 0, -10); // starting point for the ray
  8. vec3 rayDir = normalize(uv, 1); // direction of the ray
  9.  
  10. vec3 pos = camPos; // This is the current position
  11.  
  12. for(int j=0; j<100; j++) {
  13.     float dist = distanceFunction(pos); // distance to surface
  14.     if (dist < 0.001) {
  15.         // We’re close enough, call it a hit
  16.         rgb = vec3(1.0); // colour the pixel white
  17.         break; // exit the loop because we hit the surface
  18.     }
  19.    
  20.     pos += rayDir * dist; // move along the ray by the SDF distance
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement