MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / _updateScreenGeometry

Method _updateScreenGeometry

Engine/source/postFx/postEffect.cpp:475–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473}
474
475void PostEffect::_updateScreenGeometry( const Frustum &frustum,
476 GFXVertexBufferHandle<PFXVertex> *outVB )
477{
478 outVB->set( GFX, 4, GFXBufferTypeVolatile );
479
480 const Point3F *frustumPoints = frustum.getPoints();
481 const Point3F& cameraPos = frustum.getPosition();
482
483 // Perform a camera offset. We need to manually perform this offset on the postFx's
484 // polygon, which is at the far plane.
485 const Point2F& projOffset = frustum.getProjectionOffset();
486 Point3F cameraOffsetPos = cameraPos;
487 if(!projOffset.isZero())
488 {
489 // First we need to calculate the offset at the near plane. The projOffset
490 // given above can be thought of a percent as it ranges from 0..1 (or 0..-1).
491 F32 nearOffset = frustum.getNearRight() * projOffset.x;
492
493 // Now given the near plane distance from the camera we can solve the right
494 // triangle and calcuate the SIN theta for the offset at the near plane.
495 // SIN theta = x/y
496 F32 sinTheta = nearOffset / frustum.getNearDist();
497
498 // Finally, we can calcuate the offset at the far plane, which is where our sun (or vector)
499 // light's polygon is drawn.
500 F32 farOffset = frustum.getFarDist() * sinTheta;
501
502 // We can now apply this far plane offset to the far plane itself, which then compensates
503 // for the project offset.
504 MatrixF camTrans = frustum.getTransform();
505 VectorF offset = camTrans.getRightVector();
506 offset *= farOffset;
507 cameraOffsetPos += offset;
508 }
509
510 PFXVertex *vert = outVB->lock();
511
512 vert->point.set(-1.0, 1.0, 0.0);
513 vert->texCoord.set(0.0f, 0.0f);
514 vert->wsEyeRay = frustumPoints[Frustum::FarTopLeft] - cameraOffsetPos;
515 vert++;
516
517 vert->point.set(1.0, 1.0, 0.0);
518 vert->texCoord.set(1.0f, 0.0f);
519 vert->wsEyeRay = frustumPoints[Frustum::FarTopRight] - cameraOffsetPos;
520 vert++;
521
522 vert->point.set(-1.0, -1.0, 0.0);
523 vert->texCoord.set(0.0f, 1.0f);
524 vert->wsEyeRay = frustumPoints[Frustum::FarBottomLeft] - cameraOffsetPos;
525 vert++;
526
527 vert->point.set(1.0, -1.0, 0.0);
528 vert->texCoord.set(1.0f, 1.0f);
529 vert->wsEyeRay = frustumPoints[Frustum::FarBottomRight] - cameraOffsetPos;
530 vert++;
531
532 outVB->unlock();

Callers

nothing calls this directly

Calls 11

getNearRightMethod · 0.80
getNearDistMethod · 0.80
getFarDistMethod · 0.80
getRightVectorMethod · 0.80
setMethod · 0.45
getPointsMethod · 0.45
getPositionMethod · 0.45
isZeroMethod · 0.45
getTransformMethod · 0.45
lockMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected