Revert the normal-based ambient occlusion; I wasn't crazy about the look of

it.  Will perhaps revisit later.
This commit is contained in:
Andrzej Kapolka 2014-09-15 11:52:44 -07:00
parent af546e6b05
commit 4475759461
3 changed files with 33 additions and 18 deletions

View file

@ -14,6 +14,9 @@
// the depth texture
uniform sampler2D depthTexture;
// the normal texture
uniform sampler2D normalTexture;
// the random rotation texture
uniform sampler2D rotationTexture;
@ -57,10 +60,11 @@ vec3 texCoordToViewSpace(vec2 texCoord) {
}
void main(void) {
vec3 rotationX = texture2D(rotationTexture, gl_TexCoord[0].st * noiseScale).rgb;
vec3 rotationY = normalize(cross(rotationX, vec3(0.0, 0.0, 1.0)));
mat3 rotation = mat3(rotationX, rotationY, cross(rotationX, rotationY));
vec3 rotationZ = texture2D(normalTexture, gl_TexCoord[0].st).xyz * 2.0 - vec3(1.0, 1.0, 1.0);
vec3 rotationY = normalize(cross(rotationZ, texture2D(rotationTexture,
gl_TexCoord[0].st * noiseScale).xyz - vec3(0.5, 0.5, 0.5)));
mat3 rotation = mat3(cross(rotationY, rotationZ), rotationY, rotationZ);
vec3 center = texCoordToViewSpace(gl_TexCoord[0].st);
vec2 rdenominator = 1.0 / (rightTop - leftBottom);

View file

@ -2892,14 +2892,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
_entities.render();
}
// render the ambient occlusion effect if enabled
if (Menu::getInstance()->isOptionChecked(MenuOption::AmbientOcclusion)) {
PerformanceTimer perfTimer("ambientOcclusion");
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::displaySide() ... AmbientOcclusion...");
_ambientOcclusionEffect.render();
}
// restore default, white specular
glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR);
@ -2919,6 +2911,16 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
}
}
if (!selfAvatarOnly) {
// render the ambient occlusion effect if enabled
if (Menu::getInstance()->isOptionChecked(MenuOption::AmbientOcclusion)) {
PerformanceTimer perfTimer("ambientOcclusion");
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::displaySide() ... AmbientOcclusion...");
_ambientOcclusionEffect.render();
}
}
{
PerformanceTimer perfTimer("lighting");
_deferredLightingEffect.render();

View file

@ -36,12 +36,13 @@ void AmbientOcclusionEffect::init() {
+ "shaders/ambient_occlusion.frag");
_occlusionProgram->link();
// create the sample kernel: an array of spherically distributed offset vectors
// create the sample kernel: an array of hemispherically distributed offset vectors
const int SAMPLE_KERNEL_SIZE = 16;
QVector3D sampleKernel[SAMPLE_KERNEL_SIZE];
for (int i = 0; i < SAMPLE_KERNEL_SIZE; i++) {
// square the length in order to increase density towards the center
glm::vec3 vector = glm::sphericalRand(1.0f);
vector.z = glm::abs(vector.z);
float scale = randFloat();
const float MIN_VECTOR_LENGTH = 0.01f;
const float MAX_VECTOR_LENGTH = 1.0f;
@ -51,7 +52,8 @@ void AmbientOcclusionEffect::init() {
_occlusionProgram->bind();
_occlusionProgram->setUniformValue("depthTexture", 0);
_occlusionProgram->setUniformValue("rotationTexture", 1);
_occlusionProgram->setUniformValue("normalTexture", 1);
_occlusionProgram->setUniformValue("rotationTexture", 2);
_occlusionProgram->setUniformValueArray("sampleKernel", sampleKernel, SAMPLE_KERNEL_SIZE);
_occlusionProgram->setUniformValue("radius", 0.1f);
_occlusionProgram->release();
@ -71,10 +73,10 @@ void AmbientOcclusionEffect::init() {
unsigned char rotationData[ROTATION_WIDTH * ROTATION_HEIGHT * ELEMENTS_PER_PIXEL];
unsigned char* rotation = rotationData;
for (int i = 0; i < ROTATION_WIDTH * ROTATION_HEIGHT; i++) {
glm::vec3 randvec = glm::sphericalRand(1.0f);
*rotation++ = ((randvec.x + 1.0f) / 2.0f) * 255.0f;
*rotation++ = ((randvec.y + 1.0f) / 2.0f) * 255.0f;
*rotation++ = ((randvec.z + 1.0f) / 2.0f) * 255.0f;
float angle = randFloatInRange(0.0f, TWO_PI);
*rotation++ = ((glm::cos(angle) + 1.0f) / 2.0f) * 255.0f;
*rotation++ = ((glm::sin(angle) + 1.0f) / 2.0f) * 255.0f;
*rotation++ = 0.0f;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ROTATION_WIDTH, ROTATION_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, rotationData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -101,6 +103,9 @@ void AmbientOcclusionEffect::render() {
glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryDepthTextureID());
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPrimaryNormalTextureID());
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, _rotationTextureID);
// render with the occlusion shader to the secondary/tertiary buffer
@ -137,6 +142,10 @@ void AmbientOcclusionEffect::render() {
freeFBO->release();
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
// now render secondary to primary with 4x4 blur