标签: raytracing

光线追踪 / Phong

我不知道像 Phong 或 Gouraud 这样的光线追踪和着色技术之间的区别。

对于 3D 建模,必须在这些算法之间进行选择,或者它们可以在同一算法中实现。

谢谢你。

raytracing

2
推荐指数
1
解决办法
6717
查看次数

光线追踪 - 柔和的阴影

我正在实施我自己的光线追踪器作为学校项目的iPad应用程序.目前这是结果:

在此输入图像描述

我需要添加最后一个要求,软阴影,但我无法在任何地方找到完整的参考.如果我理解得很好,为了实现这个功能,我必须从交叉点射击许多光线到光源.这一个必须是区域灯.假设我使用了一个球体,我的问题是:

  • 在球体上哪个点我必须用来计算阴影射线?
  • 我如何平均结果?

3d raytracing shadow

2
推荐指数
1
解决办法
3760
查看次数

Raytracer : 高 FOV 失真

我实际上正在实现一个 C++ 光线追踪器,但我正面临着一个关于光线追踪的经典问题。当放置高垂直 FOV 时,形状离边缘越近,变形越大。

我知道为什么会发生这种失真,但我不知道如何解决它(当然,减少 FOV 是一种选择,但我认为我的代码中有一些需要更改的地方)。我一直在浏览不同的计算论坛,但没有找到任何解决方法。

这是一个屏幕截图来说明我的问题。

球体边缘失真

我认为问题在于我投射光线的视平面实际上并不平坦,但我不知道如何解决这个问题。如果您有任何解决问题的技巧,我愿意接受建议。

我在一个面向右手的系统上。相机系统向量、方向向量和光向量被归一化。

如果你需要一些代码来检查某些东西,我会把它放在你问的部分的答案中。

射线生成代码:

        // PixelScreenX = (pixelx + 0.5) / imageWidth
        // PixelCameraX = (2 ? PixelScreenx ? 1) ?
        //      ImageAspectRatio ? tan(fov / 2)
        float x = (2 * (i + 0.5f) / (float)options.width - 1) *
                options.imageAspectRatio * options.scale;

        // PixelScreeny = (pixely + 0.5) / imageHeight
        // PixelCameraY = (1 ? 2 ? PixelScreeny) ? tan(fov / 2)
        float y = (1 - 2 * (j …
Run Code Online (Sandbox Code Playgroud)

c++ geometry raytracing

2
推荐指数
1
解决办法
1428
查看次数

在 Python 光线追踪相机中实现视锥体剔除

我正在使用 Python 进行光线追踪项目,并且遇到了性能瓶颈。我相信在我的 Camera 类中实现视锥体剔除可以显着缩短渲染时间。

相机:

class Camera():
    def __init__(self, look_from, look_at, screen_width = 400 ,screen_height = 300,  field_of_view = 90., aperture = 0., focal_distance = 1.):
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.aspect_ratio = float(screen_width) / screen_height
        self.look_from = look_from
        self.look_at = look_at
        self.camera_width = np.tan(field_of_view * np.pi/180   /2.)*2.
        self.camera_height = self.camera_width/self.aspect_ratio
        self.cameraFwd = (look_at - look_from).normalize()
        self.cameraRight = (self.cameraFwd.cross(vec3(0.,1.,0.))).normalize()
        self.cameraUp = self.cameraRight.cross(self.cameraFwd)
        self.lens_radius =  aperture / 2.
        self.focal_distance = focal_distance
        self.x = np.linspace(-self.camera_width/2., self.camera_width/2., self.screen_width)
        self.y = np.linspace(self.camera_height/2., …
Run Code Online (Sandbox Code Playgroud)

python raytracing

2
推荐指数
1
解决办法
60
查看次数

导出类对象丢失vfptr的指针

首先,我试着写一个普通的,简单的Ray Tracer.在我的Ray Tracer中,我在世界上有多种类型的几何,都来自一个名为"SceneObject"的基类.我在这里列出了它的标题.

/**
Interface for all objects that will appear in a scene
*/
class SceneObject
{
public:
 mat4 M, M_inv;
 Color c;

 SceneObject();
 ~SceneObject();

 /**
 The transformation matrix to be applied to all points
 of this object.  Identity leaves the object in world frame.
 */
 void setMatrix(mat4 M);
 void setMatrix(MatrixStack mStack);
 void getMatrix(mat4& M);

 /**
 The color of the object
 */
 void setColor(Color c);
 void getColor(Color& c);

 /**
 Alter one portion of the color, leaving
 the rest as …
Run Code Online (Sandbox Code Playgroud)

c++ virtual-functions raytracing

1
推荐指数
1
解决办法
2583
查看次数

多线程光线跟踪器的噪音

这是我的第一个多线程实现,所以这可能是初学者的错误.线程处理每隔一行像素的渲染(因此所有渲染都在每个线程内处理).如果线程分别渲染屏幕的上部和下部,则问题仍然存在.

两个线程从相同的变量读取,这会导致任何问题吗?据我所知,只有写作才会导致并发问题......

可以调用相同的函数导致任何并发问题吗?而且,从我的理解,这应该不是一个问题......

两个线程写入同一变量的唯一时间是保存计算的像素颜色.它存储在一个数组中,但它们永远不会写入该数组中的相同索引.这会导致问题吗?

多线程渲染图像 (垃圾邮件防止阻止我直接发布图像..)

PS.我在两种情况下使用完全相同的实现,唯一的区别是为渲染创建的单个线程与两个线程.

c++ multithreading raytracing thread-safety

1
推荐指数
1
解决办法
796
查看次数

相同浮点计算的结果不同

在我正在进行的光线追踪分配中,我将计算从相机拍摄的光线的X偏移量; 偏移计算是这样的

FovY作为输入; 我在读取变量的那一刻就把它转换成弧度.

OffsetX = tan (FovX / 2) * ((col - (width / 2)) / (width / 2))

FovX = tan(FovY / 2) * aspect = tan(FovY / 2) * (width / height)

替换原始等式并编写代码:

float OffsetX = tan(FovY / 2.0f) * (width / height) * ((col - (width / 2.0f)) / (width / 2.0f));
Run Code Online (Sandbox Code Playgroud)

给了我一个不正确的拉伸图像,我花了好几个小时才把它弄好,这是在发现简化它之后同样的方程式之后.

最终重新排列的等式是:

float OffsetX = tan(FovY / 2.0f) * (2.0f / height) * (col - (width / 2.0f));
Run Code Online (Sandbox Code Playgroud)

我试过调试,两个方程的结果确实不同.

会有某种圆整错误吗?有人可以向我解释这个怪癖吗?

#include <cmath>
#include …
Run Code Online (Sandbox Code Playgroud)

c++ floating-point graphics raytracing

1
推荐指数
1
解决办法
230
查看次数

错误 C2666 类似的重载

我正在开发一个光线追踪项目。所以,我有很多向量操作。对于产品操作,我使用了运算符重载,遇到了一个问题。您可以在下面查看详细信息:

这些函数在一个名为 RayMath.h

//GENERAL INLINES
inline Vector operator*( float c, const Vector& v){ return v * c;   } //Func1
inline Vector operator*( const Vector& v1, Vector& v2 ) { return Vector( v1.x * v2.x, v1.y * v2.y, v1.z * v2.z ); } //Func 2
Run Code Online (Sandbox Code Playgroud)

如果我添加Func 2,它会C2666, more than one operator为使用Func1. 如果我不添加Func 2,则会出现no operator matches错误。下面是使用示例:

这些行在一个.cpp名为Renderer.cpp

Vector R = ray.direction - 2.f * Dot( ray.direction, N ) * …
Run Code Online (Sandbox Code Playgroud)

c++ raytracing operator-overloading

1
推荐指数
1
解决办法
637
查看次数

射线追踪噪音

我想知道有光线追踪经验的人是否可以帮助我找出我的程序中的一些问题,但是我不能发布很多代码,因为这个程序是学校作业.我只是想知道我是否能得到一些有助于引导我朝正确方向前进的技巧.所以提前谢谢!

首先)如您所见,我的光线追踪图像中有大量噪音.场景由悬停在平面上的单个三角形组成.还存在单个点光源.

第二)当我计算阴影射线时不会发生噪声,但它会为阴影计算错误的颜色.

我的光线追踪算法:

for each pixel,
    color c;
    for each shape in the scene
        send a ray through each pixel and see if it collides with a shape
        if it does
            color = calculate color of ray
        else, color = background color
    return color

To calculate color of ray...
    color c = 0,0,0 // rgb
    for each light source in the scene
        make a new ray (shad_ray) that starts at where the original ray hit the shape...
        ... and …
Run Code Online (Sandbox Code Playgroud)

graphics raytracing

1
推荐指数
1
解决办法
1868
查看次数

如何与C#统一进行实时光线跟踪

我正在制作一个统一的视频游戏,并决定使用光线跟踪.我有代码,但正如你将在一秒钟内看到的那样.它不是一帧一帧地渲染.这是我的光线跟踪代码,这是附加到主摄像头的主要脚本.

using UnityEngine;
using System.Collections;

public class RayTracer : MonoBehaviour
{

    public Color backgroundColor = Color.black;
    public float RenderResolution = 1f;
    public float maxDist = 100f;
    public int maxRecursion = 4;


    private Light[] lights;
    private Texture2D renderTexture;

    void Awake()
    {
        renderTexture = new Texture2D((int)(Screen.width * RenderResolution), (int)(Screen.height * RenderResolution));
        lights = FindObjectsOfType(typeof(Light)) as Light[];
    }

    void Start()
    {
        RayTrace();
    }

    void OnGUI()
    {
        GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), renderTexture);
    }

    void RayTrace()
    {
        for (int x = 0; x < …
Run Code Online (Sandbox Code Playgroud)

c# raytracing unity-game-engine

1
推荐指数
1
解决办法
9493
查看次数