Skip to content

Commit

Permalink
Merge from internal dev branch, fix serveral bugs, add rhi layer, deb…
Browse files Browse the repository at this point in the history
…ug draw...
  • Loading branch information
BoomingTechDev authored and hyv1001 committed Oct 22, 2022
1 parent 3183f4b commit 2ed2bca
Show file tree
Hide file tree
Showing 101 changed files with 15,076 additions and 7,758 deletions.
4 changes: 3 additions & 1 deletion build_windows.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@echo off

cmake -S . -B build
cmake --build build --config Release
cmake --build build --config Release

pause
8 changes: 6 additions & 2 deletions engine/3rdparty/vulkanmemoryallocator/include/vk_mem_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ extern "C" {
// see: https://clang.llvm.org/docs/AttributeReference.html#nullable
#ifndef VMA_NULLABLE
#ifdef __clang__
#define VMA_NULLABLE _Nullable
#define VMA_NULLABLE
#else
#define VMA_NULLABLE
#endif
Expand All @@ -266,7 +266,7 @@ extern "C" {
// see: https://clang.llvm.org/docs/AttributeReference.html#nonnull
#ifndef VMA_NOT_NULL
#ifdef __clang__
#define VMA_NOT_NULL _Nonnull
#define VMA_NOT_NULL
#else
#define VMA_NOT_NULL
#endif
Expand Down Expand Up @@ -13902,6 +13902,10 @@ bool VmaDefragmentationContext_T::ComputeDefragmentation_Extensive(VmaBlockVecto
}
break;
}
case StateExtensive::Operation::Cleanup:
{
break;
}
}

if (vectorState.operation == StateExtensive::Operation::Cleanup)
Expand Down
13 changes: 10 additions & 3 deletions engine/shader/glsl/combine_ui.frag
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ void main()
// Gamma correct
// TODO: select the VK_FORMAT_B8G8R8A8_SRGB surface format,
// there is no need to do gamma correction in the fragment shader
ui_color = vec4(pow(ui_color.r, 1.0 / 2.2), pow(ui_color.g, 1.0 / 2.2), pow(ui_color.b, 1.0 / 2.2), pow(ui_color.a, 1.0 / 2.2));

out_color = scene_color + ui_color;
if(ui_color.r<1e-6&&ui_color.g<1e-6&&ui_color.a<1e-6)
{
ui_color = vec4(pow(ui_color.r, 1.0 / 2.2), pow(ui_color.g, 1.0 / 2.2), pow(ui_color.b, 1.0 / 2.2), pow(ui_color.a, 1.0 / 2.2));
out_color = scene_color;
}
else
{
ui_color = vec4(pow(ui_color.r, 1.0 / 2.2), pow(ui_color.g, 1.0 / 2.2), pow(ui_color.b, 1.0 / 2.2), pow(ui_color.a, 1.0 / 2.2));
out_color = ui_color;
}
}
20 changes: 20 additions & 0 deletions engine/shader/glsl/debugdraw.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#version 450

#extension GL_GOOGLE_include_directive :enable
layout(location = 0) in vec4 fragColor;
layout(location = 1) in vec2 fragTexCoord;

layout(location = 0) out vec4 outColor;

layout(set = 0, binding = 2) uniform sampler2D texSampler;


void main(){
outColor = fragColor;
if(fragTexCoord.x >= 0.0f && fragTexCoord.y >= 0.0f)
{
vec4 tex = texture(texSampler, fragTexCoord);
float xi = tex.r;
outColor = vec4(fragColor.r*xi,fragColor.g*xi,fragColor.b*xi,fragColor.a*xi);
}
}
43 changes: 43 additions & 0 deletions engine/shader/glsl/debugdraw.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#version 450

#extension GL_GOOGLE_include_directive :enable
#include "constants.h"

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec4 inColor;
layout(location = 2) in vec2 texcoord;

layout(set = 0, binding = 0) uniform UniformBufferObject {
mat4 proj_view_matrix;
} ubo;

layout(set = 0, binding = 1) uniform UniformDynamicBufferObject {
mat4 model;
vec4 color;
} dynamic_ubo;

layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragTexCoord;

void main() {
if(texcoord.x<0)
{
gl_Position = ubo.proj_view_matrix * dynamic_ubo.model * vec4(inPosition,1.0);
}
else
{
gl_Position = vec4(inPosition,1.0);
}

gl_PointSize = 2;

if(dynamic_ubo.color.a>0.000001)
{
fragColor = dynamic_ubo.color;
}
else
{
fragColor = inColor;
}
fragTexCoord = texcoord;
}
33 changes: 33 additions & 0 deletions engine/source/editor/source/editor_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "runtime/function/render/render_camera.h"
#include "runtime/function/render/render_system.h"
#include "runtime/function/render/window_system.h"
#include "runtime/function/render/render_debug_config.h"

#include <imgui.h>
#include <imgui_internal.h>
Expand Down Expand Up @@ -336,6 +337,38 @@ namespace Piccolo
{
g_runtime_global_context.m_world_manager->saveCurrentLevel();
}
if (ImGui::BeginMenu("Debug"))
{
if (ImGui::BeginMenu("Animation"))
{
if (ImGui::MenuItem(g_runtime_global_context.m_render_debug_config->animation.show_skeleton ? "off skeleton" : "show skeleton"))
{
g_runtime_global_context.m_render_debug_config->animation.show_skeleton = !g_runtime_global_context.m_render_debug_config->animation.show_skeleton;
}
if (ImGui::MenuItem(g_runtime_global_context.m_render_debug_config->animation.show_bone_name ? "off bone name" : "show bone name"))
{
g_runtime_global_context.m_render_debug_config->animation.show_bone_name = !g_runtime_global_context.m_render_debug_config->animation.show_bone_name;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Camera"))
{
if (ImGui::MenuItem(g_runtime_global_context.m_render_debug_config->camera.show_runtime_info ? "off runtime info" : "show runtime info"))
{
g_runtime_global_context.m_render_debug_config->camera.show_runtime_info = !g_runtime_global_context.m_render_debug_config->camera.show_runtime_info;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Game Object"))
{
if (ImGui::MenuItem(g_runtime_global_context.m_render_debug_config->gameObject.show_bounding_box ? "off bounding box" : "show bounding box"))
{
g_runtime_global_context.m_render_debug_config->gameObject.show_bounding_box = !g_runtime_global_context.m_render_debug_config->gameObject.show_bounding_box;
}
ImGui::EndMenu();
}
ImGui::EndMenu();
}
if (ImGui::MenuItem("Exit"))
{
g_editor_global_context.m_engine_runtime->shutdownEngine();
Expand Down
7 changes: 4 additions & 3 deletions engine/source/runtime/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "runtime/function/physics/physics_manager.h"
#include "runtime/function/render/render_system.h"
#include "runtime/function/render/window_system.h"
#include "runtime/function/render/debugdraw/debug_draw_manager.h"

namespace Piccolo
{
Expand Down Expand Up @@ -73,7 +74,7 @@ namespace Piccolo
// exchange data between logic and render contexts
g_runtime_global_context.m_render_system->swapLogicRenderData();

rendererTick();
rendererTick(delta_time);

#ifdef ENABLE_PHYSICS_DEBUG_RENDERER
g_runtime_global_context.m_physics_manager->renderPhysicsWorld(delta_time);
Expand All @@ -95,9 +96,9 @@ namespace Piccolo
g_runtime_global_context.m_input_system->tick();
}

bool PiccoloEngine::rendererTick()
bool PiccoloEngine::rendererTick(float delta_time)
{
g_runtime_global_context.m_render_system->tick();
g_runtime_global_context.m_render_system->tick(delta_time);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion engine/source/runtime/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Piccolo

protected:
void logicalTick(float delta_time);
bool rendererTick();
bool rendererTick(float delta_time);

void calculateFPS(float delta_time);

Expand Down
10 changes: 10 additions & 0 deletions engine/source/runtime/function/animation/skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ namespace Piccolo
}
return animation_result;
}

const Bone* Skeleton::getBones() const
{
return m_bones;
}

int32_t Skeleton::getBonesCount() const
{
return m_bone_count;
}
} // namespace Piccolo
2 changes: 2 additions & 0 deletions engine/source/runtime/function/animation/skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ namespace Piccolo
void applyAnimation(const BlendStateWithClipData& blend_state);
AnimationResult outputAnimationResult();
void resetSkeleton();
const Bone* getBones() const;
int32_t getBonesCount() const;
};
} // namespace Piccolo
1 change: 1 addition & 0 deletions engine/source/runtime/function/character/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Piccolo

GObjectID getObjectID() const;
void setObject(std::shared_ptr<GObject> gobject);
std::weak_ptr<GObject> getObject() const { return m_character_object; }

void setPosition(const Vector3& position) { m_position = position; }
void setRotation(const Quaternion& rotation) { m_rotation = rotation; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ namespace Piccolo
}

const AnimationResult& AnimationComponent::getResult() const { return m_animation_res.animation_result; }

const Skeleton& AnimationComponent::getSkeleton() const { return m_skeleton; }
} // namespace Piccolo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Piccolo

const AnimationResult& getResult() const;

const Skeleton& getSkeleton() const;

protected:
META(Enable)
AnimationComponentRes m_animation_res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace Piccolo

CameraMode getCameraMode() const { return m_camera_mode; }
void setCameraMode(CameraMode mode) { m_camera_mode = mode; }
Vector3 getPosition() const { return m_position; }
Vector3 getForward() const { return m_forward; }

private:
void tickFirstPersonCamera(float delta_time);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "runtime/function/framework/component/rigidbody/rigidbody_component.h"

#include "runtime/engine.h"

#include "runtime/core/base/macro.h"

#include "runtime/function/framework/component/transform/transform_component.h"
#include "runtime/function/framework/object/object.h"
#include "runtime/function/framework/world/world_manager.h"
#include "runtime/function/global/global_context.h"
#include "runtime/function/physics/physics_scene.h"
#include "runtime/function/physics/physics_system.h"

namespace Piccolo
{
Expand All @@ -22,21 +23,20 @@ namespace Piccolo
return;
}

m_physics_actor = g_runtime_global_context.m_legacy_physics_system->createPhysicsActor(
parent_object, parent_transform->getTransformConst(), m_rigidbody_res);
std::shared_ptr<PhysicsScene> physics_scene =
g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock();
ASSERT(physics_scene);

createRigidBody(parent_transform->getTransformConst());
m_rigidbody_id = physics_scene->createRigidBody(parent_transform->getTransformConst(), m_rigidbody_res);
}

RigidBodyComponent::~RigidBodyComponent()
{
if (m_physics_actor)
{
removeRigidBody();
std::shared_ptr<PhysicsScene> physics_scene =
g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock();
ASSERT(physics_scene);

g_runtime_global_context.m_legacy_physics_system->removePhyicsActor(m_physics_actor);
m_physics_actor = nullptr;
}
physics_scene->removeRigidBody(m_rigidbody_id);
}

void RigidBodyComponent::createRigidBody(const Transform& global_transform)
Expand All @@ -45,25 +45,20 @@ namespace Piccolo
g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock();
ASSERT(physics_scene);

const uint32_t body_id = physics_scene->createRigidBody(global_transform, m_rigidbody_res);
m_physics_actor->setBodyID(body_id);
m_rigidbody_id = physics_scene->createRigidBody(global_transform, m_rigidbody_res);
}

void RigidBodyComponent::removeRigidBody()
{
const uint32_t body_id = m_physics_actor->getBodyID();

std::shared_ptr<PhysicsScene> physics_scene =
g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock();
ASSERT(physics_scene);

physics_scene->removeRigidBody(body_id);
physics_scene->removeRigidBody(m_rigidbody_id);
}

void RigidBodyComponent::updateGlobalTransform(const Transform& transform, bool is_scale_dirty)
{
m_physics_actor->setGlobalTransform(transform);

if (is_scale_dirty)
{
removeRigidBody();
Expand All @@ -76,8 +71,17 @@ namespace Piccolo
g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock();
ASSERT(physics_scene);

physics_scene->updateRigidBodyGlobalTransform(m_physics_actor->getBodyID(), transform);
physics_scene->updateRigidBodyGlobalTransform(m_rigidbody_id, transform);
}
}

void RigidBodyComponent::getShapeBoundingBoxes(std::vector<AxisAlignedBox>& out_bounding_boxes) const
{
std::shared_ptr<PhysicsScene> physics_scene =
g_runtime_global_context.m_world_manager->getCurrentActivePhysicsScene().lock();
ASSERT(physics_scene);

physics_scene->getShapeBoundingBoxes(m_rigidbody_id, out_bounding_boxes);
}

} // namespace Piccolo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "runtime/resource/res_type/components/rigid_body.h"

#include "runtime/function/framework/component/component.h"
#include "runtime/function/physics/physics_actor.h"

namespace Piccolo
{
Expand All @@ -19,6 +18,7 @@ namespace Piccolo

void tick(float delta_time) override {}
void updateGlobalTransform(const Transform& transform, bool is_scale_dirty);
void getShapeBoundingBoxes(std::vector<AxisAlignedBox> & out_boudning_boxes) const;

protected:
void createRigidBody(const Transform& global_transform);
Expand All @@ -27,6 +27,6 @@ namespace Piccolo
META(Enable)
RigidBodyComponentRes m_rigidbody_res;

PhysicsActor* m_physics_actor {nullptr};
uint32_t m_rigidbody_id {0xffffffff};
};
} // namespace Piccolo
Loading

0 comments on commit 2ed2bca

Please sign in to comment.