首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >光线跟踪器阴影底部较浅的阴影和奇怪的阴影形状

光线跟踪器阴影底部较浅的阴影和奇怪的阴影形状
EN

Stack Overflow用户
提问于 2016-02-29 08:08:25
回答 1查看 234关注 0票数 0

这是用于阴影的代码,尽管为了便于阅读,我将所有代码都放在GitHub的存储库中,this is the main code for the shadows,这是用于sphere-ray intersections的代码,这是用于plane-ray intersections的代码

代码语言:javascript
运行
复制
bool shadowed = false;
Color finalColor = closestObjectColor.Scalar(AMBIENTLIGHT); // Add ambient light to the calculation
for(const auto &lightSource : lightSources)
{
    Vector lightDir = (lightSource->position - intersectionRayPos).Normalize(); // Calculate the directional vector towards the lightSource
    FPType cosineAngle = closestObjectNormal.Dot(lightDir);
    finalColor = finalColor.Scalar(cosineAngle);

    if(cosineAngle > 0)
    {
        Ray shadowRay(intersectionRayPos, (lightSource->position - intersectionRayPos).Normalize()); // Cast a ray from the first intersection to the light

        std::vector<FPType> secondaryIntersections;
        for(const auto &sceneObject : sceneObjects)
        {
            secondaryIntersections.push_back(sceneObject->GetIntersection(shadowRay));
        }

        Vector distanceToLight = lightSource->position + (intersectionRayPos.Negative()).Normalize();
        FPType distanceToLightMagnitude = distanceToLight.Magnitude();

        for(const auto &secondaryIntersection : secondaryIntersections)
        {
            if(secondaryIntersection > TOLERANCE && secondaryIntersection <= distanceToLightMagnitude)
            {
                shadowed = true;
                finalColor = finalColor.Scalar(cosineAngle);
                break;
            }
        }
    }
}
return finalColor.Clip();

问题是我的阴影在底部或阴影的开始处较浅,这在这张图中得到了很好的说明,你也可以看到阴影的奇怪形状,我不确定这是正确的还是不诚实的:

在这里可以观察到相同的效果,并且可以非常明显地看到灰色球体后面的栗色球体上的阴影:

另一个bug是,一个球体前面的阴影以一种不好的方式移动(蓝色球体后面的栗色球体上的阴影):

EN

回答 1

Stack Overflow用户

发布于 2016-03-03 13:17:01

我们用来计算阴影的一种简单方法是:

int hitCount = 0;for (光线中的光线){allLights point2Light = ...object = GetObjectHit(point2Light);if(object == hitCount++) hitCount++;}

float shadowDarkness = (float)hitCount / (float)allLights.count;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35689999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档