mirror of https://github.com/bkaradzic/bgfx
Cleanup.
This commit is contained in:
parent
e28e458173
commit
7b3e5f84d6
|
@ -2453,16 +2453,16 @@ public:
|
|||
|
||||
float mtxProj[16];
|
||||
bx::mtxOrtho(
|
||||
mtxProj
|
||||
, 1.0f
|
||||
, -1.0f
|
||||
, 1.0f
|
||||
, -1.0f
|
||||
, -currentSmSettings->m_far
|
||||
, currentSmSettings->m_far
|
||||
, 0.0f
|
||||
, caps->homogeneousDepth
|
||||
);
|
||||
mtxProj
|
||||
, 1.0f
|
||||
, -1.0f
|
||||
, 1.0f
|
||||
, -1.0f
|
||||
, -currentSmSettings->m_far
|
||||
, currentSmSettings->m_far
|
||||
, 0.0f
|
||||
, caps->homogeneousDepth
|
||||
);
|
||||
|
||||
const uint8_t numCorners = 8;
|
||||
float frustumCorners[maxNumSplits][numCorners][3];
|
||||
|
@ -2471,34 +2471,24 @@ public:
|
|||
// Compute frustum corners for one split in world space.
|
||||
worldSpaceFrustumCorners( (float*)frustumCorners[ii], splitSlices[nn], splitSlices[ff], projWidth, projHeight, mtxViewInv);
|
||||
|
||||
float min[3] = { 9000.0f, 9000.0f, 9000.0f };
|
||||
float max[3] = { -9000.0f, -9000.0f, -9000.0f };
|
||||
bx::Vec3 min = { 9000.0f, 9000.0f, 9000.0f };
|
||||
bx::Vec3 max = { -9000.0f, -9000.0f, -9000.0f };
|
||||
|
||||
for (uint8_t jj = 0; jj < numCorners; ++jj)
|
||||
{
|
||||
// Transform to light space.
|
||||
float lightSpaceFrustumCorner[3];
|
||||
bx::vec3MulMtx(lightSpaceFrustumCorner, frustumCorners[ii][jj], lightView[0]);
|
||||
const bx::Vec3 xyz = bx::mul(bx::load<bx::Vec3>(frustumCorners[ii][jj]), lightView[0]);
|
||||
|
||||
// Update bounding box.
|
||||
min[0] = bx::min(min[0], lightSpaceFrustumCorner[0]);
|
||||
max[0] = bx::max(max[0], lightSpaceFrustumCorner[0]);
|
||||
min[1] = bx::min(min[1], lightSpaceFrustumCorner[1]);
|
||||
max[1] = bx::max(max[1], lightSpaceFrustumCorner[1]);
|
||||
min[2] = bx::min(min[2], lightSpaceFrustumCorner[2]);
|
||||
max[2] = bx::max(max[2], lightSpaceFrustumCorner[2]);
|
||||
min = bx::min(min, xyz);
|
||||
max = bx::max(max, xyz);
|
||||
}
|
||||
|
||||
float minproj[3];
|
||||
float maxproj[3];
|
||||
bx::vec3MulMtxH(minproj, min, mtxProj);
|
||||
bx::vec3MulMtxH(maxproj, max, mtxProj);
|
||||
const bx::Vec3 minproj = bx::mulH(min, mtxProj);
|
||||
const bx::Vec3 maxproj = bx::mulH(max, mtxProj);
|
||||
|
||||
float offsetx, offsety;
|
||||
float scalex, scaley;
|
||||
|
||||
scalex = 2.0f / (maxproj[0] - minproj[0]);
|
||||
scaley = 2.0f / (maxproj[1] - minproj[1]);
|
||||
float scalex = 2.0f / (maxproj.x - minproj.x);
|
||||
float scaley = 2.0f / (maxproj.y - minproj.y);
|
||||
|
||||
if (m_settings.m_stabilize)
|
||||
{
|
||||
|
@ -2507,8 +2497,8 @@ public:
|
|||
scaley = quantizer / bx::ceil(quantizer / scaley);
|
||||
}
|
||||
|
||||
offsetx = 0.5f * (maxproj[0] + minproj[0]) * scalex;
|
||||
offsety = 0.5f * (maxproj[1] + minproj[1]) * scaley;
|
||||
float offsetx = 0.5f * (maxproj.x + minproj.x) * scalex;
|
||||
float offsety = 0.5f * (maxproj.y + minproj.y) * scaley;
|
||||
|
||||
if (m_settings.m_stabilize)
|
||||
{
|
||||
|
|
|
@ -561,7 +561,7 @@ public:
|
|||
Aabb aabb;
|
||||
toAabb(aabb, lightPosRadius);
|
||||
|
||||
float box[8][3] =
|
||||
const bx::Vec3 box[8] =
|
||||
{
|
||||
{ aabb.m_min.x, aabb.m_min.y, aabb.m_min.z },
|
||||
{ aabb.m_min.x, aabb.m_min.y, aabb.m_max.z },
|
||||
|
@ -573,31 +573,24 @@ public:
|
|||
{ aabb.m_max.x, aabb.m_max.y, aabb.m_max.z },
|
||||
};
|
||||
|
||||
float xyz[3];
|
||||
bx::vec3MulMtxH(xyz, box[0], vp);
|
||||
float minx = xyz[0];
|
||||
float miny = xyz[1];
|
||||
float maxx = xyz[0];
|
||||
float maxy = xyz[1];
|
||||
float maxz = xyz[2];
|
||||
bx::Vec3 xyz = bx::mulH(box[0], vp);
|
||||
bx::Vec3 min = xyz;
|
||||
bx::Vec3 max = xyz;
|
||||
|
||||
for (uint32_t ii = 1; ii < 8; ++ii)
|
||||
{
|
||||
bx::vec3MulMtxH(xyz, box[ii], vp);
|
||||
minx = bx::min(minx, xyz[0]);
|
||||
miny = bx::min(miny, xyz[1]);
|
||||
maxx = bx::max(maxx, xyz[0]);
|
||||
maxy = bx::max(maxy, xyz[1]);
|
||||
maxz = bx::max(maxz, xyz[2]);
|
||||
xyz = bx::mulH(box[ii], vp);
|
||||
min = bx::min(min, xyz);
|
||||
max = bx::max(max, xyz);
|
||||
}
|
||||
|
||||
// Cull light if it's fully behind camera.
|
||||
if (maxz >= 0.0f)
|
||||
if (max.z >= 0.0f)
|
||||
{
|
||||
float x0 = bx::clamp( (minx * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width);
|
||||
float y0 = bx::clamp( (miny * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
|
||||
float x1 = bx::clamp( (maxx * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width);
|
||||
float y1 = bx::clamp( (maxy * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
|
||||
const float x0 = bx::clamp( (min.x * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width);
|
||||
const float y0 = bx::clamp( (min.y * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
|
||||
const float x1 = bx::clamp( (max.x * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width);
|
||||
const float y1 = bx::clamp( (max.y * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
|
||||
|
||||
if (m_showScissorRects)
|
||||
{
|
||||
|
|
|
@ -268,17 +268,12 @@ public:
|
|||
float mouseXNDC = ( m_mouseState.m_mx / (float)m_width ) * 2.0f - 1.0f;
|
||||
float mouseYNDC = ((m_height - m_mouseState.m_my) / (float)m_height) * 2.0f - 1.0f;
|
||||
|
||||
float pickEye[3];
|
||||
float mousePosNDC[3] = { mouseXNDC, mouseYNDC, 0.0f };
|
||||
bx::vec3MulMtxH(pickEye, mousePosNDC, invViewProj);
|
||||
|
||||
float pickAt[3];
|
||||
float mousePosNDCEnd[3] = { mouseXNDC, mouseYNDC, 1.0f };
|
||||
bx::vec3MulMtxH(pickAt, mousePosNDCEnd, invViewProj);
|
||||
const bx::Vec3 pickEye = bx::mulH({ mouseXNDC, mouseYNDC, 0.0f }, invViewProj);
|
||||
const bx::Vec3 pickAt = bx::mulH({ mouseXNDC, mouseYNDC, 1.0f }, invViewProj);
|
||||
|
||||
// Look at our unprojected point
|
||||
float pickView[16];
|
||||
bx::mtxLookAt(pickView, bx::load<bx::Vec3>(pickEye), bx::load<bx::Vec3>(pickAt) );
|
||||
bx::mtxLookAt(pickView, pickEye, pickAt);
|
||||
|
||||
// Tight FOV is best for picking
|
||||
float pickProj[16];
|
||||
|
|
Loading…
Reference in New Issue