Rename vecX -> floatX
This commit is contained in:
parent
fa65e99094
commit
9951ffa58e
41 changed files with 553 additions and 543 deletions
|
@ -63,9 +63,9 @@ struct Bone {
|
||||||
|
|
||||||
Bone* parent = nullptr;
|
Bone* parent = nullptr;
|
||||||
|
|
||||||
Vector3 position;
|
prism::float3 position;
|
||||||
Quaternion rotation;
|
Quaternion rotation;
|
||||||
Vector3 scale;
|
prism::float3 scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mesh : public Asset {
|
class Mesh : public Asset {
|
||||||
|
@ -74,7 +74,7 @@ public:
|
||||||
// with multiple materials with different textures, etc
|
// with multiple materials with different textures, etc
|
||||||
struct Part {
|
struct Part {
|
||||||
std::string name;
|
std::string name;
|
||||||
AABB aabb;
|
prism::aabb bounding_box;
|
||||||
|
|
||||||
GFXBuffer* bone_batrix_buffer = nullptr;
|
GFXBuffer* bone_batrix_buffer = nullptr;
|
||||||
std::vector<Matrix4x4> offset_matrices;
|
std::vector<Matrix4x4> offset_matrices;
|
||||||
|
|
|
@ -46,8 +46,8 @@ struct MaterialProperty {
|
||||||
DataType type;
|
DataType type;
|
||||||
|
|
||||||
MaterialProperty(std::string n, DataType t) : name(n), type(t) {}
|
MaterialProperty(std::string n, DataType t) : name(n), type(t) {}
|
||||||
|
|
||||||
Vector3 value;
|
prism::float3 value;
|
||||||
AssetPtr<Texture> value_tex;
|
AssetPtr<Texture> value_tex;
|
||||||
float float_value;
|
float float_value;
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,11 +61,11 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// read positions
|
// read positions
|
||||||
mesh->position_buffer = read_buffer(sizeof(Vector3));
|
mesh->position_buffer = read_buffer(sizeof(prism::float3));
|
||||||
mesh->normal_buffer = read_buffer(sizeof(Vector3));
|
mesh->normal_buffer = read_buffer(sizeof(prism::float3));
|
||||||
mesh->texture_coord_buffer = read_buffer(sizeof(Vector2));
|
mesh->texture_coord_buffer = read_buffer(sizeof(prism::float2));
|
||||||
mesh->tangent_buffer = read_buffer(sizeof(Vector3));
|
mesh->tangent_buffer = read_buffer(sizeof(prism::float3));
|
||||||
mesh->bitangent_buffer = read_buffer(sizeof(Vector3));
|
mesh->bitangent_buffer = read_buffer(sizeof(prism::float3));
|
||||||
|
|
||||||
if(mesh_type == MeshType::Skinned)
|
if(mesh_type == MeshType::Skinned)
|
||||||
mesh->bone_buffer = read_buffer(sizeof(BoneVertexData));
|
mesh->bone_buffer = read_buffer(sizeof(BoneVertexData));
|
||||||
|
@ -98,14 +98,14 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
|
||||||
|
|
||||||
file->read_string(bone);
|
file->read_string(bone);
|
||||||
file->read_string(parent);
|
file->read_string(parent);
|
||||||
|
|
||||||
Vector3 pos;
|
prism::float3 pos;
|
||||||
file->read(&pos);
|
file->read(&pos);
|
||||||
|
|
||||||
Quaternion rot;
|
Quaternion rot;
|
||||||
file->read(&rot);
|
file->read(&rot);
|
||||||
|
|
||||||
Vector3 scl;
|
prism::float3 scl;
|
||||||
file->read(&scl);
|
file->read(&scl);
|
||||||
|
|
||||||
if(!boneMapping.count(bone)) {
|
if(!boneMapping.count(bone)) {
|
||||||
|
@ -155,7 +155,7 @@ std::unique_ptr<Mesh> load_mesh(const prism::path path) {
|
||||||
file->read_string(p.name);
|
file->read_string(p.name);
|
||||||
|
|
||||||
if(version == 6) {
|
if(version == 6) {
|
||||||
file->read(&p.aabb);
|
file->read(&p.bounding_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
int numVerts = 0;
|
int numVerts = 0;
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct Collision {
|
||||||
Capsule
|
Capsule
|
||||||
} type = Type::Cube;
|
} type = Type::Cube;
|
||||||
|
|
||||||
Vector3 size;
|
prism::float3 size;
|
||||||
|
|
||||||
bool is_trigger = false;
|
bool is_trigger = false;
|
||||||
std::string trigger_id;
|
std::string trigger_id;
|
||||||
|
@ -41,12 +41,12 @@ struct Rigidbody {
|
||||||
bool enable_deactivation = true;
|
bool enable_deactivation = true;
|
||||||
bool enable_rotation = true;
|
bool enable_rotation = true;
|
||||||
|
|
||||||
void add_force(const Vector3 force) {
|
void add_force(const prism::float3 force) {
|
||||||
stored_force += force;
|
stored_force += force;
|
||||||
}
|
}
|
||||||
|
|
||||||
btRigidBody* body = nullptr;
|
btRigidBody* body = nullptr;
|
||||||
Vector3 stored_force;
|
prism::float3 stored_force;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
|
@ -57,12 +57,12 @@ struct Data {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Transform {
|
struct Transform {
|
||||||
Vector3 position, scale = Vector3(1);
|
prism::float3 position, scale = prism::float3(1);
|
||||||
Quaternion rotation;
|
Quaternion rotation;
|
||||||
|
|
||||||
Matrix4x4 model;
|
Matrix4x4 model;
|
||||||
|
|
||||||
Vector3 get_world_position() const {
|
prism::float3 get_world_position() const {
|
||||||
return {
|
return {
|
||||||
model[3][0],
|
model[3][0],
|
||||||
model[3][1],
|
model[3][1],
|
||||||
|
@ -85,7 +85,7 @@ struct Light {
|
||||||
Sun = 2
|
Sun = 2
|
||||||
} type = Type::Point;
|
} type = Type::Point;
|
||||||
|
|
||||||
Vector3 color = Vector3(1);
|
prism::float3 color = prism::float3(1);
|
||||||
|
|
||||||
float power = 10.0f;
|
float power = 10.0f;
|
||||||
float size = 1.0f;
|
float size = 1.0f;
|
||||||
|
@ -116,7 +116,7 @@ struct UI {
|
||||||
|
|
||||||
struct EnvironmentProbe {
|
struct EnvironmentProbe {
|
||||||
bool is_sized = true;
|
bool is_sized = true;
|
||||||
Vector3 size = Vector3(10);
|
prism::float3 size = prism::float3(10);
|
||||||
|
|
||||||
float intensity = 1.0;
|
float intensity = 1.0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
struct PositionKeyFrame {
|
struct PositionKeyFrame {
|
||||||
float time;
|
float time;
|
||||||
Vector3 value;
|
prism::float3 value;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const PositionKeyFrame& lhs, const PositionKeyFrame& rhs) {
|
inline bool operator==(const PositionKeyFrame& lhs, const PositionKeyFrame& rhs) {
|
||||||
|
@ -23,7 +23,7 @@ struct RotationKeyFrame {
|
||||||
|
|
||||||
struct ScaleKeyFrame {
|
struct ScaleKeyFrame {
|
||||||
float time;
|
float time;
|
||||||
Vector3 value;
|
prism::float3 value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Bone;
|
struct Bone;
|
||||||
|
|
|
@ -42,8 +42,8 @@ namespace ImGui {
|
||||||
|
|
||||||
inline bool DragQuat(const char* label, Quaternion* quat) {
|
inline bool DragQuat(const char* label, Quaternion* quat) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
Vector3 euler = quat_to_euler(*quat);
|
prism::float3 euler = quat_to_euler(*quat);
|
||||||
|
|
||||||
euler.x = degrees(euler.x);
|
euler.x = degrees(euler.x);
|
||||||
euler.y = degrees(euler.y);
|
euler.y = degrees(euler.y);
|
||||||
|
|
|
@ -23,10 +23,10 @@ public:
|
||||||
|
|
||||||
struct RayResult {
|
struct RayResult {
|
||||||
bool hasHit;
|
bool hasHit;
|
||||||
Vector3 location;
|
prism::float3 location;
|
||||||
};
|
};
|
||||||
|
|
||||||
RayResult raycast(Vector3 from, Vector3 to);
|
RayResult raycast(prism::float3 from, prism::float3 to);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<btBroadphaseInterface> broadphase;
|
std::unique_ptr<btBroadphaseInterface> broadphase;
|
||||||
|
|
|
@ -252,7 +252,7 @@ public:
|
||||||
@param target The position to be centered in the camera's view.
|
@param target The position to be centered in the camera's view.
|
||||||
@note Although this is a look at function, it applies no special attribute to the camera and simply changes it's position and rotation.
|
@note Although this is a look at function, it applies no special attribute to the camera and simply changes it's position and rotation.
|
||||||
*/
|
*/
|
||||||
void camera_look_at(Scene& scene, Object cam, Vector3 pos, Vector3 target);
|
void camera_look_at(Scene& scene, Object cam, prism::float3 pos, prism::float3 target);
|
||||||
|
|
||||||
Object load_object(Scene& scene, const nlohmann::json obj);
|
Object load_object(Scene& scene, const nlohmann::json obj);
|
||||||
nlohmann::json save_object(Object obj);
|
nlohmann::json save_object(Object obj);
|
||||||
|
|
|
@ -510,9 +510,9 @@ void engine::calculate_bone(Mesh& mesh, const Mesh::Part& part, Bone& bone, cons
|
||||||
if(parent_bone != nullptr)
|
if(parent_bone != nullptr)
|
||||||
parent_matrix = parent_bone->local_transform;
|
parent_matrix = parent_bone->local_transform;
|
||||||
|
|
||||||
Matrix4x4 local = transform::translate(Matrix4x4(), bone.position);
|
Matrix4x4 local = prism::translate(Matrix4x4(), bone.position);
|
||||||
local *= matrix_from_quat(bone.rotation);
|
local *= matrix_from_quat(bone.rotation);
|
||||||
local = transform::scale(local, bone.scale);
|
local = prism::scale(local, bone.scale);
|
||||||
|
|
||||||
bone.local_transform = parent_matrix * local;
|
bone.local_transform = parent_matrix * local;
|
||||||
|
|
||||||
|
@ -531,9 +531,9 @@ void engine::calculate_object(Scene& scene, Object object, const Object parent_o
|
||||||
|
|
||||||
auto& transform = scene.get<Transform>(object);
|
auto& transform = scene.get<Transform>(object);
|
||||||
|
|
||||||
Matrix4x4 local = transform::translate(Matrix4x4(), transform.position);
|
Matrix4x4 local = prism::translate(Matrix4x4(), transform.position);
|
||||||
local *= matrix_from_quat(transform.rotation);
|
local *= matrix_from_quat(transform.rotation);
|
||||||
local = transform::scale(local, transform.scale);
|
local = prism::scale(local, transform.scale);
|
||||||
|
|
||||||
transform.model = parent_matrix * local;
|
transform.model = parent_matrix * local;
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ void engine::update_animation_channel(Scene& scene, const AnimationChannel& chan
|
||||||
}
|
}
|
||||||
|
|
||||||
if(keyframeIndex != -1) {
|
if(keyframeIndex != -1) {
|
||||||
Vector3* targetVec = nullptr;
|
prism::float3* targetVec = nullptr;
|
||||||
if(channel.bone != nullptr)
|
if(channel.bone != nullptr)
|
||||||
targetVec = &channel.bone->position;
|
targetVec = &channel.bone->position;
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ void Physics::update(float deltaTime) {
|
||||||
for(auto [obj, rigidbody] : engine->get_scene()->get_all<Rigidbody>()) {
|
for(auto [obj, rigidbody] : engine->get_scene()->get_all<Rigidbody>()) {
|
||||||
if(rigidbody.body != nullptr) {
|
if(rigidbody.body != nullptr) {
|
||||||
if(rigidbody.type == Rigidbody::Type::Dynamic) {
|
if(rigidbody.type == Rigidbody::Type::Dynamic) {
|
||||||
if(rigidbody.stored_force != Vector3(0.0f)) {
|
if(rigidbody.stored_force != prism::float3(0.0f)) {
|
||||||
rigidbody.body->setLinearVelocity(btVector3(rigidbody.stored_force.x, rigidbody.stored_force.y, rigidbody.stored_force.z));
|
rigidbody.body->setLinearVelocity(btVector3(rigidbody.stored_force.x, rigidbody.stored_force.y, rigidbody.stored_force.z));
|
||||||
rigidbody.stored_force = Vector3(0.0f);
|
rigidbody.stored_force = prism::float3(0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ void Physics::update(float deltaTime) {
|
||||||
|
|
||||||
if(rigidbody.type == Rigidbody::Type::Dynamic) {
|
if(rigidbody.type == Rigidbody::Type::Dynamic) {
|
||||||
btTransform trans = rigidbody.body->getWorldTransform();
|
btTransform trans = rigidbody.body->getWorldTransform();
|
||||||
transform.position = Vector3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
|
transform.position = prism::float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
|
||||||
} else {
|
} else {
|
||||||
btTransform t;
|
btTransform t;
|
||||||
t.setIdentity();
|
t.setIdentity();
|
||||||
|
@ -104,7 +104,7 @@ void Physics::remove_object(Object object) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Physics::RayResult Physics::raycast(Vector3 from, Vector3 to) {
|
Physics::RayResult Physics::raycast(prism::float3 from, prism::float3 to) {
|
||||||
Physics::RayResult result;
|
Physics::RayResult result;
|
||||||
|
|
||||||
btVector3 btFrom(from.x, from.y, from.z);
|
btVector3 btFrom(from.x, from.y, from.z);
|
||||||
|
@ -131,7 +131,7 @@ Physics::RayResult Physics::raycast(Vector3 from, Vector3 to) {
|
||||||
|
|
||||||
auto vec = res.m_hitPointWorld[closestCollisionObject];;
|
auto vec = res.m_hitPointWorld[closestCollisionObject];;
|
||||||
|
|
||||||
result.location = Vector3(vec.x(), vec.y(), vec.z());
|
result.location = prism::float3(vec.x(), vec.y(), vec.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
#include "transform.hpp"
|
#include "transform.hpp"
|
||||||
#include "asset.hpp"
|
#include "asset.hpp"
|
||||||
|
|
||||||
void camera_look_at(Scene& scene, Object cam, Vector3 pos, Vector3 target) {
|
void camera_look_at(Scene& scene, Object cam, prism::float3 pos, prism::float3 target) {
|
||||||
scene.get<Transform>(cam).position = pos;
|
scene.get<Transform>(cam).position = pos;
|
||||||
scene.get<Transform>(cam).rotation = transform::quat_look_at(pos, target, Vector3(0, 1, 0));
|
scene.get<Transform>(cam).rotation = prism::quat_look_at(pos, target, prism::float3(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_transform_component(nlohmann::json j, Transform& t) {
|
void load_transform_component(nlohmann::json j, Transform& t) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ set(SRC
|
||||||
include/vector.hpp
|
include/vector.hpp
|
||||||
include/quaternion.hpp
|
include/quaternion.hpp
|
||||||
include/plane.hpp
|
include/plane.hpp
|
||||||
|
include/aabb.hpp
|
||||||
|
|
||||||
src/transform.cpp
|
src/transform.cpp
|
||||||
src/math.cpp include/ray.hpp)
|
src/math.cpp include/ray.hpp)
|
||||||
|
|
25
engine/math/include/aabb.hpp
Normal file
25
engine/math/include/aabb.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "vector.hpp"
|
||||||
|
|
||||||
|
namespace prism {
|
||||||
|
/// A 3D axis aligned bounding box.
|
||||||
|
struct aabb {
|
||||||
|
float3 min, max;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Creates an array of 8 points, each of these being one extreme of the bounding box..
|
||||||
|
inline std::array<float3, 8> get_points(const aabb& aabb) {
|
||||||
|
return {
|
||||||
|
float3(aabb.min.x, aabb.min.y, aabb.min.z),
|
||||||
|
float3(aabb.max.x, aabb.min.y, aabb.min.z),
|
||||||
|
float3(aabb.min.x, aabb.max.y, aabb.min.z),
|
||||||
|
float3(aabb.max.x, aabb.max.y, aabb.min.z),
|
||||||
|
float3(aabb.min.x, aabb.min.y, aabb.max.z),
|
||||||
|
float3(aabb.max.x, aabb.min.y, aabb.max.z),
|
||||||
|
float3(aabb.min.x, aabb.max.y, aabb.max.z),
|
||||||
|
float3(aabb.max.x, aabb.max.y, aabb.max.z)};
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ constexpr inline bool nearly_equal(const T a, const T b) {
|
||||||
|
|
||||||
Matrix4x4 matrix_from_quat(Quaternion quat);
|
Matrix4x4 matrix_from_quat(Quaternion quat);
|
||||||
Quaternion quat_from_matrix(Matrix3x3 matrix);
|
Quaternion quat_from_matrix(Matrix3x3 matrix);
|
||||||
Quaternion euler_to_quat(Vector3 angle);
|
Quaternion euler_to_quat(prism::float3 angle);
|
||||||
Vector3 quat_to_euler(Quaternion quat);
|
prism::float3 quat_to_euler(Quaternion quat);
|
||||||
Matrix4x4 inverse(Matrix4x4 m);
|
Matrix4x4 inverse(Matrix4x4 m);
|
||||||
Quaternion angle_axis(float angle, Vector3 axis);
|
Quaternion angle_axis(float angle, prism::float3 axis);
|
||||||
|
|
|
@ -13,7 +13,7 @@ public:
|
||||||
unordered_data[i] = ((i / M) == (i % N) ? diagonal : T(0));
|
unordered_data[i] = ((i / M) == (i % N) ? diagonal : T(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Matrix(const Vector4 m1_, const Vector4 m2_, const Vector4 m3_, const Vector4 m4_) {
|
constexpr Matrix(const prism::float4 m1_, const prism::float4 m2_, const prism::float4 m3_, const prism::float4 m4_) {
|
||||||
columns[0] = m1_;
|
columns[0] = m1_;
|
||||||
columns[1] = m2_;
|
columns[1] = m2_;
|
||||||
columns[2] = m3_;
|
columns[2] = m3_;
|
||||||
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
constexpr inline void operator*=(const Matrix rhs);
|
constexpr inline void operator*=(const Matrix rhs);
|
||||||
|
|
||||||
using VectorType = Vector<N, T>;
|
using VectorType = prism::Vector<N, T>;
|
||||||
|
|
||||||
constexpr VectorType& operator[](const size_t index) { return columns[index]; }
|
constexpr VectorType& operator[](const size_t index) { return columns[index]; }
|
||||||
constexpr VectorType operator[](const size_t index) const { return columns[index]; }
|
constexpr VectorType operator[](const size_t index) const { return columns[index]; }
|
||||||
|
@ -49,8 +49,8 @@ constexpr inline Matrix4x4 operator*(const Matrix4x4 lhs, const Matrix4x4 rhs) {
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline Vector4 operator*(const Matrix4x4 lhs, const Vector4 rhs) {
|
constexpr inline prism::float4 operator*(const Matrix4x4 lhs, const prism::float4 rhs) {
|
||||||
Vector4 tmp;
|
prism::float4 tmp;
|
||||||
for(int r = 0; r < 4; r++) {
|
for(int r = 0; r < 4; r++) {
|
||||||
for(int c = 0; c < 4; c++)
|
for(int c = 0; c < 4; c++)
|
||||||
tmp[r] += lhs.data[c][r] * rhs.data[c];
|
tmp[r] += lhs.data[c][r] * rhs.data[c];
|
||||||
|
|
|
@ -22,7 +22,7 @@ inline Plane normalize(const Plane& plane) {
|
||||||
return normalized_plane;
|
return normalized_plane;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float distance_to_point(const Plane& plane, const Vector3& point) {
|
inline float distance_to_point(const Plane& plane, const prism::float3& point) {
|
||||||
return plane.a * point.x +
|
return plane.a * point.x +
|
||||||
plane.b * point.y +
|
plane.b * point.y +
|
||||||
plane.c * point.z +
|
plane.c * point.z +
|
||||||
|
|
|
@ -21,15 +21,15 @@ constexpr inline Quaternion operator*(const Quaternion lhs, const float rhs) {
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline Vector3 operator*(const Quaternion& lhs, const Vector3& rhs) {
|
constexpr inline prism::float3 operator*(const Quaternion& lhs, const prism::float3& rhs) {
|
||||||
const Vector3 quatVector = Vector3(lhs.x, lhs.y, lhs.z);
|
const prism::float3 quatVector = prism::float3(lhs.x, lhs.y, lhs.z);
|
||||||
const Vector3 uv = cross(quatVector, rhs);
|
const prism::float3 uv = cross(quatVector, rhs);
|
||||||
const Vector3 uuv = cross(quatVector, uv);
|
const prism::float3 uuv = cross(quatVector, uv);
|
||||||
|
|
||||||
return rhs + ((uv * lhs.w) + uuv) * 2.0f;
|
return rhs + ((uv * lhs.w) + uuv) * 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline Vector3 operator*(const Vector3& rhs, const Quaternion& lhs) {
|
constexpr inline prism::float3 operator*(const prism::float3& rhs, const Quaternion& lhs) {
|
||||||
return lhs * rhs;
|
return lhs * rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct ray {
|
#include "vector.hpp"
|
||||||
Vector3 origin, direction;
|
|
||||||
float t = 0.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
float closest_distance_between_lines(ray& l1, ray& l2);
|
namespace prism {
|
||||||
|
struct ray {
|
||||||
|
float3 origin, direction;
|
||||||
|
float t = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
float closest_distance_between_lines(ray& l1, ray& l2);
|
||||||
|
}
|
|
@ -4,16 +4,16 @@
|
||||||
#include "vector.hpp"
|
#include "vector.hpp"
|
||||||
#include "quaternion.hpp"
|
#include "quaternion.hpp"
|
||||||
|
|
||||||
namespace transform {
|
namespace prism {
|
||||||
Matrix4x4 perspective(const float field_of_view, const float aspect, const float z_near, const float z_far);
|
Matrix4x4 perspective(float field_of_view, float aspect, float z_near, float z_far);
|
||||||
Matrix4x4 infinite_perspective(const float field_of_view, const float aspect, const float z_near);
|
Matrix4x4 infinite_perspective(float field_of_view, float aspect, float z_near);
|
||||||
|
|
||||||
Matrix4x4 orthographic(float left, float right, float bottom, float top, float zNear, float zFar);
|
Matrix4x4 orthographic(float left, float right, float bottom, float top, float zNear, float zFar);
|
||||||
|
|
||||||
Matrix4x4 look_at(const Vector3 eye, const Vector3 center, const Vector3 up);
|
Matrix4x4 look_at(float3 eye, float3 center, float3 up);
|
||||||
Quaternion quat_look_at(const Vector3 eye, const Vector3 center, const Vector3 up);
|
Quaternion quat_look_at(float3 eye, float3 center, float3 up);
|
||||||
|
|
||||||
Matrix4x4 translate(const Matrix4x4 matrix, const Vector3 translation);
|
Matrix4x4 translate(Matrix4x4 matrix, float3 translation);
|
||||||
Matrix4x4 rotate(const Matrix4x4 matrix, const float angle, const Vector3 axis);
|
Matrix4x4 rotate(Matrix4x4 matrix, float angle, float3 axis);
|
||||||
Matrix4x4 scale(const Matrix4x4 matrix, const Vector3 scale);
|
Matrix4x4 scale(Matrix4x4 matrix, float3 scale);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,254 +5,256 @@
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#define DEFINE_OPERATORS(Size) \
|
namespace prism {
|
||||||
constexpr Vector(const T scalar = T(0)) { \
|
#define DEFINE_OPERATORS(Size) \
|
||||||
for(std::size_t i = 0; i < Size; i++) \
|
constexpr Vector(const T scalar = T(0)) { \
|
||||||
data[i] = scalar; \
|
for(std::size_t i = 0; i < (Size); i++) \
|
||||||
} \
|
data[i] = scalar; \
|
||||||
constexpr T& operator[](const size_t index) { \
|
} \
|
||||||
return data[index]; \
|
constexpr T& operator[](const size_t index) { \
|
||||||
} \
|
return data[index]; \
|
||||||
constexpr T operator[](const size_t index) const { \
|
} \
|
||||||
return data[index]; \
|
constexpr T operator[](const size_t index) const { \
|
||||||
} \
|
return data[index]; \
|
||||||
constexpr Vector& operator+=(const Vector rhs) { \
|
} \
|
||||||
for(std::size_t i = 0; i < Size; i++)\
|
constexpr Vector& operator+=(const Vector rhs) { \
|
||||||
data[i] += rhs[i]; \
|
for(std::size_t i = 0; i < (Size); i++)\
|
||||||
return *this; \
|
data[i] += rhs[i]; \
|
||||||
} \
|
return *this; \
|
||||||
constexpr Vector& operator-=(const Vector rhs) { \
|
} \
|
||||||
for(std::size_t i = 0; i < Size; i++)\
|
constexpr Vector& operator-=(const Vector rhs) { \
|
||||||
data[i] -= rhs[i]; \
|
for(std::size_t i = 0; i < (Size); i++)\
|
||||||
return *this; \
|
data[i] -= rhs[i]; \
|
||||||
} \
|
return *this; \
|
||||||
constexpr Vector& operator*=(const Vector rhs) { \
|
} \
|
||||||
for(std::size_t i = 0; i < Size; i++) \
|
constexpr Vector& operator*=(const Vector rhs) { \
|
||||||
data[i] *= rhs[i]; \
|
for(std::size_t i = 0; i < (Size); i++) \
|
||||||
return *this; \
|
data[i] *= rhs[i]; \
|
||||||
} \
|
return *this; \
|
||||||
constexpr Vector& operator/=(const T scalar) { \
|
} \
|
||||||
for(std::size_t i = 0; i < Size; i++) \
|
constexpr Vector& operator/=(const T scalar) { \
|
||||||
data[i] /= scalar; \
|
for(std::size_t i = 0; i < (Size); i++) \
|
||||||
return *this; \
|
data[i] /= scalar; \
|
||||||
} \
|
return *this; \
|
||||||
constexpr T* ptr() const { \
|
} \
|
||||||
return data.data(); \
|
constexpr T* ptr() const { \
|
||||||
} \
|
return data.data(); \
|
||||||
constexpr T* ptr() { \
|
} \
|
||||||
return data.data(); \
|
constexpr T* ptr() { \
|
||||||
} \
|
return data.data(); \
|
||||||
constexpr Vector operator- () const { \
|
} \
|
||||||
Vector vec; \
|
constexpr Vector operator- () const { \
|
||||||
for(std::size_t i = 0; i < Size; i++) \
|
Vector vec; \
|
||||||
vec[i] = -data[i]; \
|
for(std::size_t i = 0; i < (Size); i++) \
|
||||||
return vec; \
|
vec[i] = -data[i]; \
|
||||||
|
return vec; \
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t N, class T>
|
||||||
|
struct Vector {
|
||||||
|
std::array<T, N> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct Vector<2, T> {
|
||||||
|
constexpr Vector(const T x_, const T y_) {
|
||||||
|
x = x_;
|
||||||
|
y = y_;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_OPERATORS(2)
|
||||||
|
|
||||||
|
union {
|
||||||
|
std::array<T, 2> data;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
T x, y;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct Vector<3, T> {
|
||||||
|
constexpr Vector(const T x_, const T y_, const T z_) {
|
||||||
|
x = x_;
|
||||||
|
y = y_;
|
||||||
|
z = z_;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_OPERATORS(3)
|
||||||
|
|
||||||
|
union {
|
||||||
|
std::array<T, 3> data;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
T x, y, z;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct alignas(16) Vector<4, T> {
|
||||||
|
constexpr Vector(const T x_, const T y_, const T z_, const T w_) {
|
||||||
|
x = x_;
|
||||||
|
y = y_;
|
||||||
|
z = z_;
|
||||||
|
w = w_;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector(const Vector<3, T> &v, const float w = 0.0f) : x(v.x), y(v.y), z(v.z), w(w) {}
|
||||||
|
|
||||||
|
DEFINE_OPERATORS(4)
|
||||||
|
|
||||||
|
union {
|
||||||
|
std::array<T, 4> data;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
T x, y, z, w;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
Vector<3, T> xyz;
|
||||||
|
T padding_xyz;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
using float2 = Vector<2, float>;
|
||||||
|
using float3 = Vector<3, float>;
|
||||||
|
using float4 = Vector<4, float>;
|
||||||
|
|
||||||
|
template<std::size_t N, class T>
|
||||||
|
constexpr inline T dot(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
||||||
|
T product = T(0.0);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < N; i++)
|
||||||
|
product += lhs[i] * rhs[i];
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t N, class T>
|
||||||
|
constexpr inline T length(const Vector<N, T> vec) {
|
||||||
|
return sqrtf(dot(vec, vec));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t N, class T>
|
||||||
|
constexpr inline Vector<N, T> lerp(const Vector<N, T> a, const Vector<N, T> b, const T t) {
|
||||||
|
Vector<N, T> vec;
|
||||||
|
for (std::size_t i = 0; i < N; i++)
|
||||||
|
vec[i] = (T(1) - t) * a[i] + t * b[i];
|
||||||
|
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t N, class T>
|
||||||
|
constexpr inline Vector<N, T> normalize(const Vector<N, T> vec) {
|
||||||
|
Vector<N, T> result;
|
||||||
|
|
||||||
|
const float len = length(vec);
|
||||||
|
for (std::size_t i = 0; i < N; i++)
|
||||||
|
result[i] = vec[i] / len;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr inline float3 cross(const float3 u, const float3 v) {
|
||||||
|
return float3(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float distance(const float3 lhs, const float3 rhs) {
|
||||||
|
const float diffX = lhs.x - rhs.x;
|
||||||
|
const float diffY = lhs.y - rhs.y;
|
||||||
|
const float diffZ = lhs.z - rhs.z;
|
||||||
|
|
||||||
|
return std::sqrt((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t N, class T>
|
||||||
|
constexpr inline T norm(const Vector<N, T> vec) {
|
||||||
|
T val = T(0);
|
||||||
|
for (std::size_t i = 0; i < N; i++)
|
||||||
|
val += abs(vec[i]);
|
||||||
|
|
||||||
|
return sqrtf(dot(vec, vec));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
struct Vector {
|
constexpr inline bool operator==(const prism::Vector<N, T> lhs, const prism::Vector<N, T> rhs) {
|
||||||
std::array<T, N> data;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct Vector<2, T> {
|
|
||||||
constexpr Vector(const T x_, const T y_) {
|
|
||||||
x = x_;
|
|
||||||
y = y_;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFINE_OPERATORS(2)
|
|
||||||
|
|
||||||
union {
|
|
||||||
std::array<T, 2> data;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
T x, y;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct Vector<3, T> {
|
|
||||||
constexpr Vector(const T x_, const T y_, const T z_) {
|
|
||||||
x = x_;
|
|
||||||
y = y_;
|
|
||||||
z = z_;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFINE_OPERATORS(3)
|
|
||||||
|
|
||||||
union {
|
|
||||||
std::array<T, 3> data;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
T x, y, z;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct alignas(16) Vector<4, T> {
|
|
||||||
constexpr Vector(const T x_, const T y_, const T z_, const T w_) {
|
|
||||||
x = x_;
|
|
||||||
y = y_;
|
|
||||||
z = z_;
|
|
||||||
w = w_;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Vector(const Vector<3, T>& v, const float w = 0.0f) : x(v.x), y(v.y), z(v.z), w(w) {}
|
|
||||||
|
|
||||||
DEFINE_OPERATORS(4)
|
|
||||||
|
|
||||||
union {
|
|
||||||
std::array<T, 4> data;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
T x, y, z, w;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct {
|
|
||||||
Vector<3, T> xyz;
|
|
||||||
T padding_xyz;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
using Vector2 = Vector<2, float>;
|
|
||||||
using Vector3 = Vector<3, float>;
|
|
||||||
using Vector4 = Vector<4, float>;
|
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
|
||||||
constexpr inline bool operator==(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
|
||||||
bool is_equal = true;
|
bool is_equal = true;
|
||||||
for(std::size_t i = 0; i < N; i++) {
|
for (std::size_t i = 0; i < N; i++) {
|
||||||
if(lhs[i] != rhs[i])
|
if (lhs[i] != rhs[i])
|
||||||
is_equal = false;
|
is_equal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_equal;
|
return is_equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline bool operator!=(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
constexpr inline bool operator!=(const prism::Vector<N, T> lhs, const prism::Vector<N, T> rhs) {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator-(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
constexpr inline prism::Vector<N, T> operator-(const prism::Vector<N, T> lhs, const prism::Vector<N, T> rhs) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] - rhs[i];
|
vec[i] = lhs[i] - rhs[i];
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator+(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
constexpr inline prism::Vector<N, T> operator+(const prism::Vector<N, T> lhs, const prism::Vector<N, T> rhs) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] + rhs[i];
|
vec[i] = lhs[i] + rhs[i];
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator*(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
constexpr inline prism::Vector<N, T> operator*(const prism::Vector<N, T> lhs, const prism::Vector<N, T> rhs) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] * rhs[i];
|
vec[i] = lhs[i] * rhs[i];
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator+(const Vector<N, T> lhs, const T scalar) {
|
constexpr inline prism::Vector<N, T> operator+(const prism::Vector<N, T> lhs, const T scalar) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] + scalar;
|
vec[i] = lhs[i] + scalar;
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator*(const Vector<N, T> lhs, const T scalar) {
|
constexpr inline prism::Vector<N, T> operator*(const prism::Vector<N, T> lhs, const T scalar) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] * scalar;
|
vec[i] = lhs[i] * scalar;
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator/(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
constexpr inline prism::Vector<N, T> operator/(const prism::Vector<N, T> lhs, const prism::Vector<N, T> rhs) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] / rhs[i];
|
vec[i] = lhs[i] / rhs[i];
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
template<std::size_t N, class T>
|
||||||
constexpr inline Vector<N, T> operator/(const Vector<N, T> lhs, const T scalar) {
|
constexpr inline prism::Vector<N, T> operator/(const prism::Vector<N, T> lhs, const T scalar) {
|
||||||
Vector<N, T> vec;
|
prism::Vector<N, T> vec;
|
||||||
for(std::size_t i = 0; i < N; i++)
|
for (std::size_t i = 0; i < N; i++)
|
||||||
vec[i] = lhs[i] / scalar;
|
vec[i] = lhs[i] / scalar;
|
||||||
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
|
||||||
constexpr inline T dot(const Vector<N, T> lhs, const Vector<N, T> rhs) {
|
|
||||||
T product = T(0.0);
|
|
||||||
|
|
||||||
for(std::size_t i = 0; i < N; i++)
|
|
||||||
product += lhs[i] * rhs[i];
|
|
||||||
|
|
||||||
return product;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
|
||||||
constexpr inline T length(const Vector<N, T> vec) {
|
|
||||||
return sqrtf(dot(vec, vec));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
|
||||||
constexpr inline Vector<N, T> lerp(const Vector<N, T> a, const Vector<N, T> b, const T t) {
|
|
||||||
Vector<N, T> vec;
|
|
||||||
for(std::size_t i = 0; i < N; i++)
|
|
||||||
vec[i] = (T(1) - t) * a[i] + t * b[i];
|
|
||||||
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
|
||||||
constexpr inline Vector<N, T> normalize(const Vector<N, T> vec) {
|
|
||||||
Vector<N, T> result;
|
|
||||||
|
|
||||||
const float len = length(vec);
|
|
||||||
for(std::size_t i = 0; i < N; i++)
|
|
||||||
result[i] = vec[i] / len;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline Vector3 cross(const Vector3 u, const Vector3 v) {
|
|
||||||
return Vector3(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float distance(const Vector3 lhs, const Vector3 rhs) {
|
|
||||||
const float diffX = lhs.x - rhs.x;
|
|
||||||
const float diffY = lhs.y - rhs.y;
|
|
||||||
const float diffZ = lhs.z - rhs.z;
|
|
||||||
|
|
||||||
return std::sqrt((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::size_t N, class T>
|
|
||||||
constexpr inline T norm(const Vector<N, T> vec) {
|
|
||||||
T val = T(0);
|
|
||||||
for(std::size_t i = 0; i < N; i++)
|
|
||||||
val += abs(vec[i]);
|
|
||||||
|
|
||||||
return sqrtf(dot(vec, vec));
|
|
||||||
}
|
|
|
@ -65,7 +65,7 @@ Quaternion quat_from_matrix(const Matrix3x3 m) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion euler_to_quat(const Vector3 angle) {
|
Quaternion euler_to_quat(const prism::float3 angle) {
|
||||||
const float cy = cosf(angle.z * 0.5f);
|
const float cy = cosf(angle.z * 0.5f);
|
||||||
const float sy = sinf(angle.z * 0.5f);
|
const float sy = sinf(angle.z * 0.5f);
|
||||||
const float cr = cosf(angle.x * 0.5f);
|
const float cr = cosf(angle.x * 0.5f);
|
||||||
|
@ -87,7 +87,7 @@ Quaternion euler_to_quat(const Vector3 angle) {
|
||||||
return normalize(result);
|
return normalize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 quat_to_euler(const Quaternion q) {
|
prism::float3 quat_to_euler(const Quaternion q) {
|
||||||
const float roll = atan2(2.0f * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z);
|
const float roll = atan2(2.0f * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z);
|
||||||
|
|
||||||
const float y = 2.0f * (q.y * q.z + q.w * q.x);
|
const float y = 2.0f * (q.y * q.z + q.w * q.x);
|
||||||
|
@ -97,7 +97,7 @@ Vector3 quat_to_euler(const Quaternion q) {
|
||||||
|
|
||||||
const float yaw = asinf(-2.0f * (q.x * q.z - q.w * q.y));
|
const float yaw = asinf(-2.0f * (q.x * q.z - q.w * q.y));
|
||||||
|
|
||||||
return Vector3(pitch, yaw, roll);
|
return prism::float3(pitch, yaw, roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 inverse(const Matrix4x4 m) {
|
Matrix4x4 inverse(const Matrix4x4 m) {
|
||||||
|
@ -125,30 +125,30 @@ Matrix4x4 inverse(const Matrix4x4 m) {
|
||||||
const float Coef22 = m[1][0] * m[3][1] - m[3][0] * m[1][1];
|
const float Coef22 = m[1][0] * m[3][1] - m[3][0] * m[1][1];
|
||||||
const float Coef23 = m[1][0] * m[2][1] - m[2][0] * m[1][1];
|
const float Coef23 = m[1][0] * m[2][1] - m[2][0] * m[1][1];
|
||||||
|
|
||||||
const Vector4 Fac0(Coef00, Coef00, Coef02, Coef03);
|
const prism::float4 Fac0(Coef00, Coef00, Coef02, Coef03);
|
||||||
const Vector4 Fac1(Coef04, Coef04, Coef06, Coef07);
|
const prism::float4 Fac1(Coef04, Coef04, Coef06, Coef07);
|
||||||
const Vector4 Fac2(Coef08, Coef08, Coef10, Coef11);
|
const prism::float4 Fac2(Coef08, Coef08, Coef10, Coef11);
|
||||||
const Vector4 Fac3(Coef12, Coef12, Coef14, Coef15);
|
const prism::float4 Fac3(Coef12, Coef12, Coef14, Coef15);
|
||||||
const Vector4 Fac4(Coef16, Coef16, Coef18, Coef19);
|
const prism::float4 Fac4(Coef16, Coef16, Coef18, Coef19);
|
||||||
const Vector4 Fac5(Coef20, Coef20, Coef22, Coef23);
|
const prism::float4 Fac5(Coef20, Coef20, Coef22, Coef23);
|
||||||
|
|
||||||
const Vector4 Vec0(m[1][0], m[0][0], m[0][0], m[0][0]);
|
const prism::float4 Vec0(m[1][0], m[0][0], m[0][0], m[0][0]);
|
||||||
const Vector4 Vec1(m[1][1], m[0][1], m[0][1], m[0][1]);
|
const prism::float4 Vec1(m[1][1], m[0][1], m[0][1], m[0][1]);
|
||||||
const Vector4 Vec2(m[1][2], m[0][2], m[0][2], m[0][2]);
|
const prism::float4 Vec2(m[1][2], m[0][2], m[0][2], m[0][2]);
|
||||||
const Vector4 Vec3(m[1][3], m[0][3], m[0][3], m[0][3]);
|
const prism::float4 Vec3(m[1][3], m[0][3], m[0][3], m[0][3]);
|
||||||
|
|
||||||
const Vector4 Inv0(Vec1 * Fac0 - Vec2 * Fac1 + Vec3 * Fac2);
|
const prism::float4 Inv0(Vec1 * Fac0 - Vec2 * Fac1 + Vec3 * Fac2);
|
||||||
const Vector4 Inv1(Vec0 * Fac0 - Vec2 * Fac3 + Vec3 * Fac4);
|
const prism::float4 Inv1(Vec0 * Fac0 - Vec2 * Fac3 + Vec3 * Fac4);
|
||||||
const Vector4 Inv2(Vec0 * Fac1 - Vec1 * Fac3 + Vec3 * Fac5);
|
const prism::float4 Inv2(Vec0 * Fac1 - Vec1 * Fac3 + Vec3 * Fac5);
|
||||||
const Vector4 Inv3(Vec0 * Fac2 - Vec1 * Fac4 + Vec2 * Fac5);
|
const prism::float4 Inv3(Vec0 * Fac2 - Vec1 * Fac4 + Vec2 * Fac5);
|
||||||
|
|
||||||
const Vector4 SignA(+1, -1, +1, -1);
|
const prism::float4 SignA(+1, -1, +1, -1);
|
||||||
const Vector4 SignB(-1, +1, -1, +1);
|
const prism::float4 SignB(-1, +1, -1, +1);
|
||||||
const Matrix4x4 Inverse(Inv0 * SignA, Inv1 * SignB, Inv2 * SignA, Inv3 * SignB);
|
const Matrix4x4 Inverse(Inv0 * SignA, Inv1 * SignB, Inv2 * SignA, Inv3 * SignB);
|
||||||
|
|
||||||
const Vector4 Row0(Inverse[0][0], Inverse[1][0], Inverse[2][0], Inverse[3][0]);
|
const prism::float4 Row0(Inverse[0][0], Inverse[1][0], Inverse[2][0], Inverse[3][0]);
|
||||||
|
|
||||||
const Vector4 Dot0(m[0] * Row0);
|
const prism::float4 Dot0(m[0] * Row0);
|
||||||
const float Dot1 = (Dot0.x + Dot0.y) + (Dot0.z + Dot0.w);
|
const float Dot1 = (Dot0.x + Dot0.y) + (Dot0.z + Dot0.w);
|
||||||
|
|
||||||
const float OneOverDeterminant = 1.0f / Dot1;
|
const float OneOverDeterminant = 1.0f / Dot1;
|
||||||
|
@ -156,7 +156,7 @@ Matrix4x4 inverse(const Matrix4x4 m) {
|
||||||
return Inverse * OneOverDeterminant;
|
return Inverse * OneOverDeterminant;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion angle_axis(const float angle, const Vector3 axis) {
|
Quaternion angle_axis(const float angle, const prism::float3 axis) {
|
||||||
const float s = sinf(angle * 0.5f);
|
const float s = sinf(angle * 0.5f);
|
||||||
|
|
||||||
Quaternion result;
|
Quaternion result;
|
||||||
|
@ -169,8 +169,8 @@ Quaternion angle_axis(const float angle, const Vector3 axis) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// from https://nelari.us/post/gizmos/
|
// from https://nelari.us/post/gizmos/
|
||||||
float closest_distance_between_lines(ray& l1, ray& l2) {
|
float prism::closest_distance_between_lines(prism::ray& l1, prism::ray& l2) {
|
||||||
const Vector3 dp = l2.origin - l1.origin;
|
const float3 dp = l2.origin - l1.origin;
|
||||||
const float v12 = dot(l1.direction, l1.direction);
|
const float v12 = dot(l1.direction, l1.direction);
|
||||||
const float v22 = dot(l2.direction, l2.direction);
|
const float v22 = dot(l2.direction, l2.direction);
|
||||||
const float v1v2 = dot(l1.direction, l2.direction);
|
const float v1v2 = dot(l1.direction, l2.direction);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
These produce left-handed matrices.
|
These produce left-handed matrices.
|
||||||
Metal/DX12 are both NDC +y down.
|
Metal/DX12 are both NDC +y down.
|
||||||
*/
|
*/
|
||||||
Matrix4x4 transform::perspective(const float field_of_view, const float aspect, const float z_near, const float z_far) {
|
Matrix4x4 prism::perspective(const float field_of_view, const float aspect, const float z_near, const float z_far) {
|
||||||
const float tan_half_fov = tanf(field_of_view / 2.0f);
|
const float tan_half_fov = tanf(field_of_view / 2.0f);
|
||||||
|
|
||||||
Matrix4x4 result(0.0f);
|
Matrix4x4 result(0.0f);
|
||||||
|
@ -22,7 +22,7 @@ Matrix4x4 transform::perspective(const float field_of_view, const float aspect,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 transform::infinite_perspective(const float field_of_view, const float aspect, const float z_near) {
|
Matrix4x4 prism::infinite_perspective(const float field_of_view, const float aspect, const float z_near) {
|
||||||
const float range = tanf(field_of_view / 2.0f) * z_near;
|
const float range = tanf(field_of_view / 2.0f) * z_near;
|
||||||
const float left = -range * aspect;
|
const float left = -range * aspect;
|
||||||
const float right = range * aspect;
|
const float right = range * aspect;
|
||||||
|
@ -39,7 +39,7 @@ Matrix4x4 transform::infinite_perspective(const float field_of_view, const float
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 transform::orthographic(float left, float right, float bottom, float top, float zNear, float zFar) {
|
Matrix4x4 prism::orthographic(float left, float right, float bottom, float top, float zNear, float zFar) {
|
||||||
Matrix4x4 result(1.0f);
|
Matrix4x4 result(1.0f);
|
||||||
result[0][0] = 2.0f / (right - left);
|
result[0][0] = 2.0f / (right - left);
|
||||||
result[1][1] = 2.0f / (top - bottom);
|
result[1][1] = 2.0f / (top - bottom);
|
||||||
|
@ -51,10 +51,10 @@ Matrix4x4 transform::orthographic(float left, float right, float bottom, float t
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 transform::look_at(const Vector3 eye, const Vector3 center, const Vector3 up) {
|
Matrix4x4 prism::look_at(const float3 eye, const float3 center, const float3 up) {
|
||||||
const Vector3 f = normalize(center - eye);
|
const float3 f = normalize(center - eye);
|
||||||
const Vector3 s = normalize(cross(up, f));
|
const float3 s = normalize(cross(up, f));
|
||||||
const Vector3 u = cross(f, s);
|
const float3 u = cross(f, s);
|
||||||
|
|
||||||
Matrix4x4 result(1.0f);
|
Matrix4x4 result(1.0f);
|
||||||
result[0][0] = s.x;
|
result[0][0] = s.x;
|
||||||
|
@ -73,20 +73,20 @@ Matrix4x4 transform::look_at(const Vector3 eye, const Vector3 center, const Vect
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 transform::translate(const Matrix4x4 matrix, const Vector3 translation) {
|
Matrix4x4 prism::translate(const Matrix4x4 matrix, const float3 translation) {
|
||||||
Matrix4x4 result(1.0f);
|
Matrix4x4 result(1.0f);
|
||||||
result[3] = Vector4(translation, 1.0);
|
result[3] = float4(translation, 1.0);
|
||||||
|
|
||||||
return matrix * result;
|
return matrix * result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 transform::rotate(const Matrix4x4 matrix, const float angle, const Vector3 v) {
|
Matrix4x4 prism::rotate(const Matrix4x4 matrix, const float angle, const float3 v) {
|
||||||
const float a = angle;
|
const float a = angle;
|
||||||
const float c = cosf(a);
|
const float c = cosf(a);
|
||||||
const float s = sinf(a);
|
const float s = sinf(a);
|
||||||
|
|
||||||
const Vector3 axis = normalize(v);
|
const float3 axis = normalize(v);
|
||||||
const Vector3 temp = Vector3((1.0f - c) * axis);
|
const float3 temp = float3((1.0f - c) * axis);
|
||||||
|
|
||||||
Matrix4x4 Rotate(1.0f);
|
Matrix4x4 Rotate(1.0f);
|
||||||
Rotate[0][0] = c + temp[0] * axis[0];
|
Rotate[0][0] = c + temp[0] * axis[0];
|
||||||
|
@ -110,7 +110,7 @@ Matrix4x4 transform::rotate(const Matrix4x4 matrix, const float angle, const Vec
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4x4 transform::scale(const Matrix4x4 matrix, const Vector3 scale) {
|
Matrix4x4 prism::scale(const Matrix4x4 matrix, const float3 scale) {
|
||||||
Matrix4x4 result(1.0f);
|
Matrix4x4 result(1.0f);
|
||||||
result[0][0] = scale.x;
|
result[0][0] = scale.x;
|
||||||
result[1][1] = scale.y;
|
result[1][1] = scale.y;
|
||||||
|
@ -119,8 +119,8 @@ Matrix4x4 transform::scale(const Matrix4x4 matrix, const Vector3 scale) {
|
||||||
return matrix * result;
|
return matrix * result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion transform::quat_look_at(const Vector3 eye, const Vector3 center, const Vector3 up) {
|
Quaternion prism::quat_look_at(const float3 eye, const float3 center, const float3 up) {
|
||||||
const Vector3 direction = normalize(center - eye);
|
const float3 direction = normalize(center - eye);
|
||||||
|
|
||||||
Matrix3x3 result(1.0f);
|
Matrix3x3 result(1.0f);
|
||||||
result[2] = direction;
|
result[2] = direction;
|
||||||
|
|
|
@ -16,12 +16,12 @@ struct CameraFrustum {
|
||||||
std::array<Plane, 6> planes;
|
std::array<Plane, 6> planes;
|
||||||
};
|
};
|
||||||
|
|
||||||
CameraFrustum extract_frustum(const Matrix4x4 combined);
|
CameraFrustum extract_frustum(Matrix4x4 combined);
|
||||||
CameraFrustum camera_extract_frustum(Scene& scene, Object cam);
|
CameraFrustum camera_extract_frustum(Scene& scene, Object cam);
|
||||||
CameraFrustum normalize_frustum(const CameraFrustum& frustum);
|
CameraFrustum normalize_frustum(const CameraFrustum& frustum);
|
||||||
|
|
||||||
bool test_point_plane(const Plane& plane, const Vector3& point);
|
bool test_point_plane(const Plane& plane, const prism::float3& point);
|
||||||
bool test_point_frustum(const CameraFrustum& frustum, const Vector3& point);
|
bool test_point_frustum(const CameraFrustum& frustum, const prism::float3& point);
|
||||||
bool test_aabb_frustum(const CameraFrustum& frustum, const AABB& aabb);
|
bool test_aabb_frustum(const CameraFrustum& frustum, const prism::aabb& aabb);
|
||||||
|
|
||||||
AABB get_aabb_for_part(const Transform& transform, const Mesh::Part& part);
|
prism::aabb get_aabb_for_part(const Transform& transform, const Mesh::Part& part);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
void render(GFXCommandBuffer* command_buffer, Scene& scene);
|
void render(GFXCommandBuffer* command_buffer, Scene& scene);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const Vector3 light_position, const Light::Type type, const CameraFrustum& frustum, const int base_instance);
|
void render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const prism::float3 light_position, const Light::Type type, const CameraFrustum& frustum, const int base_instance);
|
||||||
|
|
||||||
void render_sun(GFXCommandBuffer* command_buffer, Scene& scene, Object light_object, Light& light);
|
void render_sun(GFXCommandBuffer* command_buffer, Scene& scene, Object light_object, Light& light);
|
||||||
void render_spot(GFXCommandBuffer* command_buffer, Scene& scene, Object light_object, Light& light);
|
void render_spot(GFXCommandBuffer* command_buffer, Scene& scene, Object light_object, Light& light);
|
||||||
|
@ -45,7 +45,7 @@ private:
|
||||||
GFXFramebuffer* offscreen_framebuffer = nullptr;
|
GFXFramebuffer* offscreen_framebuffer = nullptr;
|
||||||
|
|
||||||
GFXBuffer* point_location_buffer = nullptr;
|
GFXBuffer* point_location_buffer = nullptr;
|
||||||
Vector3* point_location_map = nullptr;
|
prism::float3* point_location_map = nullptr;
|
||||||
|
|
||||||
// sun
|
// sun
|
||||||
GFXPipeline* static_sun_pipeline = nullptr;
|
GFXPipeline* static_sun_pipeline = nullptr;
|
||||||
|
|
|
@ -40,7 +40,7 @@ DoFPass::DoFPass(GFX* gfx, prism::renderer* renderer) : renderer(renderer) {
|
||||||
};
|
};
|
||||||
|
|
||||||
create_info.shader_input.push_constants = {
|
create_info.shader_input.push_constants = {
|
||||||
{sizeof(Vector4), 0}
|
{sizeof(prism::float4), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
create_info.render_pass = renderpass;
|
create_info.render_pass = renderpass;
|
||||||
|
@ -102,10 +102,10 @@ void DoFPass::render(GFXCommandBuffer* command_buffer, Scene&) {
|
||||||
command_buffer->bind_texture(aperture_texture->handle, 3);
|
command_buffer->bind_texture(aperture_texture->handle, 3);
|
||||||
|
|
||||||
//const auto extent = renderer->get_render_extent();
|
//const auto extent = renderer->get_render_extent();
|
||||||
|
|
||||||
|
prism::float4 params(render_options.depth_of_field_strength, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
Vector4 params(render_options.depth_of_field_strength, 0.0, 0.0, 0.0);
|
command_buffer->set_push_constant(¶ms, sizeof(prism::float4));
|
||||||
|
|
||||||
command_buffer->set_push_constant(¶ms, sizeof(Vector4));
|
|
||||||
|
|
||||||
command_buffer->draw(0, 4, 0, extent.width * extent.height);
|
command_buffer->draw(0, 4, 0, extent.width * extent.height);
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ void DoFPass::render(GFXCommandBuffer* command_buffer, Scene&) {
|
||||||
|
|
||||||
params.y = 1;
|
params.y = 1;
|
||||||
|
|
||||||
command_buffer->set_push_constant(¶ms, sizeof(Vector4));
|
command_buffer->set_push_constant(¶ms, sizeof(prism::float4));
|
||||||
|
|
||||||
command_buffer->draw(0, 4, 0, extent.width * extent.height);
|
command_buffer->draw(0, 4, 0, extent.width * extent.height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,11 @@ CameraFrustum normalize_frustum(const CameraFrustum& frustum) {
|
||||||
return normalized_frustum;
|
return normalized_frustum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_point_plane(const Plane& plane, const Vector3& point) {
|
bool test_point_plane(const Plane& plane, const prism::float3& point) {
|
||||||
return distance_to_point(plane, point) > 0.0;
|
return distance_to_point(plane, point) > 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_point_frustum(const CameraFrustum& frustum, const Vector3& point) {
|
bool test_point_frustum(const CameraFrustum& frustum, const prism::float3& point) {
|
||||||
bool inside_frustum = false;
|
bool inside_frustum = false;
|
||||||
|
|
||||||
for(int i = 0; i < 6; i++)
|
for(int i = 0; i < 6; i++)
|
||||||
|
@ -72,7 +72,7 @@ bool test_point_frustum(const CameraFrustum& frustum, const Vector3& point) {
|
||||||
return !inside_frustum;
|
return !inside_frustum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_aabb_frustum(const CameraFrustum& frustum, const AABB& aabb) {
|
bool test_aabb_frustum(const CameraFrustum& frustum, const prism::aabb& aabb) {
|
||||||
for(int i = 0; i < 6; i++) {
|
for(int i = 0; i < 6; i++) {
|
||||||
int out = 0;
|
int out = 0;
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ bool test_aabb_frustum(const CameraFrustum& frustum, const AABB& aabb) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB get_aabb_for_part(const Transform& transform, const Mesh::Part& part) {
|
prism::aabb get_aabb_for_part(const Transform& transform, const Mesh::Part& part) {
|
||||||
AABB aabb = {};
|
prism::aabb aabb = {};
|
||||||
aabb.min = part.aabb.min - transform.get_world_position();
|
aabb.min = part.bounding_box.min - transform.get_world_position();
|
||||||
aabb.max = transform.get_world_position() + part.aabb.max;
|
aabb.max = transform.get_world_position() + part.bounding_box.max;
|
||||||
aabb.min *= transform.scale;
|
aabb.min *= transform.scale;
|
||||||
aabb.max *= transform.scale;
|
aabb.max *= transform.scale;
|
||||||
|
|
||||||
|
|
|
@ -103,12 +103,12 @@ void ImGuiPass::render_post(GFXCommandBuffer* command_buffer, RenderTarget& targ
|
||||||
command_buffer->set_index_buffer(target.index_buffer[target.current_frame], IndexType::UINT16);
|
command_buffer->set_index_buffer(target.index_buffer[target.current_frame], IndexType::UINT16);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Matrix4x4 projection = transform::orthographic(draw_data->DisplayPos.x,
|
const Matrix4x4 projection = prism::orthographic(draw_data->DisplayPos.x,
|
||||||
draw_data->DisplayPos.x + draw_data->DisplaySize.x,
|
draw_data->DisplayPos.x + draw_data->DisplaySize.x,
|
||||||
draw_data->DisplayPos.y + draw_data->DisplaySize.y,
|
draw_data->DisplayPos.y + draw_data->DisplaySize.y,
|
||||||
draw_data->DisplayPos.y,
|
draw_data->DisplayPos.y,
|
||||||
0.0f,
|
0.0f,
|
||||||
1.0f);
|
1.0f);
|
||||||
|
|
||||||
command_buffer->set_push_constant(&projection, sizeof(Matrix4x4));
|
command_buffer->set_push_constant(&projection, sizeof(Matrix4x4));
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ GFXPipeline* MaterialCompiler::create_static_pipeline(GFXGraphicsPipelineCreateI
|
||||||
|
|
||||||
if(positions_only) {
|
if(positions_only) {
|
||||||
createInfo.vertex_input.inputs = {
|
createInfo.vertex_input.inputs = {
|
||||||
{position_buffer_index, sizeof(Vector3)}
|
{position_buffer_index, sizeof(prism::float3)}
|
||||||
};
|
};
|
||||||
|
|
||||||
createInfo.vertex_input.attributes = {
|
createInfo.vertex_input.attributes = {
|
||||||
|
@ -57,11 +57,11 @@ GFXPipeline* MaterialCompiler::create_static_pipeline(GFXGraphicsPipelineCreateI
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
createInfo.vertex_input.inputs = {
|
createInfo.vertex_input.inputs = {
|
||||||
{position_buffer_index, sizeof(Vector3)},
|
{position_buffer_index, sizeof(prism::float3)},
|
||||||
{normal_buffer_index, sizeof(Vector3)},
|
{normal_buffer_index, sizeof(prism::float3)},
|
||||||
{texcoord_buffer_index, sizeof(Vector2)},
|
{texcoord_buffer_index, sizeof(prism::float2)},
|
||||||
{tangent_buffer_index, sizeof(Vector3)},
|
{tangent_buffer_index, sizeof(prism::float3)},
|
||||||
{bitangent_buffer_index, sizeof(Vector3)}
|
{bitangent_buffer_index, sizeof(prism::float3)}
|
||||||
};
|
};
|
||||||
|
|
||||||
createInfo.vertex_input.attributes = {
|
createInfo.vertex_input.attributes = {
|
||||||
|
@ -89,7 +89,7 @@ GFXPipeline* MaterialCompiler::create_skinned_pipeline(GFXGraphicsPipelineCreate
|
||||||
|
|
||||||
if(positions_only) {
|
if(positions_only) {
|
||||||
createInfo.vertex_input.inputs = {
|
createInfo.vertex_input.inputs = {
|
||||||
{position_buffer_index, sizeof(Vector3)},
|
{position_buffer_index, sizeof(prism::float3)},
|
||||||
{bone_buffer_index, sizeof(BoneVertexData)}
|
{bone_buffer_index, sizeof(BoneVertexData)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,11 +100,11 @@ GFXPipeline* MaterialCompiler::create_skinned_pipeline(GFXGraphicsPipelineCreate
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
createInfo.vertex_input.inputs = {
|
createInfo.vertex_input.inputs = {
|
||||||
{position_buffer_index, sizeof(Vector3)},
|
{position_buffer_index, sizeof(prism::float3)},
|
||||||
{normal_buffer_index, sizeof(Vector3)},
|
{normal_buffer_index, sizeof(prism::float3)},
|
||||||
{texcoord_buffer_index, sizeof(Vector2)},
|
{texcoord_buffer_index, sizeof(prism::float2)},
|
||||||
{tangent_buffer_index, sizeof(Vector3)},
|
{tangent_buffer_index, sizeof(prism::float3)},
|
||||||
{bitangent_buffer_index, sizeof(Vector3)},
|
{bitangent_buffer_index, sizeof(prism::float3)},
|
||||||
{bone_buffer_index, sizeof(BoneVertexData)}
|
{bone_buffer_index, sizeof(BoneVertexData)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
using prism::renderer;
|
using prism::renderer;
|
||||||
|
|
||||||
struct ElementInstance {
|
struct ElementInstance {
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
uint32_t position = 0, size = 0;
|
uint32_t position = 0, size = 0;
|
||||||
uint32_t padding[2];
|
uint32_t padding[2];
|
||||||
};
|
};
|
||||||
|
@ -47,23 +47,23 @@ struct StringInstance {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneMaterial {
|
struct SceneMaterial {
|
||||||
Vector4 color, info;
|
prism::float4 color, info;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneLight {
|
struct SceneLight {
|
||||||
Vector4 positionType;
|
prism::float4 positionType;
|
||||||
Vector4 directionPower;
|
prism::float4 directionPower;
|
||||||
Vector4 colorSize;
|
prism::float4 colorSize;
|
||||||
Vector4 shadowsEnable;
|
prism::float4 shadowsEnable;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneProbe {
|
struct SceneProbe {
|
||||||
Vector4 position, size;
|
prism::float4 position, size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneInformation {
|
struct SceneInformation {
|
||||||
Vector4 options;
|
prism::float4 options;
|
||||||
Vector4 camPos;
|
prism::float4 camPos;
|
||||||
Matrix4x4 vp, lightspace;
|
Matrix4x4 vp, lightspace;
|
||||||
Matrix4x4 spotLightSpaces[max_spot_shadows];
|
Matrix4x4 spotLightSpaces[max_spot_shadows];
|
||||||
SceneMaterial materials[max_scene_materials];
|
SceneMaterial materials[max_scene_materials];
|
||||||
|
@ -74,17 +74,17 @@ struct SceneInformation {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PostPushConstants {
|
struct PostPushConstants {
|
||||||
Vector4 viewport, options, transform_ops;
|
prism::float4 viewport, options, transform_ops;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UIPushConstant {
|
struct UIPushConstant {
|
||||||
Vector2 screenSize;
|
prism::float2 screenSize;
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SkyPushConstant {
|
struct SkyPushConstant {
|
||||||
Matrix4x4 view;
|
Matrix4x4 view;
|
||||||
Vector4 sun_position_fov;
|
prism::float4 sun_position_fov;
|
||||||
float aspect;
|
float aspect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -277,14 +277,14 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
|
||||||
for(auto& [obj, camera] : cameras) {
|
for(auto& [obj, camera] : cameras) {
|
||||||
const bool requires_limited_perspective = render_options.enable_depth_of_field;
|
const bool requires_limited_perspective = render_options.enable_depth_of_field;
|
||||||
if(requires_limited_perspective) {
|
if(requires_limited_perspective) {
|
||||||
camera.perspective = transform::perspective(radians(camera.fov),
|
camera.perspective = prism::perspective(radians(camera.fov),
|
||||||
static_cast<float>(render_extent.width) / static_cast<float>(render_extent.height),
|
static_cast<float>(render_extent.width) / static_cast<float>(render_extent.height),
|
||||||
camera.near,
|
camera.near,
|
||||||
100.0f);
|
100.0f);
|
||||||
} else {
|
} else {
|
||||||
camera.perspective = transform::infinite_perspective(radians(camera.fov),
|
camera.perspective = prism::infinite_perspective(radians(camera.fov),
|
||||||
static_cast<float>(render_extent.width) / static_cast<float>(render_extent.height),
|
static_cast<float>(render_extent.width) / static_cast<float>(render_extent.height),
|
||||||
camera.near);
|
camera.near);
|
||||||
}
|
}
|
||||||
|
|
||||||
camera.view = inverse(scene->get<Transform>(obj).model);
|
camera.view = inverse(scene->get<Transform>(obj).model);
|
||||||
|
@ -326,25 +326,25 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
|
||||||
commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256);
|
commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256);
|
||||||
|
|
||||||
const float lum_range = render_options.max_luminance - render_options.min_luminance;
|
const float lum_range = render_options.max_luminance - render_options.min_luminance;
|
||||||
|
|
||||||
Vector4 params = Vector4(render_options.min_luminance,
|
prism::float4 params = prism::float4(render_options.min_luminance,
|
||||||
1.0f / lum_range,
|
1.0f / lum_range,
|
||||||
static_cast<float>(render_extent.width),
|
static_cast<float>(render_extent.width),
|
||||||
static_cast<float>(render_extent.height));
|
static_cast<float>(render_extent.height));
|
||||||
|
|
||||||
commandbuffer->set_push_constant(¶ms, sizeof(Vector4));
|
commandbuffer->set_push_constant(¶ms, sizeof(prism::float4));
|
||||||
|
|
||||||
commandbuffer->dispatch(static_cast<uint32_t>(std::ceil(static_cast<float>(render_extent.width) / 16.0f)),
|
commandbuffer->dispatch(static_cast<uint32_t>(std::ceil(static_cast<float>(render_extent.width) / 16.0f)),
|
||||||
static_cast<uint32_t>(std::ceil(static_cast<float>(render_extent.height) / 16.0f)), 1);
|
static_cast<uint32_t>(std::ceil(static_cast<float>(render_extent.height) / 16.0f)), 1);
|
||||||
|
|
||||||
commandbuffer->set_compute_pipeline(histogram_average_pipeline);
|
commandbuffer->set_compute_pipeline(histogram_average_pipeline);
|
||||||
|
|
||||||
params = Vector4(render_options.min_luminance,
|
params = prism::float4(render_options.min_luminance,
|
||||||
lum_range,
|
lum_range,
|
||||||
std::clamp(1.0f - std::exp(-(1.0f / 60.0f) * 1.1f), 0.0f, 1.0f),
|
std::clamp(1.0f - std::exp(-(1.0f / 60.0f) * 1.1f), 0.0f, 1.0f),
|
||||||
static_cast<float>(render_extent.width * render_extent.height));
|
static_cast<float>(render_extent.width * render_extent.height));
|
||||||
|
|
||||||
commandbuffer->set_push_constant(¶ms, sizeof(Vector4));
|
commandbuffer->set_push_constant(¶ms, sizeof(prism::float4));
|
||||||
|
|
||||||
commandbuffer->bind_texture(average_luminance_texture, 0);
|
commandbuffer->bind_texture(average_luminance_texture, 0);
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
|
||||||
pc.transform_ops.y = static_cast<float>(render_options.tonemapping);
|
pc.transform_ops.y = static_cast<float>(render_options.tonemapping);
|
||||||
|
|
||||||
const auto [width, height] = render_extent;
|
const auto [width, height] = render_extent;
|
||||||
pc.viewport = Vector4(1.0f / static_cast<float>(width), 1.0f / static_cast<float>(height), static_cast<float>(width), static_cast<float>(height));
|
pc.viewport = prism::float4(1.0f / static_cast<float>(width), 1.0f / static_cast<float>(height), static_cast<float>(width), static_cast<float>(height));
|
||||||
|
|
||||||
commandbuffer->set_push_constant(&pc, sizeof(PostPushConstants));
|
commandbuffer->set_push_constant(&pc, sizeof(PostPushConstants));
|
||||||
|
|
||||||
|
@ -421,20 +421,20 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
|
||||||
|
|
||||||
SceneInformation sceneInfo = {};
|
SceneInformation sceneInfo = {};
|
||||||
sceneInfo.lightspace = scene.lightSpace;
|
sceneInfo.lightspace = scene.lightSpace;
|
||||||
sceneInfo.options = Vector4(1, 0, 0, 0);
|
sceneInfo.options = prism::float4(1, 0, 0, 0);
|
||||||
sceneInfo.camPos = scene.get<Transform>(camera_object).get_world_position();
|
sceneInfo.camPos = scene.get<Transform>(camera_object).get_world_position();
|
||||||
sceneInfo.camPos.w = 2.0f * camera.near * std::tan(camera.fov * 0.5f) * (static_cast<float>(extent.width) / static_cast<float>(extent.height));
|
sceneInfo.camPos.w = 2.0f * camera.near * std::tan(camera.fov * 0.5f) * (static_cast<float>(extent.width) / static_cast<float>(extent.height));
|
||||||
sceneInfo.vp = camera.perspective * camera.view;
|
sceneInfo.vp = camera.perspective * camera.view;
|
||||||
|
|
||||||
for(const auto& [obj, light] : scene.get_all<Light>()) {
|
for(const auto& [obj, light] : scene.get_all<Light>()) {
|
||||||
SceneLight sl;
|
SceneLight sl;
|
||||||
sl.positionType = Vector4(scene.get<Transform>(obj).get_world_position(), static_cast<float>(light.type));
|
sl.positionType = prism::float4(scene.get<Transform>(obj).get_world_position(), static_cast<float>(light.type));
|
||||||
|
|
||||||
|
prism::float3 front = prism::float3(0.0f, 0.0f, 1.0f) * scene.get<Transform>(obj).rotation;
|
||||||
|
|
||||||
Vector3 front = Vector3(0.0f, 0.0f, 1.0f) * scene.get<Transform>(obj).rotation;
|
sl.directionPower = prism::float4(-front, light.power);
|
||||||
|
sl.colorSize = prism::float4(utility::from_srgb_to_linear(light.color), radians(light.spot_size));
|
||||||
sl.directionPower = Vector4(-front, light.power);
|
sl.shadowsEnable = prism::float4(light.enable_shadows, radians(light.size), 0, 0);
|
||||||
sl.colorSize = Vector4(utility::from_srgb_to_linear(light.color), radians(light.spot_size));
|
|
||||||
sl.shadowsEnable = Vector4(light.enable_shadows, radians(light.size), 0, 0);
|
|
||||||
|
|
||||||
sceneInfo.lights[sceneInfo.numLights++] = sl;
|
sceneInfo.lights[sceneInfo.numLights++] = sl;
|
||||||
}
|
}
|
||||||
|
@ -445,8 +445,8 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
|
||||||
int last_probe = 0;
|
int last_probe = 0;
|
||||||
for(const auto& [obj, probe] : scene.get_all<EnvironmentProbe>()) {
|
for(const auto& [obj, probe] : scene.get_all<EnvironmentProbe>()) {
|
||||||
SceneProbe p;
|
SceneProbe p;
|
||||||
p.position = Vector4(scene.get<Transform>(obj).position, probe.is_sized ? 1.0f : 2.0f);
|
p.position = prism::float4(scene.get<Transform>(obj).position, probe.is_sized ? 1.0f : 2.0f);
|
||||||
p.size = Vector4(probe.size, probe.intensity);
|
p.size = prism::float4(probe.size, probe.intensity);
|
||||||
|
|
||||||
sceneInfo.probes[last_probe++] = p;
|
sceneInfo.probes[last_probe++] = p;
|
||||||
}
|
}
|
||||||
|
@ -549,7 +549,7 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
|
||||||
|
|
||||||
for(const auto& [obj, light] : scene.get_all<Light>()) {
|
for(const auto& [obj, light] : scene.get_all<Light>()) {
|
||||||
if(light.type == Light::Type::Sun)
|
if(light.type == Light::Type::Sun)
|
||||||
pc.sun_position_fov = Vector4(scene.get<Transform>(obj).get_world_position(), radians(camera.fov));
|
pc.sun_position_fov = prism::float4(scene.get<Transform>(obj).get_world_position(), radians(camera.fov));
|
||||||
}
|
}
|
||||||
|
|
||||||
command_buffer->set_graphics_pipeline(sky_pipeline);
|
command_buffer->set_graphics_pipeline(sky_pipeline);
|
||||||
|
@ -644,7 +644,7 @@ void renderer::render_screen(GFXCommandBuffer *commandbuffer, ui::Screen* screen
|
||||||
gfx->copy_buffer(screen->instance_buffer, stringInstances.data(), 0, sizeof(StringInstance) * 50);
|
gfx->copy_buffer(screen->instance_buffer, stringInstances.data(), 0, sizeof(StringInstance) * 50);
|
||||||
gfx->copy_buffer(screen->elements_buffer, elementInstances.data(), sizeof(ElementInstance) * continuity.elementOffset, sizeof(ElementInstance) * elementInstances.size());
|
gfx->copy_buffer(screen->elements_buffer, elementInstances.data(), sizeof(ElementInstance) * continuity.elementOffset, sizeof(ElementInstance) * elementInstances.size());
|
||||||
|
|
||||||
const Vector2 windowSize = {static_cast<float>(extent.width), static_cast<float>(extent.height)};
|
const prism::float2 windowSize = {static_cast<float>(extent.width), static_cast<float>(extent.height)};
|
||||||
|
|
||||||
for(auto [i, element] : utility::enumerate(screen->elements)) {
|
for(auto [i, element] : utility::enumerate(screen->elements)) {
|
||||||
if(!element.visible)
|
if(!element.visible)
|
||||||
|
@ -1017,7 +1017,7 @@ void renderer::create_histogram_resources() {
|
||||||
};
|
};
|
||||||
|
|
||||||
create_info.shader_input.push_constants = {
|
create_info.shader_input.push_constants = {
|
||||||
{sizeof(Vector4), 0}
|
{sizeof(prism::float4), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
histogram_pipeline = gfx->create_compute_pipeline(create_info);
|
histogram_pipeline = gfx->create_compute_pipeline(create_info);
|
||||||
|
|
|
@ -16,23 +16,23 @@ struct PushConstant {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneMaterial {
|
struct SceneMaterial {
|
||||||
Vector4 color, info;
|
prism::float4 color, info;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneLight {
|
struct SceneLight {
|
||||||
Vector4 positionType;
|
prism::float4 positionType;
|
||||||
Vector4 directionPower;
|
prism::float4 directionPower;
|
||||||
Vector4 colorSize;
|
prism::float4 colorSize;
|
||||||
Vector4 shadowsEnable;
|
prism::float4 shadowsEnable;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneProbe {
|
struct SceneProbe {
|
||||||
Vector4 position, size;
|
prism::float4 position, size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SceneInformation {
|
struct SceneInformation {
|
||||||
Vector4 options;
|
prism::float4 options;
|
||||||
Vector4 camPos;
|
prism::float4 camPos;
|
||||||
Matrix4x4 vp, lightspace;
|
Matrix4x4 vp, lightspace;
|
||||||
Matrix4x4 spotLightSpaces[max_spot_shadows];
|
Matrix4x4 spotLightSpaces[max_spot_shadows];
|
||||||
SceneMaterial materials[max_scene_materials];
|
SceneMaterial materials[max_scene_materials];
|
||||||
|
@ -44,7 +44,7 @@ struct SceneInformation {
|
||||||
|
|
||||||
struct SkyPushConstant {
|
struct SkyPushConstant {
|
||||||
Matrix4x4 view;
|
Matrix4x4 view;
|
||||||
Vector4 sun_position_fov;
|
prism::float4 sun_position_fov;
|
||||||
float aspect;
|
float aspect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ struct FilterPushConstant {
|
||||||
const int mipLevels = 5;
|
const int mipLevels = 5;
|
||||||
|
|
||||||
const std::array<Matrix4x4, 6> sceneTransforms = {
|
const std::array<Matrix4x4, 6> sceneTransforms = {
|
||||||
transform::look_at(Vector3(0), Vector3(-1.0, 0.0, 0.0), Vector3(0.0, -1.0, 0.0)), // right
|
prism::look_at(prism::float3(0), prism::float3(-1.0, 0.0, 0.0), prism::float3(0.0, -1.0, 0.0)), // right
|
||||||
transform::look_at(Vector3(0), Vector3(1.0, 0.0, 0.0), Vector3(0.0, -1.0, 0.0)), // left
|
prism::look_at(prism::float3(0), prism::float3(1.0, 0.0, 0.0), prism::float3(0.0, -1.0, 0.0)), // left
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, -1.0, 0.0), Vector3(0.0, 0.0, -1.0)), // top
|
prism::look_at(prism::float3(0), prism::float3(0.0, -1.0, 0.0), prism::float3(0.0, 0.0, -1.0)), // top
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, 1.0, 0.0), Vector3(0.0, 0.0, 1.0)), // bottom
|
prism::look_at(prism::float3(0), prism::float3(0.0, 1.0, 0.0), prism::float3(0.0, 0.0, 1.0)), // bottom
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, 0.0, 1.0), Vector3(0.0, -1.0, 0.0)), // back
|
prism::look_at(prism::float3(0), prism::float3(0.0, 0.0, 1.0), prism::float3(0.0, -1.0, 0.0)), // back
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, 0.0, -1.0), Vector3(0.0, -1.0, 0.0)) // front
|
prism::look_at(prism::float3(0), prism::float3(0.0, 0.0, -1.0), prism::float3(0.0, -1.0, 0.0)) // front
|
||||||
};
|
};
|
||||||
|
|
||||||
inline AssetPtr<Mesh> cubeMesh;
|
inline AssetPtr<Mesh> cubeMesh;
|
||||||
|
@ -166,10 +166,10 @@ void SceneCapture::render(GFXCommandBuffer* command_buffer, Scene* scene) {
|
||||||
std::map<Material*, int> material_indices;
|
std::map<Material*, int> material_indices;
|
||||||
int numMaterialsInBuffer = 0;
|
int numMaterialsInBuffer = 0;
|
||||||
|
|
||||||
const Vector3 lightPos = scene->get<Transform>(obj).get_world_position();
|
const prism::float3 lightPos = scene->get<Transform>(obj).get_world_position();
|
||||||
|
|
||||||
const Matrix4x4 projection = transform::infinite_perspective(radians(90.0f), 1.0f, 0.1f);
|
const Matrix4x4 projection = prism::infinite_perspective(radians(90.0f), 1.0f, 0.1f);
|
||||||
const Matrix4x4 model = transform::translate(Matrix4x4(), Vector3(-lightPos.x, -lightPos.y, -lightPos.z));
|
const Matrix4x4 model = prism::translate(Matrix4x4(), prism::float3(-lightPos.x, -lightPos.y, -lightPos.z));
|
||||||
|
|
||||||
SceneInformation sceneInfo = {};
|
SceneInformation sceneInfo = {};
|
||||||
sceneInfo.lightspace = scene->lightSpace;
|
sceneInfo.lightspace = scene->lightSpace;
|
||||||
|
@ -179,13 +179,13 @@ void SceneCapture::render(GFXCommandBuffer* command_buffer, Scene* scene) {
|
||||||
|
|
||||||
for(const auto [obj, light] : scene->get_all<Light>()) {
|
for(const auto [obj, light] : scene->get_all<Light>()) {
|
||||||
SceneLight sl;
|
SceneLight sl;
|
||||||
sl.positionType = Vector4(scene->get<Transform>(obj).get_world_position(), (int)light.type);
|
sl.positionType = prism::float4(scene->get<Transform>(obj).get_world_position(), (int)light.type);
|
||||||
|
|
||||||
|
prism::float3 front = prism::float3(0.0f, 0.0f, 1.0f) * scene->get<Transform>(obj).rotation;
|
||||||
|
|
||||||
Vector3 front = Vector3(0.0f, 0.0f, 1.0f) * scene->get<Transform>(obj).rotation;
|
sl.directionPower = prism::float4(-front, light.power);
|
||||||
|
sl.colorSize = prism::float4(utility::from_srgb_to_linear(light.color), radians(light.spot_size));
|
||||||
sl.directionPower = Vector4(-front, light.power);
|
sl.shadowsEnable = prism::float4(light.enable_shadows, radians(light.size), 0, 0);
|
||||||
sl.colorSize = Vector4(utility::from_srgb_to_linear(light.color), radians(light.spot_size));
|
|
||||||
sl.shadowsEnable = Vector4(light.enable_shadows, radians(light.size), 0, 0);
|
|
||||||
|
|
||||||
sceneInfo.lights[sceneInfo.numLights++] = sl;
|
sceneInfo.lights[sceneInfo.numLights++] = sl;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ void SceneCapture::render(GFXCommandBuffer* command_buffer, Scene* scene) {
|
||||||
|
|
||||||
for(auto& [obj, light] : scene->get_all<Light>()) {
|
for(auto& [obj, light] : scene->get_all<Light>()) {
|
||||||
if(light.type == Light::Type::Sun)
|
if(light.type == Light::Type::Sun)
|
||||||
pc.sun_position_fov = Vector4(scene->get<Transform>(obj).get_world_position(), radians(90.0f));
|
pc.sun_position_fov = prism::float4(scene->get<Transform>(obj).get_world_position(), radians(90.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
command_buffer->set_graphics_pipeline(skyPipeline);
|
command_buffer->set_graphics_pipeline(skyPipeline);
|
||||||
|
@ -455,7 +455,7 @@ void SceneCapture::createIrradianceResources() {
|
||||||
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("irradiance.frag"));
|
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("irradiance.frag"));
|
||||||
|
|
||||||
GFXVertexInput input;
|
GFXVertexInput input;
|
||||||
input.stride = sizeof(Vector3);
|
input.stride = sizeof(prism::float3);
|
||||||
|
|
||||||
pipelineInfo.vertex_input.inputs.push_back(input);
|
pipelineInfo.vertex_input.inputs.push_back(input);
|
||||||
|
|
||||||
|
@ -509,7 +509,7 @@ void SceneCapture::createPrefilterResources() {
|
||||||
pipelineInfo.shaders.fragment_constants = {size_constant};
|
pipelineInfo.shaders.fragment_constants = {size_constant};
|
||||||
|
|
||||||
GFXVertexInput input;
|
GFXVertexInput input;
|
||||||
input.stride = sizeof(Vector3);
|
input.stride = sizeof(prism::float3);
|
||||||
|
|
||||||
pipelineInfo.vertex_input.inputs.push_back(input);
|
pipelineInfo.vertex_input.inputs.push_back(input);
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@ struct PushConstant {
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::array<Matrix4x4, 6> shadowTransforms = {
|
const std::array<Matrix4x4, 6> shadowTransforms = {
|
||||||
transform::look_at(Vector3(0), Vector3(1.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0)), // right
|
prism::look_at(prism::float3(0), prism::float3(1.0, 0.0, 0.0), prism::float3(0.0, 1.0, 0.0)), // right
|
||||||
transform::look_at(Vector3(0), Vector3(-1.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0)), // left
|
prism::look_at(prism::float3(0), prism::float3(-1.0, 0.0, 0.0), prism::float3(0.0, 1.0, 0.0)), // left
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, 1.0, 0.0), Vector3(0.0, 0.0, -1.0)), // top
|
prism::look_at(prism::float3(0), prism::float3(0.0, 1.0, 0.0), prism::float3(0.0, 0.0, -1.0)), // top
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, -1.0, 0.0), Vector3(0.0, 0.0, 1.0)), // bottom
|
prism::look_at(prism::float3(0), prism::float3(0.0, -1.0, 0.0), prism::float3(0.0, 0.0, 1.0)), // bottom
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, 0.0, 1.0), Vector3(0.0, 1.0, 0.0)), // back
|
prism::look_at(prism::float3(0), prism::float3(0.0, 0.0, 1.0), prism::float3(0.0, 1.0, 0.0)), // back
|
||||||
transform::look_at(Vector3(0), Vector3( 0.0, 0.0, -1.0), Vector3(0.0, 1.0, 0.0)) // front
|
prism::look_at(prism::float3(0), prism::float3(0.0, 0.0, -1.0), prism::float3(0.0, 1.0, 0.0)) // front
|
||||||
};
|
};
|
||||||
|
|
||||||
ShadowPass::ShadowPass(GFX* gfx) {
|
ShadowPass::ShadowPass(GFX* gfx) {
|
||||||
|
@ -109,7 +109,7 @@ void ShadowPass::render(GFXCommandBuffer* command_buffer, Scene& scene) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowPass::render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const Vector3 light_position, const Light::Type type, const CameraFrustum& frustum, const int base_instance) {
|
void ShadowPass::render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const prism::float3 light_position, const Light::Type type, const CameraFrustum& frustum, const int base_instance) {
|
||||||
for(auto [obj, mesh] : scene.get_all<Renderable>()) {
|
for(auto [obj, mesh] : scene.get_all<Renderable>()) {
|
||||||
if(!mesh.mesh)
|
if(!mesh.mesh)
|
||||||
continue;
|
continue;
|
||||||
|
@ -135,7 +135,7 @@ void ShadowPass::render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, c
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_buffer->bind_shader_buffer(point_location_buffer, 0, 2, sizeof(Vector3) * max_point_shadows);
|
command_buffer->bind_shader_buffer(point_location_buffer, 0, 2, sizeof(prism::float3) * max_point_shadows);
|
||||||
|
|
||||||
command_buffer->set_push_constant(&pc, sizeof(PushConstant));
|
command_buffer->set_push_constant(&pc, sizeof(PushConstant));
|
||||||
command_buffer->set_depth_bias(1.25f, 0.00f, 1.75f);
|
command_buffer->set_depth_bias(1.25f, 0.00f, 1.75f);
|
||||||
|
@ -159,7 +159,7 @@ void ShadowPass::render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, c
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_buffer->bind_shader_buffer(point_location_buffer, 0, 2, sizeof(Vector3) * max_point_shadows);
|
command_buffer->bind_shader_buffer(point_location_buffer, 0, 2, sizeof(prism::float3) * max_point_shadows);
|
||||||
|
|
||||||
command_buffer->set_push_constant(&pc, sizeof(PushConstant));
|
command_buffer->set_push_constant(&pc, sizeof(PushConstant));
|
||||||
|
|
||||||
|
@ -192,10 +192,10 @@ void ShadowPass::render_sun(GFXCommandBuffer* command_buffer, Scene& scene, Obje
|
||||||
|
|
||||||
command_buffer->set_viewport(viewport);
|
command_buffer->set_viewport(viewport);
|
||||||
|
|
||||||
const Vector3 lightPos = scene.get<Transform>(light_object).position;
|
const prism::float3 lightPos = scene.get<Transform>(light_object).position;
|
||||||
|
|
||||||
const Matrix4x4 projection = transform::orthographic(-25.0f, 25.0f, -25.0f, 25.0f, 0.1f, 100.0f);
|
const Matrix4x4 projection = prism::orthographic(-25.0f, 25.0f, -25.0f, 25.0f, 0.1f, 100.0f);
|
||||||
const Matrix4x4 view = transform::look_at(lightPos, Vector3(0), Vector3(0, 1, 0));
|
const Matrix4x4 view = prism::look_at(lightPos, prism::float3(0), prism::float3(0, 1, 0));
|
||||||
|
|
||||||
const Matrix4x4 realMVP = projection * view;
|
const Matrix4x4 realMVP = projection * view;
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ void ShadowPass::render_spot(GFXCommandBuffer* command_buffer, Scene& scene, Obj
|
||||||
|
|
||||||
command_buffer->set_viewport(viewport);
|
command_buffer->set_viewport(viewport);
|
||||||
|
|
||||||
const Matrix4x4 perspective = transform::perspective(radians(90.0f), 1.0f, 0.1f, 100.0f);
|
const Matrix4x4 perspective = prism::perspective(radians(90.0f), 1.0f, 0.1f, 100.0f);
|
||||||
|
|
||||||
const Matrix4x4 realMVP = perspective * inverse(scene.get<Transform>(light_object).model);
|
const Matrix4x4 realMVP = perspective * inverse(scene.get<Transform>(light_object).model);
|
||||||
|
|
||||||
|
@ -276,9 +276,9 @@ void ShadowPass::render_point(GFXCommandBuffer* command_buffer, Scene& scene, Ob
|
||||||
|
|
||||||
command_buffer->set_viewport(viewport);
|
command_buffer->set_viewport(viewport);
|
||||||
|
|
||||||
const Vector3 lightPos = scene.get<Transform>(light_object).get_world_position();
|
const prism::float3 lightPos = scene.get<Transform>(light_object).get_world_position();
|
||||||
|
|
||||||
const Matrix4x4 projection = transform::perspective(radians(90.0f), 1.0f, 0.1f, 100.0f);
|
const Matrix4x4 projection = prism::perspective(radians(90.0f), 1.0f, 0.1f, 100.0f);
|
||||||
const Matrix4x4 model = inverse(scene.get<Transform>(light_object).model);
|
const Matrix4x4 model = inverse(scene.get<Transform>(light_object).model);
|
||||||
|
|
||||||
const auto frustum = normalize_frustum(extract_frustum(projection * shadowTransforms[face] * model));
|
const auto frustum = normalize_frustum(extract_frustum(projection * shadowTransforms[face] * model));
|
||||||
|
@ -402,6 +402,6 @@ void ShadowPass::create_offscreen_resources() {
|
||||||
|
|
||||||
offscreen_framebuffer = gfx->create_framebuffer(info);
|
offscreen_framebuffer = gfx->create_framebuffer(info);
|
||||||
|
|
||||||
point_location_buffer = gfx->create_buffer(nullptr, sizeof(Vector3) * max_point_shadows, false, GFXBufferUsage::Storage);
|
point_location_buffer = gfx->create_buffer(nullptr, sizeof(prism::float3) * max_point_shadows, false, GFXBufferUsage::Storage);
|
||||||
point_location_map = reinterpret_cast<Vector3*>(gfx->get_buffer_contents(point_location_buffer));
|
point_location_map = reinterpret_cast<prism::float3*>(gfx->get_buffer_contents(point_location_buffer));
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,11 @@ void SMAAPass::render(GFXCommandBuffer* command_buffer, RenderTarget& target) {
|
||||||
beginInfo.render_pass = render_pass;
|
beginInfo.render_pass = render_pass;
|
||||||
|
|
||||||
struct PushConstant {
|
struct PushConstant {
|
||||||
Vector4 viewport;
|
prism::float4 viewport;
|
||||||
Matrix4x4 correction_matrix;
|
Matrix4x4 correction_matrix;
|
||||||
} pc;
|
} pc;
|
||||||
|
|
||||||
pc.viewport = Vector4(1.0f / static_cast<float>(target.extent.width), 1.0f / static_cast<float>(target.extent.height), target.extent.width, target.extent.height);
|
pc.viewport = prism::float4(1.0f / static_cast<float>(target.extent.width), 1.0f / static_cast<float>(target.extent.height), target.extent.width, target.extent.height);
|
||||||
|
|
||||||
// edge
|
// edge
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,7 @@ void SMAAPass::create_pipelines() {
|
||||||
createInfo.render_pass = render_pass;
|
createInfo.render_pass = render_pass;
|
||||||
|
|
||||||
createInfo.shader_input.push_constants = {
|
createInfo.shader_input.push_constants = {
|
||||||
{sizeof(Vector4) + sizeof(Matrix4x4), 0}
|
{sizeof(prism::float4) + sizeof(Matrix4x4), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
createInfo.shader_input.bindings = {
|
createInfo.shader_input.bindings = {
|
||||||
|
|
|
@ -4,7 +4,6 @@ set(SRC
|
||||||
include/string_utils.hpp
|
include/string_utils.hpp
|
||||||
include/timer.hpp
|
include/timer.hpp
|
||||||
include/common.hpp
|
include/common.hpp
|
||||||
include/aabb.hpp
|
|
||||||
include/file_utils.hpp
|
include/file_utils.hpp
|
||||||
include/assertions.hpp
|
include/assertions.hpp
|
||||||
include/path.hpp
|
include/path.hpp
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include "vector.hpp"
|
|
||||||
|
|
||||||
/// A 3D axis aligned bounding box.
|
|
||||||
struct AABB {
|
|
||||||
Vector3 min, max;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Creates an array of 8 points, each of these being one extreme of the bounding box..
|
|
||||||
inline std::array<Vector3, 8> get_points(const AABB& aabb) {
|
|
||||||
return {
|
|
||||||
Vector3(aabb.min.x, aabb.min.y, aabb.min.z),
|
|
||||||
Vector3(aabb.max.x, aabb.min.y, aabb.min.z),
|
|
||||||
Vector3(aabb.min.x, aabb.max.y, aabb.min.z),
|
|
||||||
Vector3(aabb.max.x, aabb.max.y, aabb.min.z),
|
|
||||||
Vector3(aabb.min.x, aabb.min.y, aabb.max.z),
|
|
||||||
Vector3(aabb.max.x, aabb.min.y, aabb.max.z),
|
|
||||||
Vector3(aabb.min.x, aabb.max.y, aabb.max.z),
|
|
||||||
Vector3(aabb.max.x, aabb.max.y, aabb.max.z)};
|
|
||||||
}
|
|
|
@ -5,16 +5,18 @@
|
||||||
#include "vector.hpp"
|
#include "vector.hpp"
|
||||||
#include "quaternion.hpp"
|
#include "quaternion.hpp"
|
||||||
|
|
||||||
inline void to_json(nlohmann::json& j, const Vector3& p) {
|
namespace prism {
|
||||||
j["x"] = p.x;
|
inline void to_json(nlohmann::json &j, const float3 &p) {
|
||||||
j["y"] = p.y;
|
j["x"] = p.x;
|
||||||
j["z"] = p.z;
|
j["y"] = p.y;
|
||||||
}
|
j["z"] = p.z;
|
||||||
|
}
|
||||||
|
|
||||||
inline void from_json(const nlohmann::json& j, Vector3& p) {
|
inline void from_json(const nlohmann::json &j, float3 &p) {
|
||||||
p.x = j["x"];
|
p.x = j["x"];
|
||||||
p.y = j["y"];
|
p.y = j["y"];
|
||||||
p.z = j["z"];
|
p.z = j["z"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void to_json(nlohmann::json& j, const Quaternion& p) {
|
inline void to_json(nlohmann::json& j, const Quaternion& p) {
|
||||||
|
|
|
@ -99,8 +99,8 @@ namespace utility {
|
||||||
return static_cast<uint16_t>(32.0f * f + 0.5f);
|
return static_cast<uint16_t>(32.0f * f + 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector3 from_srgb_to_linear(const Vector3 sRGB) {
|
inline prism::float3 from_srgb_to_linear(const prism::float3 sRGB) {
|
||||||
Vector3 linear = sRGB;
|
prism::float3 linear = sRGB;
|
||||||
for(auto& component : linear.data) {
|
for(auto& component : linear.data) {
|
||||||
if(component > 0.04045f) {
|
if(component > 0.04045f) {
|
||||||
component = std::pow((component + 0.055) / (1.055), 2.4f);
|
component = std::pow((component + 0.055) / (1.055), 2.4f);
|
||||||
|
|
|
@ -155,7 +155,7 @@ public:
|
||||||
GFXTexture* get_material_preview(Material& material);
|
GFXTexture* get_material_preview(Material& material);
|
||||||
GFXTexture* get_mesh_preview(Mesh& mesh);
|
GFXTexture* get_mesh_preview(Mesh& mesh);
|
||||||
GFXTexture* get_texture_preview(Texture& texture);
|
GFXTexture* get_texture_preview(Texture& texture);
|
||||||
GFXTexture* generate_common_preview(Scene& scene, const Vector3 camera_position);
|
GFXTexture* generate_common_preview(Scene& scene, const prism::float3 camera_position);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
GFXTexture* get_asset_thumbnail(AssetPtr<T>& asset) {
|
GFXTexture* get_asset_thumbnail(AssetPtr<T>& asset) {
|
||||||
|
@ -326,7 +326,7 @@ private:
|
||||||
|
|
||||||
bool transforming_axis = false;
|
bool transforming_axis = false;
|
||||||
SelectableObject::Axis axis;
|
SelectableObject::Axis axis;
|
||||||
Vector3 last_object_position;
|
prism::float3 last_object_position;
|
||||||
|
|
||||||
bool open_asset_popup = false;
|
bool open_asset_popup = false;
|
||||||
AssetType current_asset_type;
|
AssetType current_asset_type;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
void render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) override;
|
void render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) override;
|
||||||
|
|
||||||
void get_selected_object(int x, int y, std::function<void(SelectableObject)> callback);
|
void get_selected_object(int x, int y, std::function<void(SelectableObject)> callback);
|
||||||
void draw_arrow(GFXCommandBuffer* commandBuffer, Vector3 color, Matrix4x4 model);
|
void draw_arrow(GFXCommandBuffer* commandBuffer, prism::float3 color, Matrix4x4 model);
|
||||||
|
|
||||||
GFXTexture* get_requested_texture(PassTextureType type) override {
|
GFXTexture* get_requested_texture(PassTextureType type) override {
|
||||||
if(type == PassTextureType::SelectionSobel)
|
if(type == PassTextureType::SelectionSobel)
|
||||||
|
|
|
@ -100,7 +100,7 @@ static float previous_intersect = 0.0;
|
||||||
|
|
||||||
void CommonEditor::update(float deltaTime) {
|
void CommonEditor::update(float deltaTime) {
|
||||||
if(engine->get_scene() != nullptr) {
|
if(engine->get_scene() != nullptr) {
|
||||||
Vector3 offset;
|
prism::float3 offset;
|
||||||
|
|
||||||
willCaptureMouse = engine->get_input()->is_repeating("cameraLook") && accepting_viewport_input;
|
willCaptureMouse = engine->get_input()->is_repeating("cameraLook") && accepting_viewport_input;
|
||||||
|
|
||||||
|
@ -111,10 +111,10 @@ void CommonEditor::update(float deltaTime) {
|
||||||
pitch += engine->get_input()->get_value("lookY") * 50.0f * deltaTime;
|
pitch += engine->get_input()->get_value("lookY") * 50.0f * deltaTime;
|
||||||
|
|
||||||
const float speed = 7.00f;
|
const float speed = 7.00f;
|
||||||
|
|
||||||
Vector3 forward, right;
|
prism::float3 forward, right;
|
||||||
forward = normalize(angle_axis(yaw, Vector3(0, 1, 0)) * angle_axis(pitch, Vector3(1, 0, 0)) * Vector3(0, 0, 1));
|
forward = normalize(angle_axis(yaw, prism::float3(0, 1, 0)) * angle_axis(pitch, prism::float3(1, 0, 0)) * prism::float3(0, 0, 1));
|
||||||
right = normalize(angle_axis(yaw, Vector3(0, 1, 0)) * Vector3(1, 0, 0));
|
right = normalize(angle_axis(yaw, prism::float3(0, 1, 0)) * prism::float3(1, 0, 0));
|
||||||
|
|
||||||
float movX = engine->get_input()->get_value("movementX");
|
float movX = engine->get_input()->get_value("movementX");
|
||||||
float movY = engine->get_input()->get_value("movementY");
|
float movY = engine->get_input()->get_value("movementY");
|
||||||
|
@ -124,7 +124,7 @@ void CommonEditor::update(float deltaTime) {
|
||||||
engine->get_scene()->get<Transform>(obj).position += right * movX * speed * deltaTime;
|
engine->get_scene()->get<Transform>(obj).position += right * movX * speed * deltaTime;
|
||||||
engine->get_scene()->get<Transform>(obj).position += forward * -movY * speed * deltaTime;
|
engine->get_scene()->get<Transform>(obj).position += forward * -movY * speed * deltaTime;
|
||||||
|
|
||||||
engine->get_scene()->get<Transform>(obj).rotation = angle_axis(yaw, Vector3(0, 1, 0)) * angle_axis(pitch, Vector3(1, 0, 0));
|
engine->get_scene()->get<Transform>(obj).rotation = angle_axis(yaw, prism::float3(0, 1, 0)) * angle_axis(pitch, prism::float3(1, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
doing_viewport_input = willCaptureMouse;
|
doing_viewport_input = willCaptureMouse;
|
||||||
|
@ -156,8 +156,8 @@ void CommonEditor::update(float deltaTime) {
|
||||||
|
|
||||||
const auto width = viewport_width;
|
const auto width = viewport_width;
|
||||||
const auto height = viewport_height;
|
const auto height = viewport_height;
|
||||||
|
|
||||||
Vector2 n = Vector2(((viewport_x / (float)width) * 2) - 1,
|
prism::float2 n = prism::float2(((viewport_x / (float)width) * 2) - 1,
|
||||||
((viewport_y / (float)height) * 2) - 1); // [-1, 1] mouse coordinates
|
((viewport_y / (float)height) * 2) - 1); // [-1, 1] mouse coordinates
|
||||||
n.y = -n.y;
|
n.y = -n.y;
|
||||||
|
|
||||||
|
@ -165,37 +165,37 @@ void CommonEditor::update(float deltaTime) {
|
||||||
n.y = std::clamp(n.y, -1.0f, 1.0f);
|
n.y = std::clamp(n.y, -1.0f, 1.0f);
|
||||||
|
|
||||||
const Matrix4x4 view_proj_inverse = inverse(cam.perspective * cam.view);
|
const Matrix4x4 view_proj_inverse = inverse(cam.perspective * cam.view);
|
||||||
|
|
||||||
Vector4 ray_start = view_proj_inverse * Vector4(n.x, n.y, 0.0f, 1.0f);
|
prism::float4 ray_start = view_proj_inverse * prism::float4(n.x, n.y, 0.0f, 1.0f);
|
||||||
ray_start *= 1.0f / ray_start.w;
|
ray_start *= 1.0f / ray_start.w;
|
||||||
|
|
||||||
Vector4 ray_end = view_proj_inverse * Vector4(n.x, n.y, 1.0f, 1.0f);
|
prism::float4 ray_end = view_proj_inverse * prism::float4(n.x, n.y, 1.0f, 1.0f);
|
||||||
ray_end *= 1.0f / ray_end.w;
|
ray_end *= 1.0f / ray_end.w;
|
||||||
|
|
||||||
ray camera_ray;
|
prism::ray camera_ray;
|
||||||
camera_ray.origin = ray_start.xyz;
|
camera_ray.origin = ray_start.xyz;
|
||||||
camera_ray.direction = normalize(ray_end.xyz - ray_start.xyz);
|
camera_ray.direction = normalize(ray_end.xyz - ray_start.xyz);
|
||||||
camera_ray.t = std::numeric_limits<float>::max();
|
camera_ray.t = std::numeric_limits<float>::max();
|
||||||
|
|
||||||
auto& transform = engine->get_scene()->get<Transform>(selected_object);
|
auto& transform = engine->get_scene()->get<Transform>(selected_object);
|
||||||
|
|
||||||
ray transform_ray;
|
prism::ray transform_ray;
|
||||||
transform_ray.origin = last_object_position;
|
transform_ray.origin = last_object_position;
|
||||||
transform_ray.t = std::numeric_limits<float>::max();
|
transform_ray.t = std::numeric_limits<float>::max();
|
||||||
|
|
||||||
switch(axis) {
|
switch(axis) {
|
||||||
case SelectableObject::Axis::X:
|
case SelectableObject::Axis::X:
|
||||||
transform_ray.direction = Vector3(1, 0, 0);
|
transform_ray.direction = prism::float3(1, 0, 0);
|
||||||
break;
|
break;
|
||||||
case SelectableObject::Axis::Y:
|
case SelectableObject::Axis::Y:
|
||||||
transform_ray.direction = Vector3(0, 1, 0);
|
transform_ray.direction = prism::float3(0, 1, 0);
|
||||||
break;
|
break;
|
||||||
case SelectableObject::Axis::Z:
|
case SelectableObject::Axis::Z:
|
||||||
transform_ray.direction = Vector3(0, 0, 1);
|
transform_ray.direction = prism::float3(0, 0, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
closest_distance_between_lines(camera_ray, transform_ray);
|
prism::closest_distance_between_lines(camera_ray, transform_ray);
|
||||||
|
|
||||||
const float current_intersect = transform_ray.t;
|
const float current_intersect = transform_ray.t;
|
||||||
if(previous_intersect == 0.0)
|
if(previous_intersect == 0.0)
|
||||||
|
@ -817,9 +817,9 @@ GFXTexture* CommonEditor::get_material_preview(Material& material) {
|
||||||
scene.add<Renderable>(sphere).mesh = assetm->get<Mesh>(prism::app_domain / "models" / "sphere.model");
|
scene.add<Renderable>(sphere).mesh = assetm->get<Mesh>(prism::app_domain / "models" / "sphere.model");
|
||||||
scene.get<Renderable>(sphere).materials.push_back(assetm->get<Material>(prism::app_domain / material.path)); // we throw away our material handle here :-(
|
scene.get<Renderable>(sphere).materials.push_back(assetm->get<Material>(prism::app_domain / material.path)); // we throw away our material handle here :-(
|
||||||
|
|
||||||
scene.get<Transform>(sphere).rotation = euler_to_quat(Vector3(radians(90.0f), 0, 0));
|
scene.get<Transform>(sphere).rotation = euler_to_quat(prism::float3(radians(90.0f), 0, 0));
|
||||||
|
|
||||||
return generate_common_preview(scene, Vector3(0, 0, 3));
|
return generate_common_preview(scene, prism::float3(0, 0, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXTexture* CommonEditor::get_mesh_preview(Mesh& mesh) {
|
GFXTexture* CommonEditor::get_mesh_preview(Mesh& mesh) {
|
||||||
|
@ -830,20 +830,20 @@ GFXTexture* CommonEditor::get_mesh_preview(Mesh& mesh) {
|
||||||
|
|
||||||
float biggest_component = 0.0f;
|
float biggest_component = 0.0f;
|
||||||
for(const auto& part : scene.get<Renderable>(mesh_obj).mesh->parts) {
|
for(const auto& part : scene.get<Renderable>(mesh_obj).mesh->parts) {
|
||||||
const auto find_biggest_component = [&biggest_component](const Vector3 vec) {
|
const auto find_biggest_component = [&biggest_component](const prism::float3 vec) {
|
||||||
for(auto& component : vec.data) {
|
for(auto& component : vec.data) {
|
||||||
if(std::fabs(component) > biggest_component)
|
if(std::fabs(component) > biggest_component)
|
||||||
biggest_component = component;
|
biggest_component = component;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
find_biggest_component(part.aabb.min);
|
find_biggest_component(part.bounding_box.min);
|
||||||
find_biggest_component(part.aabb.max);
|
find_biggest_component(part.bounding_box.max);
|
||||||
|
|
||||||
scene.get<Renderable>(mesh_obj).materials.push_back(assetm->get<Material>(prism::app_domain / "materials" / "Material.material"));
|
scene.get<Renderable>(mesh_obj).materials.push_back(assetm->get<Material>(prism::app_domain / "materials" / "Material.material"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return generate_common_preview(scene, Vector3(biggest_component * 2.0f));
|
return generate_common_preview(scene, prism::float3(biggest_component * 2.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXTexture* CommonEditor::get_texture_preview(Texture& texture) {
|
GFXTexture* CommonEditor::get_texture_preview(Texture& texture) {
|
||||||
|
@ -889,11 +889,11 @@ GFXTexture* CommonEditor::get_texture_preview(Texture& texture) {
|
||||||
command_buffer->bind_texture(renderer->dummy_texture, 4);
|
command_buffer->bind_texture(renderer->dummy_texture, 4);
|
||||||
|
|
||||||
struct PostPushConstants {
|
struct PostPushConstants {
|
||||||
Vector4 viewport;
|
prism::float4 viewport;
|
||||||
Vector4 options;
|
prism::float4 options;
|
||||||
} pc;
|
} pc;
|
||||||
pc.options.w = 1.0;
|
pc.options.w = 1.0;
|
||||||
pc.viewport = Vector4(1.0 / (float)thumbnail_resolution, 1.0 / (float)thumbnail_resolution, thumbnail_resolution, thumbnail_resolution);
|
pc.viewport = prism::float4(1.0 / (float)thumbnail_resolution, 1.0 / (float)thumbnail_resolution, thumbnail_resolution, thumbnail_resolution);
|
||||||
|
|
||||||
command_buffer->set_push_constant(&pc, sizeof(PostPushConstants));
|
command_buffer->set_push_constant(&pc, sizeof(PostPushConstants));
|
||||||
|
|
||||||
|
@ -904,7 +904,7 @@ GFXTexture* CommonEditor::get_texture_preview(Texture& texture) {
|
||||||
return final_texture;
|
return final_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXTexture* CommonEditor::generate_common_preview(Scene& scene, const Vector3 camera_position) {
|
GFXTexture* CommonEditor::generate_common_preview(Scene& scene, const prism::float3 camera_position) {
|
||||||
auto gfx = engine->get_gfx();
|
auto gfx = engine->get_gfx();
|
||||||
|
|
||||||
// setup scene
|
// setup scene
|
||||||
|
@ -914,19 +914,19 @@ GFXTexture* CommonEditor::generate_common_preview(Scene& scene, const Vector3 ca
|
||||||
auto camera = scene.add_object();
|
auto camera = scene.add_object();
|
||||||
scene.add<Camera>(camera);
|
scene.add<Camera>(camera);
|
||||||
|
|
||||||
camera_look_at(scene, camera, camera_position, Vector3(0));
|
camera_look_at(scene, camera, camera_position, prism::float3(0));
|
||||||
|
|
||||||
auto light = scene.add_object();
|
auto light = scene.add_object();
|
||||||
scene.get<Transform>(light).position = Vector3(5);
|
scene.get<Transform>(light).position = prism::float3(5);
|
||||||
scene.add<Light>(light).type = Light::Type::Sun;
|
scene.add<Light>(light).type = Light::Type::Sun;
|
||||||
|
|
||||||
auto probe = scene.add_object();
|
auto probe = scene.add_object();
|
||||||
scene.add<EnvironmentProbe>(probe).is_sized = false;
|
scene.add<EnvironmentProbe>(probe).is_sized = false;
|
||||||
scene.get<Transform>(probe).position = Vector3(3);
|
scene.get<Transform>(probe).position = prism::float3(3);
|
||||||
|
|
||||||
engine->update_scene(scene);
|
engine->update_scene(scene);
|
||||||
|
|
||||||
scene.get<Camera>(camera).perspective = transform::infinite_perspective(radians(45.0f), 1.0f, 0.1f);
|
scene.get<Camera>(camera).perspective = prism::infinite_perspective(radians(45.0f), 1.0f, 0.1f);
|
||||||
scene.get<Camera>(camera).view = inverse(scene.get<Transform>(camera).model);
|
scene.get<Camera>(camera).view = inverse(scene.get<Transform>(camera).model);
|
||||||
|
|
||||||
auto renderer = engine->get_renderer();
|
auto renderer = engine->get_renderer();
|
||||||
|
@ -1010,12 +1010,12 @@ GFXTexture* CommonEditor::generate_common_preview(Scene& scene, const Vector3 ca
|
||||||
command_buffer->bind_texture(renderer->dummy_texture, 4);
|
command_buffer->bind_texture(renderer->dummy_texture, 4);
|
||||||
|
|
||||||
struct PostPushConstants {
|
struct PostPushConstants {
|
||||||
Vector4 viewport;
|
prism::float4 viewport;
|
||||||
Vector4 options;
|
prism::float4 options;
|
||||||
} pc;
|
} pc;
|
||||||
pc.options.w = 1.0;
|
pc.options.w = 1.0;
|
||||||
pc.viewport = Vector4(1.0 / (float)thumbnail_resolution, 1.0 / (float)thumbnail_resolution, thumbnail_resolution, thumbnail_resolution);
|
pc.viewport = prism::float4(1.0 / (float)thumbnail_resolution, 1.0 / (float)thumbnail_resolution, thumbnail_resolution, thumbnail_resolution);
|
||||||
|
|
||||||
command_buffer->set_push_constant(&pc, sizeof(PostPushConstants));
|
command_buffer->set_push_constant(&pc, sizeof(PostPushConstants));
|
||||||
|
|
||||||
command_buffer->draw(0, 4, 0, 1);
|
command_buffer->draw(0, 4, 0, 1);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
struct BillPushConstant {
|
struct BillPushConstant {
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
void DebugPass::initialize() {
|
void DebugPass::initialize() {
|
||||||
|
@ -25,7 +25,7 @@ void DebugPass::initialize() {
|
||||||
createInfo.shaders.fragment_src = ShaderSource(prism::path("debug.frag"));
|
createInfo.shaders.fragment_src = ShaderSource(prism::path("debug.frag"));
|
||||||
|
|
||||||
GFXVertexInput vertexInput = {};
|
GFXVertexInput vertexInput = {};
|
||||||
vertexInput.stride = sizeof(Vector3);
|
vertexInput.stride = sizeof(prism::float3);
|
||||||
|
|
||||||
createInfo.vertex_input.inputs.push_back(vertexInput);
|
createInfo.vertex_input.inputs.push_back(vertexInput);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ void DebugPass::initialize() {
|
||||||
createInfo.vertex_input.attributes.push_back(positionAttribute);
|
createInfo.vertex_input.attributes.push_back(positionAttribute);
|
||||||
|
|
||||||
createInfo.shader_input.push_constants = {
|
createInfo.shader_input.push_constants = {
|
||||||
{sizeof(Matrix4x4) + sizeof(Vector4), 0}
|
{sizeof(Matrix4x4) + sizeof(prism::float4), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
createInfo.shader_input.bindings = {
|
createInfo.shader_input.bindings = {
|
||||||
|
@ -73,7 +73,7 @@ void DebugPass::initialize() {
|
||||||
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("color.frag"));
|
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("color.frag"));
|
||||||
|
|
||||||
GFXVertexInput input;
|
GFXVertexInput input;
|
||||||
input.stride = sizeof(Vector3);
|
input.stride = sizeof(prism::float3);
|
||||||
|
|
||||||
pipelineInfo.vertex_input.inputs.push_back(input);
|
pipelineInfo.vertex_input.inputs.push_back(input);
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ void DebugPass::initialize() {
|
||||||
};
|
};
|
||||||
|
|
||||||
pipelineInfo.shader_input.push_constants = {
|
pipelineInfo.shader_input.push_constants = {
|
||||||
{sizeof(Matrix4x4) + sizeof(Vector4), 0}
|
{sizeof(Matrix4x4) + sizeof(prism::float4), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
pipelineInfo.render_pass = selectRenderPass;
|
pipelineInfo.render_pass = selectRenderPass;
|
||||||
|
@ -114,7 +114,7 @@ void DebugPass::initialize() {
|
||||||
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("color.frag"));
|
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("color.frag"));
|
||||||
|
|
||||||
GFXVertexInput input;
|
GFXVertexInput input;
|
||||||
input.stride = sizeof(Vector3);
|
input.stride = sizeof(prism::float3);
|
||||||
|
|
||||||
pipelineInfo.vertex_input.inputs.push_back(input);
|
pipelineInfo.vertex_input.inputs.push_back(input);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ void DebugPass::initialize() {
|
||||||
};
|
};
|
||||||
|
|
||||||
pipelineInfo.shader_input.push_constants = {
|
pipelineInfo.shader_input.push_constants = {
|
||||||
{sizeof(Matrix4x4) + sizeof(Vector4), 0}
|
{sizeof(Matrix4x4) + sizeof(prism::float4), 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
pipelineInfo.render_pass = sobelRenderPass;
|
pipelineInfo.render_pass = sobelRenderPass;
|
||||||
|
@ -223,10 +223,10 @@ void DebugPass::createOffscreenResources() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugPass::draw_arrow(GFXCommandBuffer* commandBuffer, Vector3 color, Matrix4x4 model) {
|
void DebugPass::draw_arrow(GFXCommandBuffer* commandBuffer, prism::float3 color, Matrix4x4 model) {
|
||||||
struct PushConstant {
|
struct PushConstant {
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
} pc;
|
} pc;
|
||||||
pc.mvp = model;
|
pc.mvp = model;
|
||||||
pc.color = color;
|
pc.color = color;
|
||||||
|
@ -244,7 +244,7 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
|
|
||||||
struct PushConstant {
|
struct PushConstant {
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
Matrix4x4 vp = camera.perspective * camera.view;
|
Matrix4x4 vp = camera.perspective * camera.view;
|
||||||
|
@ -252,17 +252,17 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
commandBuffer->set_graphics_pipeline(primitive_pipeline);
|
commandBuffer->set_graphics_pipeline(primitive_pipeline);
|
||||||
|
|
||||||
struct DebugPrimitive {
|
struct DebugPrimitive {
|
||||||
Vector3 position, size;
|
prism::float3 position, size;
|
||||||
Quaternion rotation;
|
Quaternion rotation;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<DebugPrimitive> primitives;
|
std::vector<DebugPrimitive> primitives;
|
||||||
|
|
||||||
struct DebugBillboard {
|
struct DebugBillboard {
|
||||||
Vector3 position;
|
prism::float3 position;
|
||||||
GFXTexture* texture;
|
GFXTexture* texture;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<DebugBillboard> billboards;
|
std::vector<DebugBillboard> billboards;
|
||||||
|
@ -281,7 +281,7 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
prim.position = transform.get_world_position();
|
prim.position = transform.get_world_position();
|
||||||
prim.rotation = transform.rotation;
|
prim.rotation = transform.rotation;
|
||||||
prim.size = collision.size / 2.0f;
|
prim.size = collision.size / 2.0f;
|
||||||
prim.color = collision.is_trigger ? Vector4(0, 0, 1, 1) : Vector4(0, 1, 0, 1);
|
prim.color = collision.is_trigger ? prism::float4(0, 0, 1, 1) : prism::float4(0, 1, 0, 1);
|
||||||
|
|
||||||
primitives.push_back(prim);
|
primitives.push_back(prim);
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
if(scene.has<Light>(obj)) {
|
if(scene.has<Light>(obj)) {
|
||||||
DebugBillboard bill;
|
DebugBillboard bill;
|
||||||
bill.position = transform.get_world_position();
|
bill.position = transform.get_world_position();
|
||||||
bill.color = Vector4(scene.get<Light>(obj).color, 1.0f);
|
bill.color = prism::float4(scene.get<Light>(obj).color, 1.0f);
|
||||||
|
|
||||||
switch(scene.get<Light>(obj).type) {
|
switch(scene.get<Light>(obj).type) {
|
||||||
case Light::Type::Point:
|
case Light::Type::Point:
|
||||||
|
@ -315,14 +315,14 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
prim.position = transform.get_world_position();
|
prim.position = transform.get_world_position();
|
||||||
prim.rotation = transform.rotation;
|
prim.rotation = transform.rotation;
|
||||||
prim.size = probe.size / 2.0f;
|
prim.size = probe.size / 2.0f;
|
||||||
prim.color = Vector4(0, 1, 1, 1);
|
prim.color = prism::float4(0, 1, 1, 1);
|
||||||
|
|
||||||
primitives.push_back(prim);
|
primitives.push_back(prim);
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugBillboard bill;
|
DebugBillboard bill;
|
||||||
bill.position = transform.get_world_position();
|
bill.position = transform.get_world_position();
|
||||||
bill.color = Vector4(1.0f);
|
bill.color = prism::float4(1.0f);
|
||||||
bill.texture = probeTexture->handle;
|
bill.texture = probeTexture->handle;
|
||||||
|
|
||||||
billboards.push_back(bill);
|
billboards.push_back(bill);
|
||||||
|
@ -333,9 +333,9 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
for(auto& prim : primitives) {
|
for(auto& prim : primitives) {
|
||||||
PushConstant pc;
|
PushConstant pc;
|
||||||
|
|
||||||
Matrix4x4 m = transform::translate(Matrix4x4(), prim.position);
|
Matrix4x4 m = prism::translate(Matrix4x4(), prim.position);
|
||||||
m *= matrix_from_quat(prim.rotation);
|
m *= matrix_from_quat(prim.rotation);
|
||||||
m = transform::scale(m, prim.size);
|
m = prism::scale(m, prim.size);
|
||||||
|
|
||||||
pc.mvp = vp * m;
|
pc.mvp = vp * m;
|
||||||
pc.color = prim.color;
|
pc.color = prim.color;
|
||||||
|
@ -354,7 +354,7 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
|
|
||||||
// draw primitives
|
// draw primitives
|
||||||
for(auto& bill : billboards) {
|
for(auto& bill : billboards) {
|
||||||
Matrix4x4 m = transform::translate(Matrix4x4(), bill.position);
|
Matrix4x4 m = prism::translate(Matrix4x4(), bill.position);
|
||||||
|
|
||||||
BillPushConstant pc;
|
BillPushConstant pc;
|
||||||
pc.mvp = vp * m;
|
pc.mvp = vp * m;
|
||||||
|
@ -376,17 +376,17 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
const float base_scale = 0.05f;
|
const float base_scale = 0.05f;
|
||||||
const float scale_factor = length(position - scene.get<Transform>(camObj).get_world_position());
|
const float scale_factor = length(position - scene.get<Transform>(camObj).get_world_position());
|
||||||
|
|
||||||
Matrix4x4 base_model = transform::translate(Matrix4x4(), position);
|
Matrix4x4 base_model = prism::translate(Matrix4x4(), position);
|
||||||
base_model = transform::scale(base_model, base_scale * scale_factor);
|
base_model = prism::scale(base_model, base_scale * scale_factor);
|
||||||
|
|
||||||
// draw y axis
|
// draw y axis
|
||||||
draw_arrow(commandBuffer, Vector3(0, 1, 0), vp * base_model);
|
draw_arrow(commandBuffer, prism::float3(0, 1, 0), vp * base_model);
|
||||||
|
|
||||||
// draw x axis
|
// draw x axis
|
||||||
draw_arrow(commandBuffer, Vector3(1, 0, 0), vp * base_model * matrix_from_quat(angle_axis(radians(-90.0f), Vector3(0, 0, 1))));
|
draw_arrow(commandBuffer, prism::float3(1, 0, 0), vp * base_model * matrix_from_quat(angle_axis(radians(-90.0f), prism::float3(0, 0, 1))));
|
||||||
|
|
||||||
// draw z axis
|
// draw z axis
|
||||||
draw_arrow(commandBuffer, Vector3(0, 0, 1), vp * base_model * matrix_from_quat(angle_axis(radians(90.0f), Vector3(1, 0, 0))));
|
draw_arrow(commandBuffer, prism::float3(0, 0, 1), vp * base_model * matrix_from_quat(angle_axis(radians(90.0f), prism::float3(1, 0, 0))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw sobel
|
// draw sobel
|
||||||
|
@ -407,11 +407,11 @@ void DebugPass::render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) {
|
||||||
|
|
||||||
struct PC {
|
struct PC {
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
} pc;
|
} pc;
|
||||||
|
|
||||||
pc.mvp = vp * engine->get_scene()->get<Transform>(selected_object).model;
|
pc.mvp = vp * engine->get_scene()->get<Transform>(selected_object).model;
|
||||||
pc.color = Vector4(1);
|
pc.color = prism::float4(1);
|
||||||
|
|
||||||
commandBuffer->set_push_constant(&pc, sizeof(PC));
|
commandBuffer->set_push_constant(&pc, sizeof(PC));
|
||||||
|
|
||||||
|
@ -482,14 +482,14 @@ void DebugPass::get_selected_object(int x, int y, std::function<void(SelectableO
|
||||||
const float base_scale = 0.05f;
|
const float base_scale = 0.05f;
|
||||||
const float scale_factor = length(position - engine->get_scene()->get<Transform>(camObj).position);
|
const float scale_factor = length(position - engine->get_scene()->get<Transform>(camObj).position);
|
||||||
|
|
||||||
const Matrix4x4 translate_model = transform::translate(Matrix4x4(), position);
|
const Matrix4x4 translate_model = prism::translate(Matrix4x4(), position);
|
||||||
const Matrix4x4 scale_model = transform::scale(Matrix4x4(), base_scale * scale_factor);
|
const Matrix4x4 scale_model = prism::scale(Matrix4x4(), base_scale * scale_factor);
|
||||||
|
|
||||||
add_arrow(SelectableObject::Axis::Y, translate_model * scale_model);
|
add_arrow(SelectableObject::Axis::Y, translate_model * scale_model);
|
||||||
|
|
||||||
add_arrow(SelectableObject::Axis::X, translate_model * matrix_from_quat(angle_axis(radians(-90.0f), Vector3(0, 0, 1))) * scale_model);
|
add_arrow(SelectableObject::Axis::X, translate_model * matrix_from_quat(angle_axis(radians(-90.0f), prism::float3(0, 0, 1))) * scale_model);
|
||||||
|
|
||||||
add_arrow(SelectableObject::Axis::Z, translate_model * matrix_from_quat(angle_axis(radians(90.0f), Vector3(1, 0, 0))) * scale_model);
|
add_arrow(SelectableObject::Axis::Z, translate_model * matrix_from_quat(angle_axis(radians(90.0f), prism::float3(1, 0, 0))) * scale_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXCommandBuffer* commandBuffer = engine->get_gfx()->acquire_command_buffer();
|
GFXCommandBuffer* commandBuffer = engine->get_gfx()->acquire_command_buffer();
|
||||||
|
@ -536,13 +536,13 @@ void DebugPass::get_selected_object(int x, int y, std::function<void(SelectableO
|
||||||
|
|
||||||
struct PC {
|
struct PC {
|
||||||
Matrix4x4 mvp;
|
Matrix4x4 mvp;
|
||||||
Vector4 color;
|
prism::float4 color;
|
||||||
} pc;
|
} pc;
|
||||||
|
|
||||||
pc.mvp = camera.perspective * camera.view * model;
|
pc.mvp = camera.perspective * camera.view * model;
|
||||||
|
|
||||||
if(object.render_type == SelectableObject::RenderType::Sphere)
|
if(object.render_type == SelectableObject::RenderType::Sphere)
|
||||||
pc.mvp = transform::scale(pc.mvp, Vector3(object.sphere_size));
|
pc.mvp = prism::scale(pc.mvp, prism::float3(object.sphere_size));
|
||||||
|
|
||||||
pc.color = {
|
pc.color = {
|
||||||
float((i & 0x000000FF) >> 0) / 255.0f,
|
float((i & 0x000000FF) >> 0) / 255.0f,
|
||||||
|
|
|
@ -50,7 +50,7 @@ void prepScene() {
|
||||||
|
|
||||||
scene->add<Camera>(camera);
|
scene->add<Camera>(camera);
|
||||||
|
|
||||||
camera_look_at(*scene, camera, Vector3(0, 2, 3), Vector3(0));
|
camera_look_at(*scene, camera, prism::float3(0, 2, 3), prism::float3(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepThreePointLighting() {
|
void prepThreePointLighting() {
|
||||||
|
@ -63,7 +63,7 @@ void prepThreePointLighting() {
|
||||||
scene->get(sun_light).name = "sun light";
|
scene->get(sun_light).name = "sun light";
|
||||||
scene->get(sun_light).editor_object = true;
|
scene->get(sun_light).editor_object = true;
|
||||||
|
|
||||||
scene->get<Transform>(sun_light).position = Vector3(15);
|
scene->get<Transform>(sun_light).position = prism::float3(15);
|
||||||
scene->add<Light>(sun_light).type = Light::Type::Sun;
|
scene->add<Light>(sun_light).type = Light::Type::Sun;
|
||||||
scene->get<Light>(sun_light).power = 5.0f;
|
scene->get<Light>(sun_light).power = 5.0f;
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ void prepPrefabScene() {
|
||||||
scene->get(plane).name = "plane";
|
scene->get(plane).name = "plane";
|
||||||
scene->get(plane).editor_object = true;
|
scene->get(plane).editor_object = true;
|
||||||
|
|
||||||
scene->get<Transform>(plane).position = Vector3(0, -1, 0);
|
scene->get<Transform>(plane).position = prism::float3(0, -1, 0);
|
||||||
scene->get<Transform>(plane).scale = Vector3(50);
|
scene->get<Transform>(plane).scale = prism::float3(50);
|
||||||
|
|
||||||
scene->add<Renderable>(plane).mesh = assetm->get<Mesh>(prism::app_domain / "models/plane.model");
|
scene->add<Renderable>(plane).mesh = assetm->get<Mesh>(prism::app_domain / "models/plane.model");
|
||||||
|
|
||||||
|
@ -93,8 +93,8 @@ Renderable* prepMaterialScene() {
|
||||||
scene->get(plane).name = "plane";
|
scene->get(plane).name = "plane";
|
||||||
scene->get(plane).editor_object = true;
|
scene->get(plane).editor_object = true;
|
||||||
|
|
||||||
scene->get<Transform>(plane).position = Vector3(0, -1, 0);
|
scene->get<Transform>(plane).position = prism::float3(0, -1, 0);
|
||||||
scene->get<Transform>(plane).scale = Vector3(50);
|
scene->get<Transform>(plane).scale = prism::float3(50);
|
||||||
|
|
||||||
scene->add<Renderable>(plane).mesh = assetm->get<Mesh>(prism::app_domain / "models/plane.model");
|
scene->add<Renderable>(plane).mesh = assetm->get<Mesh>(prism::app_domain / "models/plane.model");
|
||||||
scene->get<Renderable>(plane).materials.push_back(assetm->get<Material>(prism::app_domain / "materials/Material.material"));
|
scene->get<Renderable>(plane).materials.push_back(assetm->get<Material>(prism::app_domain / "materials/Material.material"));
|
||||||
|
@ -103,7 +103,7 @@ Renderable* prepMaterialScene() {
|
||||||
scene->get(sphere).name = "sphere";
|
scene->get(sphere).name = "sphere";
|
||||||
scene->get(sphere).editor_object = true;
|
scene->get(sphere).editor_object = true;
|
||||||
|
|
||||||
scene->get<Transform>(sphere).rotation = euler_to_quat(Vector3(radians(90.0f), 0, 0));
|
scene->get<Transform>(sphere).rotation = euler_to_quat(prism::float3(radians(90.0f), 0, 0));
|
||||||
|
|
||||||
scene->add<Renderable>(sphere).mesh = assetm->get<Mesh>(prism::app_domain / "models/sphere.model");
|
scene->add<Renderable>(sphere).mesh = assetm->get<Mesh>(prism::app_domain / "models/sphere.model");
|
||||||
|
|
||||||
|
|
Reference in a new issue