remove line thickness from the grid, add ambient light, fix lightmap texture resize
This commit is contained in:
@@ -293,10 +293,11 @@
|
|||||||
<node height="30" justify="center"><text text="File" font-face="arial" font-size="11"/></node>
|
<node height="30" justify="center"><text text="File" font-face="arial" font-size="11"/></node>
|
||||||
<node height="30" justify="center" margin="5 0 0 0"><text text="Shading" font-face="arial" font-size="11"/></node>
|
<node height="30" justify="center" margin="5 0 0 0"><text text="Shading" font-face="arial" font-size="11"/></node>
|
||||||
<node height="20" justify="center" margin="5 0 0 0"><text text="Wireframe" font-face="arial" font-size="11"/></node>
|
<node height="20" justify="center" margin="5 0 0 0"><text text="Wireframe" font-face="arial" font-size="11"/></node>
|
||||||
<node height="20" justify="center"><text text="Thickness" font-face="arial" font-size="11"/></node>
|
<!--<node height="20" justify="center"><text text="Thickness" font-face="arial" font-size="11"/></node>-->
|
||||||
<node height="20" justify="center"><text text="Height" font-face="arial" font-size="11"/></node>
|
<node height="20" justify="center"><text text="Height" font-face="arial" font-size="11"/></node>
|
||||||
<node height="20" justify="center"><text text="L-Yaw" font-face="arial" font-size="11"/></node>
|
<node height="20" justify="center"><text text="L-Yaw" font-face="arial" font-size="11"/></node>
|
||||||
<node height="20" justify="center"><text text="L-Pitch" font-face="arial" font-size="11"/></node>
|
<node height="20" justify="center"><text text="L-Pitch" font-face="arial" font-size="11"/></node>
|
||||||
|
<node height="20" justify="center"><text text="Ambient" font-face="arial" font-size="11"/></node>
|
||||||
<node height="30" justify="center" margin="5 0 0 0"><text text="Samples" font-face="arial" font-size="11"/></node>
|
<node height="30" justify="center" margin="5 0 0 0"><text text="Samples" font-face="arial" font-size="11"/></node>
|
||||||
<node height="30" justify="center" margin="5 0 0 0"><text text="Tex Res." font-face="arial" font-size="11"/></node>
|
<node height="30" justify="center" margin="5 0 0 0"><text text="Tex Res." font-face="arial" font-size="11"/></node>
|
||||||
</node>
|
</node>
|
||||||
@@ -312,15 +313,16 @@
|
|||||||
<combobox id="grid-heightmap-shading" width="100%" height="30" combo-list="Transparent,Flat,Solid,Textured" default="0"/>
|
<combobox id="grid-heightmap-shading" width="100%" height="30" combo-list="Transparent,Flat,Solid,Textured" default="0"/>
|
||||||
</node>
|
</node>
|
||||||
<node height="20" pad="1" width="100%" margin="5 0 0 0"><slider-h id="grid-heightmap-wireframe" value="1.0"/></node>
|
<node height="20" pad="1" width="100%" margin="5 0 0 0"><slider-h id="grid-heightmap-wireframe" value="1.0"/></node>
|
||||||
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-thickness" value="0.5"/></node>
|
<!--<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-thickness" value="0.5"/></node>-->
|
||||||
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-height" value="0.25"/></node>
|
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-height" value="0.25"/></node>
|
||||||
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-lyaw" value="0.5"/></node>
|
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-lyaw" value="0.5"/></node>
|
||||||
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-lpitch" value="0.5"/></node>
|
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-lpitch" value="0.5"/></node>
|
||||||
|
<node height="20" pad="1" width="100%"><slider-h id="grid-heightmap-ambient" value="0.0"/></node>
|
||||||
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
|
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
|
||||||
<combobox id="grid-heightmap-samples" width="100%" height="30" combo-list="1,4,8,16,32,64,128" default="3"/>
|
<combobox id="grid-heightmap-samples" width="100%" height="30" combo-list="1,4,8,16,32,64,128" default="2"/>
|
||||||
</node>
|
</node>
|
||||||
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
|
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
|
||||||
<combobox id="grid-heightmap-texres" width="100%" height="30" combo-list="256,512,1024,2048,4096" default="2"/>
|
<combobox id="grid-heightmap-texres" width="100%" height="30" combo-list="256,512,1024,2048,4096" default="1"/>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ void App::initShaders()
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" float edge = (zero_count > 1 && zero_count < 9) ? 0.75 : 0.0;\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";
|
"}\n";
|
||||||
// TEXTURE COMP ERASE
|
// TEXTURE COMP ERASE
|
||||||
static const char* shader_comp_erase_f =
|
static const char* shader_comp_erase_f =
|
||||||
@@ -525,11 +525,12 @@ void App::initShaders()
|
|||||||
static const char* shader_lambert_f =
|
static const char* shader_lambert_f =
|
||||||
SHADER_VERSION
|
SHADER_VERSION
|
||||||
"uniform mediump vec3 light_dir;\n"
|
"uniform mediump vec3 light_dir;\n"
|
||||||
|
"uniform mediump float ambient;\n"
|
||||||
"in mediump vec3 n;\n"
|
"in mediump vec3 n;\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), 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"
|
//" frag = vec4(normalize(n) * 0.5 + 0.5, 1.0);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
@@ -551,13 +552,14 @@ void App::initShaders()
|
|||||||
SHADER_VERSION
|
SHADER_VERSION
|
||||||
"uniform mediump sampler2D tex;\n"
|
"uniform mediump sampler2D tex;\n"
|
||||||
"uniform mediump vec3 light_dir;\n"
|
"uniform mediump vec3 light_dir;\n"
|
||||||
|
"uniform mediump float ambient;\n"
|
||||||
"in mediump vec3 n;\n"
|
"in mediump vec3 n;\n"
|
||||||
"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), normalize(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 + ambient, 1.0);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
// BAKE UVS
|
// BAKE UVS
|
||||||
|
|||||||
@@ -73,13 +73,10 @@ void NodeBorder::draw()
|
|||||||
|
|
||||||
if (m_thinkness > 0 && m_border_color.a > 0.f)
|
if (m_thinkness > 0 && m_border_color.a > 0.f)
|
||||||
{
|
{
|
||||||
float current_width = 1;
|
//glLineWidth(m_thinkness);
|
||||||
glGetFloatv(GL_LINE_WIDTH, ¤t_width);
|
|
||||||
glLineWidth(m_thinkness);
|
|
||||||
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
||||||
m_border_color.a < 1.f ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
m_border_color.a < 1.f ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
||||||
m_plane.draw_stroke();
|
m_plane.draw_stroke();
|
||||||
glLineWidth(current_width);
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,10 +337,6 @@ void NodeCanvas::draw()
|
|||||||
m_cache_rtt.unbindTexture();
|
m_cache_rtt.unbindTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (auto& mode : *m_canvas->m_mode)
|
|
||||||
mode->on_Draw(ortho_proj, proj, camera);
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
auto transform_mode = static_cast<CanvasModeTransform*>(Canvas::modes[(int)Canvas::kCanvasMode::Transform][0]);
|
auto transform_mode = static_cast<CanvasModeTransform*>(Canvas::modes[(int)Canvas::kCanvasMode::Transform][0]);
|
||||||
bool importing = transform_mode->m_action == CanvasModeTransform::ActionType::Import;
|
bool importing = transform_mode->m_action == CanvasModeTransform::ActionType::Import;
|
||||||
@@ -357,6 +353,9 @@ void NodeCanvas::draw()
|
|||||||
|
|
||||||
App::I.grid->draw_heightmap(proj, camera);
|
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);
|
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
||||||
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
||||||
m_sampler.unbind();
|
m_sampler.unbind();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ void NodePanelGrid::init_controls()
|
|||||||
m_hm_height = find<NodeSliderH>("grid-heightmap-height");
|
m_hm_height = find<NodeSliderH>("grid-heightmap-height");
|
||||||
m_hm_lyaw = find<NodeSliderH>("grid-heightmap-lyaw");
|
m_hm_lyaw = find<NodeSliderH>("grid-heightmap-lyaw");
|
||||||
m_hm_lpitch = find<NodeSliderH>("grid-heightmap-lpitch");
|
m_hm_lpitch = find<NodeSliderH>("grid-heightmap-lpitch");
|
||||||
|
m_hm_ambient = find<NodeSliderH>("grid-heightmap-ambient");
|
||||||
m_hm_shading = find<NodeComboBox>("grid-heightmap-shading");
|
m_hm_shading = find<NodeComboBox>("grid-heightmap-shading");
|
||||||
m_hm_texres = find<NodeComboBox>("grid-heightmap-texres");
|
m_hm_texres = find<NodeComboBox>("grid-heightmap-texres");
|
||||||
m_hm_samples = find<NodeComboBox>("grid-heightmap-samples");
|
m_hm_samples = find<NodeComboBox>("grid-heightmap-samples");
|
||||||
@@ -139,8 +140,19 @@ void NodePanelGrid::init_controls()
|
|||||||
gl.restore();
|
gl.restore();
|
||||||
};
|
};
|
||||||
m_hm_texres->on_select = [this](Node*, int index) {
|
m_hm_texres->on_select = [this](Node*, int index) {
|
||||||
int rexres = get_texres();
|
int texres = get_texres();
|
||||||
m_texture.create(rexres, rexres);
|
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();
|
int rexres = get_texres();
|
||||||
m_texture.create(rexres, rexres);
|
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());
|
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
|
float NodePanelGrid::get_thickness() const
|
||||||
{
|
{
|
||||||
return glm::lerp(m_line_range[0], m_line_range[1], m_hm_thickness->get_value());
|
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::use(kShader::Lambert);
|
||||||
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||||
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
|
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
|
||||||
|
ShaderManager::u_float(kShaderUniform::Ambient, get_ambient());
|
||||||
m_hm_plane.draw_fill();
|
m_hm_plane.draw_fill();
|
||||||
}
|
}
|
||||||
else if (m_shade_mode == ShadeMode::Flat)
|
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::use(kShader::LambertLightmap);
|
||||||
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||||
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
|
ShaderManager::u_vec3(kShaderUniform::LightDir, light_dir);
|
||||||
|
ShaderManager::u_float(kShaderUniform::Ambient, get_ambient());
|
||||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||||
m_sampler_linear.bind(0);
|
m_sampler_linear.bind(0);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
m_texture.bind();
|
m_texture.bind();
|
||||||
m_hm_plane.draw_fill();
|
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();
|
m_hm_plane.draw_fill();
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
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();
|
m_hm_plane.draw_stroke();
|
||||||
glLineWidth(current_width);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,7 +376,7 @@ void NodePanelGrid::bake_uvs()
|
|||||||
int hit = 0;
|
int hit = 0;
|
||||||
for (int s = 0; s < samples; s++)
|
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<float> ray;
|
nanort::Ray<float> ray;
|
||||||
ray.org[0] = pos.x;// + nor.x * 0.005;
|
ray.org[0] = pos.x;// + nor.x * 0.005;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public:
|
|||||||
NodeSliderH* m_hm_thickness;
|
NodeSliderH* m_hm_thickness;
|
||||||
NodeSliderH* m_hm_lyaw;
|
NodeSliderH* m_hm_lyaw;
|
||||||
NodeSliderH* m_hm_lpitch;
|
NodeSliderH* m_hm_lpitch;
|
||||||
|
NodeSliderH* m_hm_ambient;
|
||||||
NodeComboBox* m_hm_texres;
|
NodeComboBox* m_hm_texres;
|
||||||
NodeComboBox* m_hm_samples;
|
NodeComboBox* m_hm_samples;
|
||||||
NodeButton* m_render;
|
NodeButton* m_render;
|
||||||
@@ -73,6 +74,7 @@ public:
|
|||||||
void init_controls();
|
void init_controls();
|
||||||
int get_samples() const;
|
int get_samples() const;
|
||||||
int get_texres() const;
|
int get_texres() const;
|
||||||
|
float get_ambient() const;
|
||||||
float get_thickness() const;
|
float get_thickness() const;
|
||||||
float get_resolution() const;
|
float get_resolution() const;
|
||||||
float get_height() const;
|
float get_height() const;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ enum class kShaderUniform : uint16_t
|
|||||||
UseFragCoordUV2 = const_hash("fragUV2"),
|
UseFragCoordUV2 = const_hash("fragUV2"),
|
||||||
LightDir = const_hash("light_dir"),
|
LightDir = const_hash("light_dir"),
|
||||||
Mode = const_hash("mode"),
|
Mode = const_hash("mode"),
|
||||||
|
Ambient = const_hash("ambient"),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class kShader : uint16_t
|
enum class kShader : uint16_t
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ struct gl_state
|
|||||||
scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
scissor_test = glIsEnabled(GL_SCISSOR_TEST);
|
||||||
glGetIntegerv(GL_VIEWPORT, vp);
|
glGetIntegerv(GL_VIEWPORT, vp);
|
||||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||||
glGetFloatv(GL_LINE_WIDTH, &line_width);
|
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
|
glGetIntegerv(GL_CURRENT_PROGRAM, &program);
|
||||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb);
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb);
|
||||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_tex);
|
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_tex);
|
||||||
@@ -217,6 +216,5 @@ struct gl_state
|
|||||||
}
|
}
|
||||||
glActiveTexture(active_tex);
|
glActiveTexture(active_tex);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cube);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cube);
|
||||||
glLineWidth(line_width);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user