<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      【Ray Tracing The Next Week 超詳解】 光線追蹤2-8 Volume

       

       Preface

      今天有兩個東東,一個是體積煙霧,一個是封面圖

      下一篇我們總結項目代碼

       

      Chapter 8:Volumes

      我們需要為我們的光線追蹤器添加新的物體——煙、霧,也稱為participating media。 我們還需要補充一個材質——次表面散射材質,它有點像物體內的濃霧。

      體渲染通常的做法是,在體的內部有很多隨機表面,來實現散射的效果。比如一束煙可以表示為,在這束煙的內部任意位置,都可以存在一個面,以此來實現煙、霧

       

      對于一個恒定密度體,一條光線通過其中的時候,在煙霧體中傳播的時候也會發生散射,光線在煙霧體中能傳播多遠,也是由煙霧體的密度決定的,密度越高,光線穿透性越差,光線傳播的距離也越短。從而實現煙霧的透光性。

      引用書中一張圖(光線可穿透可散射)

      當光線通過體積時,它可能在任何點散射。 光線在任何小距離dL中散射的概率為:

      概率= C * dL,其中C與體積的光密度成比例。

      對于恒定體積,我們只需要密度C和邊界。 

       

      /// isotropic.hpp
      
      // -----------------------------------------------------
      // [author]        lv
      // [begin ]        2019.1
      // [brief ]        the isotropic-class for the ray-tracing project
      //                from the 《ray tracing the next week》
      // -----------------------------------------------------
      
      #pragma once
      
      
      namespace rt
      {
      
      class isotropic :public material
          {
      public:
          isotropic(texture* tex) :_albedo(tex) {  }
      
          virtual bool scatter(const ray& InRay, const hitInfo& info, rtvec& attenuation, ray& scattered)const override
              {
              scattered = ray(info._p, lvgm::random_unit_sphere());
              attenuation = _albedo->value(info._u, info._v, info._p);
              return true;
              }
      
      private:
          texture * _albedo;
          };
      
      } // rt namespace

       

      這個材質的散射原理和漫反射磨砂材質的大同小異,均屬于碰撞點轉換為新視點,沿任意方向發射新的視線,只不過漫反射的視線方向向量指向外相切球體表面,而isotropic的視線方向指向以碰撞點為球心的單位球體表面

      區別就在于

      漫反射的散射光線不可能指到物體內部,它一定是散射到表面外部(視線方向指向外切球體表面)

      isotropic材質的散射光線可以沿原來的方向一往前,以此視線透光性

      因為煙霧內部只是顆粒而不存在真正不可穿透的幾何實體,所以漫反射實體不可穿透,只能散射到表面外部,而煙霧可穿透

       

      接下來我們看一下煙霧體

      /// constant_medium.hpp
      
      // -----------------------------------------------------
      // [author]        lv
      // [begin ]        2019.1
      // [brief ]        the constant_dedium-class for the ray-tracing project
      //                from the 《ray tracing the next week》
      // -----------------------------------------------------
      
      
      #pragma once
      
      namespace rt
      {
      
      class constant_medium :public intersect
          {
      public:
          constant_medium(intersect* p, rtvar d, texture* tex);
      
          virtual bool hit(const ray& sight, rtvar t_min, rtvar t_max, hitInfo& info)const override;
      
          virtual aabb getbox()const override;
      
      private:
          intersect* _item;
      
          rtvar _density;    //煙霧密度
      
          material* _materialp;
          };
      
      
      
      inline constant_medium::constant_medium(intersect* p, rtvar d, texture* tex)
          :_item(p)
          ,_density(d)
          ,_materialp(new isotropic(tex))
          {
          }
      
      aabb constant_medium::getbox()const
          {
          return _item->getbox();
          }
      
      bool constant_medium::hit(const ray& sight, rtvar t_min, rtvar t_max, hitInfo& info)const 
          {
          hitInfo info1, info2;
          if (_item->hit(sight, -rtInf(), rtInf(), info1)) {
              if (_item->hit(sight, info1._t + 0.0001, rtInf(), info2)) {
                  if (info1._t < t_min)
                      info1._t = t_min;
                  if (info2._t > t_max)
                      info2._t = t_max;
                  if (info1._t >= info2._t)
                      return false;
                  if (info1._t < 0)
                      info1._t = 0;
                  float distance_inside_boundary = (info2._t - info1._t)*sight.direction().normal();
                  float hit_distance = -(1 / _density)*log(lvgm::rand01());
                  if (hit_distance < distance_inside_boundary) {
                      info._t = info1._t + hit_distance / sight.direction().normal();
                      info._p = sight.go(info._t);
                      info._n = rtvec(1, 0, 0);  // arbitrary
                      info._materialp = _materialp;
                      return true;
                      }
                  }
              }
          return false;
          }
      
      } // rt namespace

       

       

      hit函數里面是一些邊界合法性檢測

       

      場景測試代碼

      intersect* cornell_smoke()
      {
          intersect ** list = new intersect*[9];
      
          int cnt = 0;
          material* red = new lambertian(new constant_texture(rtvec(0.65, 0.05, 0.05)));
          material * blue = new lambertian(new constant_texture(rtvec(0.05, 0.05, 0.73)));
          material* white = new lambertian(new constant_texture(rtvec(0.73, 0.73, 0.73)));
          material* green = new lambertian(new constant_texture(rtvec(0.12, 0.45, 0.15)));
          material* light = new areaLight(new constant_texture(rtvec(7, 7, 7)));
      
          list[cnt++] = new xz_rect(113, 443, 127, 432, 550, light);
          list[cnt++] = new flip_normal(new xz_rect(113, 443, 127, 432, 550, light));
          list[cnt++] = new flip_normal(new yz_rect(0, 555, 0, 555, 555, green));
          list[cnt++] = new yz_rect(0, 555, 0, 555, 0, red);
          list[cnt++] = new flip_normal(new xz_rect(0, 555, 0, 555, 555, white));
          list[cnt++] = new xz_rect(0, 555, 0, 555, 0, white);
          list[cnt++] = new flip_normal(new xy_rect(0, 555, 0, 555, 555, blue));
      
          intersect* box1 = new translate(new rotate_y(new box(rtvec(), rtvec(165, 165, 165), white), -18), rtvec(130, 0, 65));
          intersect* box2 = new translate(new rotate_y(new box(rtvec(), rtvec(165, 320, 165), white), 15), rtvec(265, 0, 295));
      
          list[cnt++] = new constant_medium(box2, 0.006, new constant_texture(rtvec(0.8, 0.58, 0.)));
          list[cnt++] = new constant_medium(box1, 0.008, new constant_texture(rtvec(0.9, 0.2, 0.72)));
      
          return new intersections(list, cnt);
      }

       

      下面是效果:sample -> 1000

       

      注釋 // arbitrary處為隨機方向,之前為(1,0,0)

      我覺得改為(rand01(),rand01(),rand01())較為合適,下面是改之后的效果

       

      Chapter 9:A Scene Testing All New Features

      最后的封面圖是這樣一個場景:

      體積霧:有一個藍色的次表面散射球體,但是這個東西并沒有單獨實現,而是把它包裹在了一個玻璃球內。

      體積霧:整個場景是由層薄薄的霧氣籠蓋著的

      長方體:地面是一堆隨機長方體

      玻璃球:一個作為藍色煙霧的容器,一個是單純的玻璃球

      映射紋理:地球紋理球體

      過程紋理:柏林噪聲紋理球體

      運動模糊球體:有一個棕色的運動球體

      鏡面球體:銀白色的鏡面球

      區域光照:頂部是一個長方形的區域光源

      其他未說明材質的都是漫反射

      渲染器中剩下的最大缺陷是沒有陰影射線,但這就是為什么我們容易獲得焦散和次表面散射效果的原因。

       

      下面是渲染代碼,關于相機參數設置還需等待渲染結果出來才能公布

      VS四開,渲染了一天還沒完,我也實屬無奈

       

      intersect* finalScene()
      {
          int nb = 20;
          intersect ** list = new intersect*[30];
          intersect ** boxlist = new intersect*[2000];
          intersect ** boxlist2 = new intersect*[2000];
          
          material * white = new lambertian(new constant_texture(rtvec(0.73, 0.73, 0.73)));
          material * ground = new lambertian(new constant_texture(rtvec(0.48, 0.83, 0.53)));
      
          int b = 0;
          for (int i = 0; i < nb; ++i)
              for (int j = 0; j < nb; ++j)
              {
                  rtvar w = 100;
                  rtvar x0 = -1000 + i*w;
                  rtvar z0 = -1000 + j*w;
                  rtvar y0 = 0;
                  rtvar x1 = x0 + w;
                  rtvar y1 = 100 * (lvgm::rand01() + 0.01);
                  rtvar z1 = z0 + w;
                  boxlist[b++] = new box(rtvec(x0, y0, z0), rtvec(x1, y1, z1), ground);
              }
      
          int l = 0;
          list[l++] = new bvh_node(boxlist, b, 0, 1);
          material * light = new areaLight(new constant_texture(rtvec(10, 10, 10)));
          list[l++] = new xz_rect(123, 423, 147, 412, 550, light);
          rtvec center(400, 400, 200);
          list[l++] = new moving_sphere(center, center + rtvec(30, 0, 0), 0, 1, 50, new lambertian(new constant_texture(rtvec(0.7, 0.3, 0.1))));
          list[l++] = new sphere(rtvec(260, 150, 45), 50, new dielectric(1.5));
          list[l++] = new sphere(rtvec(0, 150, 145), 50, new metal(new constant_texture(rtvec(0.8, 0.8, 0.9)), 10.0));
              
          intersect * boundary = new sphere(rtvec(360, 150, 145), 70, new dielectric(1.5));
          list[l++] = boundary;
          list[l++] = new constant_medium(boundary, 0.2, new constant_texture(rtvec(0.2, 0.4, 0.9)));
          boundary = new sphere(rtvec(), 5000, new dielectric(1.5));
          list[l++] = new constant_medium(boundary, 0.0011, new constant_texture(rtvec(1., 1., 1.)));
          
          int x, y, n;
          unsigned char * tex = stbi_load("earthmap.jpg", &x, &y, &n, 0);
          material * emat = new lambertian(new image_texture(tex, x, y));
          list[l++] = new sphere(rtvec(400, 200, 400), 100, emat);
          texture * pertext = new noise_texture(0.1);
          list[l++] = new sphere(rtvec(220, 280, 300), 80, new lambertian(pertext));
          int ns = 1000;
          for (int j = 0; j < ns; ++j)
              boxlist2[j] = new sphere(rtvec(165 * lvgm::rand01(), 165 * lvgm::rand01(), lvgm::rand01()), 10, white);
      
          list[l++] = new translate(new rotate_y(new bvh_node(boxlist2, ns, 0, 1), 15), rtvec(-100, 270, 395));
      
          return new intersections(list, l);
      }

       

      /-----------------------更新線-------------------------------/

      對應的相機參數

       

       

      效果

      其中,薄霧效果太重了,霧氣參數應該小一點,大約在1e-4左右較好

      vfov可能太大了,45°應該更好一點吧

      鏡頭應該更靠近些

       

      感謝您的閱讀,生活愉快~

       

      posted @ 2019-01-25 20:59  林-兮  閱讀(1789)  評論(5)    收藏  舉報
      主站蜘蛛池模板: 国产精品久久蜜臀av| 欧美熟妇乱子伦XX视频| 欧美乱妇高清无乱码免费| 国产成人午夜福利在线播放| 亚洲欧美综合中文| 无码A级毛片免费视频下载| 亚洲无线看天堂av| 中文字幕人妻中出制服诱惑| 亚洲狠狠婷婷综合久久久| 日韩欧美人妻一区二区三区| 91精品国产色综合久久不| 美女无遮挡免费视频网站| 精品国产精品中文字幕| 久久精品蜜芽亚洲国产av| 99久久久国产精品消防器材| 国产精品久久人妻无码网站一区| 蜜臀av久久国产午夜福利软件| 少妇人妻综合久久中文字幕| 淳化县| 亚洲乱码日产精品一二三| 亚洲精品国模一区二区| 热99久久这里只有精品| 日韩av中文字幕有码| 高清无码爆乳潮喷在线观看| 午夜激情小视频一区二区| 熟女人妻aⅴ一区二区三区电影| av一区二区中文字幕| 国产亚洲精品AA片在线播放天| 精品人妻av区乱码| 亚洲av中文一区二区| 天堂网亚洲综合在线| 亚洲综合一区二区三区不卡| 小污女小欲女导航| 国产精品视频一区二区三区不卡| 色94色欧美sute亚洲线路二| 爱性久久久久久久久| 性欧美VIDEOFREE高清大喷水| 东京热人妻无码一区二区av| 天堂资源在线| 亚洲男人天堂2021| 亚洲男人第一无码av网|