diff --git a/data/layout.xml b/data/layout.xml
index d0a539d..6b1db2b 100644
--- a/data/layout.xml
+++ b/data/layout.xml
@@ -293,10 +293,11 @@
-
+
+
@@ -312,15 +313,16 @@
-
+
+
-
+
-
+
diff --git a/src/app_shaders.cpp b/src/app_shaders.cpp
index 5e1f84a..5dd866b 100644
--- a/src/app_shaders.cpp
+++ b/src/app_shaders.cpp
@@ -168,7 +168,7 @@ void App::initShaders()
" }\n"
" }\n"
" float edge = (zero_count > 1 && zero_count < 9) ? 0.75 : 0.0;\n"
- " frag = vec4(col.rgb, edge);\n"
+ " frag = vec4(col.rgb, edge * (1.0 - zero_count / 9.f));\n"
"}\n";
// TEXTURE COMP ERASE
static const char* shader_comp_erase_f =
@@ -525,11 +525,12 @@ void App::initShaders()
static const char* shader_lambert_f =
SHADER_VERSION
"uniform mediump vec3 light_dir;\n"
+ "uniform mediump float ambient;\n"
"in mediump vec3 n;\n"
"out mediump vec4 frag;\n"
"void main() {\n"
" mediump float d = max(0.0, dot(normalize(n), light_dir));\n"
- " frag = vec4(vec3(d), 1.0);\n"
+ " frag = vec4(vec3(d) + ambient, 1.0);\n"
//" frag = vec4(normalize(n) * 0.5 + 0.5, 1.0);\n"
"}\n";
@@ -551,13 +552,14 @@ void App::initShaders()
SHADER_VERSION
"uniform mediump sampler2D tex;\n"
"uniform mediump vec3 light_dir;\n"
+ "uniform mediump float ambient;\n"
"in mediump vec3 n;\n"
"in mediump vec2 uv;\n"
"out mediump vec4 frag;\n"
"void main() {\n"
" mediump float d = max(0.0, dot(normalize(n), normalize(light_dir)));\n"
" mediump vec4 c = texture(tex, uv);\n"
- " frag = vec4(c.rgb * d, 1.0);\n"
+ " frag = vec4(c.rgb * d + ambient, 1.0);\n"
"}\n";
// BAKE UVS
diff --git a/src/node_border.cpp b/src/node_border.cpp
index d52839c..fddf5e2 100644
--- a/src/node_border.cpp
+++ b/src/node_border.cpp
@@ -73,13 +73,10 @@ void NodeBorder::draw()
if (m_thinkness > 0 && m_border_color.a > 0.f)
{
- float current_width = 1;
- glGetFloatv(GL_LINE_WIDTH, ¤t_width);
- glLineWidth(m_thinkness);
+ //glLineWidth(m_thinkness);
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
m_border_color.a < 1.f ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
m_plane.draw_stroke();
- glLineWidth(current_width);
glDisable(GL_BLEND);
}
}
diff --git a/src/node_canvas.cpp b/src/node_canvas.cpp
index 6c47d2e..c5d7454 100644
--- a/src/node_canvas.cpp
+++ b/src/node_canvas.cpp
@@ -337,10 +337,6 @@ void NodeCanvas::draw()
m_cache_rtt.unbindTexture();
}
-
- for (auto& mode : *m_canvas->m_mode)
- mode->on_Draw(ortho_proj, proj, camera);
-
glDisable(GL_DEPTH_TEST);
auto transform_mode = static_cast(Canvas::modes[(int)Canvas::kCanvasMode::Transform][0]);
bool importing = transform_mode->m_action == CanvasModeTransform::ActionType::Import;
@@ -357,6 +353,9 @@ void NodeCanvas::draw()
App::I.grid->draw_heightmap(proj, camera);
+ for (auto& mode : *m_canvas->m_mode)
+ mode->on_Draw(ortho_proj, proj, camera);
+
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
m_sampler.unbind();
diff --git a/src/node_panel_grid.cpp b/src/node_panel_grid.cpp
index 645e39b..d8bf69d 100644
--- a/src/node_panel_grid.cpp
+++ b/src/node_panel_grid.cpp
@@ -38,6 +38,7 @@ void NodePanelGrid::init_controls()
m_hm_height = find("grid-heightmap-height");
m_hm_lyaw = find("grid-heightmap-lyaw");
m_hm_lpitch = find("grid-heightmap-lpitch");
+ m_hm_ambient = find("grid-heightmap-ambient");
m_hm_shading = find("grid-heightmap-shading");
m_hm_texres = find("grid-heightmap-texres");
m_hm_samples = find("grid-heightmap-samples");
@@ -139,8 +140,19 @@ void NodePanelGrid::init_controls()
gl.restore();
};
m_hm_texres->on_select = [this](Node*, int index) {
- int rexres = get_texres();
- m_texture.create(rexres, rexres);
+ int texres = get_texres();
+ if (texres != m_texture.size().x)
+ return;
+
+ // get the texture data and resize it
+ m_texture.bind();
+ Image img;
+ img.create(m_texture.size().x, m_texture.size().y);
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data.get());
+ m_texture.unbind();
+ Image resized = img.resize(texres, texres);
+ m_texture.create(resized);
+ m_texture.create_mipmaps();
};
int rexres = get_texres();
m_texture.create(rexres, rexres);
@@ -162,6 +174,11 @@ int NodePanelGrid::get_texres() const
return atoi(m_hm_texres->m_items[m_hm_texres->m_current_index].c_str());
}
+float NodePanelGrid::get_ambient() const
+{
+ return glm::pow(m_hm_ambient->get_value(), 3);
+}
+
float NodePanelGrid::get_thickness() const
{
return glm::lerp(m_line_range[0], m_line_range[1], m_hm_thickness->get_value());
@@ -217,6 +234,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
ShaderManager::use(kShader::Lambert);
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
+ ShaderManager::u_float(kShaderUniform::Ambient, get_ambient());
m_hm_plane.draw_fill();
}
else if (m_shade_mode == ShadeMode::Flat)
@@ -234,11 +252,13 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
ShaderManager::use(kShader::LambertLightmap);
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
+ ShaderManager::u_float(kShaderUniform::Ambient, get_ambient());
ShaderManager::u_int(kShaderUniform::Tex, 0);
m_sampler_linear.bind(0);
glActiveTexture(GL_TEXTURE0);
m_texture.bind();
m_hm_plane.draw_fill();
+ m_texture.unbind();
}
}
@@ -260,11 +280,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
m_hm_plane.draw_fill();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
- float current_width = 1;
- glGetFloatv(GL_LINE_WIDTH, ¤t_width);
- glLineWidth(get_thickness());
m_hm_plane.draw_stroke();
- glLineWidth(current_width);
}
}
}
@@ -360,7 +376,7 @@ void NodePanelGrid::bake_uvs()
int hit = 0;
for (int s = 0; s < samples; s++)
{
- auto dir = glm::normalize(light_dir + glm::sphericalRand(.1f));
+ auto dir = glm::normalize(light_dir + glm::sphericalRand(.5f));
nanort::Ray ray;
ray.org[0] = pos.x;// + nor.x * 0.005;
diff --git a/src/node_panel_grid.h b/src/node_panel_grid.h
index 863669d..5e7ea83 100644
--- a/src/node_panel_grid.h
+++ b/src/node_panel_grid.h
@@ -50,6 +50,7 @@ public:
NodeSliderH* m_hm_thickness;
NodeSliderH* m_hm_lyaw;
NodeSliderH* m_hm_lpitch;
+ NodeSliderH* m_hm_ambient;
NodeComboBox* m_hm_texres;
NodeComboBox* m_hm_samples;
NodeButton* m_render;
@@ -73,6 +74,7 @@ public:
void init_controls();
int get_samples() const;
int get_texres() const;
+ float get_ambient() const;
float get_thickness() const;
float get_resolution() const;
float get_height() const;
diff --git a/src/shader.h b/src/shader.h
index 5a664fd..be18aaf 100644
--- a/src/shader.h
+++ b/src/shader.h
@@ -32,6 +32,7 @@ enum class kShaderUniform : uint16_t
UseFragCoordUV2 = const_hash("fragUV2"),
LightDir = const_hash("light_dir"),
Mode = const_hash("mode"),
+ Ambient = const_hash("ambient"),
};
enum class kShader : uint16_t
diff --git a/src/util.h b/src/util.h
index 459ba48..7228899 100644
--- a/src/util.h
+++ b/src/util.h
@@ -188,7 +188,6 @@ struct gl_state
scissor_test = glIsEnabled(GL_SCISSOR_TEST);
glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
- glGetFloatv(GL_LINE_WIDTH, &line_width);
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb);
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_tex);
@@ -217,6 +216,5 @@ struct gl_state
}
glActiveTexture(active_tex);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube);
- glLineWidth(line_width);
}
};