Fix heightmap shadow rt and draw the light pos
This commit is contained in:
@@ -236,11 +236,10 @@ bool App::check_license()
|
|||||||
{
|
{
|
||||||
return true; // TODO: for distribuiton only
|
return true; // TODO: for distribuiton only
|
||||||
|
|
||||||
/*
|
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if (curl)
|
if (curl)
|
||||||
{
|
{
|
||||||
std::string url = "https://panopainter.com/license/53C5DE19-7B8F-42B8-8399-C99D28B66401.php";
|
std::string url = "https://panopainter.com/license/7565D057-ACBE-4721-9A4E-F342D3DDB7D8.php";
|
||||||
//std::string url = "https://panopainter.com/license/E8EDC2FE-E1BD-4AB1-91BD-FCCD926739BD.php"; // wacom
|
//std::string url = "https://panopainter.com/license/E8EDC2FE-E1BD-4AB1-91BD-FCCD926739BD.php"; // wacom
|
||||||
//std::string url = "https://panopainter.com/license/A744FBA9-BC6C-43C8-BD24-0CCE24B3D985.php"; // others
|
//std::string url = "https://panopainter.com/license/A744FBA9-BC6C-43C8-BD24-0CCE24B3D985.php"; // others
|
||||||
|
|
||||||
@@ -264,7 +263,6 @@ bool App::check_license()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::upload(std::string filename, std::string name, std::function<void(float)> progress)
|
void App::upload(std::string filename, std::string name, std::function<void(float)> progress)
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ void select_button(Node* main, T* button) {
|
|||||||
main->find<NodeButtonCustom>("btn-pen")->set_color(color_button_normal);
|
main->find<NodeButtonCustom>("btn-pen")->set_color(color_button_normal);
|
||||||
main->find<NodeButtonCustom>("btn-erase")->set_color(color_button_normal);
|
main->find<NodeButtonCustom>("btn-erase")->set_color(color_button_normal);
|
||||||
main->find<NodeButtonCustom>("btn-line")->set_color(color_button_normal);
|
main->find<NodeButtonCustom>("btn-line")->set_color(color_button_normal);
|
||||||
main->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
//main->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
||||||
main->find<NodeButton>("btn-grid")->set_color(color_button_normal);
|
main->find<NodeButton>("btn-grid")->set_color(color_button_normal);
|
||||||
main->find<NodeButton>("btn-copy")->set_color(color_button_normal);
|
main->find<NodeButton>("btn-copy")->set_color(color_button_normal);
|
||||||
main->find<NodeButton>("btn-cut")->set_color(color_button_normal);
|
main->find<NodeButton>("btn-cut")->set_color(color_button_normal);
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ void App::initShaders()
|
|||||||
"in mediump vec2 uv;\n"
|
"in mediump vec2 uv;\n"
|
||||||
"out mediump vec4 frag;\n"
|
"out mediump vec4 frag;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" mediump float d = max(0.0, dot(normalize(n), light_dir));\n"
|
" mediump float d = max(0.0, dot(normalize(n), normalize(light_dir)));\n"
|
||||||
" mediump vec4 c = texture(tex, uv);\n"
|
" mediump vec4 c = texture(tex, uv);\n"
|
||||||
" frag = vec4(c.rgb * d, 1.0);\n"
|
" frag = vec4(c.rgb * d, 1.0);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ kEventResult Node::on_event(Event* e)
|
|||||||
case kEventType::MouseDownR:
|
case kEventType::MouseDownR:
|
||||||
case kEventType::MouseUpL:
|
case kEventType::MouseUpL:
|
||||||
case kEventType::MouseUpR:
|
case kEventType::MouseUpR:
|
||||||
if ((inside || m_mouse_captured) && (handle_event(e) == kEventResult::Consumed || m_force_mouse_capture))
|
if ((inside || m_mouse_captured) && ((handle_event(e) == kEventResult::Consumed) || m_force_mouse_capture))
|
||||||
return kEventResult::Consumed;
|
return kEventResult::Consumed;
|
||||||
break;
|
break;
|
||||||
case kEventType::MouseMove:
|
case kEventType::MouseMove:
|
||||||
|
|||||||
@@ -133,8 +133,9 @@ void NodePanelGrid::init_controls()
|
|||||||
m_groud_opacity->set_value(0);
|
m_groud_opacity->set_value(0);
|
||||||
gl.restore();
|
gl.restore();
|
||||||
};
|
};
|
||||||
m_texture.create(1024, 1024);
|
m_texture.create(2048, 2048);
|
||||||
m_sampler_linear.create();
|
m_sampler_linear.create(GL_NEAREST);
|
||||||
|
m_sphere.create<8, 8>(.0001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float NodePanelGrid::get_height() const
|
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
|
auto mvp = proj * camera
|
||||||
* glm::translate(glm::vec3(0, get_offset(), 0));
|
* 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
|
// DRAW SOLID
|
||||||
if (m_hm_image.m_data)
|
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)
|
if (m_shade_mode == ShadeMode::Solid)
|
||||||
{
|
{
|
||||||
@@ -225,7 +235,11 @@ void NodePanelGrid::bake_uvs()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
RTT fb;
|
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);
|
fb.create(m_texture.size().x, m_texture.size().y, -1, GL_RGBA32F);
|
||||||
|
#endif
|
||||||
fb.bindFramebuffer();
|
fb.bindFramebuffer();
|
||||||
fb.clear({ 1, 0, 0, 1 });
|
fb.clear({ 1, 0, 0, 1 });
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
@@ -238,13 +252,13 @@ void NodePanelGrid::bake_uvs()
|
|||||||
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
ShaderManager::u_int(kShaderUniform::Mode, 0);
|
||||||
m_hm_plane.draw_fill();
|
m_hm_plane.draw_fill();
|
||||||
std::unique_ptr<float[]> data_nor(fb.readTextureDataFloat());
|
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
|
// bake position
|
||||||
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
ShaderManager::u_int(kShaderUniform::Mode, 1);
|
||||||
m_hm_plane.draw_fill();
|
m_hm_plane.draw_fill();
|
||||||
std::unique_ptr<float[]> data_pos(fb.readTextureDataFloat());
|
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.unbindFramebuffer();
|
||||||
fb.destroy();
|
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_yaw = m_hm_lyaw->get_value() * glm::pi<float>() * 2.f;
|
||||||
auto light_pitch = m_hm_lpitch->get_value() * 5;
|
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 light_dir = glm::normalize(light_pos);
|
||||||
|
|
||||||
auto data_out = std::make_unique<uint8_t[]>(fb.getWidth() * fb.getHeight() * 4);
|
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++)
|
for (int x = 0; x < fb.getWidth(); x++)
|
||||||
{
|
{
|
||||||
int i = y * fb.getHeight() + x;
|
int i = y * fb.getHeight() + x;
|
||||||
auto nor = glm::make_vec4(&data_nor[i * 4]);
|
auto nor = glm::make_vec3(&data_nor[i * 4]);
|
||||||
auto pos = glm::make_vec4(&data_pos[i * 4]);
|
auto pos = glm::make_vec3(&data_pos[i * 4]);
|
||||||
auto& out = *reinterpret_cast<glm::i8vec4*>(&data_out[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;
|
nanort::Ray<float> ray;
|
||||||
ray.org[0] = pos.x;// + nor.x * 0.005;
|
ray.org[0] = pos.x;// + nor.x * 0.005;
|
||||||
ray.org[1] = pos.y;// + nor.y * 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[1] = light_dir.y;
|
||||||
ray.dir[2] = light_dir.z;
|
ray.dir[2] = light_dir.z;
|
||||||
|
|
||||||
float kFar = 1.0e+30f;
|
float kFar = 20.0;
|
||||||
ray.min_t = 0.001f;
|
ray.min_t = 0.01f;
|
||||||
ray.max_t = kFar;
|
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::TriangleIntersector<> triangle_intersector(reinterpret_cast<float*>(m_hm_plane.vertices.data()), m_hm_plane.idx.data(), sizeof(vertex_t));
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
NodeButton* m_render;
|
NodeButton* m_render;
|
||||||
NodeButton* m_commit;
|
NodeButton* m_commit;
|
||||||
HeightmapPlane m_hm_plane;
|
HeightmapPlane m_hm_plane;
|
||||||
|
Sphere m_sphere;
|
||||||
Image m_hm_image;
|
Image m_hm_image;
|
||||||
Texture2D m_texture;
|
Texture2D m_texture;
|
||||||
Sampler m_sampler_linear;
|
Sampler m_sampler_linear;
|
||||||
|
|||||||
@@ -286,7 +286,6 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale, flo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generate indices
|
// generate indices
|
||||||
const glm::vec3 yscale(1, height, 1);
|
|
||||||
for (int y = 0; y < div; y++)
|
for (int y = 0; y < div; y++)
|
||||||
{
|
{
|
||||||
int i = y * (div + 1);
|
int i = y * (div + 1);
|
||||||
@@ -298,8 +297,8 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale, flo
|
|||||||
*pi++ = i;
|
*pi++ = i;
|
||||||
*pi++ = i + div + 2;
|
*pi++ = i + div + 2;
|
||||||
*pi++ = i + 1;
|
*pi++ = i + 1;
|
||||||
auto n = glm::triangleNormal(xyz(vertices[i].pos) * yscale,
|
auto n = glm::triangleNormal(xyz(vertices[i].pos),
|
||||||
xyz(vertices[i + div + 1].pos) * yscale, xyz(vertices[i + 1].pos) * yscale);
|
xyz(vertices[i + div + 1].pos), xyz(vertices[i + 1].pos));
|
||||||
vertices[i].nor += n;
|
vertices[i].nor += n;
|
||||||
vertices[i + 1].nor += n;
|
vertices[i + 1].nor += n;
|
||||||
vertices[i + div + 1].nor += n;
|
vertices[i + div + 1].nor += n;
|
||||||
|
|||||||
Reference in New Issue
Block a user