multisampled random rays

This commit is contained in:
2019-01-12 23:37:54 +01:00
parent 6b0dc38ee4
commit c3220b5b15
3 changed files with 32 additions and 28 deletions

View File

@@ -133,8 +133,9 @@ void NodePanelGrid::init_controls()
m_groud_opacity->set_value(0);
gl.restore();
};
m_texture.create(2048, 2048);
m_sampler_linear.create(GL_NEAREST);
m_texture.create(1024, 1024);
m_sampler_linear.create();
m_sampler_linear.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
m_sphere.create<8, 8>(.0001f);
}
@@ -297,35 +298,34 @@ void NodePanelGrid::bake_uvs()
auto pos = glm::make_vec3(&data_pos[i * 4]);
auto& out = *reinterpret_cast<glm::i8vec4*>(&data_out[i * 4]);
if (glm::dot(nor, light_dir) <= 0.f)
{
out = { 50, 50, 50, 255 };
continue;
}
// if (glm::dot(nor, light_dir) <= 0.f)
// {
// out = { 50, 50, 50, 255 };
// continue;
// }
nanort::Ray<float> ray;
ray.org[0] = pos.x;// + nor.x * 0.005;
ray.org[1] = pos.y;// + nor.y * 0.005;
ray.org[2] = pos.z;// + nor.z * 0.005;
ray.dir[0] = light_dir.x;
ray.dir[1] = light_dir.y;
ray.dir[2] = light_dir.z;
float kFar = 20.0;
ray.min_t = 0.01f;
ray.max_t = kFar;
nanort::TriangleIntersector<> triangle_intersector(reinterpret_cast<float*>(m_hm_plane.vertices.data()), m_hm_plane.idx.data(), sizeof(vertex_t));
nanort::TriangleIntersection<> isect;
bool hit = m_rt_accel.Traverse(ray, triangle_intersector, &isect);
if (hit)
int hit = 0;
for (int s = 0; s < 16; s++)
{
out = { 50, 50, 50, 255 };
}
else
{
out = { 255, 255, 255, 255 };
auto dir = glm::normalize(light_dir + glm::sphericalRand(.1f));
nanort::Ray<float> ray;
ray.org[0] = pos.x;// + nor.x * 0.005;
ray.org[1] = pos.y;// + nor.y * 0.005;
ray.org[2] = pos.z;// + nor.z * 0.005;
ray.dir[0] = dir.x;
ray.dir[1] = dir.y;
ray.dir[2] = dir.z;
float kFar = 2000.0;
ray.min_t = 0.005f;
ray.max_t = kFar;
nanort::TriangleIntersector<> triangle_intersector(reinterpret_cast<float*>(m_hm_plane.vertices.data()), m_hm_plane.idx.data(), sizeof(vertex_t));
nanort::TriangleIntersection<> isect;
hit += m_rt_accel.Traverse(ray, triangle_intersector, &isect);
}
out = glm::lerp(glm::vec4(255, 255, 255, 255), glm::vec4(50, 50, 50, 255), hit / 16.f);
}
}
#if _WIN32 || __IOS__ || __OSX__
@@ -333,4 +333,5 @@ void NodePanelGrid::bake_uvs()
#endif
//stbi_write_jpg("bake-out.jpg", fb.getWidth(), fb.getHeight(), 4, data_out.get(), 75);
m_texture.update(data_out.get());
m_texture.create_mipmaps();
}