Ray Tracing—运动模糊(MotionBlur)

MotionBlur
• 运动模糊是景物图象中的移动效果。它比较明显地出现在长时间暴光或场景内的物体快速移动的情形里。
• 为什么会出现运动模糊
摄影机的工作原理是在很短的时间里把场景在胶片上暴光。场景中的光线投射在胶片上,引起化学反应,最终产生图片。这就是暴光。如果在暴光的过程中,场景发生变化,则就会产生模糊的画面。

实现步骤:(c#实现)

1.在Ray.class中加入time变量

2.调整camera 类加入变量 time1 和 time2,生成一个在time1 和 time2之间的随机数,作为Ray中的time参数

3.添加Moving_sphere类,定义产生运动模糊的球体,time0时球心在center0,
time1时球心在center1, 根据公式center0 +
((time - time0) / (time1 - time0))*(center1 - center0)生成一个点,作为产生运动模糊球体跟光线求交点时的球心

4.在world类的BuildTestScene()方法中将材质为diffuse的球体定义为产生运动模糊的球体

5.在Form2中更新camera的定义:

Camera cam = new Camera(
                new Point3D(11, 4, 1),
                new Point3D(0, 0, 0),
                new Vector3D(0, 1, 0),
                40, (double)nx / (double)ny,
                 0, 1);

主要代码:
Moving_sphere.cs

class Moving_sphere: GeometryObject
{
    
    
        Point3D center0, center1;
        double time0, time1;
        double radius; 
        public Point3D Center0 {
    
     get => center0; set => center0 = value; }
        public Point3D Center1 {
    
     get => center1; set => center1 = value; }
        public double Time0 {
    
     get => time0; set => time0 = value; }
        public double Time1 {
    
     get => time1; set => time1 = value; }
        public double Radius {
    
     get => radius; set => radius = value; }
        public Moving_sphere(){
    
    }
        public Moving_sphere(Point3D cen0, Point3D cen1, double t0, double t1, double r)
        {
    
    
            Center0 = cen0;
            Center1 = cen1;
            Time0 = t0;
            Time1 = t1;
            Radius = r;        
        }
        public Point3D center(float time)
        {
    
    return Center0 + ((time - Time0) / (Time1 - Time0)) * (Center1 - Center0);}

World.cs

//diffuse
 Moving_sphere spDiffuse = new Moving_sphere(center, center + new Vector3D(0, 0.5 * random(), 0), 0.0, 1.0, 0.25);
 Lambert lam = new Lambert(new SColor(
                                random() * random(), 
                                random() * random(), 
                                random() * random()));
spDiffuse.GloMaterial = lam;
this.AddGeoObj(spDiffuse);

最终效果图:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/sunshine543123/article/details/106716457