Fix heightmap shadow rt and draw the light pos
This commit is contained in:
@@ -133,8 +133,9 @@ void NodePanelGrid::init_controls()
|
||||
m_groud_opacity->set_value(0);
|
||||
gl.restore();
|
||||
};
|
||||
m_texture.create(1024, 1024);
|
||||
m_sampler_linear.create();
|
||||
m_texture.create(2048, 2048);
|
||||
m_sampler_linear.create(GL_NEAREST);
|
||||
m_sphere.create<8, 8>(.0001f);
|
||||
}
|
||||
|
||||
float NodePanelGrid::get_height() const
|
||||
@@ -157,13 +158,22 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
|
||||
auto mvp = proj * camera
|
||||
* glm::translate(glm::vec3(0, get_offset(), 0));
|
||||
|
||||
auto light_yaw = m_hm_lyaw->get_value() * glm::pi<float>() * 2.f;
|
||||
auto light_pitch = m_hm_lpitch->get_value() * 5;
|
||||
auto light_pos = glm::vec3(sinf(light_yaw), light_pitch + get_offset(), cosf(light_yaw));
|
||||
auto light_dir = glm::normalize(light_pos);
|
||||
|
||||
// DRAW SUN SPHERE
|
||||
glDisable(GL_BLEND);
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, proj * camera *
|
||||
glm::translate(light_pos) * glm::scale(glm::vec3(.1f)));
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, { 1, 0, 0, 1 });
|
||||
m_sphere.draw_fill();
|
||||
|
||||
// DRAW SOLID
|
||||
if (m_hm_image.m_data)
|
||||
{
|
||||
auto light_yaw = m_hm_lyaw->get_value() * glm::pi<float>() * 2.f;
|
||||
auto light_pitch = m_hm_lpitch->get_value() * 5;
|
||||
auto light_pos = glm::vec3(sinf(light_yaw), light_pitch, cosf(light_yaw));
|
||||
auto light_dir = glm::normalize(light_pos);
|
||||
|
||||
if (m_shade_mode == ShadeMode::Solid)
|
||||
{
|
||||
@@ -225,7 +235,11 @@ void NodePanelGrid::bake_uvs()
|
||||
return;
|
||||
|
||||
RTT fb;
|
||||
#if defined(__IOS__) || defined(__ANDROID__)
|
||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA16F);
|
||||
#else
|
||||
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
|
||||
#endif
|
||||
fb.bindFramebuffer();
|
||||
fb.clear({ 1, 0, 0, 1 });
|
||||
glDisable(GL_BLEND);
|
||||
@@ -238,13 +252,13 @@ void NodePanelGrid::bake_uvs()
|
||||
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
||||
m_hm_plane.draw_fill();
|
||||
std::unique_ptr<float[]> data_nor(fb.readTextureDataFloat());
|
||||
//stbi_write_jpg("bake-nor.jpg", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 75);
|
||||
//stbi_write_png("bake-nor.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||
|
||||
// bake position
|
||||
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
||||
m_hm_plane.draw_fill();
|
||||
std::unique_ptr<float[]> data_pos(fb.readTextureDataFloat());
|
||||
//stbi_write_jpg("bake-pos.jpg", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 75);
|
||||
//stbi_write_png("bake-pos.png", fb.getWidth(), fb.getHeight(), 4, fb.readTextureData(), 0);
|
||||
|
||||
fb.unbindFramebuffer();
|
||||
fb.destroy();
|
||||
@@ -263,7 +277,7 @@ void NodePanelGrid::bake_uvs()
|
||||
|
||||
auto light_yaw = m_hm_lyaw->get_value() * glm::pi<float>() * 2.f;
|
||||
auto light_pitch = m_hm_lpitch->get_value() * 5;
|
||||
auto light_pos = glm::vec3(sinf(light_yaw), light_pitch, cosf(light_yaw));
|
||||
auto light_pos = glm::vec3(sinf(light_yaw), light_pitch + get_offset(), cosf(light_yaw));
|
||||
auto light_dir = glm::normalize(light_pos);
|
||||
|
||||
auto data_out = std::make_unique<uint8_t[]>(fb.getWidth() * fb.getHeight() * 4);
|
||||
@@ -272,10 +286,16 @@ void NodePanelGrid::bake_uvs()
|
||||
for (int x = 0; x < fb.getWidth(); x++)
|
||||
{
|
||||
int i = y * fb.getHeight() + x;
|
||||
auto nor = glm::make_vec4(&data_nor[i * 4]);
|
||||
auto pos = glm::make_vec4(&data_pos[i * 4]);
|
||||
auto nor = glm::make_vec3(&data_nor[i * 4]);
|
||||
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;
|
||||
}
|
||||
|
||||
nanort::Ray<float> ray;
|
||||
ray.org[0] = pos.x;// + nor.x * 0.005;
|
||||
ray.org[1] = pos.y;// + nor.y * 0.005;
|
||||
@@ -284,8 +304,8 @@ void NodePanelGrid::bake_uvs()
|
||||
ray.dir[1] = light_dir.y;
|
||||
ray.dir[2] = light_dir.z;
|
||||
|
||||
float kFar = 1.0e+30f;
|
||||
ray.min_t = 0.001f;
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user