Advertisement
Guest User

Untitled

a guest
May 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. double phongIlluminationAchromatic(double ambientIntensity, double diffuseIntensity, double specularIntensity,double ambientReflecCoef, double diffuseReflecCoef, double specularReflecCoef,double shininess,double kc, double kl, double kq,CVec3df pointOnSurface, CVec3df surfaceNormal, CVec3df lightPosition, CVec3df viewPoint)
  2. {
  3.     CVec3df s; // s is the light vector
  4.     CVec3df v;// v is the view vector
  5.     double d;// d is distance from point on surface to light source
  6.  
  7.     s = lightPosition - pointOnSurface;
  8.     d = length(s);
  9.     v = viewPoint - pointOnSurface;
  10.  
  11.     double ambientReflection = ambientIntensity * ambientReflecCoef; //the ambient Intensity
  12.     double diffuseReflection = diffuseIntensity * diffuseReflecCoef; //the diffuse Intensity
  13.     double specularReflection = specularIntensity * specularReflecCoef; //the specular Intensity
  14.     double distance = kc + kl + pow(kq, 2); //distance from light source
  15.    
  16.     s.normaliseDestructive();
  17.     v.normaliseDestructive();
  18.     CVec3df h = s + v;
  19.     h.normaliseDestructive();
  20.    
  21.     double diffuse = diffuseReflection * (double(s.dot(surfaceNormal)) / length(s) * length(surfaceNormal));
  22.     double specular = specularReflection * pow(double(s.dot(h) / length(s) * length(h)), shininess);
  23.    
  24.     double result = ambientReflection + (diffuse + specular) / distance;
  25.    
  26.     return result;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement