Intersection ʹϚςϦΞϧใʢambient/diffuse/specularʣΛηοτ 38 void intersectObjects(inout Intersection intersection, inout Ray ray) { float d; float distance = 0.0; vec3 p = ray.origin; for (float i = 0.0; i < 100.0; i++) { d = dObjects(p); distance += d; p = ray.origin + distance * ray.direction; intersection.count = i; if (abs(d) < EPS || distance > 100.0) break; } if (abs(d) < EPS && distance < intersection.distance) { intersection.distance = distance; intersection.hit = true; intersection.position = p; intersection.normal = calcNormal(p, dScene); if (abs(dSphereLeft(p)) < EPS) { intersection.ambient = vec3(0.0); intersection.diffuse = vec3(0.0); intersection.specular = vec3(0.5); intersection.reflectance = 0.9; } else if (abs(dSphereCenter(p)) < EPS) { intersection.ambient = vec3(0.3, 0.3, 0.6) * 1.2; intersection.diffuse = vec3(0.3, 0.3, 0.6) * 0.5; intersection.specular = vec3(0.3); intersection.reflectance = 0.2; } else if (abs(dMengerSpongeRight(p)) < EPS) { intersection.ambient = vec3(0.1, 0.2, 0.1) * 2.0; intersection.diffuse = vec3(0.1, 0.2, 0.1) * 0.2; intersection.specular = vec3(0.0); intersection.reflectance = 0.0; } } } if (abs(dSphereLeft(p)) < EPS) { intersection.ambient = vec3(0.0); intersection.diffuse = vec3(0.0); intersection.specular = vec3(0.5); intersection.reflectance = 0.9; } else if (abs(dSphereCenter(p)) < EPS) { intersection.ambient = vec3(0.3, 0.3, 0.6) * 1.2; intersection.diffuse = vec3(0.3, 0.3, 0.6) * 0.5; intersection.specular = vec3(0.3); intersection.reflectance = 0.2; } else if (abs(dMengerSpongeRight(p)) < EPS) { intersection.ambient = vec3(0.1, 0.2, 0.1) * 2.0; intersection.diffuse = vec3(0.1, 0.2, 0.1) * 0.2; intersection.specular = vec3(0.0); intersection.reflectance = 0.0; }