| 35 | static const bool EnableShadowMips = true; |
| 36 | |
| 37 | static void GenerateHemisphere(uint64 NumUSlices, uint64 NumVSlices, ID3D11Device* device, |
| 38 | ID3D11BufferPtr& vtxBuffer, ID3D11BufferPtr& idxBuffer, uint64& numIndices) |
| 39 | { |
| 40 | Assert_(NumUSlices >= 3); |
| 41 | Assert_(NumVSlices >= 2); |
| 42 | |
| 43 | std::vector<Float3> hemisphereVerts; |
| 44 | |
| 45 | // Add the vert at the top |
| 46 | hemisphereVerts.push_back(Float3(0.0f, 0.0f, 1.0f)); |
| 47 | |
| 48 | // Add the rings |
| 49 | for(uint64 v = 0; v < NumVSlices; ++v) |
| 50 | { |
| 51 | for(uint64 u = 0; u < NumUSlices; ++u) |
| 52 | { |
| 53 | const float theta = ((v + 1.0f) / NumVSlices) * Pi_2; |
| 54 | const float phi = (float(u) / NumUSlices) * Pi2; |
| 55 | |
| 56 | Float3 pos; |
| 57 | pos.x = std::sin(theta) * std::cos(phi); |
| 58 | pos.y = std::sin(theta) * std::sin(phi); |
| 59 | pos.z = std::cos(theta); |
| 60 | |
| 61 | hemisphereVerts.push_back(pos); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | Assert_(hemisphereVerts.size() <= UINT32_MAX); |
| 66 | |
| 67 | // Add the top ring of triangles |
| 68 | std::vector<uint32> hemisphereIndices; |
| 69 | for(uint32 u = 0; u < NumUSlices; ++u) |
| 70 | { |
| 71 | hemisphereIndices.push_back(0); |
| 72 | hemisphereIndices.push_back(u + 1); |
| 73 | |
| 74 | if(u < NumUSlices - 1) |
| 75 | hemisphereIndices.push_back(u + 2); |
| 76 | else |
| 77 | hemisphereIndices.push_back(1); |
| 78 | } |
| 79 | |
| 80 | // Add the rest of the rings |
| 81 | uint32 prevRowStart = 1; |
| 82 | uint32 currRowStart = uint32(NumUSlices + 1); |
| 83 | for(uint32 v = 1; v < NumVSlices; ++v) |
| 84 | { |
| 85 | for(uint32 u = 0; u < NumUSlices; ++u) |
| 86 | { |
| 87 | uint32 nextBottom = currRowStart + u + 1; |
| 88 | uint32 nextTop = prevRowStart + u + 1; |
| 89 | if(u == NumUSlices - 1) |
| 90 | { |
| 91 | nextBottom = currRowStart; |
| 92 | nextTop = prevRowStart; |
| 93 | } |
| 94 | |