MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / applyAlphaFadeToLowerPart

Function applyAlphaFadeToLowerPart

src/content/Sky.cpp:495–519  ·  view source on GitHub ↗

* 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... */

Source from the content-addressed store, hash-verified

493 * Gothic does this after loading the mesh. A better way would have been to simply bake this into the mesh...
494 */
495static 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/**

Callers 1

Calls 3

clampFunction · 0.85
sinusSlowEndFunction · 0.85
toRGBA8Method · 0.80

Tested by

no test coverage detected