【问题标题】:Raytracer 2D Light Model brokenRaytracer 2D 光照模型损坏
【发布时间】:2014-12-21 06:23:05
【问题描述】:

我正在尝试实现一个用于教育和艺术目的的小型 2d 射线追踪器。 但是我的 lightmodel 代码中似乎有一个错误。

如您所见,该线路的一个站点比另一个站点看起来要亮得多。

这是渲染代码: RENDERING CODE GLSL

我认为原因可能是随机数生成器,但我不放心,也不知道如何证明这一点。

编辑:但有时我会得到很好的结果,如下所示:

我将这段代码用于 Ray Line - Intersection。 Ray Line - Intersection

【问题讨论】:

    标签: glsl raytracing


    【解决方案1】:

    在这里找到代码中的错误:

    public static Vector2? lineSegmentIntersection(Vector2 r0, Vector2 r1, Vector2 a, Vector2 b)
    {
        Vector2 s1, s2;
        s1 = r1; // FOR A RAY IT HAS TO LOOK LIKE THIS !
        s2 = b - a;
    
        float s, t;
        s = (-s1.Y * (r0.X - a.X) + s1.X * (r0.Y - a.Y)) / (-s2.X * s1.Y + s1.X * s2.Y);
        t = (s2.X * (r0.Y - a.Y) - s2.Y * (r0.X - a.X)) / (-s2.X * s1.Y + s1.X * s2.Y);
    
        if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
        {
            // Collision detected
            // Return the point of intersection
            return new Vector2(r0.X + (t * s1.X), r0.Y + (t * s1.Y));
        }
    
        return null; // No collision
    }
    

    【讨论】:

      猜你喜欢
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多