Some tweaks to vector component handling
authorMikko Rasa <tdb@tdb.fi>
Mon, 14 Mar 2022 07:16:52 +0000 (09:16 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 14 Mar 2022 07:16:52 +0000 (09:16 +0200)
source/builders/vertexbuilder.h
source/effects/ambientocclusion.cpp
source/materials/directionallight.cpp
source/materials/pointlight.cpp
source/materials/programdata.h
source/render/camera.cpp

index 09d9ed602ebdd0ce569527bb194dc129f29ac4ec..7fdc15bcab1212624ef1f9bd9885b94b23ed3606 100644 (file)
@@ -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); }
index a519b80aaf7e67090908f159bd076b72cb624b8c..c7fff846fbbe655b7d25f0d5b7daf886ed42d866 100644 (file)
@@ -79,7 +79,7 @@ void AmbientOcclusion::set_n_samples(unsigned n)
                Geometry::Angle<float> a = Geometry::Angle<float>::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<int>(n));
 }
 
index 0afc160ba3e35fd729249a4a0d446aea560698a9..61e98093a6996857c627926e52272f5ef8bfc06f 100644 (file)
@@ -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);
 }
index 3147eaa31bab0640fbe9c7aa62b54f5729890f5e..1607066c093df4501556ccde918faf650dd05c00 100644 (file)
@@ -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);
 }
index dbbf5f488d6173e2b9436df925d81bdce2db8f16..bc98847b26417f84dd18f1f3e17970276750f3e3 100644 (file)
@@ -267,7 +267,7 @@ public:
 
 template<typename T, unsigned N>
 void ProgramData::uniform(Tag tag, const LinAl::Vector<T, N> &v)
-{ uniform(tag, TypeTraits<LinAl::Vector<T, N>>::type, 1, &v.x); }
+{ uniform(tag, TypeTraits<LinAl::Vector<T, N>>::type, 1, &v[0]); }
 
 template<typename T, unsigned R, unsigned C>
 void ProgramData::uniform(Tag tag, const LinAl::Matrix<T, R, C> &v)
@@ -275,7 +275,7 @@ void ProgramData::uniform(Tag tag, const LinAl::Matrix<T, R, C> &v)
 
 template<typename T, unsigned N>
 void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Vector<T, N> *v)
-{ uniform(tag, TypeTraits<LinAl::Vector<T, N>>::type, n, &v[0].x); }
+{ uniform(tag, TypeTraits<LinAl::Vector<T, N>>::type, n, &v[0][0]); }
 
 template<typename T, unsigned R, unsigned C>
 void ProgramData::uniform_array(Tag tag, unsigned n, const LinAl::Matrix<T, R, C> *v)
index 6c85a7321d79af70adcda2a96d2f3c9e636fc4ad..bc8de57e51068b3eaa450ee996ccb79d108fc72b 100644 (file)
@@ -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