diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index 169e820e5..afe408c5e 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -1275,12 +1275,13 @@ struct ShadowVolume bool m_cap; }; -void shadowVolumeLightTransform(float* __restrict _outLightPos - , const float* __restrict _scale - , const float* __restrict _rotate - , const float* __restrict _translate - , const float* __restrict _lightPos // world pos - ) +void shadowVolumeLightTransform( + float* __restrict _outLightPos + , const float* __restrict _scale + , const float* __restrict _rotate + , const float* __restrict _translate + , const float* __restrict _lightPos // world pos + ) { /** * Instead of transforming all the vertices, transform light instead: @@ -1315,19 +1316,19 @@ void shadowVolumeLightTransform(float* __restrict _outLightPos float mtx[16]; bx::mtxMul(mtx, tmp0, invScale); - float origin[3] = { 0.0f, 0.0f, 0.0f }; - bx::vec3MulMtx(_outLightPos, origin, mtx); + bx::store(_outLightPos, bx::mul({ 0.0f, 0.0f, 0.0f }, mtx) ); } -void shadowVolumeCreate(ShadowVolume& _shadowVolume - , Group& _group - , uint16_t _stride - , const float* _mtx - , const float* _light // in model space - , ShadowVolumeImpl::Enum _impl = ShadowVolumeImpl::DepthPass - , ShadowVolumeAlgorithm::Enum _algo = ShadowVolumeAlgorithm::FaceBased - , bool _textureAsStencil = false - ) +void shadowVolumeCreate( + ShadowVolume& _shadowVolume + , Group& _group + , uint16_t _stride + , const float* _mtx + , const float* _light // in model space + , ShadowVolumeImpl::Enum _impl = ShadowVolumeImpl::DepthPass + , ShadowVolumeAlgorithm::Enum _algo = ShadowVolumeAlgorithm::FaceBased + , bool _textureAsStencil = false + ) { const uint8_t* vertices = _group.m_vertices; const FaceArray& faces = _group.m_faces; @@ -1708,33 +1709,27 @@ void createNearClipVolume(float* __restrict _outPlanes24f // -1.0f - behind near plane const float lightSide = float( (d > delta) - (d < -delta) ); - float t = bx::tan(bx::toRad(_fovy)*0.5f) * _near; - float b = -t; - float r = t * _aspect; - float l = -r; + const float t = bx::tan(bx::toRad(_fovy)*0.5f) * _near; + const float b = -t; + const float r = t * _aspect; + const float l = -r; - float cornersV[4][3] = + const bx::Vec3 corners[4] = { - { r, t, _near }, - { l, t, _near }, - { l, b, _near }, - { r, b, _near }, + bx::mul({ r, t, _near }, mtxViewInv), + bx::mul({ l, t, _near }, mtxViewInv), + bx::mul({ l, b, _near }, mtxViewInv), + bx::mul({ r, b, _near }, mtxViewInv), }; - float corners[4][3]; - bx::vec3MulMtx(corners[0], cornersV[0], mtxViewInv); - bx::vec3MulMtx(corners[1], cornersV[1], mtxViewInv); - bx::vec3MulMtx(corners[2], cornersV[2], mtxViewInv); - bx::vec3MulMtx(corners[3], cornersV[3], mtxViewInv); - float planeNormals[4][3]; for (uint8_t ii = 0; ii < 4; ++ii) { float* outNormal = planeNormals[ii]; float* outPlane = volumePlanes[ii]; - const bx::Vec3 c0 = bx::load(corners[ii]); - const bx::Vec3 planeVec = bx::sub(c0, bx::load(corners[(ii-1)&3]) ); + const bx::Vec3 c0 = corners[ii]; + const bx::Vec3 planeVec = bx::sub(c0, corners[(ii-1)&3]); const bx::Vec3 light = bx::sub(bx::load(_lightPos), bx::mul(c0, _lightPos[3]) ); const bx::Vec3 normal = bx::mul(bx::cross(planeVec, light), lightSide); diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index 0622074ae..10a492787 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1076,7 +1076,7 @@ void worldSpaceFrustumCorners(float* _corners24f const float fh = _far * _projHeight; const uint8_t numCorners = 8; - const float corners[numCorners][3] = + const bx::Vec3 corners[numCorners] = { { -nw, nh, _near }, { nw, nh, _near }, @@ -1092,7 +1092,7 @@ void worldSpaceFrustumCorners(float* _corners24f float (*out)[3] = (float(*)[3])_corners24f; for (uint8_t ii = 0; ii < numCorners; ++ii) { - bx::vec3MulMtx( (float*)&out[ii], (float*)&corners[ii], _invViewMtx); + bx::store(&out[ii], bx::mul(corners[ii], _invViewMtx) ); } }