Fix for off-axis ambient occlusion.

This commit is contained in:
Andrzej Kapolka 2013-09-08 17:52:35 -07:00
parent 699007691b
commit ddf92b39c7
4 changed files with 20 additions and 11 deletions

View file

@ -44,8 +44,7 @@ float texCoordToViewSpaceZ(vec2 texCoord) {
// given a texture coordinate, returns the 3D view space coordinate
vec3 texCoordToViewSpace(vec2 texCoord) {
float z = texCoordToViewSpaceZ(texCoord);
return vec3(((texCoord * 2.0 - vec2(1.0 - gl_ProjectionMatrix[2][0], 1.0)) *
(rightTop - leftBottom) + rightTop + leftBottom) * z / (-2.0 * near), z);
return vec3((leftBottom + texCoord * (rightTop - leftBottom)) * (-z / near), z);
}
void main(void) {

View file

@ -438,7 +438,7 @@ void Application::updateProjectionMatrix() {
float left, right, bottom, top, nearVal, farVal;
glm::vec4 nearClipPlane, farClipPlane;
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
// If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the
// _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum
@ -446,13 +446,6 @@ void Application::updateProjectionMatrix() {
nearVal = _viewFrustumOffsetCamera.getNearClip();
farVal = _viewFrustumOffsetCamera.getFarClip();
}
// when mirrored, we must flip left and right
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
float tmp = left;
left = -right;
right = -tmp;
}
glFrustum(left, right, bottom, top, nearVal, farVal);
glMatrixMode(GL_MODELVIEW);
@ -2144,6 +2137,19 @@ void Application::setupWorldLight(Camera& whichCamera) {
glMateriali(GL_FRONT, GL_SHININESS, 96);
}
void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near,
float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, near, far, nearClipPlane, farClipPlane);
// when mirrored, we must flip left and right
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
float tmp = left;
left = -right;
right = -tmp;
}
}
void Application::displaySide(Camera& whichCamera) {
// transform by eye offset

View file

@ -135,6 +135,10 @@ public:
void setupWorldLight(Camera& whichCamera);
/// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account.
void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near,
float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
virtual void nodeAdded(Node* node);
virtual void nodeKilled(Node* node);
virtual void packetSentNotification(ssize_t length);

View file

@ -103,7 +103,7 @@ void AmbientOcclusionEffect::render() {
float left, right, bottom, top, nearVal, farVal;
glm::vec4 nearClipPlane, farClipPlane;
Application::getInstance()->getViewFrustum()->computeOffAxisFrustum(
Application::getInstance()->computeOffAxisFrustum(
left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
_occlusionProgram->bind();