Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float distanceFunction(vec3 p) {
- return length(p) - 1.0; // This is the distance to a sphere at (0,0,0), radius 1.0
- }
- vec3 rgb = vec3(0.0); // start with black pixel
- vec3 camPos = vec3(0, 0, -10); // starting point for the ray
- vec3 rayDir = normalize(uv, 1); // direction of the ray
- vec3 pos = camPos; // This is the current position
- for(int j=0; j<100; j++) {
- float dist = distanceFunction(pos); // distance to surface
- if (dist < 0.001) {
- // Weβre close enough, call it a hit
- rgb = vec3(1.0); // colour the pixel white
- break; // exit the loop because we hit the surface
- }
- pos += rayDir * dist; // move along the ray by the SDF distance
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement