光线追踪-运动模糊

光线追踪-运动模糊

第一步

光线的类新增成员变量_time来记录当前时间点

class ray
{
   
    public:
        ray() {
   }
        ray(const vec3& a, const vec3& b, float ti = 0.0) {
    A = a; B = b; _time = ti;}
        vec3 origin() const       {
    return A; }
        vec3 direction() const    {
    return B; }
        float time() const    {
    return _time; }//time的封装函数
        vec3 point_at_parameter(float t) const {
    return A + t*B; }

        vec3 A;
        vec3 B;
        float _time;//这是新增的成员变量——时间
};

第二步

  1. 给原有的camera类中加入float型的成员变量time0和time1作为记录物体运动的时间区间的两个端点。
  2. 并在camera类的构造函数中加入t0和t1两个参数来初始化time0和time1
  3. 在生成光线的方法中,在time0和time1之间随机取一个时间作为当前生成光线的时间点
class camera {
   
    public:
        camera(vec3 lookfrom, vec3 lookat, vec3 vup,
               float vfov /* vfov is top to bottom in degrees */,
               float aspect, float aperture, float focus_dist,
               float t0, float t1) {
   

            time0 = t0;//2
            time1 = t1;//2
            lens_radius = aperture / 2;
            float theta = vfov*M_PI/180;
            float half_height = tan(theta/2);
            float half_width = aspect * half_height;
            origin = lookfrom;
            w = unit_vector(lookfrom - lookat);
            u = unit_vector(cross(vup, w));
            v = cross(w, u);
            lower_left_corner = origin
                              - half_width*focus_dist*u
                              - half_height*focus_dist*v
                              - focus_dist*w;
            horizontal = 2*half_width*focus_dist*u;
            vertical = 2*half_height*focus_dist*v;
        }

        ray get_ray(float s, float t) 
        {
   
            vec3 rd = lens_radius*random_in_unit_disk();
            vec3 offset = u * rd.x() + v * rd.y();
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值