Commit c55c61d4 authored by Florian Oetke's avatar Florian Oetke
Browse files

Merge branch 'develop' of gitlab.com:lowkey42/mirrage into develop

parents d1aefd6e ea0d1cd3
......@@ -17,6 +17,7 @@ build_gcc:
- rm -rf src
- cmake -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=../bin -DCMAKE_BUILD_TYPE=Release -DMIRRAGE_EXPORT_EXECUTABLE=ON ..
- cmake --build . --target src/install
- cmake --build . --target test
- wget -nc -Omodel_data.tar.xz https://github.com/lowkey42/mirrage/releases/download/v0.2/model_data.tar.xz
- cd bin/bin
- tar xf ../../model_data.tar.xz
......@@ -40,6 +41,7 @@ build_clang:
- rm -rf src
- cmake -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=../bin -DCMAKE_BUILD_TYPE=Release -DMIRRAGE_EXPORT_EXECUTABLE=ON ..
- cmake --build . --target src/install
- cmake --build . --target test
- wget -nc -Omodel_data.tar.xz https://github.com/lowkey42/mirrage/releases/download/v0.2/model_data.tar.xz
- cd bin/bin
- tar xf ../../model_data.tar.xz
......
......@@ -34,3 +34,6 @@
[submodule "dependencies/moodycamel"]
path = dependencies/moodycamel
url = https://github.com/cameron314/concurrentqueue.git
[submodule "dependencies/doctest"]
path = dependencies/doctest
url = https://github.com/onqtam/doctest.git
......@@ -83,6 +83,12 @@ if(MIRRAGE_ENABLE_COTIRE)
endif()
endif()
option(MIRRAGE_ENABLE_TESTS "Enable unit tests" ON)
if(MIRRAGE_ENABLE_TESTS)
enable_testing()
endif()
add_subdirectory(dependencies)
add_subdirectory(src)
......@@ -59,9 +59,6 @@ frag_shader:gi_reproject = shader/bin/gi_reproject.frag.spv
vert_shader:median_filter = shader/bin/fullscreen.vert.spv
frag_shader:median_filter = shader/bin/median_filter.frag.spv
vert_shader:voxelization = shader/bin/voxelization.vert.spv
frag_shader:voxelization = shader/bin/voxelization.frag.spv
vert_shader:luminance = shader/bin/fullscreen.vert.spv
frag_shader:luminance = shader/bin/luminance.frag.spv
......
......@@ -112,6 +112,7 @@ void main() {
vec2 raycast_hit_uv;
vec3 raycast_hit_point;
// TODO: try scaling stride based on startLod for better results at low resolutions
if(spec_visible &&
traceScreenSpaceRay1(P+(dir*0.25+jitter*0.1), dir, pcs.projection, depth_sampler,
depthSize, 1.0, global_uniforms.proj_planes.x,
......
......@@ -31,7 +31,7 @@ uint calc_histogram_index(float luminance) {
shared uint local_histogram[HISTOGRAM_SLOTS];
void main() {
ivec2 data_size = imageSize(input_image);
vec2 data_size = vec2(imageSize(input_image));
uint group_id = gl_WorkGroupID.x + gl_WorkGroupID.y*gl_NumWorkGroups.x;
uint num_groups = gl_NumWorkGroups.x*gl_NumWorkGroups.y;
......@@ -50,9 +50,9 @@ void main() {
// build local histogram
for(uint x=gl_GlobalInvocationID.x; x<data_size.x; x+=stride.x) {
for(uint y=gl_GlobalInvocationID.y; y<data_size.y; y+=stride.y) {
vec2 rel_p = (vec2(x,y) - vec2(data_size)) / min(data_size.x, data_size.y)*2;
vec2 rel_p = (vec2(x,y)*2 - data_size) / min(data_size.x, data_size.y);
float dist2 = dot(rel_p,rel_p);
if(dist2 < 0.75) {
if(dist2 < 1) {
vec3 color = imageLoad(input_image, ivec2(x,y)).rgb;
float lum = log(tm_luminance(color*10));
atomicAdd(local_histogram[calc_histogram_index(lum)], 1);
......
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "normal_encoding.glsl"
#include "global_uniforms.glsl"
layout(location = 0) in Vertex_data {
vec3 world_pos;
vec2 tex_coords;
} vertex_out;
layout(location = 0) out uvec4 voxel_data[2];
layout(set=1, binding = 0) uniform sampler2D albedo_sampler;
void main() {
vec4 albedo = texture(albedo_sampler, vertex_out.tex_coords);
if(albedo.a < 0.1)
discard;
float z = gl_FragCoord.z;
float near = global_uniforms.proj_planes.x;
float far = global_uniforms.proj_planes.y;
// TODO
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "global_uniforms.glsl"
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec3 tangent;
layout(location = 3) in vec2 tex_coords;
layout(location = 0) out Vertex_data {
vec3 world_pos;
vec2 tex_coords;
} vertex_out;
layout(push_constant) uniform Per_model_uniforms {
mat4 model;
} model_uniforms;
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
vec4 world_pos = model_uniforms.model * vec4(position, 1.0);
vertex_out.world_pos = world_pos.xyz;
gl_Position = global_uniforms.view_proj_mat * world_pos;
vertex_out.tex_coords = tex_coords;
}
......@@ -18,6 +18,7 @@ add_subdirectory(physfs)
include(plog_interface.cmake)
include(robin-map_interface.cmake)
include(doctest_interface.cmake)
add_subdirectory(sf2)
......
Subproject commit cd1d7474374c8cebed5c609564cdaa2f5184be25
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(doctest)
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest>
$<INSTALL_INTERFACE:include>)
install(TARGETS doctest EXPORT doctestTargets)
export(
EXPORT doctestTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/doctestTargets.cmake"
)
install(
EXPORT doctestTargets FILE doctestTargets.cmake
NAMESPACE doctest::
DESTINATION lib/cmake
)
......@@ -27,6 +27,7 @@ target_link_libraries(demo
plog
glm::glm
sf2
doctest
)
option(MIRRAGE_COMPILE_SHADERS "Compile demo shaders" OFF)
......
......@@ -5,6 +5,8 @@
* See LICENSE file for details. *
\*****************************************************************************/
#define DOCTEST_CONFIG_IMPLEMENT
#include "game_engine.hpp"
#include "test_screen.hpp"
......@@ -13,6 +15,7 @@
#include <mirrage/asset/asset_manager.hpp>
#include <SDL2/SDL.h>
#include <doctest.h>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Log.h>
#include <glm/vec2.hpp>
......@@ -43,6 +46,13 @@ int main(int argc, char** argv)
int main(int argc, char** argv, char** env)
{
#endif
doctest::Context context;
context.setOption("no-run", true);
context.applyCommandLine(argc, argv);
auto res = context.run();
if(context.shouldExit())
return res;
init_env(argc, argv, env);
......@@ -53,7 +63,7 @@ int main(int argc, char** argv, char** env)
shutdown();
return 0;
return res;
}
namespace {
......
......@@ -114,7 +114,7 @@ namespace mirrage::systems {
s.write_virtual(sf2::vmember("frames", frames));
}
Nim_system::Nim_system(ecs::Entity_manager& ecs) : _nim_components(ecs.list<Nim_comp>()) {}
Nim_system::Nim_system(ecs::Entity_manager& ecs) : _ecs(ecs), _nim_components(ecs.list<Nim_comp>()) {}
namespace {
template <class T>
......@@ -203,12 +203,12 @@ namespace mirrage::systems {
auto light_color = catmull_rom(_current_position, colors, _loop);
auto pos_diff = glm::distance2(transform.position(), position);
auto orientation_diff = glm::abs(glm::dot(transform.orientation(), orientation) - 1);
auto pos_diff = glm::distance2(transform.position, position);
auto orientation_diff = glm::abs(glm::dot(transform.orientation, orientation) - 1);
if(pos_diff > 0.00001f || orientation_diff > 0.0001f) {
transform.orientation(orientation);
transform.position(position);
transform.orientation = orientation;
transform.position = position;
}
entity.get<renderer::Directional_light_comp>().process([&](auto& light) {
......@@ -273,7 +273,7 @@ namespace mirrage::systems {
light.color().r, light.color().g, light.color().b, light.intensity());
});
return std::make_tuple(transform.position(), transform.orientation(), color);
return std::make_tuple(transform.position, transform.orientation, color);
});
}
......@@ -281,7 +281,7 @@ namespace mirrage::systems {
{
_affected_entities.clear();
for(auto& nim_comp : _nim_components) {
_affected_entities.emplace(nim_comp.uid(), nim_comp.owner());
_affected_entities.emplace(nim_comp.uid(), nim_comp.owner(_ecs));
}
}
} // namespace mirrage::systems
......@@ -23,8 +23,7 @@ namespace mirrage::systems {
friend void load_component(ecs::Deserializer& state, Nim_comp&);
friend void save_component(ecs::Serializer& state, const Nim_comp&);
Nim_comp() = default;
Nim_comp(ecs::Entity_manager& manager, ecs::Entity_handle owner) : Component(manager, owner) {}
using Component::Component;
auto uid() const noexcept { return _uid; }
......@@ -118,7 +117,8 @@ namespace mirrage::systems {
private:
using Entity_lookup_table = std::unordered_map<util::Str_id, ecs::Entity_facet>;
Nim_comp::Pool& _nim_components;
ecs::Entity_manager& _ecs;
Nim_comp::Pool& _nim_components;
Entity_lookup_table _affected_entities;
......
......@@ -77,7 +77,7 @@ namespace mirrage {
_camera = _meta_system.entities().emplace("camera");
auto cornell = _meta_system.entities().emplace("cornell");
cornell.get<Transform_comp>().process([&](auto& transform) { transform.position({1000, 0, 0}); });
cornell.get<Transform_comp>().process([&](auto& transform) { transform.position = {1000, 0, 0}; });
_meta_system.entities().emplace("sponza");
......@@ -103,8 +103,8 @@ namespace mirrage {
case "create"_strid:
_meta_system.entities().emplace("cube").get<Transform_comp>().process(
[&](auto& transform) {
auto& cam = _camera.get<Transform_comp>().get_or_throw();
transform.position(cam.position() + cam.direction());
auto& cam = _camera.get<Transform_comp>().get_or_throw();
transform.position = cam.position + cam.direction();
});
break;
......@@ -117,7 +117,7 @@ namespace mirrage {
}
case "print"_strid: {
auto cam = _camera.get<Transform_comp>().get_or_throw().position();
auto cam = _camera.get<Transform_comp>().get_or_throw().position;
LOG(plog::info) << "Setup: \n"
<< " Camera position: " << cam.x << "/" << cam.y << "/" << cam.z
<< "\n"
......@@ -220,7 +220,7 @@ namespace mirrage {
const Preset& p = presets[preset_id - 1];
_camera.get<Transform_comp>().process(
[&](auto& transform) { transform.position(p.camera_position); });
[&](auto& transform) { transform.position = p.camera_position; });
_cam_yaw = p.camera_yaw;
_cam_pitch = p.camera_pitch;
......@@ -274,7 +274,7 @@ namespace mirrage {
auto direction = glm::vec3{std::cos(_cam_pitch) * std::cos(_cam_yaw),
std::sin(_cam_pitch),
std::cos(_cam_pitch) * std::sin(_cam_yaw)};
transform.look_at(transform.position() - direction);
transform.look_at(transform.position - direction);
});
_look = {0.f, 0.f};
......@@ -653,7 +653,8 @@ namespace mirrage {
auto lum = std::exp(log_lum);
nk_label(ctx, to_fixed_str(lum, 5).c_str(), NK_TEXT_CENTERED);
auto percentage = static_cast<double>(histogram[_last_selected_histogram]) / histogram_sum;
auto percentage = static_cast<double>(histogram[_last_selected_histogram])
/ std::max(1.0, histogram_sum);
nk_label(ctx, "Percentage", NK_TEXT_CENTERED);
nk_label(ctx, (to_fixed_str(percentage * 100, 4) + " %").c_str(), NK_TEXT_CENTERED);
......@@ -700,9 +701,9 @@ namespace mirrage {
void Test_screen::_update_sun_position()
{
_sun.get<Transform_comp>().process([&](auto& transform) {
transform.orientation(glm::quat(glm::vec3(
(_sun_elevation - 2.f) * glm::pi<float>() / 2.f, glm::pi<float>() * _sun_azimuth, 0.f)));
transform.position(transform.direction() * -60.f);
transform.orientation = glm::quat(glm::vec3(
(_sun_elevation - 2.f) * glm::pi<float>() / 2.f, glm::pi<float>() * _sun_azimuth, 0.f));
transform.position = transform.direction() * -60.f;
});
}
} // namespace mirrage
......@@ -23,5 +23,6 @@ target_link_libraries(mesh_converter
assimp
sf2
stb_image
doctest
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment