gpt4 book ai didi

java - 球体光线追踪 - 镜面高光

转载 作者:行者123 更新时间:2023-11-30 08:31:37 25 4
gpt4 key购买 nike

我在为我的球体设置正确的光照模型时遇到了一些问题。具体来说,我无法正确获得球体的镜面高光。这是我在光线追踪球体时看到的:
Wrong specular highlights

现在,镜面高光看起来应该更像这样:
Correct specular highlights

据我了解,照明模型(对于这些漫射球体)如下所示:
Lighting model

其中cr是球体的颜色,ca是光的环境分量,cl是球体的颜色光,n是球体交点处的法线,l是光的方向,cp是颜色镜面反射高光,e是eye/Look From,r是球体表面的反射 vector ,指数中的p是指到 phong 常数/指数(光线有多紧/多松)。

这是我的过程:

public Color calculateIlluminationModel(Vector normal, Scene scene)
{
//c = cr * ca + cr * cl * max(0, n \dot l)) + cl * cp * max(0, e \dot r)^p
Vector lightSourceColor = getColorVector(scene.getLight().getLightColor()); //cl
Vector diffuseReflectanceColor = getColorVector(getMaterialColor()); //cr
Vector ambientColor = getColorVector(scene.getLight().getAmbientLightColor()); //ca
Vector specularHighlightColor = getColorVector(getSpecularHighlight()); //cp
Vector directionToLight = scene.getLight().getDirectionToLight(); //l
Vector reflectionVector = normal.multiply(2).multiply(normal.crossProduct(directionToLight)).subtract(directionToLight); //r = 2n(n \dot l) - l

Vector ambientTerm = diffuseReflectanceColor.multiply(ambientColor);
double angleBetweenLightAndNormal = directionToLight.dotProduct(normal);
Vector diffuseTerm = diffuseReflectanceColor.multiply(lightSourceColor).multiply(Math.max(0, angleBetweenLightAndNormal));
Vector phongTerm = lightSourceColor.multiply(specularHighlightColor).multiply(Math.pow(Math.max(0, scene.getCameraSettings().getLookFrom().dotProduct(reflectionVector)), (double) getPhongConstant()));
return getVectorColor(ambientTerm.add(diffuseTerm).add(phongTerm));
}

请注意,在这种情况下,phong 项的眼睛分量是相机的视角,即 (0, 0, 1),光线的方向是 (1, 0, 0)。

知道为什么我的镜面反射高光位于球体顶部而不是面向光的方向吗?

如果我泄露了您需要帮助我的任何重要细节,请告诉我。

最佳答案

应该根据表面法线和入射光线方向计算反射 vector ,而不是像现在这样根据光线方向。

关于java - 球体光线追踪 - 镜面高光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40569883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com