|
@@ -7,6 +7,7 @@ struct hit{
|
|
Vector3f normal;
|
|
Vector3f normal;
|
|
Vector3f indir;
|
|
Vector3f indir;
|
|
Vector3f outdir;
|
|
Vector3f outdir;
|
|
|
|
+ const material& mat;
|
|
};
|
|
};
|
|
std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sampler _rng)const{
|
|
std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sampler _rng)const{
|
|
using namespace Eigen;
|
|
using namespace Eigen;
|
|
@@ -25,8 +26,9 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
for(int i = 0;i < n;i++){
|
|
for(int i = 0;i < n;i++){
|
|
|
|
|
|
Eigen::Vector3d accum(0,0,0);
|
|
Eigen::Vector3d accum(0,0,0);
|
|
-
|
|
|
|
- for(size_t smp = 0;smp < 128;smp++){
|
|
|
|
|
|
+ std::vector<hit> hits;
|
|
|
|
+ hits.reserve(6);
|
|
|
|
+ for(size_t smp = 0;smp < 512;smp++){
|
|
Eigen::Vector3f di = lookray + (left * ((pert_dis(rng.m_rng) + float(i - n2)) / n2 / 1.5)) + realup * ((pert_dis(rng.m_rng) + float(j - n2)) / n2 / 1.5);
|
|
Eigen::Vector3f di = lookray + (left * ((pert_dis(rng.m_rng) + float(i - n2)) / n2 / 1.5)) + realup * ((pert_dis(rng.m_rng) + float(j - n2)) / n2 / 1.5);
|
|
di.normalize();
|
|
di.normalize();
|
|
struct RTCRayHit rayhit;
|
|
struct RTCRayHit rayhit;
|
|
@@ -38,8 +40,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
rayhit.ray.dir_z = di.z();
|
|
rayhit.ray.dir_z = di.z();
|
|
Vector3f hitpos = pos;
|
|
Vector3f hitpos = pos;
|
|
Vector3f transport(1,1,1);
|
|
Vector3f transport(1,1,1);
|
|
- std::vector<hit> hits;
|
|
|
|
- hits.reserve(6);
|
|
|
|
|
|
+ hits.clear();
|
|
for(size_t bounces = 0;bounces < 6;bounces++){
|
|
for(size_t bounces = 0;bounces < 6;bounces++){
|
|
struct RTCIntersectContext context;
|
|
struct RTCIntersectContext context;
|
|
rtcInitIntersectContext(&context);
|
|
rtcInitIntersectContext(&context);
|
|
@@ -53,7 +54,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
raycasts++;
|
|
raycasts++;
|
|
if(rayhit.hit.geomID != RTC_INVALID_GEOMETRY_ID){
|
|
if(rayhit.hit.geomID != RTC_INVALID_GEOMETRY_ID){
|
|
if(sc.emitters.contains(rayhit.hit.geomID)){
|
|
if(sc.emitters.contains(rayhit.hit.geomID)){
|
|
- Eigen::Vector3d transport(0,1,1);
|
|
|
|
|
|
+ Eigen::Vector3d transport(sc.added_objects[sc.geom_id_to_object_index_map.find(rayhit.hit.geomID)->second]->mat.tex->eval(0,0).cast<double>());
|
|
for(auto it = hits.rbegin();it != hits.rend();it++){
|
|
for(auto it = hits.rbegin();it != hits.rend();it++){
|
|
transport.array() *= it->outdir.dot(it->normal);
|
|
transport.array() *= it->outdir.dot(it->normal);
|
|
for(const auto& pl : sc.pointlight){
|
|
for(const auto& pl : sc.pointlight){
|
|
@@ -62,7 +63,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
Vector3f sh_ray(pl.pos - it->pos);
|
|
Vector3f sh_ray(pl.pos - it->pos);
|
|
if(sh_ray.dot(it->normal) < 0)continue;
|
|
if(sh_ray.dot(it->normal) < 0)continue;
|
|
float sh_ray_length = sh_ray.norm();
|
|
float sh_ray_length = sh_ray.norm();
|
|
- sh_ray.normalize();
|
|
|
|
|
|
+ sh_ray /= sh_ray_length;
|
|
RTCRay rsh_ray;
|
|
RTCRay rsh_ray;
|
|
rsh_ray.org_x = it->pos.x();
|
|
rsh_ray.org_x = it->pos.x();
|
|
rsh_ray.org_y = it->pos.y();
|
|
rsh_ray.org_y = it->pos.y();
|
|
@@ -97,7 +98,8 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
Vector3f(rayhit.ray.org_x, rayhit.ray.org_y, rayhit.ray.org_z),
|
|
Vector3f(rayhit.ray.org_x, rayhit.ray.org_y, rayhit.ray.org_z),
|
|
hitnormal,
|
|
hitnormal,
|
|
Vector3f(rayhit.ray.dir_x, rayhit.ray.dir_y, rayhit.ray.dir_z),
|
|
Vector3f(rayhit.ray.dir_x, rayhit.ray.dir_y, rayhit.ray.dir_z),
|
|
- newdir
|
|
|
|
|
|
+ newdir,
|
|
|
|
+ (sc.added_objects[sc.geom_id_to_object_index_map.find(rayhit.hit.geomID)->second]->mat)
|
|
});
|
|
});
|
|
transport *= newdir.dot(hitnormal);
|
|
transport *= newdir.dot(hitnormal);
|
|
rayhit.ray.dir_x = newdir.x();
|
|
rayhit.ray.dir_x = newdir.x();
|
|
@@ -137,10 +139,41 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
goto inner;
|
|
goto inner;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ {
|
|
|
|
+ Eigen::Vector3d transport(0,0,0);
|
|
|
|
+ for(auto it = hits.rbegin();it != hits.rend();it++){
|
|
|
|
+ transport.array() *= it->outdir.dot(it->normal);
|
|
|
|
+ for(const auto& pl : sc.pointlight){
|
|
|
|
+ struct RTCIntersectContext sh_context;
|
|
|
|
+ rtcInitIntersectContext(&sh_context);
|
|
|
|
+ Vector3f sh_ray(pl.pos - it->pos);
|
|
|
|
+ if(sh_ray.dot(it->normal) < 0)continue;
|
|
|
|
+ float sh_ray_length = sh_ray.norm();
|
|
|
|
+ sh_ray.normalize();
|
|
|
|
+ RTCRay rsh_ray;
|
|
|
|
+ rsh_ray.org_x = it->pos.x();
|
|
|
|
+ rsh_ray.org_y = it->pos.y();
|
|
|
|
+ rsh_ray.org_z = it->pos.z();
|
|
|
|
+ rsh_ray.dir_x = sh_ray.x();
|
|
|
|
+ rsh_ray.dir_y = sh_ray.y();
|
|
|
|
+ rsh_ray.dir_z = sh_ray.z();
|
|
|
|
+ rsh_ray.tnear = 0.001f;
|
|
|
|
+ rsh_ray.tfar = sh_ray_length;
|
|
|
|
+ rsh_ray.mask = -1;
|
|
|
|
+ rsh_ray.flags = 0;
|
|
|
|
+ raycasts++;
|
|
|
|
+ rtcOccluded1(sc.m_scene, &sh_context, &rsh_ray);
|
|
|
|
+ if(rsh_ray.tfar > 0){
|
|
|
|
+ transport += pl.color.cast<double>() * std::abs(sh_ray.dot(it->normal)) * 1 / (sh_ray_length * sh_ray_length);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ accum += transport;
|
|
|
|
+ }
|
|
inner:
|
|
inner:
|
|
(void)0;
|
|
(void)0;
|
|
}
|
|
}
|
|
- img[j * n + i] = (accum.cast<float>() / 32.0f).array().pow(0.5f).matrix();
|
|
|
|
|
|
+ img[j * n + i] = (accum.cast<float>() / 512.0f).array().pow(0.5f).matrix();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|