diff --git a/CMakeLists.txt b/CMakeLists.txt index e9e696730..6b5b3d67c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ PROJECT(GUACAMOLE CXX) # version number set(GUACAMOLE_MAJOR 0) set(GUACAMOLE_MINOR 7) -set(GUACAMOLE_PATCH 1) +set(GUACAMOLE_PATCH 2) set(GUACAMOLE_VERSION ${GUACAMOLE_MAJOR}.${GUACAMOLE_MINOR}.${GUACAMOLE_PATCH}) set(GUACAMOLE_DESCRIPTION "GUACAMOLE - an astonishing virtual reality engine") set(GUACAMOLE_HOMEPAGE "http://www.GUACAMOLE.org") diff --git a/include/gua/renderer/GBufferPass.hpp b/include/gua/renderer/GBufferPass.hpp index bcaf5b481..ceb62d8a5 100644 --- a/include/gua/renderer/GBufferPass.hpp +++ b/include/gua/renderer/GBufferPass.hpp @@ -88,7 +88,8 @@ class GBufferPass : public GeometryPass { CameraMode eye, std::size_t viewid); - void update_ubershader_from_scene(SerializedScene const& scene, + void update_ubershader_from_scene(RenderContext const& ctx, + SerializedScene const& scene, SceneGraph const& graph); void initialize_state_objects(RenderContext const& ctx); @@ -101,7 +102,7 @@ class GBufferPass : public GeometryPass { std::unordered_map ubershaders_; /** - * copy of all material names in scene + * copy of all material names in scene * * - necessary to generate gbuffermappings of ubershaders */ diff --git a/include/gua/renderer/NURBSUberShader.hpp b/include/gua/renderer/NURBSUberShader.hpp index b426c1c4e..55121a59b 100644 --- a/include/gua/renderer/NURBSUberShader.hpp +++ b/include/gua/renderer/NURBSUberShader.hpp @@ -32,14 +32,14 @@ namespace gua { */ class NURBSUberShader : public GeometryUberShader { - public : // typedefs, enums + public : // typedefs, enums enum pass { transform_feedback_pass = 0, final_pass = 1 }; - public : + public : /*virtual*/ void create (std::set const& material_names); diff --git a/include/gua/renderer/UberShader.hpp b/include/gua/renderer/UberShader.hpp index fe0a41ea2..c1270d0c0 100644 --- a/include/gua/renderer/UberShader.hpp +++ b/include/gua/renderer/UberShader.hpp @@ -77,7 +77,7 @@ class UberShader { { UniformValue tmp(value); - for (auto const& program : programs_) { + for (auto const& program : programs_) { program->apply_uniform(context, &tmp, name, position); } @@ -104,13 +104,13 @@ class UberShader { std::string const& name) const; /** - * returns a program in enumerated order + * returns a program in enumerated order */ virtual std::shared_ptr const& get_program(unsigned index = 0) const; /** * returns a container with all involved programs of this ubershader - */ + */ std::vector> const& programs() const; /** diff --git a/include/gua/renderer/Video3DUberShader.hpp b/include/gua/renderer/Video3DUberShader.hpp index 8b7d193fb..7f15ece7a 100644 --- a/include/gua/renderer/Video3DUberShader.hpp +++ b/include/gua/renderer/Video3DUberShader.hpp @@ -48,7 +48,7 @@ class GUA_DLL Video3DUberShader : public GeometryUberShader { void create(std::set const& material_names); /*virtual*/ bool upload_to(RenderContext const& context) const; - + /*virtual*/ stage_mask const get_stage_mask() const; /*virtual*/ void preframe(RenderContext const& context) const; @@ -94,7 +94,7 @@ class GUA_DLL Video3DUberShader : public GeometryUberShader { std::string const _blend_pass_vertex_shader () const; std::string const _blend_pass_fragment_shader () const; - + private: // attributes static const unsigned MAX_NUM_KINECTS = 6; @@ -106,14 +106,14 @@ class GUA_DLL Video3DUberShader : public GeometryUberShader { mutable std::vector no_bfc_rasterizer_state_; mutable std::vector nearest_sampler_state_; mutable std::vector linear_sampler_state_; - + mutable std::vector depth_stencil_state_warp_pass_; mutable std::vector depth_stencil_state_blend_pass_; mutable std::vector fullscreen_quad_; mutable std::vector fullscreen_quad2_; - + }; } diff --git a/src/gua/databases/MaterialDatabase.cpp b/src/gua/databases/MaterialDatabase.cpp index 74922f4d8..a6548b828 100644 --- a/src/gua/databases/MaterialDatabase.cpp +++ b/src/gua/databases/MaterialDatabase.cpp @@ -54,7 +54,6 @@ void MaterialDatabase::load_material(std::string const& filename) { if (!instance()->is_supported(filename)) { auto mat = std::make_shared(filename, filename); instance()->add(filename, mat); - Logger::LOG_MESSAGE << "MaterialDatabase::load_material() : loading " << filename << std::endl; } } diff --git a/src/gua/renderer/GBufferPass.cpp b/src/gua/renderer/GBufferPass.cpp index fa46db437..743ab0a2a 100644 --- a/src/gua/renderer/GBufferPass.cpp +++ b/src/gua/renderer/GBufferPass.cpp @@ -110,7 +110,7 @@ void GBufferPass::rendering(SerializedScene const& scene, ctx.render_context->set_depth_stencil_state(depth_stencil_state_); // make sure all ubershaders are available - update_ubershader_from_scene(scene, graph); + update_ubershader_from_scene(ctx, scene, graph); // draw all drawable geometries for (auto const& type_ressource_pair : scene.geometrynodes_) { @@ -310,7 +310,7 @@ void GBufferPass::display_rays(RenderContext const& ctx, for (auto const& ray : scene.rays_) { meshubershader->draw( ctx, - "gua_plane_geometry", + "gua_ray_geometry", "gua_bounding_box", ray->get_cached_world_transform(), scm::math::inverse(ray->get_cached_world_transform()), @@ -380,7 +380,8 @@ void GBufferPass::display_quads(RenderContext const& ctx, //////////////////////////////////////////////////////////////////////////////// -void GBufferPass::update_ubershader_from_scene(SerializedScene const& scene, +void GBufferPass::update_ubershader_from_scene(RenderContext const& ctx, + SerializedScene const& scene, SceneGraph const& graph) { bool ubershader_available = true; for (auto const& geometry_pair : scene.geometrynodes_) { @@ -398,6 +399,7 @@ void GBufferPass::update_ubershader_from_scene(SerializedScene const& scene, GeometryDatabase::instance()->lookup(geode->get_filename()); if (ressource) { auto ubershader = ressource->get_ubershader(); + ubershader->cleanup(ctx); ubershader->create(materials_); ubershaders_[type] = ubershader; } @@ -441,6 +443,7 @@ void GBufferPass::apply_material_mapping( std::set const& materials) { materials_ = materials; Singleton::instance()->create(materials_); + // Singleton::instance(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gua/renderer/NURBSUberShader.cpp b/src/gua/renderer/NURBSUberShader.cpp index 3f3c5d527..7acc15547 100644 --- a/src/gua/renderer/NURBSUberShader.cpp +++ b/src/gua/renderer/NURBSUberShader.cpp @@ -731,30 +731,30 @@ std::string const NURBSUberShader::_final_geometry_shader () const geom_shader << method.second << std::endl; } - geom_shader << R"( - void main() - { - for ( int i = 0; i != 3; ++i ) - { - gIndex = teIndex[i]; - gTessCoord = teTessCoord[i]; - - // write built-in input for material - /////////////////////////////////////////////////////// - gua_texcoords = gTessCoord; - - gua_position_varying = (gua_model_matrix * tePosition[i]).xyz; - gua_object_normal = teNormal[i].xyz; - gua_object_tangent = teTangent[i].xyz; - gua_object_bitangent = teBitangent[i].xyz; - gua_object_position = tePosition[i].xyz; - + geom_shader << R"( + void main() + { + for ( int i = 0; i != 3; ++i ) + { + gIndex = teIndex[i]; + gTessCoord = teTessCoord[i]; + + // write built-in input for material + /////////////////////////////////////////////////////// + gua_texcoords = gTessCoord; + + gua_position_varying = (gua_model_matrix * tePosition[i]).xyz; + gua_object_normal = teNormal[i].xyz; + gua_object_tangent = teTangent[i].xyz; + gua_object_bitangent = teBitangent[i].xyz; + gua_object_position = tePosition[i].xyz; + vec4 world_normal = gua_normal_matrix * vec4 (teNormal[i].xyz, 0.0); - gua_world_normal = normalize ( world_normal.xyz ); - gua_world_tangent = normalize ( gua_normal_matrix * vec4 (teTangent[i].xyz, 0.0) ).xyz; - gua_world_bitangent = normalize ( gua_normal_matrix * vec4 (teBitangent[i].xyz, 0.0) ).xyz; - gua_world_position = (gua_model_matrix * tePosition[i]).xyz; - /////////////////////////////////////////////////////// + gua_world_normal = normalize ( world_normal.xyz ); + gua_world_tangent = normalize ( gua_normal_matrix * vec4 (teTangent[i].xyz, 0.0) ).xyz; + gua_world_bitangent = normalize ( gua_normal_matrix * vec4 (teBitangent[i].xyz, 0.0) ).xyz; + gua_world_position = (gua_model_matrix * tePosition[i]).xyz; + /////////////////////////////////////////////////////// )"; // generated code @@ -796,25 +796,25 @@ std::string const NURBSUberShader::_final_fragment_shader () const { std::string fragment_shader; - fragment_shader += R"( - #version 420 core - #extension GL_NV_bindless_texture : require - #extension GL_NV_gpu_shader5 : enable - - #define TRIM_ERROR_TOLERANCE 0.00001 - - precision highp float; - - flat in uint gIndex; - in vec2 gTessCoord; - + fragment_shader += R"( + #version 420 core + #extension GL_NV_bindless_texture : require + #extension GL_NV_gpu_shader5 : enable + + #define TRIM_ERROR_TOLERANCE 0.00001 + + precision highp float; + + flat in uint gIndex; + in vec2 gTessCoord; + uniform samplerBuffer attribute_texture; - - uniform samplerBuffer trim_partition; - uniform samplerBuffer trim_contourlist; - uniform samplerBuffer trim_curvelist; - uniform samplerBuffer trim_curvedata; - uniform samplerBuffer trim_pointdata; + + uniform samplerBuffer trim_partition; + uniform samplerBuffer trim_contourlist; + uniform samplerBuffer trim_curvelist; + uniform samplerBuffer trim_curvedata; + uniform samplerBuffer trim_pointdata; )"; fragment_shader += NURBSShader::curve_horner_evaluation(); @@ -829,77 +829,77 @@ std::string const NURBSUberShader::_final_fragment_shader () const fragment_shader += R"( in vec3 gua_position_varying; - + //***** generated input defintion - @input_definition - - // uniforms - uniform mat4 gua_projection_matrix; - uniform mat4 gua_view_matrix; - uniform mat4 gua_model_matrix; - uniform mat4 gua_normal_matrix; - uniform mat4 gua_inverse_projection_view_matrix; - uniform vec3 gua_camera_position; - - uniform float gua_texel_width; - uniform float gua_texel_height; - - + @input_definition + + // uniforms + uniform mat4 gua_projection_matrix; + uniform mat4 gua_view_matrix; + uniform mat4 gua_model_matrix; + uniform mat4 gua_normal_matrix; + uniform mat4 gua_inverse_projection_view_matrix; + uniform vec3 gua_camera_position; + + uniform float gua_texel_width; + uniform float gua_texel_height; + + //***** generated uniform definition - @uniform_definition - + @uniform_definition + //***** generated output definition - @output_definition - - // global gua_* methods - vec2 gua_get_quad_coords() { - return vec2(gl_FragCoord.x * gua_texel_width, gl_FragCoord.y * gua_texel_height); - } + @output_definition + + // global gua_* methods + vec2 gua_get_quad_coords() { + return vec2(gl_FragCoord.x * gua_texel_width, gl_FragCoord.y * gua_texel_height); + } )"; GuaMethodsFactory method_factory; fragment_shader += method_factory.get_sampler_casts(); fragment_shader += R"( - uint gua_get_material_id() { + uint gua_get_material_id() { return gua_uint_gbuffer_varying_0.x; - } - - vec3 gua_get_position() { - return gua_position_varying; - } + } + + vec3 gua_get_position() { + return gua_position_varying; + } //***** generated material methods - @material_methods - - // main switch - void main() - { - vec4 data = texelFetch(attribute_texture, int(gIndex) * 5); - uint trim_index = floatBitsToUint(data.w); - - vec4 nurbs_domain = texelFetch(attribute_texture, int(gIndex) * 5 + 1); - - vec2 domain_size = vec2(nurbs_domain.z - nurbs_domain.x, nurbs_domain.w - nurbs_domain.y); - - vec2 uv_nurbs = gTessCoord.xy * domain_size + nurbs_domain.xy; - - int tmp = 0; - bool trimmed = trim (trim_partition, - trim_contourlist, - trim_curvelist, - trim_curvedata, - trim_pointdata, - uv_nurbs, - int(trim_index), 1, tmp, 0.0001f, 16); - if ( trimmed ) { - discard; - } + @material_methods + + // main switch + void main() + { + vec4 data = texelFetch(attribute_texture, int(gIndex) * 5); + uint trim_index = floatBitsToUint(data.w); + + vec4 nurbs_domain = texelFetch(attribute_texture, int(gIndex) * 5 + 1); + + vec2 domain_size = vec2(nurbs_domain.z - nurbs_domain.x, nurbs_domain.w - nurbs_domain.y); + + vec2 uv_nurbs = gTessCoord.xy * domain_size + nurbs_domain.xy; + + int tmp = 0; + bool trimmed = trim (trim_partition, + trim_contourlist, + trim_curvelist, + trim_curvedata, + trim_pointdata, + uv_nurbs, + int(trim_index), 1, tmp, 0.0001f, 16); + if ( trimmed ) { + discard; + } @material_switch gua_uint_gbuffer_out_0.x = gua_uint_gbuffer_varying_0.x; - } + } )"; // input from vertex shader @@ -949,7 +949,7 @@ std::string const NURBSUberShader::_final_fragment_shader () const std::string const& material_name, scm::math::mat4 const& model_matrix, scm::math::mat4 const& normal_matrix, - Frustum const& /*frustum*/, + Frustum const& /*frustum*/, std::size_t viewid) const { throw std::runtime_error("NURBSUberShader::predraw(): not implemented"); @@ -963,7 +963,7 @@ void NURBSUberShader::draw(RenderContext const& ctx, std::string const& material_name, scm::math::mat4 const& model_matrix, scm::math::mat4 const& normal_matrix, - Frustum const& /*frustum*/, + Frustum const& /*frustum*/, std::size_t /*viewid*/) const { auto geometry = std::static_pointer_cast(GeometryDatabase::instance()->lookup(filename)); @@ -1012,7 +1012,7 @@ void NURBSUberShader::draw(RenderContext const& ctx, std::string const& material_name, scm::math::mat4 const& model_matrix, scm::math::mat4 const& normal_matrix, - Frustum const& /*frustum*/, + Frustum const& /*frustum*/, std::size_t /*viewid*/) const { throw std::runtime_error("NURBSUberShader::postdraw(): not implemented"); diff --git a/src/gua/renderer/TriMeshLoader.cpp b/src/gua/renderer/TriMeshLoader.cpp index 048ae5a0e..f92d526fd 100644 --- a/src/gua/renderer/TriMeshLoader.cpp +++ b/src/gua/renderer/TriMeshLoader.cpp @@ -55,12 +55,12 @@ namespace gua { TriMeshLoader::TriMeshLoader() : GeometryLoader(), - node_counter_(0) + node_counter_(0) {} //////////////////////////////////////////////////////////////////////////////// - std::shared_ptr TriMeshLoader::load_geometry(std::string const& file_name, unsigned flags) + std::shared_ptr TriMeshLoader::load_geometry(std::string const& file_name, unsigned flags) { std::shared_ptr cached_node; std::string key(file_name + "_" + string_utils::to_string(flags)); @@ -73,9 +73,11 @@ namespace gua { } else { + std::cout << file_name << " " << flags << std::endl; + bool fileload_succeed = false; - if (is_supported(file_name)) + if (is_supported(file_name)) { cached_node = load(file_name, flags); cached_node->update_cache(); @@ -117,7 +119,7 @@ namespace gua { (std::string const& node_name, std::string const& file_name, std::string const& fallback_material, - unsigned flags) + unsigned flags) { auto cached_node(load_geometry(file_name, flags)); @@ -300,7 +302,7 @@ std::shared_ptr TriMeshLoader::get_tree(std::shared_ptr //////////////////////////////////////////////////////////////////////////////// void TriMeshLoader::apply_fallback_material(std::shared_ptr const& root, - std::string const& fallback_material) const + std::string const& fallback_material) const { auto g_node(std::dynamic_pointer_cast(root)); diff --git a/src/gua/renderer/UberShader.cpp b/src/gua/renderer/UberShader.cpp index 848c0d6bd..af08f76d2 100644 --- a/src/gua/renderer/UberShader.cpp +++ b/src/gua/renderer/UberShader.cpp @@ -46,8 +46,11 @@ UberShader::~UberShader() //////////////////////////////////////////////////////////////////////////////// -void UberShader::create(std::set const& material_names) +void UberShader::create(std::set const& material_names) { + + programs_.clear(); + vshader_factory_ = gua::make_unique( ShadingModel::GBUFFER_VERTEX_STAGE, material_names ); @@ -60,7 +63,7 @@ void UberShader::create(std::set const& material_names) LayerMapping vshader_output_mapping = vshader_factory_->get_output_mapping(); fshader_factory_->add_inputs_to_main_functions( - { &vshader_output_mapping }, + { &vshader_output_mapping }, ShadingModel::GBUFFER_VERTEX_STAGE ); diff --git a/src/gua/renderer/Video3DUberShader.cpp b/src/gua/renderer/Video3DUberShader.cpp index 309ac762f..9476ced1a 100644 --- a/src/gua/renderer/Video3DUberShader.cpp +++ b/src/gua/renderer/Video3DUberShader.cpp @@ -55,7 +55,7 @@ Video3DUberShader::Video3DUberShader() //////////////////////////////////////////////////////////////////////////////// -void Video3DUberShader::create(std::set const& material_names) +void Video3DUberShader::create(std::set const& material_names) { UberShader::create(material_names); @@ -93,7 +93,7 @@ std::string const Video3DUberShader::_warp_pass_vertex_shader() const //////////////////////////////////////////////////////////////////////////////// std::string const Video3DUberShader::_warp_pass_geometry_shader() const -{ +{ std::string geometry_shader( Resources::lookup_shader(Resources::shaders_uber_shaders_gbuffer_video3d_warp_pass_geom) ); @@ -191,7 +191,7 @@ bool Video3DUberShader::upload_to (RenderContext const& context) const // initialize Texture Arrays (kinect depths & colors) if ( context.id >= warp_color_result_.size() || - context.id >= warp_depth_result_.size()) + context.id >= warp_depth_result_.size()) { warp_depth_result_.resize(context.id + 1); warp_color_result_.resize(context.id + 1); @@ -242,11 +242,11 @@ bool Video3DUberShader::upload_to (RenderContext const& context) const depth_stencil_state_blend_pass_.resize(context.id + 1); depth_stencil_state_blend_pass_[context.id] = context.render_device->create_depth_stencil_state(true, true, scm::gl::COMPARISON_LESS); } - if (context.id >= no_bfc_rasterizer_state_.size()) - { + if (context.id >= no_bfc_rasterizer_state_.size()) + { no_bfc_rasterizer_state_.resize(context.id + 1); - no_bfc_rasterizer_state_[context.id] = context.render_device->create_rasterizer_state(scm::gl::FILL_SOLID, scm::gl::CULL_NONE); - } + no_bfc_rasterizer_state_[context.id] = context.render_device->create_rasterizer_state(scm::gl::FILL_SOLID, scm::gl::CULL_NONE); + } return upload_succeeded; } @@ -289,11 +289,11 @@ void Video3DUberShader::draw(RenderContext const& ctx, Frustum const& /*frustum*/, std::size_t viewid) const { - if (!GeometryDatabase::instance()->is_supported(ksfile_name) || + if (!GeometryDatabase::instance()->is_supported(ksfile_name) || !MaterialDatabase::instance()->is_supported(material_name)) { gua::Logger::LOG_WARNING << "Video3DUberShader::draw(): No such video or material." << ksfile_name << ", " << material_name << std::endl; return; - } + } auto video3d_ressource = std::static_pointer_cast(GeometryDatabase::instance()->lookup(ksfile_name)); auto material = MaterialDatabase::instance()->lookup(material_name); @@ -336,13 +336,13 @@ void Video3DUberShader::draw(RenderContext const& ctx, warp_result_fbo_[ctx.id]->clear_attachments(); warp_result_fbo_[ctx.id]->attach_depth_stencil_buffer(warp_depth_result_[ctx.id], 0, layer); warp_result_fbo_[ctx.id]->attach_color_buffer(0, warp_color_result_[ctx.id], 0, layer); - + // bind and clear fbo ctx.render_context->set_frame_buffer(warp_result_fbo_[ctx.id]); ctx.render_context->clear_depth_stencil_buffer(warp_result_fbo_[ctx.id]); ctx.render_context->clear_color_buffer(warp_result_fbo_[ctx.id], 0, scm::math::vec4f(0.0f, 0.0f, 0.0f, 0.0f)); ctx.render_context->set_viewport(scm::gl::viewport(scm::math::vec2ui(0,0), warp_color_result_[ctx.id]->dimensions())); - + // set uniforms get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).getTexSizeInvD(), "tex_size_inv"); get_program(warp_pass)->set_uniform(ctx, int(layer), "layer"); diff --git a/src/gua/scenegraph/Node.cpp b/src/gua/scenegraph/Node.cpp index eaea881d9..30e473309 100644 --- a/src/gua/scenegraph/Node.cpp +++ b/src/gua/scenegraph/Node.cpp @@ -359,7 +359,6 @@ namespace gua { //////////////////////////////////////////////////////////////////////////////// void Node::set_dirty() const { - self_dirty_ = true; set_children_dirty(); set_parent_dirty(); } @@ -379,9 +378,9 @@ namespace gua { if (!self_dirty_) { self_dirty_ = true; child_dirty_ = true; - } - for (auto child : children_) { - child->set_children_dirty(); + for (auto child : children_) { + child->set_children_dirty(); + } } } diff --git a/src/gua/scenegraph/TriMeshNode.cpp b/src/gua/scenegraph/TriMeshNode.cpp index 58eb3eae7..10fa6de1c 100644 --- a/src/gua/scenegraph/TriMeshNode.cpp +++ b/src/gua/scenegraph/TriMeshNode.cpp @@ -175,22 +175,22 @@ namespace gua { // // "type='file'&file='data/objects/monkey.obj'&id=0&flags=0" - if (filename_changed_) + if (filename_changed_) { - if (filename_ != "") + if (filename_ != "") { - if (!GeometryDatabase::instance()->is_supported(filename_)) + if (!GeometryDatabase::instance()->is_supported(filename_)) { auto params(string_utils::split(filename_, '&')); - if (params.size() == 4) + if (params.size() == 4) { - if (params[0] == "type=file") + if (params[0] == "type=file") { auto tmp_filename(string_utils::split(params[1], '=')); auto tmp_flags(string_utils::split(params[3], '=')); - if (tmp_filename.size() == 2 && tmp_flags.size() == 2) + if (tmp_filename.size() == 2 && tmp_flags.size() == 2) { std::string filename(tmp_filename[1]); std::string flags_string(tmp_flags[1]); @@ -224,11 +224,11 @@ namespace gua { // // data/materials/Stones.gmd - if (material_changed_) + if (material_changed_) { - if (material_ != "") + if (material_ != "") { - if (!MaterialDatabase::instance()->is_supported(material_)) + if (!MaterialDatabase::instance()->is_supported(material_)) { MaterialDatabase::instance()->load_material(material_); }