Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- {
- CVec3df s; // s is the light vector
- CVec3df v;// v is the view vector
- double d;// d is distance from point on surface to light source
- s = lightPosition - pointOnSurface;
- d = length(s);
- v = viewPoint - pointOnSurface;
- double ambientReflection = ambientIntensity * ambientReflecCoef; //the ambient Intensity
- double diffuseReflection = diffuseIntensity * diffuseReflecCoef; //the diffuse Intensity
- double specularReflection = specularIntensity * specularReflecCoef; //the specular Intensity
- double distance = kc + kl + pow(kq, 2); //distance from light source
- s.normaliseDestructive();
- v.normaliseDestructive();
- CVec3df h = s + v;
- h.normaliseDestructive();
- double diffuse = diffuseReflection * (double(s.dot(surfaceNormal)) / length(s) * length(surfaceNormal));
- double specular = specularReflection * pow(double(s.dot(h) / length(s) * length(h)), shininess);
- double result = ambientReflection + (diffuse + specular) / distance;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement