Fix deferred lighting for rear view mirror.

This commit is contained in:
Andrzej Kapolka 2014-09-12 18:56:07 -07:00
parent f8772135b1
commit e36ff0d238
4 changed files with 19 additions and 15 deletions

View file

@ -695,8 +695,6 @@ void Application::paintGL() {
displaySide(whichCamera);
glPopMatrix();
_glowEffect.render();
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
renderRearViewMirror(_mirrorViewRect);
@ -704,6 +702,8 @@ void Application::paintGL() {
_rearMirrorTools->render(true);
}
_glowEffect.render();
{
PerformanceTimer perfTimer("renderOverlay");
// PrioVR will only work if renderOverlay is called, calibration is connected to Application::renderingOverlay()

View file

@ -72,9 +72,13 @@ void DeferredLightingEffect::render() {
int viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
const int VIEWPORT_X_INDEX = 0;
const int VIEWPORT_Y_INDEX = 1;
const int VIEWPORT_WIDTH_INDEX = 2;
const int VIEWPORT_HEIGHT_INDEX = 3;
float sMin = viewport[VIEWPORT_X_INDEX] / (float)primaryFBO->width();
float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)primaryFBO->width();
float tMin = viewport[VIEWPORT_Y_INDEX] / (float)primaryFBO->height();
float tHeight = viewport[VIEWPORT_HEIGHT_INDEX] / (float)primaryFBO->height();
ProgramObject* program = &_directionalLight;
const LightLocations* locations = &_directionalLightLocations;
@ -109,13 +113,13 @@ void DeferredLightingEffect::render() {
program->setUniformValue(locations->nearLocation, nearVal);
program->setUniformValue(locations->depthScale, (farVal - nearVal) / farVal);
float nearScale = -1.0f / nearVal;
float sScale = 1.0f / sWidth;
float depthTexCoordScaleS = (right - left) * nearScale * sScale;
float depthTexCoordScaleS = (right - left) * nearScale / sWidth;
float depthTexCoordScaleT = (top - bottom) * nearScale / tHeight;
program->setUniformValue(locations->depthTexCoordOffset, left * nearScale - sMin * depthTexCoordScaleS,
bottom * nearScale);
program->setUniformValue(locations->depthTexCoordScale, depthTexCoordScaleS, (top - bottom) * nearScale);
bottom * nearScale - tMin * depthTexCoordScaleT);
program->setUniformValue(locations->depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
renderFullscreenQuad(sMin, sMin + sWidth);
renderFullscreenQuad(sMin, sMin + sWidth, tMin, tMin + tHeight);
program->release();
@ -145,7 +149,7 @@ void DeferredLightingEffect::render() {
glBindTexture(GL_TEXTURE_2D, freeFBO->texture());
glEnable(GL_TEXTURE_2D);
renderFullscreenQuad(sMin, sMin + sWidth);
renderFullscreenQuad(sMin, sMin + sWidth, tMin, tMin + tHeight);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);

View file

@ -12,15 +12,15 @@
#include "InterfaceConfig.h"
#include "RenderUtil.h"
void renderFullscreenQuad(float sMin, float sMax) {
void renderFullscreenQuad(float sMin, float sMax, float tMin, float tMax) {
glBegin(GL_QUADS);
glTexCoord2f(sMin, 0.0f);
glTexCoord2f(sMin, tMin);
glVertex2f(-1.0f, -1.0f);
glTexCoord2f(sMax, 0.0f);
glTexCoord2f(sMax, tMin);
glVertex2f(1.0f, -1.0f);
glTexCoord2f(sMax, 1.0f);
glTexCoord2f(sMax, tMax);
glVertex2f(1.0f, 1.0f);
glTexCoord2f(sMin, 1.0f);
glTexCoord2f(sMin, tMax);
glVertex2f(-1.0f, 1.0f);
glEnd();
}

View file

@ -12,7 +12,7 @@
#ifndef hifi_RenderUtil_h
#define hifi_RenderUtil_h
/// Renders a quad from (-1, -1, 0) to (1, 1, 0) with texture coordinates from (sMin, 0) to (sMax, 1).
void renderFullscreenQuad(float sMin = 0.0f, float sMax = 1.0f);
/// Renders a quad from (-1, -1, 0) to (1, 1, 0) with texture coordinates from (sMin, tMin) to (sMax, tMax).
void renderFullscreenQuad(float sMin = 0.0f, float sMax = 1.0f, float tMin = 0.0f, float tMax = 1.0f);
#endif // hifi_RenderUtil_h