From 0740b29de788a7e50bc7ed8505e01dcb141a9741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 10 Dec 2018 19:39:00 -0800 Subject: [PATCH] Cleanup. --- examples/03-raymarch/raymarch.cpp | 6 ++--- examples/14-shadowvolumes/shadowvolumes.cpp | 29 +++++++++----------- examples/27-terrain/terrain.cpp | 2 +- examples/common/bgfx_utils.cpp | 30 +++++++++------------ tools/geometryc/geometryc.cpp | 26 ++++++++---------- 5 files changed, 39 insertions(+), 54 deletions(-) diff --git a/examples/03-raymarch/raymarch.cpp b/examples/03-raymarch/raymarch.cpp index a07e01848..929aff125 100644 --- a/examples/03-raymarch/raymarch.cpp +++ b/examples/03-raymarch/raymarch.cpp @@ -224,11 +224,9 @@ public: float mtxInv[16]; bx::mtxInverse(mtxInv, mtx); - float lightDirModel[4] = { -0.4f, -0.5f, -1.0f, 0.0f }; - float lightDirModelN[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - bx::vec3Norm(lightDirModelN, lightDirModel); float lightDirTime[4]; - bx::vec4MulMtx(lightDirTime, lightDirModelN, mtxInv); + const bx::Vec3 lightDirModelN = bx::normalize(bx::Vec3{-0.4f, -0.5f, -1.0f}); + bx::store(lightDirTime, bx::mul(lightDirModelN, mtxInv) ); lightDirTime[3] = time; bgfx::setUniform(u_lightDirTime, lightDirTime); diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index e3273c8d1..b9587f035 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -155,26 +155,21 @@ void mtxBillboard(float* __restrict _result } void planeNormal(float* __restrict _result - , const float* __restrict _v0 - , const float* __restrict _v1 - , const float* __restrict _v2 - ) + , const float* __restrict _v0 + , const float* __restrict _v1 + , const float* __restrict _v2 + ) { - float vec0[3], vec1[3]; - float cross[3]; + const bx::Vec3 v0 = bx::load(_v0); + const bx::Vec3 v1 = bx::load(_v1); + const bx::Vec3 v2 = bx::load(_v2); + const bx::Vec3 vec0 = bx::sub(v1, v0); + const bx::Vec3 vec1 = bx::sub(v2, v1); + const bx::Vec3 cross = bx::cross(vec0, vec1); - vec0[0] = _v1[0] - _v0[0]; - vec0[1] = _v1[1] - _v0[1]; - vec0[2] = _v1[2] - _v0[2]; + bx::store(_result, bx::normalize(cross) ); - vec1[0] = _v2[0] - _v1[0]; - vec1[1] = _v2[1] - _v1[1]; - vec1[2] = _v2[2] - _v1[2]; - - bx::vec3Cross(cross, vec0, vec1); - bx::vec3Norm(_result, cross); - - _result[3] = -bx::vec3Dot(_result, _v0); + _result[3] = -bx::dot(bx::load(_result), bx::load(_v0) ); } struct Uniforms diff --git a/examples/27-terrain/terrain.cpp b/examples/27-terrain/terrain.cpp index 8ae06d568..535bdff97 100644 --- a/examples/27-terrain/terrain.cpp +++ b/examples/27-terrain/terrain.cpp @@ -358,7 +358,7 @@ public: bx::vec4MulMtx(ray_world, ray_eye, invViewMtx); float ray_dir[3]; - bx::vec3Norm(ray_dir, ray_world); + bx::store(ray_dir, bx::normalize(bx::load(ray_world) ) ); ray_dir[0] *= -1.0; ray_dir[1] *= -1.0; ray_dir[2] *= -1.0; diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index fd3b87251..f1fdf2254 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -285,13 +285,13 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl uint32_t i1 = indices[1]; uint32_t i2 = indices[2]; - bgfx::vertexUnpack(&v0.m_x, bgfx::Attrib::Position, _decl, _vertices, i0); + bgfx::vertexUnpack(&v0.m_x, bgfx::Attrib::Position, _decl, _vertices, i0); bgfx::vertexUnpack(&v0.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i0); - bgfx::vertexUnpack(&v1.m_x, bgfx::Attrib::Position, _decl, _vertices, i1); + bgfx::vertexUnpack(&v1.m_x, bgfx::Attrib::Position, _decl, _vertices, i1); bgfx::vertexUnpack(&v1.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i1); - bgfx::vertexUnpack(&v2.m_x, bgfx::Attrib::Position, _decl, _vertices, i2); + bgfx::vertexUnpack(&v2.m_x, bgfx::Attrib::Position, _decl, _vertices, i2); bgfx::vertexUnpack(&v2.m_u, bgfx::Attrib::TexCoord0, _decl, _vertices, i2); const float bax = v1.m_x - v0.m_x; @@ -333,25 +333,21 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl for (uint32_t ii = 0; ii < _numVertices; ++ii) { - const float* tanu = &tangents[ii*6]; - const float* tanv = &tangents[ii*6 + 3]; + const bx::Vec3 tanu = bx::load(&tangents[ii*6]); + const bx::Vec3 tanv = bx::load(&tangents[ii*6 + 3]); - float normal[4]; - bgfx::vertexUnpack(normal, bgfx::Attrib::Normal, _decl, _vertices, ii); - float ndt = bx::vec3Dot(normal, tanu); + float nxyzw[4]; + bgfx::vertexUnpack(nxyzw, bgfx::Attrib::Normal, _decl, _vertices, ii); - float nxt[3]; - bx::vec3Cross(nxt, normal, tanu); - - float tmp[3]; - tmp[0] = tanu[0] - normal[0] * ndt; - tmp[1] = tanu[1] - normal[1] * ndt; - tmp[2] = tanu[2] - normal[2] * ndt; + const bx::Vec3 normal = bx::load(nxyzw); + const float ndt = bx::dot(normal, tanu); + const bx::Vec3 nxt = bx::cross(normal, tanu); + const bx::Vec3 tmp = bx::sub(tanu, bx::mul(normal, ndt) ); float tangent[4]; - bx::vec3Norm(tangent, tmp); + bx::store(tangent, bx::normalize(tmp) ); + tangent[3] = bx::dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f; - tangent[3] = bx::vec3Dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f; bgfx::vertexPack(tangent, true, bgfx::Attrib::Tangent, _decl, _vertices, ii); } diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index 1e1f175e1..1174b30f7 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -236,25 +236,21 @@ void calcTangents(void* _vertices, uint16_t _numVertices, bgfx::VertexDecl _decl for (uint32_t ii = 0; ii < _numVertices; ++ii) { - const float* tanu = &tangents[ii*6]; - const float* tanv = &tangents[ii*6 + 3]; + const bx::Vec3 tanu = bx::load(&tangents[ii*6]); + const bx::Vec3 tanv = bx::load(&tangents[ii*6 + 3]); - float normal[4]; - bgfx::vertexUnpack(normal, bgfx::Attrib::Normal, _decl, _vertices, ii); - float ndt = bx::vec3Dot(normal, tanu); + float nxyzw[4]; + bgfx::vertexUnpack(nxyzw, bgfx::Attrib::Normal, _decl, _vertices, ii); - float nxt[3]; - bx::vec3Cross(nxt, normal, tanu); - - float tmp[3]; - tmp[0] = tanu[0] - normal[0] * ndt; - tmp[1] = tanu[1] - normal[1] * ndt; - tmp[2] = tanu[2] - normal[2] * ndt; + const bx::Vec3 normal = bx::load(nxyzw); + const float ndt = bx::dot(normal, tanu); + const bx::Vec3 nxt = bx::cross(normal, tanu); + const bx::Vec3 tmp = bx::sub(tanu, bx::mul(normal, ndt) ); float tangent[4]; - bx::vec3Norm(tangent, tmp); + bx::store(tangent, bx::normalize(tmp) ); + tangent[3] = bx::dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f; - tangent[3] = bx::vec3Dot(nxt, tanv) < 0.0f ? -1.0f : 1.0f; bgfx::vertexPack(tangent, true, bgfx::Attrib::Tangent, _decl, _vertices, ii); } @@ -1002,7 +998,7 @@ int main(int _argc, const char* _argv[]) if (hasNormal) { float normal[4]; - bx::vec3Norm(normal, (float*)&normals[index.m_normal]); + bx::store(normal, bx::normalize(bx::load(&normals[index.m_normal]) ) ); bgfx::vertexPack(normal, true, bgfx::Attrib::Normal, decl, vertices); }