|
@@ -8,6 +8,7 @@ struct hit{
|
|
|
Vector3f indir;
|
|
|
Vector3f outdir;
|
|
|
const material& mat;
|
|
|
+ Vector2f uv;
|
|
|
};
|
|
|
std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sampler _rng)const{
|
|
|
using namespace Eigen;
|
|
@@ -55,13 +56,13 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
if(rayhit.hit.geomID != RTC_INVALID_GEOMETRY_ID){
|
|
|
if(sc.emitters.contains(rayhit.hit.geomID)){
|
|
|
|
|
|
- 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>());
|
|
|
+ Eigen::Vector3d transport(sc.added_objects[sc.geom_id_to_object_index_map.find(rayhit.hit.geomID)->second]->mat.tex->eval(Vector2f(0,0)).cast<double>());
|
|
|
for(auto it = hits.rbegin();it != hits.rend();it++){
|
|
|
transport.array() *= (it->mat.m_bsdf->eval(
|
|
|
-it->outdir,
|
|
|
-it->indir,
|
|
|
it->normal
|
|
|
- ).array().cast<double>()) * it->mat.tex->eval(0,0).array().cast<double>();
|
|
|
+ ).array().cast<double>()) * it->mat.tex->eval(it->uv).array().cast<double>();
|
|
|
for(const auto& pl : sc.pointlight){
|
|
|
struct RTCIntersectContext sh_context;
|
|
|
rtcInitIntersectContext(&sh_context);
|
|
@@ -83,7 +84,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
raycasts++;
|
|
|
rtcOccluded1(sc.m_scene, &sh_context, &rsh_ray);
|
|
|
if(rsh_ray.tfar > 0){
|
|
|
- transport.array() += pl.color.cast<double>().array() * it->mat.m_bsdf->eval(-sh_ray.normalized(), it->indir, it->normal).cast<double>().array() * it->mat.tex->eval(0,0).array().cast<double>() * (1.0 / double(sh_ray_length * sh_ray_length));
|
|
|
+ transport.array() += pl.color.cast<double>().array() * it->mat.m_bsdf->eval(-sh_ray.normalized(), it->indir, it->normal).cast<double>().array() * it->mat.tex->eval(it->uv).array().cast<double>() * (1.0 / double(sh_ray_length * sh_ray_length));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -99,12 +100,31 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
if(newdir.dot(hitnormal) <= 0){
|
|
|
newdir *= -1.0f;
|
|
|
}
|
|
|
+ Vector2f uvcoordinate(0,0);
|
|
|
+ {
|
|
|
+ if(auto v = dynamic_cast<mesh_object*>(sc.added_objects[sc.geom_id_to_object_index_map.find(rayhit.hit.geomID)->second].get())){
|
|
|
+ std::array<size_t, 3> triangle_indices;
|
|
|
+ triangle_indices[0] = sc.added_meshes[v->mesh_index].Indices[rayhit.hit.primID * 3 + 0];
|
|
|
+ triangle_indices[1] = sc.added_meshes[v->mesh_index].Indices[rayhit.hit.primID * 3 + 1];
|
|
|
+ triangle_indices[2] = sc.added_meshes[v->mesh_index].Indices[rayhit.hit.primID * 3 + 2];
|
|
|
+ const objl::Vertex& v0 = sc.added_meshes[v->mesh_index].Vertices[triangle_indices[0]];
|
|
|
+ const objl::Vertex& v1 = sc.added_meshes[v->mesh_index].Vertices[triangle_indices[1]];
|
|
|
+ const objl::Vertex& v2 = sc.added_meshes[v->mesh_index].Vertices[triangle_indices[2]];
|
|
|
+ float hu = rayhit.hit.u;
|
|
|
+ float hv = rayhit.hit.v;
|
|
|
+ uvcoordinate =
|
|
|
+ hu * Eigen::Map<const Eigen::Vector2f>(reinterpret_cast<const float*>(&v1.TextureCoordinate)) +
|
|
|
+ hv * Eigen::Map<const Eigen::Vector2f>(reinterpret_cast<const float*>(&v2.TextureCoordinate)) +
|
|
|
+ (1 - hu - hv) * Eigen::Map<const Eigen::Vector2f>(reinterpret_cast<const float*>(&v0.TextureCoordinate));
|
|
|
+ }
|
|
|
+ }
|
|
|
hits.push_back(hit{
|
|
|
Vector3f(rayhit.ray.org_x, rayhit.ray.org_y, rayhit.ray.org_z),
|
|
|
hitnormal,
|
|
|
Vector3f(rayhit.ray.dir_x, rayhit.ray.dir_y, rayhit.ray.dir_z),
|
|
|
newdir,
|
|
|
- (sc.added_objects[sc.geom_id_to_object_index_map.find(rayhit.hit.geomID)->second]->mat)
|
|
|
+ (sc.added_objects[sc.geom_id_to_object_index_map.find(rayhit.hit.geomID)->second]->mat),
|
|
|
+ uvcoordinate
|
|
|
});
|
|
|
transport *= newdir.dot(hitnormal);
|
|
|
rayhit.ray.dir_x = newdir.x();
|
|
@@ -118,7 +138,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
-it->outdir,
|
|
|
-it->indir,
|
|
|
it->normal
|
|
|
- ).array().cast<double>() * it->mat.tex->eval(0,0).array().cast<double>();
|
|
|
+ ).array().cast<double>() * it->mat.tex->eval(it->uv).array().cast<double>();
|
|
|
for(const auto& pl : sc.pointlight){
|
|
|
struct RTCIntersectContext sh_context;
|
|
|
rtcInitIntersectContext(&sh_context);
|
|
@@ -140,7 +160,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
raycasts++;
|
|
|
rtcOccluded1(sc.m_scene, &sh_context, &rsh_ray);
|
|
|
if(rsh_ray.tfar > 0){
|
|
|
- transport.array() += pl.color.cast<double>().array() * it->mat.m_bsdf->eval(-sh_ray.normalized(), it->indir, it->normal).cast<double>().array() * it->mat.tex->eval(0,0).array().cast<double>() * (1.0 / double(sh_ray_length * sh_ray_length));
|
|
|
+ transport.array() += pl.color.cast<double>().array() * it->mat.m_bsdf->eval(-sh_ray.normalized(), it->indir, it->normal).cast<double>().array() * it->mat.tex->eval(it->uv).array().cast<double>() * (1.0 / double(sh_ray_length * sh_ray_length));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -155,7 +175,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
-it->outdir,
|
|
|
-it->indir,
|
|
|
it->normal
|
|
|
- ).array().cast<double>()) * it->mat.tex->eval(0,0).array().cast<double>();
|
|
|
+ ).array().cast<double>()) * it->mat.tex->eval(it->uv).array().cast<double>();
|
|
|
for(const auto& pl : sc.pointlight){
|
|
|
struct RTCIntersectContext sh_context;
|
|
|
rtcInitIntersectContext(&sh_context);
|
|
@@ -177,7 +197,7 @@ std::vector<Eigen::Vector3f> camera::get_image(const scene& sc, size_t n, sample
|
|
|
raycasts++;
|
|
|
rtcOccluded1(sc.m_scene, &sh_context, &rsh_ray);
|
|
|
if(rsh_ray.tfar > 0){
|
|
|
- transport.array() += pl.color.cast<double>().array() * it->mat.m_bsdf->eval(-sh_ray.normalized(), it->indir, it->normal).cast<double>().array() * it->mat.tex->eval(0,0).array().cast<double>() * (1.0 / double(sh_ray_length * sh_ray_length));
|
|
|
+ transport.array() += pl.color.cast<double>().array() * it->mat.m_bsdf->eval(-sh_ray.normalized(), it->indir, it->normal).cast<double>().array() * it->mat.tex->eval(it->uv).array().cast<double>() * (1.0 / double(sh_ray_length * sh_ray_length));
|
|
|
}
|
|
|
}
|
|
|
}
|