| 515 | } |
| 516 | |
| 517 | OrthoFit FitOrthoSphere(const Mat4& lightView, const Vec3& center, float radius, int resolution, float zPad) |
| 518 | { |
| 519 | OrthoFit fit; |
| 520 | if (radius < 1e-4f) |
| 521 | { |
| 522 | radius = 1e-4f; |
| 523 | } |
| 524 | int res = resolution > 0 ? resolution : 1; |
| 525 | |
| 526 | Vec3 lc = TransformPoint(lightView, center); |
| 527 | float diam = 2.0f * radius; |
| 528 | float texel = diam / static_cast<float>(res); |
| 529 | |
| 530 | // Snap the min corner to the texel grid, then pad one texel each side so the |
| 531 | // snap can never clip the sphere. Extent stays a fixed multiple of the texel, |
| 532 | // so the projection scale is identical frame to frame. |
| 533 | float minX = std::floor((lc.x - radius) / texel) * texel - texel; |
| 534 | float minY = std::floor((lc.y - radius) / texel) * texel - texel; |
| 535 | float ext = diam + 2.0f * texel; |
| 536 | float maxX = minX + ext; |
| 537 | float maxY = minY + ext; |
| 538 | |
| 539 | float zMin = lc.z - radius; |
| 540 | float zMax = lc.z + radius + std::max(0.0f, zPad); |
| 541 | |
| 542 | fit.minB = {minX, minY, zMin}; |
| 543 | fit.maxB = {maxX, maxY, zMax}; |
| 544 | fit.proj = Ortho(minX, maxX, minY, maxY, -zMax, -zMin); |
| 545 | return fit; |
| 546 | } |
| 547 | |
| 548 | Mat4 ComputeCascadeLightVP(const Vec3& sunDir, const Vec3& up, const Mat4& invCameraViewProj, float t0, float t1, |
| 549 | int resolution, float zPad) |
no test coverage detected