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
19 changes: 7 additions & 12 deletions engine/src/components/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ Matrix4 Camera::projectionMatrix() const {
Returns result of transformation.
*/
Vector3 Camera::project(const Vector3 &worldSpace, const Matrix4 &modelView, const Matrix4 &projection) {
Vector4 in;
Vector4 out;

in = Vector4(worldSpace.x, worldSpace.y, worldSpace.z, 1.0f);
out = modelView * in;
in = projection * out;
Vector4 in(worldSpace.x, worldSpace.y, worldSpace.z, 1.0f);
Vector4 out(modelView * in);
in = projection * out;

if(in.w == 0.0f) {
return Vector3(); // false;
Expand All @@ -75,17 +72,15 @@ Vector3 Camera::project(const Vector3 &worldSpace, const Matrix4 &modelView, con
Returns result of transformation.
*/
Vector3 Camera::unproject(const Vector3 &screenSpace, const Matrix4 &modelView, const Matrix4 &projection) {
Matrix4 final;
Vector4 in;
Vector4 out;

final = (projection * modelView).inverse();
Matrix4 final((projection * modelView).inverse());

Vector4 in;
in.x = (screenSpace.x) * 2.0f - 1.0f;
in.y = (screenSpace.y) * 2.0f - 1.0f;
in.z = 2.0f * screenSpace.z - 1.0f;
in.w = 1.0f;
out = final * in;

Vector4 out(final * in);

if(out.w == 0.0f) {
return Vector3(); // false
Expand Down
20 changes: 10 additions & 10 deletions engine/src/pipelinetasks/shadowmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void ShadowMap::areaLightUpdate(PipelineContext *context, AreaLight *light, list

float zNear = 0.1f;
float zFar = light->radius();
Matrix4 crop = Matrix4::perspective(90.0f, 1.0f, zNear, zFar);
Matrix4 crop(Matrix4::perspective(90.0f, 1.0f, zNear, zFar));

Matrix4 wt = t->worldTransform();
Matrix4 wt(t->worldTransform());
Vector3 position(wt[12], wt[13], wt[14]);

Matrix4 wp;
Expand Down Expand Up @@ -149,16 +149,16 @@ void ShadowMap::areaLightUpdate(PipelineContext *context, AreaLight *light, list

void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light, list<Renderable *> &components, const Camera &camera) {
CommandBuffer *buffer = context->buffer();
Vector4 distance;

float nearPlane = camera.nearPlane();

Matrix4 p = buffer->projection();
Matrix4 p(camera.projectionMatrix());

float split = SPLIT_WEIGHT;
float farPlane = camera.farPlane();
float ratio = farPlane / nearPlane;

Vector4 distance;
Vector4 planeDistance;
for(int i = 0; i < MAX_LODS; i++) {
float f = (i + 1) / static_cast<float>(MAX_LODS);
Expand All @@ -171,12 +171,12 @@ void ShadowMap::directLightUpdate(PipelineContext *context, DirectLight *light,
}

Transform *lightTransform = light->transform();
Quaternion lightRot = lightTransform->worldQuaternion();
Matrix4 rot = Matrix4(lightRot.toMatrix()).inverse();
Quaternion lightRot(lightTransform->worldQuaternion());
Matrix4 rot(Matrix4(lightRot.toMatrix()).inverse());

Transform *cameraTransform = camera.transform();
Vector3 cameraPos = cameraTransform->worldPosition();
Quaternion cameraRot = cameraTransform->worldQuaternion();
Vector3 cameraPos(cameraTransform->worldPosition());
Quaternion cameraRot(cameraTransform->worldQuaternion());

bool orthographic = camera.orthographic();
float sigma = (camera.orthographic()) ? camera.orthoSize() : camera.fov();
Expand Down Expand Up @@ -263,7 +263,7 @@ void ShadowMap::pointLightUpdate(PipelineContext *context, PointLight *light, li

float zNear = 0.1f;
float zFar = light->attenuationRadius();
Matrix4 crop = Matrix4::perspective(90.0f, 1.0f, zNear, zFar);
Matrix4 crop(Matrix4::perspective(90.0f, 1.0f, zNear, zFar));

Matrix4 wt(t->worldTransform());
Vector3 position(wt[12], wt[13], wt[14]);
Expand Down Expand Up @@ -328,7 +328,7 @@ void ShadowMap::spotLightUpdate(PipelineContext *context, SpotLight *light, list

float zNear = 0.1f;
float zFar = light->attenuationDistance();
Matrix4 crop = Matrix4::perspective(light->outerAngle() * 2.0f, 1.0f, zNear, zFar);
Matrix4 crop(Matrix4::perspective(light->outerAngle() * 2.0f, 1.0f, zNear, zFar));

int32_t x = 0;
int32_t y = 0;
Expand Down