Commit 25eeb01e authored by Florian Oetke's avatar Florian Oetke
Browse files

Merge branch 'feature/animation' into 'develop'

Basic Animation-Support

See merge request lowkey42/mirrage!8
parents 09cff367 deb38c2b
......@@ -11,22 +11,19 @@ build_gcc:
script:
- export CC=gcc
- export CXX=g++
- mkdir build
- mkdir -p build
- cd build
- mkdir bin
- mkdir -p bin
- 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
artifacts:
paths:
- build/bin
expire_in: 1 day
cache:
key: "${CI_PIPELINE_ID}-${CI_COMMIT_REF_SLUG}"
key: "gcc_${CI_COMMIT_REF_SLUG}"
paths:
- build
......@@ -35,22 +32,22 @@ build_clang:
script:
- export CC=clang
- export CXX=clang++
- mkdir build
- mkdir -p build
- cd build
- mkdir bin
- mkdir -p bin
- 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
- wget https://github.com/lowkey42/mirrage/releases/download/v0.2/model_data_lbs.tar.xz || true
- cd bin/bin
- tar xf ../../model_data.tar.xz
- tar xf ../../model_data_lbs.tar.xz
artifacts:
paths:
- build/bin
expire_in: 1 week
cache:
key: "${CI_PIPELINE_ID}-${CI_COMMIT_REF_SLUG}"
key: "clang_${CI_COMMIT_REF_SLUG}"
paths:
- build
......@@ -59,7 +56,7 @@ build_scanbuild:
script:
- export CC=clang
- export CXX=clang++
- mkdir build
- mkdir -p build
- cd build
- scan-build --use-c++=clang++ --use-cc=clang cmake -DMIRRAGE_FORCE_LIBCPP=ON -DMIRRAGE_ENABLE_COTIRE=OFF -G "Unix Makefiles" ..
- scan-build -o result --use-c++=clang++ --use-cc=clang -enable-checker deadcode.DeadStores -enable-checker security.insecureAPI.UncheckedReturn --status-bugs -v cmake --build . || true
......
......@@ -10,6 +10,8 @@ vert_shader:shadow_model = shader/bin/shadow_model.vert.spv
frag_shader:shadow_model = shader/bin/shadow_model.frag.spv
vert_shader:model = shader/bin/model.vert.spv
vert_shader:model_animated = shader/bin/model_animated.vert.spv
vert_shader:model_animated_dqs = shader/bin/model_animated_dqs.vert.spv
frag_shader:model = shader/bin/model.frag.spv
frag_shader:model_emissive = shader/bin/model_emissive.frag.spv
frag_shader:model_alphatest = shader/bin/model_alphatest.frag.spv
......
......@@ -7,10 +7,9 @@
layout(early_fragment_tests) in;
layout(location = 0) in vec3 world_pos;
layout(location = 1) in vec3 view_pos;
layout(location = 2) in vec3 normal;
layout(location = 3) in vec2 tex_coords;
layout(location = 0) in vec3 view_pos;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 tex_coords;
layout(location = 0) out vec4 depth_out;
......@@ -47,10 +46,6 @@ void main() {
depth_out = vec4(-view_pos.z / global_uniforms.proj_planes.y, 0,0,1);
albedo_mat_id_out = vec4(albedo.rgb, 0.0);
mat_data_out = vec4(encode_normal(normal), roughness, metallic);
float disect = model_uniforms.options.x;
if(disect>0 && world_pos.z>=disect)
discard;
}
vec3 decode_tangent_normal(vec2 tn) {
......
......@@ -9,13 +9,12 @@ layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 tex_coords;
layout(location = 0) out vec3 out_world_pos;
layout(location = 1) out vec3 out_view_pos;
layout(location = 2) out vec3 out_normal;
layout(location = 3) out vec2 out_tex_coords;
layout(location = 0) out vec3 out_view_pos;
layout(location = 1) out vec3 out_normal;
layout(location = 2) out vec2 out_tex_coords;
layout(push_constant) uniform Per_model_uniforms {
mat4 model;
mat4 model_to_view;
vec4 light_color;
vec4 options;
} model_uniforms;
......@@ -26,15 +25,11 @@ out gl_PerVertex {
void main() {
mat4 model_to_view = global_uniforms.view_mat * model_uniforms.model;
vec4 world_pos = model_uniforms.model * vec4(position, 1.0);
vec4 view_pos = model_to_view * vec4(position, 1.0);
vec4 view_pos = model_uniforms.model_to_view * vec4(position, 1.0);
out_world_pos = world_pos.xyz / world_pos.w;
out_view_pos = view_pos.xyz / view_pos.w;
gl_Position = global_uniforms.proj_mat * view_pos;
out_normal = (model_to_view * vec4(normal, 0.0)).xyz;
out_normal = (model_uniforms.model_to_view * vec4(normal, 0.0)).xyz;
out_tex_coords = tex_coords;
gl_Position = global_uniforms.proj_mat * view_pos;
}
......@@ -5,10 +5,9 @@
#include "global_uniforms.glsl"
#include "normal_encoding.glsl"
layout(location = 0) in vec3 world_pos;
layout(location = 1) in vec3 view_pos;
layout(location = 2) in vec3 normal;
layout(location = 3) in vec2 tex_coords;
layout(location = 0) in vec3 view_pos;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 tex_coords;
layout(location = 0) out vec4 depth_out;
......@@ -48,10 +47,6 @@ void main() {
depth_out = vec4(-view_pos.z / global_uniforms.proj_planes.y, 0,0,1);
albedo_mat_id_out = vec4(albedo.rgb, 0.0);
mat_data_out = vec4(encode_normal(normal), roughness, metallic);
float disect = model_uniforms.options.x;
if(disect>0 && world_pos.z>=disect)
discard;
}
vec3 decode_tangent_normal(vec2 tn) {
......
#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 vec2 tex_coords;
layout(location = 3) in ivec4 bone_ids;
layout(location = 4) in vec4 bone_weights;
layout(location = 0) out vec3 out_view_pos;
layout(location = 1) out vec3 out_normal;
layout(location = 2) out vec2 out_tex_coords;
layout(set=2, binding = 0, std140) uniform Bone_uniforms {
mat3x4 offset[64];
} bones;
layout(push_constant) uniform Per_model_uniforms {
mat4 model_to_view;
vec4 light_color;
vec4 options;
} model_uniforms;
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
float unused_weight = 1.0 - dot(bone_weights, vec4(1.0));
mat3x4 bone = bones.offset[bone_ids[0]] * bone_weights[0]
+ bones.offset[bone_ids[1]] * bone_weights[1]
+ bones.offset[bone_ids[2]] * bone_weights[2]
+ bones.offset[bone_ids[3]] * bone_weights[3]
+ mat3x4(1) * unused_weight;
vec3 p = vec4(position, 1.0) * bone;
vec3 n = vec4(normal, 0.0) * bone;
//p = position;
//n = normal;
vec4 view_pos = model_uniforms.model_to_view * vec4(p, 1.0);
out_view_pos = view_pos.xyz / view_pos.w;
out_normal = (model_uniforms.model_to_view * vec4(n, 0.0)).xyz;
out_tex_coords = tex_coords;
gl_Position = global_uniforms.proj_mat * view_pos;
}
#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 vec2 tex_coords;
layout(location = 3) in ivec4 bone_ids;
layout(location = 4) in vec4 bone_weights;
layout(location = 0) out vec3 out_view_pos;
layout(location = 1) out vec3 out_normal;
layout(location = 2) out vec2 out_tex_coords;
layout(set=2, binding = 0, std140) uniform Bone_uniforms {
mat3x4 offset[64];
} bones;
layout(push_constant) uniform Per_model_uniforms {
mat4 model_to_view;
vec4 light_color;
vec4 options;
} model_uniforms;
out gl_PerVertex {
vec4 gl_Position;
};
vec3 transform_position(vec3 p, mat3x4 dq) {
p *= dq[2].xyz;
return p +
2 * cross(dq[0].xyz, cross(dq[0].xyz, p) + dq[0].w*p) +
2 * (dq[0].w * dq[1].xyz - dq[1].w * dq[0].xyz +
cross(dq[0].xyz, dq[1].xyz));
}
vec3 transform_normal(vec3 n, mat3x4 dq) {
return n + 2.0 * cross(dq[0].xyz, cross(dq[0].xyz, n) + dq[0].w * n);
}
void main() {
float unused_weight = 1.0 - dot(bone_weights, vec4(1.0));
mat3x4 identity_dqs = mat3x4(vec4(1,0,0,0), vec4(0,0,0,0), vec4(1,1,1,1));
mat3x4[] dq = mat3x4[](
bones.offset[bone_ids[0]],
bones.offset[bone_ids[1]],
bones.offset[bone_ids[2]],
bones.offset[bone_ids[3]]
);
// antipodality handling
for(uint i=1; i<=3; i++) {
if (dot(dq[0][0], dq[i][0]) < 0.0) {
dq[i][0] *= -1.0;
dq[i][1] *= -1.0;
}
}
mat3x4 bone = dq[0] * bone_weights[0]
+ dq[1] * bone_weights[1]
+ dq[2] * bone_weights[2]
+ dq[3] * bone_weights[3]
+ identity_dqs * unused_weight;
float dq_len = length(bone[0]);
bone[0] /= dq_len;
bone[1] /= dq_len;
vec3 p = transform_position(position, bone);
vec3 n = transform_normal (normal, bone);
vec4 view_pos = model_uniforms.model_to_view * vec4(p, 1.0);
out_view_pos = view_pos.xyz / view_pos.w;
out_normal = (model_uniforms.model_to_view * vec4(n, 0.0)).xyz;
out_tex_coords = tex_coords;
gl_Position = global_uniforms.proj_mat * view_pos;
}
......@@ -5,10 +5,9 @@
#include "global_uniforms.glsl"
#include "normal_encoding.glsl"
layout(location = 0) in vec3 world_pos;
layout(location = 1) in vec3 view_pos;
layout(location = 2) in vec3 normal;
layout(location = 3) in vec2 tex_coords;
layout(location = 0) in vec3 view_pos;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 tex_coords;
layout(location = 0) out vec4 depth_out;
......
......@@ -44,7 +44,7 @@
},
"mouse_buttons": {
{"button":1, "clicks":0}: {"type":"continuous", "action":"capture_mouse"},
{"button":1, "clicks":0}: {"type":"continuous", "action":"capture_ptr"},
{"button":3, "clicks":0}: {"type":"once", "action":"create"}
},
"mouse_movement": {"type": "range", "action": "mouse_look"}
......
Subproject commit 6a57dbf0c2fcdbaa9d36671da65dbdde2377a741
Subproject commit 26cc9aa8881064c6f43caac653d809d8717f4c4e
#include "game_engine.hpp"
#include <mirrage/renderer/deferred_renderer.hpp>
#include <mirrage/renderer/pass/animation_pass.hpp>
#include <mirrage/renderer/pass/blit_pass.hpp>
#include <mirrage/renderer/pass/bloom_pass.hpp>
#include <mirrage/renderer/pass/deferred_pass.hpp>
......@@ -29,6 +30,7 @@ namespace mirrage {
*this,
window(),
util::make_vector(renderer::make_pass_factory<renderer::Frustum_culling_pass_factory>(),
renderer::make_pass_factory<renderer::Animation_pass_factory>(),
renderer::make_pass_factory<renderer::Shadowmapping_pass_factory>(),
renderer::make_pass_factory<renderer::Deferred_pass_factory>(),
renderer::make_pass_factory<renderer::Gen_mipmap_pass_factory>(),
......
......@@ -4,6 +4,7 @@
#include "meta_system.hpp"
#include "systems/nim_system.hpp"
#include <mirrage/renderer/animation_comp.hpp>
#include <mirrage/renderer/light_comp.hpp>
#include <mirrage/renderer/model_comp.hpp>
#include <mirrage/renderer/pass/gui_pass.hpp>
......@@ -71,6 +72,31 @@ namespace mirrage {
, _window_fullscreen(engine.window().fullscreen() != graphic::Fullscreen::no)
{
_animation_test_dqs = _meta_system.entities().emplace("monk");
_animation_test_dqs.get<Transform_comp>().process([](auto& transform) {
transform.position = {-8, 0, -0.5f - 1.f};
transform.orientation = glm::quatLookAt(glm::vec3{-1, 0, 0}, glm::vec3{0, 1, 0});
});
_animation_test_lbs = _meta_system.entities().emplace("monk_lbs");
_animation_test_lbs.get<Transform_comp>().process([](auto& transform) {
transform.position = {-8, 0, -0.5f + 1.f};
transform.orientation = glm::quatLookAt(glm::vec3{-1, 0, 0}, glm::vec3{0, 1, 0});
});
_animation_test2_dqs = _meta_system.entities().emplace("rotation_test");
_animation_test2_dqs.get<Transform_comp>().process([](auto& transform) {
transform.position = {-4, 0, -0.5f - 1.f};
});
_animation_test2_lbs = _meta_system.entities().emplace("rotation_test_lbs");
_animation_test2_lbs.get<Transform_comp>().process([](auto& transform) {
transform.position = {-4, 0, -0.5f + 1.f};
});
_camera = _meta_system.entities().emplace("camera");
auto cornell = _meta_system.entities().emplace("cornell");
......@@ -166,7 +192,7 @@ namespace mirrage {
switch(e.id) {
case "quit"_strid: _engine.screens().leave(); break;
case "capture_mouse"_strid:
case "capture_ptr"_strid:
_engine.input().capture_mouse(e.begin);
_mouse_look = e.begin;
_set_preset(0);
......@@ -320,6 +346,7 @@ namespace mirrage {
if(_show_ui) {
_draw_settings_window();
_draw_histogram_window();
_draw_animation_window();
if(_show_profiler) {
_meta_system.renderer().profiler().enable();
......@@ -695,6 +722,131 @@ namespace mirrage {
#endif
}
void Test_screen::_draw_animation_window()
{
auto anim_mb = _animation_test_dqs.get<renderer::Simple_animation_controller_comp>();
auto anim_lbs_mb = _animation_test_lbs.get<renderer::Simple_animation_controller_comp>();
if(anim_mb.is_nothing())
return;
auto& anim = anim_mb.get_or_throw();
auto ctx = _gui.ctx();
if(nk_begin_titled(ctx,
"Animation",
"Animation",
_gui.centered_right(300, 500),
NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_TITLE | NK_WINDOW_MINIMIZABLE)) {
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "Animation", NK_TEXT_LEFT);
auto animations_strs = std::array<const char*, 9>{
{"[None]", "Attack", "Dance", "Die", "Flee", "Idle", "Sad", "Sleep", "Walk"}};
auto animations_ids = std::array<util::Str_id, 9>{{""_strid,
"attack"_strid,
"dance"_strid,
"die"_strid,
"flee"_strid,
"idle"_strid,
"sad"_strid,
"sleep"_strid,
"walk"_strid}};
(void) animations_ids;
auto curr_animation_id = anim.animation_id().get_or(""_strid);
auto curr_idx =
std::distance(animations_ids.begin(),
std::find(animations_ids.begin(), animations_ids.end(), curr_animation_id));
auto new_idx = nk_combo(ctx,
animations_strs.data(),
animations_strs.size(),
int(curr_idx),
14,
nk_vec2(100.f, 200));
if(new_idx != curr_idx) {
anim.play(animations_ids.at(std::size_t(new_idx)));
anim_lbs_mb.process([&](auto& anim) { anim.play(animations_ids.at(std::size_t(new_idx))); });
}
anim.animation().process([&](auto& curr_animation) {
auto dqs_states = _animation_test_dqs.get<renderer::Animation_comp>().get_or_throw().states();
auto lbs_states = _animation_test_lbs.get<renderer::Animation_comp>().get_or_throw().states();
auto time = 0.f;
auto curr_dqs_state = std::find_if(dqs_states.begin(), dqs_states.end(), [&](auto& s) {
return &*s.animation == &*curr_animation;
});
auto curr_lbs_state = std::find_if(lbs_states.begin(), lbs_states.end(), [&](auto& s) {
return &*s.animation == &*curr_animation;
});
if(curr_dqs_state != dqs_states.end()) {
time = curr_dqs_state->time;
} else if(curr_lbs_state != lbs_states.end()) {
time = curr_dqs_state->time;
}
auto duration = curr_animation->duration();
nk_label(ctx, "Time", NK_TEXT_LEFT);
auto new_time = nk_slide_float(ctx, 0.f, time, duration, 0.01f);
if(std::abs(new_time - time) > 0.00001f) {
if(curr_dqs_state != dqs_states.end())
curr_dqs_state->time = time;
if(curr_lbs_state != lbs_states.end())
curr_lbs_state->time = time;
}
nk_label(ctx,
(util::to_string(new_time) + " / " + util::to_string(duration)).c_str(),
NK_TEXT_LEFT);
auto speed = anim.speed();
nk_property_float(ctx, "Speed", 0.f, &speed, 5.f, 0.01f, 0.2f);
anim.speed(speed);
if(anim.paused())
anim.pause(!nk_button_label(ctx, "Continue"));
else
anim.pause(nk_button_label(ctx, "Pause"));
if(anim.reversed())
anim.reverse(!nk_button_label(ctx, "Reverse (->)"));
else
anim.reverse(nk_button_label(ctx, "Reverse (<-)"));
if(anim.looped())
anim.loop(!nk_button_label(ctx, "Once"));
else
anim.loop(nk_button_label(ctx, "Repeat"));
anim_lbs_mb.process([&](auto& anim_lbs) {
anim_lbs.pause(anim.paused());
anim_lbs.reverse(anim.reversed());
anim_lbs.loop(anim.looped());
});
});
}
nk_label(ctx, "Rotation Test", NK_TEXT_LEFT);
_animation_test2_dqs.get<renderer::Simple_animation_controller_comp>().process([&](auto& anim) {
if(anim.paused())
anim.pause(!nk_button_label(ctx, "Continue"));
else
anim.pause(nk_button_label(ctx, "Pause"));
_animation_test2_lbs.get<renderer::Simple_animation_controller_comp>().process(
[&](auto& anim_lbs) { anim_lbs.pause(anim.paused()); });
});
nk_end(ctx);
}
void Test_screen::_update_sun_position()
{
......
......@@ -44,6 +44,10 @@ namespace mirrage {
ecs::Entity_facet _camera;
ecs::Entity_facet _sun;
ecs::Entity_facet _animation_test_dqs;
ecs::Entity_facet _animation_test_lbs;
ecs::Entity_facet _animation_test2_dqs;
ecs::Entity_facet _animation_test2_lbs;
float _sun_elevation = 0.92f;
float _sun_azimuth = 1.22f;
......@@ -79,5 +83,6 @@ namespace mirrage {
void _draw_settings_window();
void _draw_profiler_window();
void _draw_histogram_window();
void _draw_animation_window();
};
} // namespace mirrage
......@@ -4,13 +4,19 @@ project(mirrage_mesh_converter LANGUAGES CXX)
add_executable(mesh_converter
animation_parser.cpp
animation_parser.hpp
common.hpp
filesystem.cpp
filesystem.hpp
main.cpp
model_parser.hpp
model_parser.cpp
material_parser.hpp
material_parser.cpp
filesystem.hpp
filesystem.cpp
material_parser.hpp
model_parser.cpp
model_parser.hpp
skeleton_parser.cpp
skeleton_parser.hpp
${BACKWARD_ENABLE}
)
add_backward(mesh_converter)
......
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