Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:

ios:
name: iOS
runs-on: macos-13
runs-on: macos-15
needs: version

steps:
Expand Down Expand Up @@ -217,7 +217,7 @@ jobs:

tvos:
name: tvOS
runs-on: macos-13
runs-on: macos-15
needs: version

steps:
Expand Down Expand Up @@ -334,6 +334,7 @@ jobs:
name: FreeBSD
runs-on: ubuntu-latest
needs: version
if: false

steps:
- name: Checkout repository
Expand Down Expand Up @@ -582,6 +583,7 @@ jobs:

- name: Upload FreeBSD
uses: actions/upload-release-asset@v1
if: false
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ThunderEngine-freebsd-x64.7z
Expand Down
28 changes: 7 additions & 21 deletions engine/includes/commandbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,16 @@ class ComputeInstance;
class RenderTarget;
class Texture;
class Mesh;
class Camera;

struct Global {
Matrix4 view;
Matrix4 projection;
Matrix4 cameraView;
Matrix4 cameraProjection;
Matrix4 cameraProjectionInv;
Matrix4 cameraScreenToWorld;
Matrix4 cameraWorldToScreen;

Vector4 cameraPosition;
Vector4 cameraTarget;
Vector4 cameraScreen;
Vector4 shadowPageSize;

float clip;
float time;
float deltaTime;
float padding[13];
Vector4 cameraParams;
Vector4 params;
};

class ENGINE_EXPORT CommandBuffer: public Object {
Expand All @@ -41,6 +32,8 @@ class ENGINE_EXPORT CommandBuffer: public Object {
public:
CommandBuffer();

void begin();

virtual void dispatchCompute(ComputeInstance *shader, int32_t groupsX, int32_t groupsY, int32_t groupsZ);

virtual void drawMesh(Mesh *mesh, uint32_t sub, uint32_t layer, MaterialInstance &instance);
Expand All @@ -49,12 +42,12 @@ class ENGINE_EXPORT CommandBuffer: public Object {

virtual void setViewProjection(const Matrix4 &view, const Matrix4 &projection);

virtual void setGlobalValue(const char *name, const Variant &value);

virtual void setGlobalTexture(const TString &name, Texture *texture);

virtual void setViewport(int32_t x, int32_t y, int32_t width, int32_t height);

virtual void setCameraProperties(Camera *camera);

virtual void enableScissor(int32_t x, int32_t y, int32_t width, int32_t height);

virtual void disableScissor();
Expand All @@ -68,8 +61,6 @@ class ENGINE_EXPORT CommandBuffer: public Object {
virtual void beginDebugMarker(const TString &name);
virtual void endDebugMarker();

Vector2 viewport() const;

static Vector4 idToColor(uint32_t id);

static bool isInited();
Expand All @@ -81,11 +72,6 @@ class ENGINE_EXPORT CommandBuffer: public Object {

Material::Textures m_textures;

int32_t m_viewportX;
int32_t m_viewportY;
int32_t m_viewportWidth;
int32_t m_viewportHeight;

};

#endif // COMMANDBUFFER_H
6 changes: 3 additions & 3 deletions engine/includes/components/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ENGINE_EXPORT Camera : public Component {
A_PROPERTY(float, near, Camera::nearPlane, Camera::setNear),
A_PROPERTY(float, far, Camera::farPlane, Camera::setFar),
A_PROPERTY(float, size, Camera::orthoSize, Camera::setOrthoSize),
A_PROPERTY(float, focalDistance, Camera::focal, Camera::setFocal),
A_PROPERTY(float, focalDistance, Camera::focalDistance, Camera::setFocalDistance),
A_PROPERTYEX(Vector4, backgroundColor, Camera::color, Camera::setColor, "editor=Color"),
A_PROPERTY(bool, orthographic, Camera::orthographic, Camera::setOrthographic)
)
Expand Down Expand Up @@ -46,8 +46,8 @@ class ENGINE_EXPORT Camera : public Component {
float farPlane() const;
void setFar(const float distance);

float focal() const;
void setFocal(const float focal);
float focalDistance() const;
void setFocalDistance(const float focal);

float fov() const;
void setFov(const float angle);
Expand Down
4 changes: 1 addition & 3 deletions engine/includes/pipelinecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ENGINE_EXPORT PipelineContext : public Object {
void setCurrentCamera(Camera *camera);
Camera *currentCamera() const;

Vector2 size() const;
void resize(int32_t width, int32_t height);

void invalidateTasks();
Expand All @@ -100,9 +101,6 @@ class ENGINE_EXPORT PipelineContext : public Object {

Callbacks m_postObservers;

Matrix4 m_cameraView;
Matrix4 m_cameraProjection;

AABBox m_worldBound;

RenderList m_sceneRenderables;
Expand Down
64 changes: 25 additions & 39 deletions engine/src/commandbuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "commandbuffer.h"

#include <cstring>
#include "components/camera.h"
#include "components/transform.h"
#include "timer.h"

static bool s_Inited = false;

Expand All @@ -13,12 +15,14 @@ static bool s_Inited = false;
It provides methods for issuing rendering commands, setting global parameters, and managing textures.
*/

CommandBuffer::CommandBuffer() :
m_viewportX(0),
m_viewportY(0),
m_viewportWidth(1),
m_viewportHeight(1) {
CommandBuffer::CommandBuffer() {
uint32_t size = Texture::maxTextureSize();
m_global.params.x = 1.0f / (float)size;
}

void CommandBuffer::begin() {
m_global.params.y = Timer::time();
m_global.params.z = Timer::deltaTime();
}
/*!
Dispatches a compute \a shader with the specified workgroup dimensions.
Expand Down Expand Up @@ -79,28 +83,7 @@ void CommandBuffer::setInited() {
void CommandBuffer::setViewProjection(const Matrix4 &view, const Matrix4 &projection) {
m_global.view = view;
m_global.projection = projection;
}
/*!
Sets a global \a value based on its \a name.
*/
void CommandBuffer::setGlobalValue(const char *name, const Variant &value) {
static const std::unordered_map<std::string, std::pair<size_t, size_t>> offsets = {
{"camera.position", std::make_pair(offsetof(Global, cameraPosition), sizeof(Global::cameraPosition))},
{"camera.target", std::make_pair(offsetof(Global, cameraTarget), sizeof(Global::cameraTarget))},
{"camera.view", std::make_pair(offsetof(Global, cameraView), sizeof(Global::cameraView))},
{"camera.projectionInv", std::make_pair(offsetof(Global, cameraProjectionInv), sizeof(Global::cameraProjectionInv))},
{"camera.projection", std::make_pair(offsetof(Global, cameraProjection), sizeof(Global::cameraProjection))},
{"camera.screenToWorld", std::make_pair(offsetof(Global, cameraScreenToWorld), sizeof(Global::cameraScreenToWorld))},
{"camera.worldToScreen", std::make_pair(offsetof(Global, cameraWorldToScreen), sizeof(Global::cameraWorldToScreen))},
{"camera.screen", std::make_pair(offsetof(Global, cameraScreen), sizeof(Global::cameraScreen))},
{"shadow.pageSize", std::make_pair(offsetof(Global, shadowPageSize), sizeof(Global::shadowPageSize))},
};

auto it = offsets.find(name);
if(it != offsets.end()) {
void *src = value.data();
memcpy(reinterpret_cast<uint8_t *>(&m_global) + it->second.first, src, it->second.second);
}
m_global.cameraWorldToScreen = projection * view;
}
/*!
Sets a global \a texture based on its \a name.
Expand Down Expand Up @@ -157,25 +140,28 @@ void CommandBuffer::beginDebugMarker(const TString &name) {
*/
void CommandBuffer::endDebugMarker() {

}
/*!
Returns Vector2 representing the viewport dimensions.
*/
Vector2 CommandBuffer::viewport() const {
return Vector2(m_viewportWidth, m_viewportHeight);
}
/*!
Sets the viewport dimensions.
Parameters \a x and \a y represents viewport coordinates.
\a width and \a height viewport dimensions.
*/
void CommandBuffer::setViewport(int32_t x, int32_t y, int32_t width, int32_t height) {
m_viewportX = x;
m_viewportY = y;
m_viewportWidth = width;
m_viewportHeight = height;
m_global.cameraParams.z = 1.0f / (float)width;
m_global.cameraParams.w = 1.0f / (float)height;
}
/*!
Sets the \a camera specific global variables.
This function sets up view, projection and clipping planes global shader variables.
*/
void CommandBuffer::setCameraProperties(Camera *camera) {
setViewProjection(camera->viewMatrix(), camera->projectionMatrix());

Transform *t = camera->transform();

setGlobalValue("camera.screen", Vector4(width, height, 1.0f / (float)width, 1.0f / (float)height));
m_global.cameraPosition = t->worldPosition();
m_global.cameraParams.x = camera->nearPlane();
m_global.cameraParams.y = camera->farPlane();
}
/*!
Enables scissor testing with the specified parameters.
Expand Down
5 changes: 2 additions & 3 deletions engine/src/components/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,14 @@ void Camera::setRatio(float ratio) {
/*!
Returns a focal distance for the camera.
*/
float Camera::focal() const {
float Camera::focalDistance() const {
return m_focal;
}
/*!
Sets a \a focal distance for the camera.
*/
void Camera::setFocal(const float focal) {
void Camera::setFocalDistance(const float focal) {
m_focal = focal;
recalcProjection();
}
/*!
Returns the color with which the screen will be cleared.
Expand Down
24 changes: 12 additions & 12 deletions engine/src/editor/viewport/cameracontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CameraController::CameraController() :

Actor *actor = Engine::composeActor<Camera>(gCamera);
m_activeCamera = actor->getComponent<Camera>();
m_activeCamera->setFocal(10.0f);
m_activeCamera->setFocalDistance(10.0f);
m_activeCamera->setOrthoSize(10.0f);

m_activeCamera->setColor(Vector4(0.2f, 0.2f, 0.2f, 0.0f));
Expand Down Expand Up @@ -138,7 +138,7 @@ void CameraController::update() {
}
} else if(Input::isMouseButton(Input::MOUSE_MIDDLE) && !m_blockMove) {
Transform *t = m_activeCamera->transform();
float mult = m_activeCamera->orthographic() ? 1.0f : m_activeCamera->focal() * 0.1f;
float mult = m_activeCamera->orthographic() ? 1.0f : m_activeCamera->focalDistance() * 0.1f;
cameraMove((t->quaternion() * p) * mult);
m_saved = Vector2(pos.x, pos.y);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ void CameraController::move() {
}

if(m_focalLengthTarget > 0.0f) {
m_activeCamera->setFocal(MIX(m_activeCamera->focal(), m_focalLengthTarget, m_transferProgress));
m_activeCamera->setFocalDistance(MIX(m_activeCamera->focalDistance(), m_focalLengthTarget, m_transferProgress));
}

m_transferProgress += 2.0f * DT;
Expand All @@ -185,7 +185,7 @@ void CameraController::move() {
}

if(m_focalLengthTarget > 0.0f) {
m_activeCamera->setFocal(m_focalLengthTarget);
m_activeCamera->setFocalDistance(m_focalLengthTarget);
}
}
}
Expand All @@ -196,7 +196,7 @@ void CameraController::move() {
dir.normalize();

Vector3 delta = (dir * m_cameraSpeed.z) + dir.cross(Vector3(0.0f, 1.0f, 0.0f)) * m_cameraSpeed.x;
t->setPosition(pos - delta * m_activeCamera->focal() * 0.1f);
t->setPosition(pos - delta * m_activeCamera->focalDistance() * 0.1f);

m_cameraSpeed -= m_cameraSpeed * 10.0f * DT;
if(m_cameraSpeed.length() <= .01f) {
Expand Down Expand Up @@ -270,9 +270,9 @@ void CameraController::cameraZoom(float delta) {
m_activeCamera->setOrthoSize(scale);
} else {
float scale = delta * 0.01f;
float focal = CLAMP(m_activeCamera->focal() - scale, m_zoomLimit.x, m_zoomLimit.y);
float focal = CLAMP(m_activeCamera->focalDistance() - scale, m_zoomLimit.x, m_zoomLimit.y);

m_activeCamera->setFocal(focal);
m_activeCamera->setFocalDistance(focal);

Transform *t = m_activeCamera->transform();
t->setPosition(t->position() - t->quaternion() * Vector3(0.0f, 0.0f, scale));
Expand All @@ -285,15 +285,15 @@ void CameraController::cameraRotate(const Vector3 &delta) {
Vector3 euler = t->rotation() - delta;

if(!m_cameraFree) {
Vector3 dir = t->position() - t->quaternion() * Vector3(0.0f, 0.0f, m_activeCamera->focal());
t->setPosition(dir + Quaternion(euler) * Vector3(0.0f, 0.0f, m_activeCamera->focal()));
Vector3 dir = t->position() - t->quaternion() * Vector3(0.0f, 0.0f, m_activeCamera->focalDistance());
t->setPosition(dir + Quaternion(euler) * Vector3(0.0f, 0.0f, m_activeCamera->focalDistance()));
}
t->setRotation(euler);
}

void CameraController::cameraMove(const Vector3 &delta) {
Transform *t = m_activeCamera->transform();
t->setPosition(t->position() - delta * ((m_activeCamera->orthographic()) ? m_activeCamera->orthoSize() : m_activeCamera->focal()));
t->setPosition(t->position() - delta * ((m_activeCamera->orthographic()) ? m_activeCamera->orthoSize() : m_activeCamera->focalDistance()));
}

void CameraController::restoreState(const VariantMap &state) {
Expand All @@ -316,7 +316,7 @@ void CameraController::restoreState(const VariantMap &state) {

it = state.find(gFocal);
if(it != state.end()) {
m_activeCamera->setFocal((*it).second.toFloat());
m_activeCamera->setFocalDistance((*it).second.toFloat());
}

it = state.find(gOrthoSize);
Expand All @@ -338,7 +338,7 @@ VariantMap CameraController::saveState() const {
result[gPosition] = t->position();
result[gRotation] = t->rotation();
result[gOrthographic] = m_activeCamera->orthographic();
result[gFocal] = m_activeCamera->focal();
result[gFocal] = m_activeCamera->focalDistance();
result[gOrthoSize] = m_activeCamera->orthoSize();
result[gGridAxis] = static_cast<int>(m_gridAxis);
}
Expand Down
Loading
Loading