* Sets the alpha-values of the lowest vertices in the mesh to do some fading. * * Gothic does this after loading the mesh. A better way would have been to simply bake this into the mesh... */
| 493 | * Gothic does this after loading the mesh. A better way would have been to simply bake this into the mesh... |
| 494 | */ |
| 495 | static void applyAlphaFadeToLowerPart(ZenLoad::PackedMesh& mesh) |
| 496 | { |
| 497 | float lowestVertex = mesh.bbox[0].y; |
| 498 | float highestVertex = mesh.bbox[1].y; |
| 499 | float heightTotal = highestVertex - lowestVertex; |
| 500 | |
| 501 | const float heightTotalInv = 1.0f / heightTotal; |
| 502 | |
| 503 | for(ZenLoad::WorldVertex& vx : mesh.vertices) |
| 504 | { |
| 505 | if(vx.Position.y > 0) |
| 506 | { |
| 507 | vx.Color = 0xFFFFFFFF; |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | float vertexHeightRatio = Math::clamp(1.0f - (vx.Position.y - lowestVertex) * heightTotalInv, 0.0f, 1.0f); |
| 512 | |
| 513 | const float alpha = 1.0f - Math::sinusSlowEnd(vertexHeightRatio); |
| 514 | Math::float4 color = Math::float4(1.0f, 1.0f, 1.0f, alpha); |
| 515 | |
| 516 | vx.Color = color.toRGBA8(); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | |
| 522 | /** |
no test coverage detected