0

我正在尝试在这个cpp 框架中实现 phong 闪电模型。

扩散效果很好,但镜面反射似乎照亮了球体的角落……我不太确定为什么,因为公式似乎是正确的。有人有想法吗?

实际输出:

在此处输入图像描述

我的代码如下所示:

Material *material = obj->material;            //the hit objects material
Point hit = ray.at(min_t);                     //the hit point
Vector N = obj->normal(hit);                   //the normal at hit point
Vector V = -ray.D;                             //the view vector

Color color = material->color;
double colorFactor = material->ka;

for( size_t i = 0; i < numLights ; ++i)
{
    Vector lightsVector = hit - lights[i]->position;
    lightsVector.normalize();
    Vector vectorReflection = (2*(N.dot(lightsVector))*N) - lightsVector;
    vectorReflection.normalize();
    double diffusion = std::max<double>(0.0,-material->kd*(lightsVector.dot(N)));
    double specular =  material->ks*pow(std::max<double>(0.0,vectorReflection.dot(V.normalized())),material->n);
    std::cout << specular << std::endl;
    colorFactor +=  diffusion + specular;
}
color *=colorFactor;

我非常感谢你能给我的任何提示......

4

0 回答 0