Skip to content

Instantly share code, notes, and snippets.

@omaraflak
Last active August 4, 2020 15:26
Show Gist options
  • Save omaraflak/76929293e838780e5e253965b9a39e31 to your computer and use it in GitHub Desktop.
Save omaraflak/76929293e838780e5e253965b9a39e31 to your computer and use it in GitHub Desktop.
# ...
if is_shadowed:
break
# RGB
illumination = np.zeros((3))
# ambiant
illumination += nearest_object['ambient'] * light['ambient']
# diffuse
illumination += nearest_object['diffuse'] * light['diffuse'] * np.dot(intersection_to_light, normal_to_surface)
# specular
intersection_to_camera = normalize(camera - intersection)
H = normalize(intersection_to_light + intersection_to_camera)
illumination += nearest_object['specular'] * light['specular'] * np.dot(normal_to_surface, H) ** (nearest_object['shininess'] / 4)
image[i, j] = np.clip(illumination, 0, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment