remove line thickness from the grid, add ambient light, fix lightmap texture resize

This commit is contained in:
2019-01-19 17:32:19 +01:00
parent d8c8a4b7ed
commit 7980fd4c37
8 changed files with 41 additions and 24 deletions

View File

@@ -293,10 +293,11 @@
<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="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="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="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="Tex Res." font-face="arial" font-size="11"/></node>
</node>
@@ -312,15 +313,16 @@
<combobox id="grid-heightmap-shading" width="100%" height="30" combo-list="Transparent,Flat,Solid,Textured" default="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-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-ambient" value="0.0"/></node>
<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 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>

View File

@@ -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

View File

@@ -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, &current_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);
}
}

View File

@@ -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<CanvasModeTransform*>(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();

View File

@@ -38,6 +38,7 @@ void NodePanelGrid::init_controls()
m_hm_height = find<NodeSliderH>("grid-heightmap-height");
m_hm_lyaw = find<NodeSliderH>("grid-heightmap-lyaw");
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_texres = find<NodeComboBox>("grid-heightmap-texres");
m_hm_samples = find<NodeComboBox>("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, &current_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<float> ray;
ray.org[0] = pos.x;// + nor.x * 0.005;

View File

@@ -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;

View File

@@ -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

View File

@@ -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);
}
};