mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 13:49:46 +02:00
The other part of the Oculus ambient occlusion fix.
This commit is contained in:
parent
e406988ed3
commit
f6b3a6ceca
3 changed files with 24 additions and 11 deletions
|
@ -30,6 +30,12 @@ uniform vec2 leftBottom;
|
||||||
// the right and top edges of the view window
|
// the right and top edges of the view window
|
||||||
uniform vec2 rightTop;
|
uniform vec2 rightTop;
|
||||||
|
|
||||||
|
// an offset value to apply to the texture coordinates
|
||||||
|
uniform vec2 texCoordOffset;
|
||||||
|
|
||||||
|
// a scale value to apply to the texture coordinates
|
||||||
|
uniform vec2 texCoordScale;
|
||||||
|
|
||||||
// the radius of the effect
|
// the radius of the effect
|
||||||
uniform float radius;
|
uniform float radius;
|
||||||
|
|
||||||
|
@ -38,7 +44,7 @@ uniform vec2 noiseScale;
|
||||||
|
|
||||||
// given a texture coordinate, returns the 3D view space z coordinate
|
// given a texture coordinate, returns the 3D view space z coordinate
|
||||||
float texCoordToViewSpaceZ(vec2 texCoord) {
|
float texCoordToViewSpaceZ(vec2 texCoord) {
|
||||||
return (far * near) / (texture2D(depthTexture, texCoord).r * (far - near) - far);
|
return (far * near) / (texture2D(depthTexture, texCoord * texCoordScale + texCoordOffset).r * (far - near) - far);
|
||||||
}
|
}
|
||||||
|
|
||||||
// given a texture coordinate, returns the 3D view space coordinate
|
// given a texture coordinate, returns the 3D view space coordinate
|
||||||
|
|
|
@ -57,6 +57,8 @@ void AmbientOcclusionEffect::init() {
|
||||||
_leftBottomLocation = _occlusionProgram->uniformLocation("leftBottom");
|
_leftBottomLocation = _occlusionProgram->uniformLocation("leftBottom");
|
||||||
_rightTopLocation = _occlusionProgram->uniformLocation("rightTop");
|
_rightTopLocation = _occlusionProgram->uniformLocation("rightTop");
|
||||||
_noiseScaleLocation = _occlusionProgram->uniformLocation("noiseScale");
|
_noiseScaleLocation = _occlusionProgram->uniformLocation("noiseScale");
|
||||||
|
_texCoordOffsetLocation = _occlusionProgram->uniformLocation("texCoordOffset");
|
||||||
|
_texCoordScaleLocation = _occlusionProgram->uniformLocation("texCoordScale");
|
||||||
|
|
||||||
// generate the random rotation texture
|
// generate the random rotation texture
|
||||||
glGenTextures(1, &_rotationTextureID);
|
glGenTextures(1, &_rotationTextureID);
|
||||||
|
@ -106,22 +108,25 @@ void AmbientOcclusionEffect::render() {
|
||||||
Application::getInstance()->computeOffAxisFrustum(
|
Application::getInstance()->computeOffAxisFrustum(
|
||||||
left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||||
|
|
||||||
|
int viewport[4];
|
||||||
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||||
|
const int VIEWPORT_X_INDEX = 0;
|
||||||
|
const int VIEWPORT_WIDTH_INDEX = 2;
|
||||||
|
QSize widgetSize = Application::getInstance()->getGLWidget()->size();
|
||||||
|
float sMin = viewport[VIEWPORT_X_INDEX] / (float)widgetSize.width();
|
||||||
|
float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)widgetSize.width();
|
||||||
|
|
||||||
_occlusionProgram->bind();
|
_occlusionProgram->bind();
|
||||||
_occlusionProgram->setUniformValue(_nearLocation, nearVal);
|
_occlusionProgram->setUniformValue(_nearLocation, nearVal);
|
||||||
_occlusionProgram->setUniformValue(_farLocation, farVal);
|
_occlusionProgram->setUniformValue(_farLocation, farVal);
|
||||||
_occlusionProgram->setUniformValue(_leftBottomLocation, left, bottom);
|
_occlusionProgram->setUniformValue(_leftBottomLocation, left, bottom);
|
||||||
_occlusionProgram->setUniformValue(_rightTopLocation, right, top);
|
_occlusionProgram->setUniformValue(_rightTopLocation, right, top);
|
||||||
QSize widgetSize = Application::getInstance()->getGLWidget()->size();
|
_occlusionProgram->setUniformValue(_noiseScaleLocation, viewport[VIEWPORT_WIDTH_INDEX] / (float)ROTATION_WIDTH,
|
||||||
_occlusionProgram->setUniformValue(_noiseScaleLocation, widgetSize.width() / (float)ROTATION_WIDTH,
|
|
||||||
widgetSize.height() / (float)ROTATION_HEIGHT);
|
widgetSize.height() / (float)ROTATION_HEIGHT);
|
||||||
|
_occlusionProgram->setUniformValue(_texCoordOffsetLocation, sMin, 0.0f);
|
||||||
|
_occlusionProgram->setUniformValue(_texCoordScaleLocation, sWidth, 1.0f);
|
||||||
|
|
||||||
int viewport[4];
|
renderFullscreenQuad();
|
||||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
|
||||||
const int VIEWPORT_X_INDEX = 0;
|
|
||||||
const int VIEWPORT_WIDTH_INDEX = 2;
|
|
||||||
float sMin = viewport[VIEWPORT_X_INDEX] / (float)widgetSize.width();
|
|
||||||
float sMax = (viewport[VIEWPORT_X_INDEX] + viewport[VIEWPORT_WIDTH_INDEX]) / (float)widgetSize.width();
|
|
||||||
renderFullscreenQuad(sMin, sMax);
|
|
||||||
|
|
||||||
_occlusionProgram->release();
|
_occlusionProgram->release();
|
||||||
|
|
||||||
|
@ -141,7 +146,7 @@ void AmbientOcclusionEffect::render() {
|
||||||
_blurProgram->bind();
|
_blurProgram->bind();
|
||||||
_blurProgram->setUniformValue(_blurScaleLocation, 1.0f / widgetSize.width(), 1.0f / widgetSize.height());
|
_blurProgram->setUniformValue(_blurScaleLocation, 1.0f / widgetSize.width(), 1.0f / widgetSize.height());
|
||||||
|
|
||||||
renderFullscreenQuad(sMin, sMax);
|
renderFullscreenQuad(sMin, sMin + sWidth);
|
||||||
|
|
||||||
_blurProgram->release();
|
_blurProgram->release();
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ private:
|
||||||
int _leftBottomLocation;
|
int _leftBottomLocation;
|
||||||
int _rightTopLocation;
|
int _rightTopLocation;
|
||||||
int _noiseScaleLocation;
|
int _noiseScaleLocation;
|
||||||
|
int _texCoordOffsetLocation;
|
||||||
|
int _texCoordScaleLocation;
|
||||||
|
|
||||||
ProgramObject* _blurProgram;
|
ProgramObject* _blurProgram;
|
||||||
int _blurScaleLocation;
|
int _blurScaleLocation;
|
||||||
|
|
Loading…
Reference in a new issue