Skip to content
Snippets Groups Projects
Commit 3371b52c authored by aboensch's avatar aboensch
Browse files

Merge branch 'feature/#445_mesh_render_settings_component'

# Conflicts:
#	tests/CMakeLists.txt
parents d9b5260e 648fbe26
Branches
Tags
No related merge requests found
Showing
with 224 additions and 91 deletions
......@@ -36,6 +36,7 @@
#include "phx/input/input_system.hpp"
#include "phx/rendering/auxiliary/splash_screen.hpp"
#include "phx/rendering/components/mesh_handle.hpp"
#include "phx/rendering/components/mesh_render_settings.hpp"
#include "phx/resources/loaders/assimp_model_loader.hpp"
#include "phx/resources/loaders/scene_loader.hpp"
#include "phx/setup.hpp"
......@@ -101,7 +102,9 @@ int main(int, char**) {
auto boundingbox_mesh_handle = boundingbox_transform->GetChild(0)
->GetEntity()
->GetFirstComponent<phx::MeshHandle>();
boundingbox_mesh_handle->SetWireframeMode(true);
auto render_settings =
model_boundingbox->AddComponent<phx::MeshRenderSettings>();
render_settings->SetWireframeMode(true);
std::array<glm::vec3, 2> bbox =
boundingbox_mesh_handle->GetMesh()->GetBoundingBox();
......
......@@ -206,6 +206,7 @@ std::unique_ptr<Material> HMD::GetControllerMaterial(Controller controller) {
auto material = std::make_unique<phx::Material>();
material->SetAmbientColor(glm::vec3(0.1, 0.1, 0.1));
material->SetSpecularColor(glm::vec3(0.3, 0.3, 0.3));
material->SetShininess(1.0f);
auto texture = ResourceManager::instance().DeclareResource<Image>(
{{"TYPE", "openVR"},
......
......@@ -32,10 +32,6 @@ void MeshHandle::SetMesh(ResourcePointer<Mesh> mesh) { mesh_ = mesh; }
ResourcePointer<Mesh> MeshHandle::GetMesh() const { return mesh_; }
void MeshHandle::SetWireframeMode(bool enabled) { wireframe_mode_ = enabled; }
bool MeshHandle::GetWireframeMode() const { return wireframe_mode_; }
std::string MeshHandle::ToString() const {
if (mesh_ == nullptr) return GetName() + " (MeshHandle <empty>)";
......
......@@ -25,10 +25,10 @@
#include <string>
#include "phx/core/component.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/export.hpp"
#include "phx/resources/resource_pointer.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/utility/aspects/nameable.hpp"
#include "phx/export.hpp"
namespace phx {
/**
......@@ -41,9 +41,6 @@ class PHOENIX_EXPORT MeshHandle final : public Component, public Nameable {
void SetMesh(ResourcePointer<Mesh> mesh);
ResourcePointer<Mesh> GetMesh() const;
void SetWireframeMode(bool enabled);
bool GetWireframeMode() const;
std::string ToString() const override;
protected:
......@@ -57,7 +54,6 @@ class PHOENIX_EXPORT MeshHandle final : public Component, public Nameable {
private:
ResourcePointer<Mesh> mesh_{nullptr};
bool wireframe_mode_ = false;
};
} // namespace phx
......
//------------------------------------------------------------------------------
// Project Phoenix
//
// Copyright (c) 2017-2018 RWTH Aachen University, Germany,
// Virtual Reality & Immersive Visualization Group.
//------------------------------------------------------------------------------
// License
//
// Licensed under the 3-Clause BSD License (the "License");
// you may not use this file except in compliance with the License.
// See the file LICENSE for the full text.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
#include "phx/rendering/components/mesh_render_settings.hpp"
namespace phx {
const MeshRenderSettings MeshRenderSettings::default_settings_;
void MeshRenderSettings::SetWireframeMode(const bool enabled) {
wireframe_mode_ = enabled;
}
bool MeshRenderSettings::GetWireframeMode() const { return wireframe_mode_; }
const MeshRenderSettings* MeshRenderSettings::GetDefault() {
return &default_settings_;
}
} // namespace phx
//------------------------------------------------------------------------------
// Project Phoenix
//
// Copyright (c) 2017-2018 RWTH Aachen University, Germany,
// Virtual Reality & Immersive Visualization Group.
//------------------------------------------------------------------------------
// License
//
// Licensed under the 3-Clause BSD License (the "License");
// you may not use this file except in compliance with the License.
// See the file LICENSE for the full text.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
#ifndef LIBRARY_PHX_RENDERING_COMPONENTS_MESH_RENDER_SETTINGS_HPP_
#define LIBRARY_PHX_RENDERING_COMPONENTS_MESH_RENDER_SETTINGS_HPP_
#include "phx/core/component.hpp"
#include "phx/export.hpp"
namespace phx {
/**
* A component holding a simple pointer to a mesh
*/
class PHOENIX_EXPORT MeshRenderSettings final : public Component {
public:
virtual ~MeshRenderSettings() = default;
void SetWireframeMode(bool enabled);
bool GetWireframeMode() const;
static const MeshRenderSettings* GetDefault();
private:
bool wireframe_mode_ = false;
static const MeshRenderSettings default_settings_;
};
} // namespace phx
#endif // LIBRARY_PHX_RENDERING_COMPONENTS_MESH_RENDER_SETTINGS_HPP_
......@@ -35,9 +35,9 @@
#include "phx/core/logger.hpp"
#include "phx/rendering/components/transform.hpp"
#include "phx/resources/resource_utils.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/resources/types/shader_source.hpp"
#include "phx/resources/resource_utils.hpp"
namespace phx {
......@@ -223,9 +223,15 @@ void GeometryPass::Draw(const RenderingInstance& rendering_instance) {
SetTransformShaderUniforms(model_matrix, view_matrix, projection_matrix);
SetMaterialShaderUniforms(rendering_instance.material);
const MeshRenderSettings* render_settings =
rendering_instance.mesh_render_settings;
if (render_settings == nullptr) {
render_settings = MeshRenderSettings::GetDefault();
}
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK,
rendering_instance.wireframe_mode ? GL_LINE : GL_FILL);
render_settings->GetWireframeMode() ? GL_LINE : GL_FILL);
glDrawElements(
GL_TRIANGLES,
static_cast<GLsizei>(rendering_instance.mesh->GetIndices().size()),
......@@ -291,18 +297,10 @@ void GeometryPass::SetLightShaderUniforms() {
}
}
void GeometryPass::SetMaterialShaderUniforms(Material* material) {
glm::uvec4 texture_toggle(0, 0, 0, 0);
glm::vec3 ambient_color(1, 0, 0);
glm::vec3 diffuse_color(1, 0, 0);
glm::vec3 specular_color(1, 0, 0);
float shininess = 1.0f;
if (material != nullptr) {
ambient_color = material->GetAmbientColor();
diffuse_color = material->GetDiffuseColor();
specular_color = material->GetSpecularColor();
texture_toggle =
void GeometryPass::SetMaterialShaderUniforms(const Material* material) {
if (material == nullptr) material = Material::GetDefault();
const glm::uvec4 texture_toggle =
glm::uvec4(material->GetAmbientTexture() != nullptr ? 1u : 0u,
material->GetDiffuseTexture() != nullptr ? 1u : 0u,
material->GetSpecularTexture() != nullptr ? 1u : 0u, 0u);
......@@ -319,13 +317,12 @@ void GeometryPass::SetMaterialShaderUniforms(Material* material) {
shader_program_->uniform_location("material.specular_tex"),
gl::texture_handle(*material->GetSpecularTexture()));
shininess = material->GetShininess();
}
shader_program_->SetUniform("material.texture_toggle", texture_toggle);
shader_program_->SetUniform("material.ambient", ambient_color);
shader_program_->SetUniform("material.diffuse", diffuse_color);
shader_program_->SetUniform("material.specular", specular_color);
shader_program_->SetUniform("material.shininess", shininess);
shader_program_->SetUniform("material.ambient", material->GetAmbientColor());
shader_program_->SetUniform("material.diffuse", material->GetDiffuseColor());
shader_program_->SetUniform("material.specular",
material->GetSpecularColor());
shader_program_->SetUniform("material.shininess", material->GetShininess());
}
bool GeometryPass::IsValid() const {
......
......@@ -41,6 +41,7 @@ SUPPRESS_WARNINGS_END
#include "phx/rendering/backend/shader_program.hpp"
#include "phx/rendering/components/light.hpp"
#include "phx/rendering/components/material_handle.hpp"
#include "phx/rendering/components/mesh_render_settings.hpp"
#include "phx/rendering/components/projection.hpp"
#include "phx/rendering/components/transform.hpp"
#include "phx/rendering/render_passes/render_pass.hpp"
......@@ -62,7 +63,7 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass {
Mesh* mesh = nullptr;
Material* material = nullptr;
Transform* transform = nullptr;
bool wireframe_mode = false;
MeshRenderSettings* mesh_render_settings = nullptr;
};
struct RenderOffset {
std::size_t vertex_offset;
......@@ -118,7 +119,7 @@ class PHOENIX_EXPORT GeometryPass : public RenderPass {
const glm::mat4& view_matrix,
const glm::mat4& projection_matrix);
void SetLightShaderUniforms();
void SetMaterialShaderUniforms(Material* material);
void SetMaterialShaderUniforms(const Material* material);
std::unique_ptr<ShaderProgram> shader_program_;
......
......@@ -22,24 +22,20 @@
#include "phx/rendering/rendering_system.hpp"
#include <iostream>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "phx/core/engine.hpp"
#include "phx/core/logger.hpp"
#include "phx/core/runtime_component.hpp"
#include "phx/core/scene.hpp"
#include "phx/core/system.hpp"
#include "phx/rendering/components/light.hpp"
#include "phx/rendering/components/material_handle.hpp"
#include "phx/rendering/components/mesh_handle.hpp"
#include "phx/rendering/components/projection.hpp"
#include "phx/rendering/components/mesh_render_settings.hpp"
#include "phx/rendering/components/transform.hpp"
#include "phx/resources/types/mesh.hpp"
#include "gl/opengl.hpp"
......@@ -79,14 +75,15 @@ void RenderingSystem::Update(const FrameTimer::TimeInfo&) {
auto light = entity->GetFirstComponent<Light>();
auto transform = entity->GetFirstComponent<Transform>();
auto material_handle = entity->GetFirstComponent<MaterialHandle>();
if (transform != nullptr) {
if (mesh_handle != nullptr) {
Material* material = nullptr;
if (material_handle != nullptr)
material = material_handle->GetMaterial().Get();
auto mesh_render_settings = entity->GetFirstComponent<MeshRenderSettings>();
if (transform != nullptr) {
if (mesh_handle != nullptr) {
rendering_instances.push_back({mesh_handle->GetMesh().Get(), material,
transform,
mesh_handle->GetWireframeMode()});
transform, mesh_render_settings});
} else if (light != nullptr) {
light_transform_pairs.push_back(
std::pair<Light*, Transform*>(light, transform));
......
......@@ -32,10 +32,10 @@
#include "phx/core/scene.hpp"
#include "phx/core/system.hpp"
#include "phx/display/display_system.hpp"
#include "phx/export.hpp"
#include "phx/rendering/backend/render_target.hpp"
#include "phx/rendering/render_passes/geometry_pass.hpp"
#include "phx/rendering/frame_graph.hpp"
#include "phx/export.hpp"
#include "phx/rendering/render_passes/geometry_pass.hpp"
namespace phx {
......
......@@ -32,6 +32,7 @@
namespace phx {
const char Material::UNNAMED[] = "UnnamedMaterial";
const Material Material::default_material_;
glm::vec3 Material::GetDiffuseColor() const { return diffuse_color_; }
void Material::SetDiffuseColor(glm::vec3 color) { diffuse_color_ = color; }
......@@ -41,11 +42,10 @@ ResourcePointer<Image> Material::GetDiffuseImage() const {
}
void Material::SetDiffuseImage(ResourcePointer<Image> image) {
diffuse_image_ = image;
SetTexture(diffuse_image_, &diffuse_texture_);
}
gl::texture_2d* Material::GetDiffuseTexture() {
if (diffuse_image_ && !diffuse_texture_)
SetTexture(diffuse_image_, &diffuse_texture_);
gl::texture_2d* Material::GetDiffuseTexture() const {
return diffuse_texture_.get();
}
......@@ -57,11 +57,10 @@ ResourcePointer<Image> Material::GetAmbientImage() const {
}
void Material::SetAmbientImage(ResourcePointer<Image> image) {
ambient_image_ = image;
SetTexture(ambient_image_, &ambient_texture_);
}
gl::texture_2d* Material::GetAmbientTexture() {
if (ambient_image_ && !ambient_texture_)
SetTexture(ambient_image_, &ambient_texture_);
gl::texture_2d* Material::GetAmbientTexture() const {
return ambient_texture_.get();
}
......@@ -73,11 +72,10 @@ ResourcePointer<Image> Material::GetSpecularImage() const {
}
void Material::SetSpecularImage(ResourcePointer<Image> image) {
specular_image_ = image;
SetTexture(specular_image_, &specular_texture_);
}
gl::texture_2d* Material::GetSpecularTexture() {
if (specular_image_ && !specular_texture_)
SetTexture(specular_image_, &specular_texture_);
gl::texture_2d* Material::GetSpecularTexture() const {
return specular_texture_.get();
}
......@@ -93,6 +91,8 @@ void Material::SetShininess(float shininess) {
}
}
const Material* Material::GetDefault() { return &default_material_; }
void Material::SetTexture(ResourcePointer<Image> image,
std::shared_ptr<gl::texture_2d>* texture) {
if (image == nullptr) return;
......
......@@ -35,11 +35,11 @@ SUPPRESS_WARNINGS_BEGIN
#include "glm/vec3.hpp"
SUPPRESS_WARNINGS_END
#include "phx/export.hpp"
#include "phx/resources/resource.hpp"
#include "phx/resources/resource_pointer.hpp"
#include "phx/resources/types/image.hpp"
#include "phx/utility/aspects/nameable.hpp"
#include "phx/export.hpp"
namespace phx {
......@@ -62,28 +62,27 @@ class PHOENIX_EXPORT Material : public Resource, public Nameable {
ResourcePointer<Image> GetDiffuseImage() const;
void SetDiffuseImage(ResourcePointer<Image> image);
gl::texture_2d* GetDiffuseTexture();
gl::texture_2d* GetDiffuseTexture() const;
glm::vec3 GetAmbientColor() const;
void SetAmbientColor(glm::vec3 color);
ResourcePointer<Image> GetAmbientImage() const;
void SetAmbientImage(ResourcePointer<Image> image);
gl::texture_2d* GetAmbientTexture();
gl::texture_2d* GetAmbientTexture() const;
glm::vec3 GetSpecularColor() const;
void SetSpecularColor(glm::vec3 color);
ResourcePointer<Image> GetSpecularImage() const;
void SetSpecularImage(ResourcePointer<Image> image);
gl::texture_2d* GetSpecularTexture();
gl::texture_2d* GetSpecularTexture() const;
float GetShininess() const;
void SetShininess(float shininess);
static const Material* GetDefault();
private:
void SetTexture(ResourcePointer<Image> image,
std::shared_ptr<gl::texture_2d>* texture);
......@@ -97,7 +96,9 @@ class PHOENIX_EXPORT Material : public Resource, public Nameable {
glm::vec3 ambient_color_ = glm::vec3(0, 0, 0);
glm::vec3 diffuse_color_ = glm::vec3(1, 0, 0);
glm::vec3 specular_color_ = glm::vec3(1, 1, 1);
float shininess_ = 1.0f;
float shininess_ = 64.0f;
static const Material default_material_;
};
} // namespace phx
......
......@@ -36,8 +36,8 @@ class PHOENIX_EXPORT Hierarchical {
public:
virtual ~Hierarchical() {
Hierarchical::SetParent(nullptr);
for (auto child : children_) {
child->SetParent(nullptr);
while (children_.size() != 0) {
children_[0]->SetParent(nullptr);
}
}
......
......@@ -209,6 +209,18 @@ add_mocked_test(test_openvr_controller_system
LIBRARIES phoenix
MOCKS opengl_mock openvr_mock sdl_mock
)
add_mocked_test(test_assimp_loader
LIBRARIES phoenix test_utilities
MOCKS opengl_mock
)
add_mocked_test(test_model
LIBRARIES phoenix
MOCKS opengl_mock
)
add_mocked_test(test_scene_loader
LIBRARIES phoenix
MOCKS opengl_mock
)
add_mocked_test(integration_test_model_rendering
LIBRARIES phoenix test_utilities
......@@ -227,6 +239,9 @@ add_mocked_test(integration_test_hmd
MOCKS openvr_mock
)
get_unmocked_test_sources(PHOENIX_TEST_SOURCES)
# This adds all cpp files in tests as single tests that were not used with
......@@ -238,3 +253,4 @@ add_tests(NAME "phoenix-tests"
LIBRARIES phoenix test_utilities
PATH_TO_ADD ${PROJECT_BINARY_DIR}/library
)
tests/reference_images/model_loading_wireframe.png

131 B

tests/reference_images/triangle_without_material.png

129 B | W: | H:

tests/reference_images/triangle_without_material.png

130 B | W: | H:

tests/reference_images/triangle_without_material.png
tests/reference_images/triangle_without_material.png
tests/reference_images/triangle_without_material.png
tests/reference_images/triangle_without_material.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -27,18 +27,18 @@
#include "phx/suppress_warnings.hpp"
#include "phx/resources/loaders/assimp_model_loader.hpp"
#include "phx/core/frame_timer.hpp"
#include "phx/core/scene.hpp"
#include "phx/display/display_system_window.hpp"
#include "phx/display/window.hpp"
#include "phx/core/frame_timer.hpp"
#include "phx/rendering/backend/opengl_image_buffer_data.hpp"
#include "phx/rendering/components/mesh_handle.hpp"
#include "phx/rendering/components/mesh_render_settings.hpp"
#include "phx/rendering/rendering_system.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/resources/resource_declaration.hpp"
#include "phx/resources/loaders/assimp_model_loader.hpp"
#include "phx/resources/resource_manager.hpp"
#include "phx/resources/resource_utils.hpp"
#include "phx/core/scene.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/setup.hpp"
#include "test_utilities/opengl_buffer_data_comparison.hpp"
......@@ -134,7 +134,7 @@ SCENARIO(
"If no light and camera are give the model rendering takes default values",
"[phx][phx::ModelLoading]") {
ALLOW_CALL(openvr_mock.Get(), VR_IsHmdPresent()).RETURN(false);
GIVEN("A complete scene with two differently colored bunnies.") {
GIVEN("A complete scene with a bunny") {
std::unique_ptr<phx::Engine> engine = phx::Setup::CreateDefaultEngine();
auto scene = engine->GetScene();
......@@ -158,4 +158,34 @@ SCENARIO(
}
}
SCENARIO("We can render meshes as wireframe.",
"[phx][phx::MeshRenderSettings]") {
ALLOW_CALL(openvr_mock.Get(), VR_IsHmdPresent()).RETURN(false);
GIVEN("A complete scene with a bunny") {
std::unique_ptr<phx::Engine> engine = phx::Setup::CreateDefaultEngine();
auto scene = engine->GetScene();
auto bunny =
LoadBunny(glm::vec3(0.0f, -0.1f, -0.3f), 0.0f, "bunny", scene.get());
auto rendering_system = engine->GetSystem<phx::RenderingSystem>();
auto display_system = engine->GetSystem<phx::DisplaySystemWindow>();
WHEN("We set the rendering to be done in wireframe") {
auto render_settings = bunny->AddComponent<phx::MeshRenderSettings>();
render_settings->SetWireframeMode(true);
THEN("the rendering matches our reference image") {
rendering_system->Update(phx::FrameTimer::TimeInfo{});
display_system->Update(phx::FrameTimer::TimeInfo());
phx::OpenGLImageBufferData<phx::OpenGLImageBufferDataType_RGB> buffer(
1024, 768);
buffer.ReadColorPixels(true);
test_utilities::OpenGLBufferComparison::
REQUIRE_REFERENCE_IMAGE_SIMILARITY(
buffer, "model_loading_wireframe.png", 1.0);
}
}
}
}
SUPPRESS_WARNINGS_END
......@@ -35,8 +35,8 @@
#include "phx/rendering/backend/opengl_image_buffer_data.hpp"
#include "phx/rendering/components/mesh_handle.hpp"
#include "phx/rendering/rendering_system.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/resources/resource_manager.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/setup.hpp"
SUPPRESS_WARNINGS_BEGIN
......
......@@ -26,14 +26,18 @@
#include "catch/catch.hpp"
#include "mocks/opengl_mock.hpp"
#include "phx/core/logger.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/resources/loaders/assimp_model_loader.hpp"
#include "phx/resources/resource_utils.hpp"
#include "phx/resources/types/mesh.hpp"
#include "phx/utility/aspects/nameable.hpp"
#include "test_utilities/log_capture.hpp"
extern template struct trompeloeil::reporter<trompeloeil::specialized>;
class TestLogger {
public:
TestLogger() : log_capture_{std::make_shared<test_utilities::LogCapture>()} {
......@@ -49,6 +53,7 @@ class TestLogger {
SCENARIO("The assimp loader loads models using the Assimp library.",
"[phx][phx::AssimpLoader]") {
OPENGL_MOCK_ALLOW_ANY_CALL
GIVEN("A plain loader") {
phx::CreateDefaultLogger();
TestLogger test_logger;
......
......@@ -42,7 +42,7 @@ SCENARIO("The material component keeps track of its attributes",
REQUIRE(material.GetAmbientColor() == glm::vec3(0, 0, 0));
REQUIRE(material.GetSpecularColor() == glm::vec3(1, 1, 1));
REQUIRE(material.GetDiffuseColor() == glm::vec3(1, 0, 0));
REQUIRE(material.GetShininess() == 1.0f);
REQUIRE(material.GetShininess() == 64.0f);
}
WHEN("we assign it to be some other material") {
glm::vec3 blue(0, 0, 1), white(1, 1, 1), green(0, 1, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment