| 229 | } |
| 230 | |
| 231 | void PlanarShadowEffect::GetModelSpaceTriangles() |
| 232 | { |
| 233 | for (size_t i = 0; i < mPlaneVisuals.size(); ++i) |
| 234 | { |
| 235 | auto const& visual = mPlaneVisuals[i]; |
| 236 | auto const& vbuffer = visual->GetVertexBuffer(); |
| 237 | auto const& vformat = vbuffer->GetFormat(); |
| 238 | |
| 239 | // Verify the vertex format satisfies the constraints. |
| 240 | int32_t index = vformat.GetIndex(VASemantic::POSITION, 0); |
| 241 | LogAssert( |
| 242 | index >= 0, |
| 243 | "The POSITION semantic must occur with unit 0."); |
| 244 | |
| 245 | DFType posType = vformat.GetType(index); |
| 246 | LogAssert( |
| 247 | posType == DF_R32G32B32_FLOAT || posType == DF_R32G32B32A32_FLOAT, |
| 248 | "The POSITION must be 3-tuple or 4-tuple float-valued."); |
| 249 | |
| 250 | uint32_t offset = vformat.GetOffset(index); |
| 251 | LogAssert( |
| 252 | offset == 0, |
| 253 | "The POSITION must occur first in the vertex format."); |
| 254 | |
| 255 | auto const& ibuffer = visual->GetIndexBuffer(); |
| 256 | IPType primitiveType = ibuffer->GetPrimitiveType(); |
| 257 | LogAssert( |
| 258 | primitiveType == IPType::IP_TRIMESH, |
| 259 | "The visual must have TRIMESH topology (for now)."); |
| 260 | |
| 261 | // Get the first triangle's vertex indices. Get the model-space |
| 262 | // vertices from the vertex buffer. |
| 263 | std::array<uint32_t, 3> v{}; |
| 264 | ibuffer->GetTriangle(0, v[0], v[1], v[2]); |
| 265 | char const* rawData = vbuffer->GetData(); |
| 266 | size_t const stride = static_cast<size_t>(vformat.GetVertexSize()); |
| 267 | auto& triangle = mModelSpaceTriangles[i]; |
| 268 | for (size_t j = 0; j < 3; ++j) |
| 269 | { |
| 270 | auto vertices = reinterpret_cast<Vector3<float> const*>( |
| 271 | rawData + v[j] * stride); |
| 272 | triangle[j] = HLift(*vertices, 1.0f); |
| 273 | } |
| 274 | |
| 275 | // The planar shadow effect is responsible for drawing the planes. |
| 276 | visual->culling = CullingMode::ALWAYS; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | bool PlanarShadowEffect::GetProjectionMatrix(size_t i, Matrix4x4<float>& projection) |
| 281 | { |
nothing calls this directly
no test coverage detected