Skip to content

Commit

Permalink
UMVE: add seperate overlay- and fix texture-shader
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoehrle committed Aug 24, 2015
1 parent f0abf40 commit 0ee0f16
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
17 changes: 16 additions & 1 deletion apps/umve/scene_addins/addin_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ AddinState::load_shaders (void)
this->wireframe_shader = ogl::ShaderProgram::create();
if (!this->texture_shader)
this->texture_shader = ogl::ShaderProgram::create();
if (!this->overlay_shader)
this->overlay_shader = ogl::ShaderProgram::create();

/* Setup search paths for shader files. */
std::string home_dir = util::fs::get_home_dir();
Expand All @@ -104,6 +106,7 @@ AddinState::load_shaders (void)
bool found_surface = false;
bool found_wireframe = false;
bool found_texture = false;
bool found_overlay = false;
for (std::size_t i = 0; i < shader_paths.size(); ++i)
{
try
Expand All @@ -117,6 +120,9 @@ AddinState::load_shaders (void)
if (!found_texture)
found_texture = this->texture_shader->try_load_all
(shader_paths[i] + "texture_330");
if (!found_overlay)
found_overlay = this->overlay_shader->try_load_all
(shader_paths[i] + "overlay_330");
}
catch (util::Exception& e)
{
Expand Down Expand Up @@ -148,6 +154,12 @@ AddinState::load_shaders (void)
load_shaders_from_resources(this->texture_shader,
":/shaders/texture_330");
}
if (!found_overlay)
{
std::cout << "Using built-in overlay shader." << std::endl;
load_shaders_from_resources(this->overlay_shader,
":/shaders/overlay_330");
}
}

void
Expand All @@ -167,12 +179,15 @@ AddinState::send_uniform (ogl::Camera const& cam)
this->texture_shader->bind();
this->texture_shader->send_uniform("viewmat", cam.view);
this->texture_shader->send_uniform("projmat", cam.proj);

/* Setup overlay shader. */
this->overlay_shader->bind();
}

void
AddinState::init_ui (void)
{
this->gui_renderer = ogl::create_fullscreen_quad(this->texture_shader);
this->gui_renderer = ogl::create_fullscreen_quad(this->overlay_shader);
this->gui_texture = ogl::Texture::create();
}

Expand Down
1 change: 1 addition & 0 deletions apps/umve/scene_addins/addin_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct AddinState
ogl::ShaderProgram::Ptr surface_shader;
ogl::ShaderProgram::Ptr wireframe_shader;
ogl::ShaderProgram::Ptr texture_shader;
ogl::ShaderProgram::Ptr overlay_shader;
mve::Scene::Ptr scene;
mve::View::Ptr view;

Expand Down
15 changes: 15 additions & 0 deletions apps/umve/shaders/overlay_330.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 330 core

in vec3 onormal;
smooth in vec2 otexuv;

uniform vec3 light1 = vec3(0.0, 0.0, 5.0);
uniform sampler2D texunit;
uniform vec4 ccolor = vec4(0.7, 0.7, 0.7, 1.0);

layout(location=0) out vec4 frag_color;

void main(void)
{
frag_color = texture(texunit, otexuv);
}
15 changes: 15 additions & 0 deletions apps/umve/shaders/overlay_330.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 330 core

in vec4 pos;
in vec3 normal;
in vec2 texuv;

out vec3 onormal;
smooth out vec2 otexuv;

void main(void)
{
onormal = normal;
otexuv = texuv;
gl_Position = pos;
}
1 change: 1 addition & 0 deletions apps/umve/shaders/texture_330.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ smooth in vec2 otexuv;

uniform vec3 light1 = vec3(0.0, 0.0, 5.0);
uniform sampler2D texunit;
uniform vec4 ccolor = vec4(0.7, 0.7, 0.7, 1.0);

layout(location=0) out vec4 frag_color;

Expand Down
3 changes: 1 addition & 2 deletions apps/umve/shaders/texture_330.vert
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ void main(void)
{
onormal = normal;
otexuv = texuv;
//gl_Position = projmat * (viewmat * pos);
gl_Position = pos;
gl_Position = projmat * (viewmat * pos);
}
2 changes: 2 additions & 0 deletions apps/umve/umve.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
<file>shaders/texture_330.vert</file>
<file>shaders/wireframe_330.frag</file>
<file>shaders/wireframe_330.vert</file>
<file>shaders/overlay_330.frag</file>
<file>shaders/overlay_330.vert</file>
</qresource>
</RCC>

0 comments on commit 0ee0f16

Please sign in to comment.