Reworking shader compilation to not need reflection
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
CameraComponent.h
|
||||
CameraComponent.cpp
|
||||
Component.h
|
||||
Component.cpp
|
||||
PrimitiveComponent.cpp
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "CameraComponent.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
CameraComponent::CameraComponent()
|
||||
: bNeedsProjectionBuild(true)
|
||||
, bNeedsViewBuild(true)
|
||||
, originPoint(0, 0, 0)
|
||||
, cameraPosition(0, 0, 0)
|
||||
{
|
||||
distance = 50;
|
||||
rotationX = 0;
|
||||
rotationY = -0.5f;
|
||||
}
|
||||
|
||||
CameraComponent::~CameraComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void CameraComponent::mouseMove(float deltaX, float deltaY)
|
||||
{
|
||||
//0.01 mouse sensitivity
|
||||
rotationX += deltaX/100.f;
|
||||
rotationY += deltaY/100.f;
|
||||
rotationY = std::clamp(rotationY, -1.5f, 1.5f);
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void CameraComponent::mouseScroll(double x)
|
||||
{
|
||||
distance += static_cast<float>(x);
|
||||
distance = std::max(distance, 1.f);
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void CameraComponent::moveOrigin(float up)
|
||||
{
|
||||
originPoint.y += up;
|
||||
bNeedsViewBuild = true;
|
||||
}
|
||||
|
||||
void CameraComponent::buildViewMatrix()
|
||||
{
|
||||
Matrix4 rotation = glm::rotate(Matrix4(), rotationX, Vector(0, 1, 0));
|
||||
rotation = glm::rotate(rotation, rotationY, Vector(1, 0, 0));
|
||||
Vector4 translation(0, 0, distance, 1);
|
||||
translation = rotation * translation;
|
||||
|
||||
cameraPosition = originPoint + Vector(translation);
|
||||
viewMatrix = glm::lookAt(cameraPosition, originPoint, Vector(0, 1, 0));
|
||||
|
||||
bNeedsViewBuild = false;
|
||||
}
|
||||
|
||||
void CameraComponent::buildProjectionMatrix()
|
||||
{
|
||||
projectionMatrix = glm::perspective(fieldOfView, aspectRatio, 1.0f, 1000.f);
|
||||
static Matrix4 correctionMatrix =
|
||||
Matrix4(
|
||||
Vector4(1, 0, 0, 0),
|
||||
Vector4(0, 1, 0, 0),
|
||||
Vector4(0, 0, 0.5f, 0),
|
||||
Vector4(0, 0, 0.5f, 1));
|
||||
projectionMatrix = correctionMatrix * projectionMatrix;
|
||||
bNeedsProjectionBuild = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include "Component.h"
|
||||
#include "Math/Matrix.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class CameraComponent : public Component
|
||||
{
|
||||
public:
|
||||
CameraComponent();
|
||||
virtual ~CameraComponent();
|
||||
|
||||
Matrix4 getViewMatrix()
|
||||
{
|
||||
if (bNeedsViewBuild)
|
||||
{
|
||||
buildViewMatrix();
|
||||
}
|
||||
return viewMatrix;
|
||||
}
|
||||
Matrix4 getProjectionMatrix()
|
||||
{
|
||||
if (bNeedsProjectionBuild)
|
||||
{
|
||||
buildProjectionMatrix();
|
||||
}
|
||||
return projectionMatrix;
|
||||
}
|
||||
void mouseMove(float deltaX, float deltaY);
|
||||
void mouseScroll(double x);
|
||||
void moveOrigin(float up);
|
||||
float aspectRatio;
|
||||
float fieldOfView;
|
||||
private:
|
||||
bool bNeedsViewBuild;
|
||||
bool bNeedsProjectionBuild;
|
||||
void buildViewMatrix();
|
||||
void buildProjectionMatrix();
|
||||
|
||||
float rotationX;
|
||||
float rotationY;
|
||||
float distance;
|
||||
|
||||
Vector eye;
|
||||
Vector originPoint;
|
||||
Vector cameraPosition;
|
||||
//Transforms relative to actor
|
||||
Matrix4 viewMatrix;
|
||||
Matrix4 projectionMatrix;
|
||||
};
|
||||
DEFINE_REF(CameraComponent);
|
||||
} // namespace Seele
|
||||
@@ -124,6 +124,11 @@ void Component::setParent(PComponent newParent)
|
||||
parent = newParent;
|
||||
}
|
||||
|
||||
void Component::setOwner(PActor newOwner)
|
||||
{
|
||||
owner = newOwner;
|
||||
}
|
||||
|
||||
void Component::internalSetTransform(Vector newLocation, Quaternion newRotation)
|
||||
{
|
||||
if (parent != nullptr)
|
||||
|
||||
@@ -15,6 +15,8 @@ public:
|
||||
void tick(float deltaTime);
|
||||
PComponent getParent();
|
||||
PActor getOwner();
|
||||
void setParent(PComponent parent);
|
||||
void setOwner(PActor owner);
|
||||
virtual void notifySceneAttach(PScene scene);
|
||||
|
||||
void setWorldLocation(Vector location);
|
||||
@@ -34,7 +36,6 @@ public:
|
||||
Transform getTransform() const;
|
||||
|
||||
private:
|
||||
void setParent(PComponent parent);
|
||||
void internalSetTransform(Vector newLocation, Quaternion newRotation);
|
||||
void propagateTransformUpdate();
|
||||
void updateComponentTransform(Quaternion relativeRotationQuat);
|
||||
|
||||
@@ -17,7 +17,7 @@ PrimitiveComponent::PrimitiveComponent(PMeshAsset asset)
|
||||
for (uint32 i = 0; i < assetMeshes.size(); i++)
|
||||
{
|
||||
auto& batch = staticMeshes[i];
|
||||
batch.material = assetMeshes[i]->referencedMaterial->getRenderMaterial();
|
||||
batch.material = assetMeshes[i]->referencedMaterial;
|
||||
batch.isBackfaceCullingDisabled = false;
|
||||
batch.isCastingShadow = true;
|
||||
batch.primitiveComponent = this;
|
||||
|
||||
Reference in New Issue
Block a user