2
我認爲這些應該是循環的。我認爲我的法線有問題,但我沒有發現他們有什麼問題。再次,爲法線找到一個好的測試是困難的。爲什麼我的鏡面高光橢圓?
下面是每個光我的陰影代碼,而忽略了對反射遞歸部分:
lighting = (hit.obj.ambient + hit.obj.emission);
const glm::vec3 view_direction = glm::normalize(eye - hit.pos);
const glm::vec3 reflection = glm::normalize((static_cast<float>(2) * (glm::dot(view_direction, hit.normal) * hit.normal)) - view_direction);
for(int i = 0; i < numused; ++i)
{
glm::vec3 hit_to_light = (lights[i].pos - hit.pos);
float dist = glm::length(hit_to_light);
glm::vec3 light_direction = glm::normalize(hit_to_light);
Ray lightray(hit.pos, light_direction);
Intersection blocked = Intersect(lightray, scene, verbose ? verbose : false);
if(blocked.dist >= dist)
{
glm::vec3 halfangle = glm::normalize(view_direction + light_direction);
float specular_multiplier = pow(std::max(glm::dot(halfangle,hit.normal), 0.f), shininess);
glm::vec3 attenuation_term = lights[i].rgb * (1.0f/(attenuation + dist * linear + dist*dist * quad));
glm::vec3 diffuse_term = hit.obj.diffuse * (std::max(glm::dot(light_direction,hit.normal) , 0.f));
glm::vec3 specular_term = hit.obj.specular * specular_multiplier;
}
}
,這裏是哪裏變換對象空間正常行對於世界空間:
*norm = glm::normalize(transinv * glm::vec4(glm::normalize(p - sphere_center), 0));
使用完整的Phong模型,而不是布林 - 海防,我得到淚滴亮點:
如果根據(的絕對值)在交叉點得到以下圖像(R = X,G = Y,B = Z)正常的I彩色像素:
如何你改變你的法線?既然你可能從球體開始並且非均勻地縮放它們,你需要使用轉置逆而不是正則轉換矩陣(參見[這個問題])(https://math.stackexchange.com/questions/924659/transformation-of -a-surface-normal)更多詳細信息) –
我確實使用了transpose inverse來轉換法線,我使用'glm :: transpose(glm :: inverse(object_transform))'所以我不認爲矩陣計算錯誤。爲了防止出現問題,我會將正常轉換線添加到此問題中。 – user393454
雖然它可能還不是完整的解決方案,但是您是否嘗試從Blinn-Phong模型(僅爲近似值)轉換到完整的Phong模型,即用'dot(reflection,light_direction)替換'dot(halfangle,normal)' )'? –