| 671 | } |
| 672 | |
| 673 | void PostEffect::_updateScreenGeometry( const Frustum &frustum, |
| 674 | GFXVertexBufferHandle<PFXVertex> *outVB ) |
| 675 | { |
| 676 | outVB->set( GFX, 4, GFXBufferTypeVolatile ); |
| 677 | |
| 678 | const Point3F *frustumPoints = frustum.getPoints(); |
| 679 | const Point3F& cameraPos = frustum.getPosition(); |
| 680 | |
| 681 | // Perform a camera offset. We need to manually perform this offset on the postFx's |
| 682 | // polygon, which is at the far plane. |
| 683 | const Point2F& projOffset = frustum.getProjectionOffset(); |
| 684 | Point3F cameraOffsetPos = cameraPos; |
| 685 | if(!projOffset.isZero()) |
| 686 | { |
| 687 | // First we need to calculate the offset at the near plane. The projOffset |
| 688 | // given above can be thought of a percent as it ranges from 0..1 (or 0..-1). |
| 689 | F32 nearOffset = frustum.getNearRight() * projOffset.x; |
| 690 | |
| 691 | // Now given the near plane distance from the camera we can solve the right |
| 692 | // triangle and calcuate the SIN theta for the offset at the near plane. |
| 693 | // SIN theta = x/y |
| 694 | F32 sinTheta = nearOffset / frustum.getNearDist(); |
| 695 | |
| 696 | // Finally, we can calcuate the offset at the far plane, which is where our sun (or vector) |
| 697 | // light's polygon is drawn. |
| 698 | F32 farOffset = frustum.getFarDist() * sinTheta; |
| 699 | |
| 700 | // We can now apply this far plane offset to the far plane itself, which then compensates |
| 701 | // for the project offset. |
| 702 | MatrixF camTrans = frustum.getTransform(); |
| 703 | VectorF offset = camTrans.getRightVector(); |
| 704 | offset *= farOffset; |
| 705 | cameraOffsetPos += offset; |
| 706 | } |
| 707 | |
| 708 | PFXVertex *vert = outVB->lock(); |
| 709 | |
| 710 | vert->point.set(-1.0, 1.0, 0.0); |
| 711 | vert->texCoord.set(0.0f, 0.0f); |
| 712 | vert->wsEyeRay = frustumPoints[Frustum::FarTopLeft] - cameraOffsetPos; |
| 713 | vert++; |
| 714 | |
| 715 | vert->point.set(1.0, 1.0, 0.0); |
| 716 | vert->texCoord.set(1.0f, 0.0f); |
| 717 | vert->wsEyeRay = frustumPoints[Frustum::FarTopRight] - cameraOffsetPos; |
| 718 | vert++; |
| 719 | |
| 720 | vert->point.set(-1.0, -1.0, 0.0); |
| 721 | vert->texCoord.set(0.0f, 1.0f); |
| 722 | vert->wsEyeRay = frustumPoints[Frustum::FarBottomLeft] - cameraOffsetPos; |
| 723 | vert++; |
| 724 | |
| 725 | vert->point.set(1.0, -1.0, 0.0); |
| 726 | vert->texCoord.set(1.0f, 1.0f); |
| 727 | vert->wsEyeRay = frustumPoints[Frustum::FarBottomRight] - cameraOffsetPos; |
| 728 | vert++; |
| 729 | |
| 730 | outVB->unlock(); |
nothing calls this directly
no test coverage detected