From 8d211effd0c6db66e57f9ffd8ee712eef6069a1c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 14 Mar 2022 09:16:52 +0200 Subject: [PATCH] Some tweaks to vector component handling --- source/builders/vertexbuilder.h | 6 +++--- source/effects/ambientocclusion.cpp | 2 +- source/materials/directionallight.cpp | 2 +- source/materials/pointlight.cpp | 2 +- source/materials/programdata.h | 4 ++-- source/render/camera.cpp | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/builders/vertexbuilder.h b/source/builders/vertexbuilder.h index 09d9ed60..7fdc15bc 100644 --- a/source/builders/vertexbuilder.h +++ b/source/builders/vertexbuilder.h @@ -61,7 +61,7 @@ public: { vertex(Vector4(x, y, z, w)); } void vertex(const Vector3 &v) - { vertex(Vector4(v.x, v.y, v.z, 1)); } + { vertex(compose(v, 1.0f)); } void vertex(const Vector4 &v) { vertex_(mtx*v); } @@ -81,13 +81,13 @@ public: { normal(Vector3(x, y, z)); } void normal(const Vector3 &n) - { attrib(get_attribute_semantic(NORMAL3), mtx*Vector4(n.x, n.y, n.z, 0)); } + { attrib(get_attribute_semantic(NORMAL3), mtx*compose(n, 0.0f)); } void tangent(float x, float y, float z) { tangent(Vector3(x, y, z)); } void tangent(const Vector3 &t) - { attrib(get_attribute_semantic(TANGENT3), mtx*Vector4(t.x, t.y, t.z, 0)); } + { attrib(get_attribute_semantic(TANGENT3), mtx*compose(t, 0.0f)); } void texcoord(float s) { texcoord(s, 0, 0, 1); } diff --git a/source/effects/ambientocclusion.cpp b/source/effects/ambientocclusion.cpp index a519b80a..c7fff846 100644 --- a/source/effects/ambientocclusion.cpp +++ b/source/effects/ambientocclusion.cpp @@ -79,7 +79,7 @@ void AmbientOcclusion::set_n_samples(unsigned n) Geometry::Angle a = Geometry::Angle::from_turns(d); sample_points[i] = Vector3(cos(a)*r, sin(a)*r, z)*(0.1f+0.9f*d*d); } - shdata.uniform3_array("sample_points", n, &sample_points[0].x); + shdata.uniform3_array("sample_points", n, &sample_points[0][0]); shdata.uniform("n_samples", static_cast(n)); } diff --git a/source/materials/directionallight.cpp b/source/materials/directionallight.cpp index 0afc160b..61e98093 100644 --- a/source/materials/directionallight.cpp +++ b/source/materials/directionallight.cpp @@ -47,7 +47,7 @@ void DirectionalLight::set_transmittance(const Color &t) void DirectionalLight::update_shader_data(ProgramData &shdata, const string &base) const { shdata.uniform(base+".type", 1); - shdata.uniform(base+".position", -direction.x, -direction.y, -direction.z, 0.0f); + shdata.uniform(base+".position", compose(-direction, 0.0f)); shdata.uniform(base+".color", color.r*transmittance.r, color.g*transmittance.g, color.b*transmittance.b); shdata.uniform(base+".attenuation", 1.0f, 0.0f, 0.0f); } diff --git a/source/materials/pointlight.cpp b/source/materials/pointlight.cpp index 3147eaa3..1607066c 100644 --- a/source/materials/pointlight.cpp +++ b/source/materials/pointlight.cpp @@ -37,7 +37,7 @@ void PointLight::set_attenuation(float c, float l, float q) void PointLight::update_shader_data(ProgramData &shdata, const string &base) const { shdata.uniform(base+".type", 2); - shdata.uniform(base+".position", position.x, position.y, position.z, 1.0f); + shdata.uniform(base+".position", compose(position, 1.0f)); shdata.uniform(base+".color", color.r, color.g, color.b); shdata.uniform3(base+".attenuation", attenuation); } diff --git a/source/materials/programdata.h b/source/materials/programdata.h index dbbf5f48..bc98847b 100644 --- a/source/materials/programdata.h +++ b/source/materials/programdata.h @@ -267,7 +267,7 @@ public: template void ProgramData::uniform(Tag tag, const LinAl::Vector &v) -{ uniform(tag, TypeTraits>::type, 1, &v.x); } +{ uniform(tag, TypeTraits>::type, 1, &v[0]); } template void ProgramData::uniform(Tag tag, const LinAl::Matrix &v) @@ -275,7 +275,7 @@ void ProgramData::uniform(Tag tag, const LinAl::Matrix &v) template void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Vector *v) -{ uniform(tag, TypeTraits>::type, n, &v[0].x); } +{ uniform(tag, TypeTraits>::type, n, &v[0][0]); } template void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Matrix *v) diff --git a/source/render/camera.cpp b/source/render/camera.cpp index 6c85a732..bc8de57e 100644 --- a/source/render/camera.cpp +++ b/source/render/camera.cpp @@ -110,7 +110,7 @@ Vector3 Camera::project(const Vector4 &p) const Vector3 Camera::project(const Vector3 &p) const { - return project(Vector4(p.x, p.y, p.z, 1.0)); + return project(compose(p, 1.0f)); } Vector4 Camera::unproject(const Vector4 &p) const @@ -122,7 +122,7 @@ Vector4 Camera::unproject(const Vector4 &p) const Vector3 Camera::unproject(const Vector3 &p) const { - return unproject(Vector4(p.x, p.y, p.z, 1.0f)).slice<3>(0); + return unproject(compose(p, 1.0f)).slice<3>(0); } bool Camera::is_in_frustum(const Renderable &renderable) const -- 2.45.2