Created
November 19, 2016 01:36
-
-
Save Vatyx/357695d8f76cf7ddb4ce5a6429f42cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec3 Raytracer::getLighting(vec3 point, vec3 norm, vec3 origin, Lighting* lighting) | |
{ | |
vec3 intensity(0, 0, 0); | |
auto ka = lighting->ka; | |
auto intensityAmbient = lighting->ia; | |
intensity = ka * intensityAmbient; | |
for (vec3 pointLight : lights) | |
{ | |
bool shadow = false; | |
Ray virRay = Ray(point + .001 * norm, pointLight - point); | |
for (Surface* surface : surfaces) | |
{ | |
float t = 0; | |
if (surface->findIntersect(virRay, t)) | |
{ | |
if (0 < t && t < 1) | |
{ | |
shadow = true; | |
break; | |
} | |
} | |
} | |
if (shadow) | |
continue; | |
vec3 L = pointLight - point; | |
L.make_unit_vector(); | |
vec3 intensityDiffuse(1, 1, 1); | |
auto kd = lighting->kd; | |
auto ks = lighting->ks; | |
int n = lighting->n; | |
vec3 R = L - 2 * dot(L, norm) * norm; | |
R.make_unit_vector(); | |
vec3 eye = point - origin; | |
eye.make_unit_vector(); | |
if (dot(L, norm) > 0) | |
{ | |
intensity = intensity + (kd * intensityDiffuse * dot(L, norm)); //diffuse light; | |
intensity = intensity + (ks * intensityDiffuse * pow(max(0.0f, dot(R, eye)), n)); //specular light; | |
} | |
} | |
return intensity; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment