Merge branch 'main' into PlayerController

This commit is contained in:
Glence 2023-02-24 18:04:26 +08:00
commit dfbd1d027c
16 changed files with 50 additions and 76 deletions

View File

@ -39,8 +39,7 @@ void main()
fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
if (fragColor.a < 0.01f) if (fragColor.a < 0.01f)
{ {
fragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); discard;
// discard;
} }
fragColor.a = MatProp.data[In2.materialIndex].alpha; fragColor.a = MatProp.data[In2.materialIndex].alpha;

Binary file not shown.

View File

@ -10,8 +10,8 @@ namespace SHADE
{ {
SHCameraComponent::SHCameraComponent() SHCameraComponent::SHCameraComponent()
:yaw(0.0f), pitch(0.0f), roll(0.0f) :yaw(0.0f), pitch(0.0f), roll(0.0f)
, width(1920.0f), height(1080.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(0.5f) , width(1920.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(0.5f)
, perspProj(true), dirtyView(true), dirtyProj(true) , perspProj(true), dirtyView(true), dirtyProj(true), followScreenAR(true)
, viewMatrix(), perspProjMatrix(), orthoProjMatrix() , viewMatrix(), perspProjMatrix(), orthoProjMatrix()
, position(), offset() , position(), offset()
{ {
@ -122,11 +122,6 @@ namespace SHADE
} }
void SHCameraComponent::SetHeight(float height) noexcept
{
this->height = height;
dirtyProj = true;
}
void SHCameraComponent::SetNear(float znear) noexcept void SHCameraComponent::SetNear(float znear) noexcept
{ {
@ -176,10 +171,7 @@ namespace SHADE
return width; return width;
} }
float SHCameraComponent::GetHeight() const noexcept
{
return height;
}
float SHCameraComponent::GetNear() const noexcept float SHCameraComponent::GetNear() const noexcept
{ {
@ -191,10 +183,7 @@ namespace SHADE
return zFar; return zFar;
} }
float SHCameraComponent::GetAspectRatio() const noexcept
{
return width/height;
}
float SHCameraComponent::GetFOV() const noexcept float SHCameraComponent::GetFOV() const noexcept
{ {
@ -251,11 +240,11 @@ RTTR_REGISTRATION
.property("Yaw", &SHCameraComponent::GetYaw, &SHCameraComponent::SetYaw) .property("Yaw", &SHCameraComponent::GetYaw, &SHCameraComponent::SetYaw)
.property("Roll", &SHCameraComponent::GetRoll, &SHCameraComponent::SetRoll) .property("Roll", &SHCameraComponent::GetRoll, &SHCameraComponent::SetRoll)
.property("Width", &SHCameraComponent::GetWidth, &SHCameraComponent::SetWidth) .property("Width", &SHCameraComponent::GetWidth, &SHCameraComponent::SetWidth)
.property("Height", &SHCameraComponent::GetHeight, &SHCameraComponent::SetHeight)
.property("Near", &SHCameraComponent::GetNear, &SHCameraComponent::SetNear) .property("Near", &SHCameraComponent::GetNear, &SHCameraComponent::SetNear)
.property("Far", &SHCameraComponent::GetFar, &SHCameraComponent::SetFar) .property("Far", &SHCameraComponent::GetFar, &SHCameraComponent::SetFar)
.property("Perspective", &SHCameraComponent::GetIsPerspective, &SHCameraComponent::SetIsPerspective) .property("Perspective", &SHCameraComponent::GetIsPerspective, &SHCameraComponent::SetIsPerspective)
.property("FOV", &SHCameraComponent::GetFOV, &SHCameraComponent::SetFOV); .property("FOV", &SHCameraComponent::GetFOV, &SHCameraComponent::SetFOV);
} }

View File

@ -19,7 +19,6 @@ namespace SHADE
float roll; float roll;
float width; float width;
float height;
float zNear; float zNear;
float zFar; float zFar;
float fov; float fov;
@ -27,7 +26,6 @@ namespace SHADE
bool dirtyView; bool dirtyView;
bool dirtyProj; bool dirtyProj;
SHMatrix viewMatrix; SHMatrix viewMatrix;
SHMatrix perspProjMatrix; SHMatrix perspProjMatrix;
SHMatrix orthoProjMatrix; SHMatrix orthoProjMatrix;
@ -45,6 +43,8 @@ namespace SHADE
SHCameraComponent(); SHCameraComponent();
virtual ~SHCameraComponent(); virtual ~SHCameraComponent();
bool followScreenAR;
//Getters and setters. //Getters and setters.
void SetYaw(float yaw) noexcept; void SetYaw(float yaw) noexcept;
@ -57,7 +57,6 @@ namespace SHADE
void SetPosition(SHVec3 pos) noexcept; void SetPosition(SHVec3 pos) noexcept;
void SetWidth(float width) noexcept; void SetWidth(float width) noexcept;
void SetHeight(float height) noexcept;
void SetNear(float znear) noexcept; void SetNear(float znear) noexcept;
void SetFar(float zfar) noexcept; void SetFar(float zfar) noexcept;
void SetFOV(float fov) noexcept; void SetFOV(float fov) noexcept;
@ -70,11 +69,9 @@ namespace SHADE
float GetRoll() const noexcept; float GetRoll() const noexcept;
float GetWidth() const noexcept; float GetWidth() const noexcept;
float GetHeight() const noexcept;
float GetNear() const noexcept; float GetNear() const noexcept;
float GetFar() const noexcept; float GetFar() const noexcept;
float GetAspectRatio() const noexcept;
float GetFOV() const noexcept; float GetFOV() const noexcept;
bool GetIsPerspective() const noexcept; bool GetIsPerspective() const noexcept;

View File

@ -99,13 +99,13 @@ namespace SHADE
return 0.0f; return 0.0f;
} }
float SHCameraDirector::GetHeight() noexcept //float SHCameraDirector::GetHeight() noexcept
{ //{
SHCameraComponent* camComponent = GetMainCameraComponent(); // SHCameraComponent* camComponent = GetMainCameraComponent();
if (camComponent) // if (camComponent)
return camComponent->GetHeight(); // return camComponent->GetHeight();
else // else
return 0.0f; // return 0.0f;
} //}
} }

View File

@ -31,7 +31,7 @@ namespace SHADE
SHMatrix const& GetOrthoMatrix() noexcept; SHMatrix const& GetOrthoMatrix() noexcept;
SHMatrix const& GetPerspectiveMatrix() noexcept; SHMatrix const& GetPerspectiveMatrix() noexcept;
float GetWidth() noexcept; float GetWidth() noexcept;
float GetHeight() noexcept; //float GetHeight() noexcept;
private: private:
SHMatrix viewMatrix; SHMatrix viewMatrix;

View File

@ -116,7 +116,6 @@ namespace SHADE
editorCamera.SetYaw(0.0f); editorCamera.SetYaw(0.0f);
editorCamera.SetRoll(0.0f); editorCamera.SetRoll(0.0f);
editorCamera.SetWidth(1080.0f); editorCamera.SetWidth(1080.0f);
editorCamera.SetHeight(720.0f);
editorCamera.SetFar(10000000.0f); editorCamera.SetFar(10000000.0f);
editorCamera.movementSpeed = 2.0f; editorCamera.movementSpeed = 2.0f;
editorCamera.perspProj = true; editorCamera.perspProj = true;
@ -144,18 +143,7 @@ namespace SHADE
//std::cout << EVENT_DATA->resizeWidth << std::endl; //std::cout << EVENT_DATA->resizeWidth << std::endl;
//std::cout << EVENT_DATA->resizeHeight << std::endl; //std::cout << EVENT_DATA->resizeHeight << std::endl;
screenAspectRatio = (float)EVENT_DATA->resizeWidth / (float)EVENT_DATA->resizeHeight;
for (auto director : directorHandleList)
{
auto camera = SHComponentManager::GetComponent_s<SHCameraComponent>(director->mainCameraEID);
if (camera)
{
camera->SetWidth(EVENT_DATA->resizeWidth);
camera->SetHeight(EVENT_DATA->resizeHeight);
}
}
return eventPtr->handle; return eventPtr->handle;
@ -340,7 +328,7 @@ namespace SHADE
if (camera.dirtyProj == true) if (camera.dirtyProj == true)
{ {
//Perspective projection matrix. //Perspective projection matrix.
const float ASPECT_RATIO = (camera.GetAspectRatio()); const float ASPECT_RATIO = (screenAspectRatio);
const float TAN_HALF_FOV = tan(SHMath::DegreesToRadians(camera.fov) * 0.5f); const float TAN_HALF_FOV = tan(SHMath::DegreesToRadians(camera.fov) * 0.5f);
camera.perspProjMatrix = SHMatrix::Identity; camera.perspProjMatrix = SHMatrix::Identity;
camera.perspProjMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV); camera.perspProjMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV);
@ -357,7 +345,7 @@ namespace SHADE
const float right = camera.GetWidth() * 0.5f; const float right = camera.GetWidth() * 0.5f;
const float left = -right; const float left = -right;
const float top = camera.GetHeight() * 0.5f; const float top = camera.GetWidth() / screenAspectRatio * 0.5f;
const float btm = -top; const float btm = -top;
const float n = camera.GetNear(); const float n = camera.GetNear();
const float f = camera.GetFar(); const float f = camera.GetFar();
@ -574,11 +562,11 @@ namespace SHADE
auto editor = SHSystemManager::GetSystem<SHEditor>(); auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor->editorState != SHEditor::State::PLAY) if (editor->editorState != SHEditor::State::PLAY)
{ {
return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetHeight() }; return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetWidth() / screenAspectRatio };
} }
else else
{ {
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() }; return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetWidth() / screenAspectRatio };
} }
#else #else

View File

@ -21,6 +21,8 @@ namespace SHADE
SHCameraComponent editorCamera; SHCameraComponent editorCamera;
SHCameraArmComponent editorCameraArm; SHCameraArmComponent editorCameraArm;
float screenAspectRatio{16.0f/9.0f};
SHResourceLibrary<SHCameraDirector> directorLibrary; SHResourceLibrary<SHCameraDirector> directorLibrary;
std::vector<DirectorHandle> directorHandleList; std::vector<DirectorHandle> directorHandleList;

View File

@ -59,7 +59,7 @@ namespace SHADE
camSystem->UpdateEditorArm(SHFrameRateController::GetRawDeltaTime(), shouldUpdateCamArm, targetPos); camSystem->UpdateEditorArm(SHFrameRateController::GetRawDeltaTime(), shouldUpdateCamArm, targetPos);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
if (Begin()) if (Begin())
{ {
ImGuizmo::SetDrawlist(); ImGuizmo::SetDrawlist();
@ -101,6 +101,7 @@ namespace SHADE
} }
} }
} }
ImGui::PopStyleColor();
ImGuizmo::SetRect(beginCursorPos.x, beginCursorPos.y, beginContentRegionAvailable.x, beginContentRegionAvailable.y); ImGuizmo::SetRect(beginCursorPos.x, beginCursorPos.y, beginContentRegionAvailable.x, beginContentRegionAvailable.y);
if(editor->editorState != SHEditor::State::PLAY) if(editor->editorState != SHEditor::State::PLAY)
transformGizmo.Draw(); transformGizmo.Draw();

View File

@ -1178,7 +1178,7 @@ namespace SHADE
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>(); auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
#ifdef SHEDITOR #ifdef SHEDITOR
cameraSystem->GetEditorCamera()->SetWidth(static_cast<float>(resizeWidth)); cameraSystem->GetEditorCamera()->SetWidth(static_cast<float>(resizeWidth));
cameraSystem->GetEditorCamera()->SetHeight(static_cast<float>(resizeHeight)); //cameraSystem->GetEditorCamera()->SetAspectRatio(static_cast<float>(resizeWidth) / static_cast<float>(resizeHeight));
// Create new event and broadcast it // Create new event and broadcast it
SHWindowResizeEvent newEvent; SHWindowResizeEvent newEvent;
@ -1188,7 +1188,12 @@ namespace SHADE
SHEventManager::BroadcastEvent<SHWindowResizeEvent>(newEvent, SH_WINDOW_RESIZE_EVENT); SHEventManager::BroadcastEvent<SHWindowResizeEvent>(newEvent, SH_WINDOW_RESIZE_EVENT);
#else #else
// Create new event and broadcast it
SHWindowResizeEvent newEvent;
newEvent.resizeWidth = resizeWidth;
newEvent.resizeHeight = resizeHeight;
SHEventManager::BroadcastEvent<SHWindowResizeEvent>(newEvent, SH_WINDOW_RESIZE_EVENT);
#endif #endif
} }

View File

@ -40,7 +40,7 @@ namespace SHADE
if (SHVkUtil::IsDepthStencilAttachment(vkDescriptions[i].format)) if (SHVkUtil::IsDepthStencilAttachment(vkDescriptions[i].format))
clearColors[i].depthStencil = vk::ClearDepthStencilValue(1.0f, 0); clearColors[i].depthStencil = vk::ClearDepthStencilValue(1.0f, 0);
else else
clearColors[i].color = { {{0.0f, 0.0f, 0.0f, 1.0f}} }; clearColors[i].color = { {{0.0f, 0.0f, 0.0f, 0.0f}} };
} }

View File

@ -28,16 +28,19 @@ namespace SHADE
void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept
{ {
defaultTexture = texture; defaultTexture = texture;
SHResourceManager::LoadOrGet<SHTexture>(texture);
} }
void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept
{ {
hoveredTexture = texture; hoveredTexture = texture;
SHResourceManager::LoadOrGet<SHTexture>(texture);\
} }
void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept
{ {
clickedTexture = texture; clickedTexture = texture;
SHResourceManager::LoadOrGet<SHTexture>(texture);
} }

View File

@ -1,6 +1,7 @@
#include "SHpch.h" #include "SHpch.h"
#include "SHToggleButtonComponent.h" #include "SHToggleButtonComponent.h"
#include "Resource/SHResourceManager.h"
#include "Graphics/MiddleEnd/Textures/SHTextureLibrary.h"
namespace SHADE namespace SHADE
{ {
@ -28,11 +29,13 @@ namespace SHADE
void SHToggleButtonComponent::SetDefaultTexture(AssetID texture) noexcept void SHToggleButtonComponent::SetDefaultTexture(AssetID texture) noexcept
{ {
defaultTexture = texture; defaultTexture = texture;
SHResourceManager::LoadOrGet<SHTexture>(texture);
} }
void SHToggleButtonComponent::SetToggledTexture(AssetID texture) noexcept void SHToggleButtonComponent::SetToggledTexture(AssetID texture) noexcept
{ {
toggledTexture = texture; toggledTexture = texture;
SHResourceManager::LoadOrGet<SHTexture>(texture);
} }
void SHToggleButtonComponent::SetValue(bool value) noexcept void SHToggleButtonComponent::SetValue(bool value) noexcept

View File

@ -313,8 +313,8 @@ namespace SHADE
{ {
auto material = renderable->GetModifiableMaterial(); auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID; comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID)->TextureArrayIndex); material->SetProperty("data.textureIndex", SHResourceManager::Get<SHTexture>(textureID)->TextureArrayIndex);
loadTexture = true;
} }
@ -368,8 +368,8 @@ namespace SHADE
{ {
auto material = renderable->GetModifiableMaterial(); auto material = renderable->GetModifiableMaterial();
comp.currentTexture = textureID; comp.currentTexture = textureID;
material->SetProperty("data.textureIndex", SHResourceManager::LoadOrGet<SHTexture>(textureID)); material->SetProperty("data.textureIndex", SHResourceManager::Get<SHTexture>(textureID)->TextureArrayIndex);
loadTexture = true;
} }
@ -381,6 +381,8 @@ namespace SHADE
{ {
SHUISystem* system = (SHUISystem*)GetSystem(); SHUISystem* system = (SHUISystem*)GetSystem();
auto& dense = SHComponentManager::GetDense<SHButtonComponent>(); auto& dense = SHComponentManager::GetDense<SHButtonComponent>();
//We ensure that the textures are loaded before we do the update.
SHResourceManager::FinaliseChanges();
for (auto& comp : dense) for (auto& comp : dense)
{ {
if (SHSceneManager::CheckNodeAndComponentsActive<SHButtonComponent>(comp.GetEID())) if (SHSceneManager::CheckNodeAndComponentsActive<SHButtonComponent>(comp.GetEID()))
@ -393,11 +395,6 @@ namespace SHADE
if (SHSceneManager::CheckNodeAndComponentsActive<SHToggleButtonComponent>(comp.GetEID())) if (SHSceneManager::CheckNodeAndComponentsActive<SHToggleButtonComponent>(comp.GetEID()))
system->UpdateToggleButtonComponent(comp); system->UpdateToggleButtonComponent(comp);
} }
if (system->loadTexture == true)
{
system->loadTexture = false;
SHResourceManager::FinaliseChanges();
}
} }
SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept SHVec2 SHUISystem::CanvasToScreenPoint(SHVec2& const canvasPoint, bool normalized) noexcept

View File

@ -50,15 +50,8 @@ namespace SHADE
{ {
GetNativeComponent()->SetWidth(val); GetNativeComponent()->SetWidth(val);
} }
float Camera::Height::get()
{
return (GetNativeComponent()->GetHeight());
}
void Camera::Height::set(float val)
{
GetNativeComponent()->SetHeight(val);
}
float Camera::Near::get() float Camera::Near::get()
{ {
return (GetNativeComponent()->GetNear()); return (GetNativeComponent()->GetNear());

View File

@ -35,11 +35,7 @@ namespace SHADE
float get(); float get();
void set(float val); void set(float val);
} }
property float Height
{
float get();
void set(float val);
}
property float Near property float Near
{ {
float get(); float get();
@ -62,6 +58,7 @@ namespace SHADE
} }
void SetMainCamera(size_t directorIndex); void SetMainCamera(size_t directorIndex);
void SetMainCamera(); void SetMainCamera();
void LookAt(Vector3 targetPosition); void LookAt(Vector3 targetPosition);