From 7a4d2f8cb9472cffcec191b7d2ee9a47313990b3 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 1 Jun 2017 15:17:37 -0400 Subject: [PATCH] Fixed water reflectance and added gamma control to ATM (Still need the add the option to turn off the atm in globebrowsing). --- data/scene/atmosphereearth.scene | 4 +- .../atmosphere/shaders/deferred_test_fs.glsl | 50 +++++++++++-------- .../shaders/globalchunkedlodpatch_fs.glsl | 4 +- .../shaders/localchunkedlodpatch_fs.glsl | 5 +- .../shaders/texturetilemapping.hglsl | 6 +-- .../globebrowsing/shaders/tilefragcolor.hglsl | 6 +-- src/rendering/framebufferrenderer.cpp | 9 +++- 7 files changed, 48 insertions(+), 36 deletions(-) diff --git a/data/scene/atmosphereearth.scene b/data/scene/atmosphereearth.scene index 88771e95e2..05f080d893 100644 --- a/data/scene/atmosphereearth.scene +++ b/data/scene/atmosphereearth.scene @@ -87,10 +87,10 @@ return { "sun", --"atmosphereearth", --"atmospheremars", - "moon", + --"moon", "lodglobes/earth", - "lodglobes/mars", + --"lodglobes/mars", --"lodglobes/moon", --"toyvolume", diff --git a/modules/atmosphere/shaders/deferred_test_fs.glsl b/modules/atmosphere/shaders/deferred_test_fs.glsl index 373ebce6da..8b38fdc042 100644 --- a/modules/atmosphere/shaders/deferred_test_fs.glsl +++ b/modules/atmosphere/shaders/deferred_test_fs.glsl @@ -42,6 +42,7 @@ uniform sampler3D inscatterTexture; uniform sampler2DMS mainPositionTexture; uniform sampler2DMS mainNormalReflectanceTexture; uniform sampler2DMS mainColorTexture; +uniform sampler2DMS otherDataTexture; uniform int nAaSamples; @@ -480,7 +481,8 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor */ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const float r, const float mu, const vec3 attenuationXtoX0, const vec4 groundColor, - const vec4 normalReflectance, const float irradianceFactor) + const vec4 normalReflectance, const float irradianceFactor, + const float waterReflectance) { vec3 reflectedRadiance = vec3(0.0f); @@ -488,8 +490,8 @@ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const vec3 x0 = x + t * v; float r0 = length(x0); // Normal of intersection point. - vec3 n = normalReflectance.xyz; - vec4 groundReflectance = groundColor * vec4(.35); + vec3 n = normalize(normalReflectance.xyz); + vec4 groundReflectance = groundColor * vec4(.37); //reflectance.w = 1.0; // L0 is not included in the irradiance texture. @@ -507,7 +509,8 @@ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const * sunRadiance / M_PI; // Specular reflection from sun on oceans and rivers - if (normalReflectance.w > 0.0) { + //if (normalReflectance.a < 0.0) { + if (waterReflectance > 0.1) { vec3 h = normalize(s - v); // Fresnell Schlick's approximation float fresnel = 0.02f + 0.98f * pow(1.0f - dot(-v, h), 5.0f); @@ -515,7 +518,7 @@ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const float waterBrdf = fresnel * pow(max(dot(h, n), 0.0f), 150.0f); // Adding Fresnell and Water BRDFs approximation to the final surface color // (After adding the sunRadiance and the attenuation of the Sun through atmosphere) - groundRadiance += normalReflectance.w * max(waterBrdf, 0.0) * transmittanceL0 * sunRadiance; + groundRadiance += waterReflectance * max(waterBrdf, 0.0) * transmittanceL0 * sunRadiance; } // Finally, we attenuate the surface Radiance from the the point x0 to the camera location. @@ -551,32 +554,33 @@ vec3 sunColor(const vec3 x, const float t, const vec3 v, const vec3 s, const flo } void main() { - //float geoDepth = 0.0; + //float mainDepth = 0.0; vec4 meanColor = vec4(0.0); vec4 meanNormal = vec4(0.0); vec4 meanPosition = vec4(0.0); + vec4 meanOtherData = vec4(0.0); //vec4 positionArray[nAaSamples]; - vec4 positionArray[8]; + //vec4 positionArray[8]; float maxAlpha = -1.0; for (int i = 0; i < nAaSamples; i++) { meanNormal += texelFetch(mainNormalReflectanceTexture, ivec2(gl_FragCoord), i); vec4 color = texelFetch(mainColorTexture, ivec2(gl_FragCoord), i); if ( color.a > maxAlpha ) maxAlpha = color.a; - meanColor += color; - meanPosition += texelFetch(mainPositionTexture, ivec2(gl_FragCoord), i); - positionArray[i] = texelFetch(mainPositionTexture, ivec2(gl_FragCoord), i); - // geoDepth += denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), i).x); + meanColor += color; + meanPosition += texelFetch(mainPositionTexture, ivec2(gl_FragCoord), i); + meanOtherData += texelFetch(otherDataTexture, ivec2(gl_FragCoord), i); + //positionArray[i] = texelFetch(mainPositionTexture, ivec2(gl_FragCoord), i); + //mainDepth += denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), i).x); } - meanColor /= nAaSamples; - meanNormal /= nAaSamples; - meanPosition /= nAaSamples; - // geoDepth /= nAaSamples; + meanColor /= nAaSamples; + meanNormal /= nAaSamples; + meanPosition /= nAaSamples; + meanOtherData /= nAaSamples; + //mainDepth /= nAaSamples; meanColor.a = maxAlpha; - - meanNormal.xyz = normalize(meanNormal.xyz); - + // Ray in object space dRay ray; dvec4 planetPositionObjectCoords = dvec4(0.0); @@ -649,7 +653,8 @@ void main() { maxLength, pixelDepth, meanColor); vec3 groundColor = groundColor(x, tF, v, s, r, mu, attenuation, - meanColor, meanNormal, irradianceFactor); + meanColor, meanNormal, irradianceFactor, + meanOtherData.r); vec3 sunColor = sunColor(x, tF, v, s, r, mu, irradianceFactor); vec4 finalRadiance = vec4(HDR(inscatterColor + groundColor + sunColor), 1.0); @@ -690,8 +695,8 @@ void main() { // intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, Rt+EPSILON, // insideATM, offset, maxLength ); - intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, Rt-10*EPSILON, - insideATM, offset, maxLength ); + intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, + Rt-10*EPSILON, insideATM, offset, maxLength ); if ( intersectATM ) { // Now we check is if the atmosphere is occluded, i.e., if the distance to the pixel @@ -766,7 +771,8 @@ void main() { maxLength, pixelDepth, meanColor); vec3 groundColor = groundColor(x, tF, v, s, r, mu, attenuation, - meanColor, meanNormal, irradianceFactor); + meanColor, meanNormal, irradianceFactor, + meanOtherData.r); vec3 sunColor = sunColor(x, tF, v, s, r, mu, irradianceFactor); // Final Color of ATM plus terrain: diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl index 2ee924721d..ca1f8d2eba 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl @@ -34,10 +34,10 @@ Fragment getFragment() { #endif // SHOW_CHUNK_EDGES // TODO: Change the color for the new deferred system (JCC) - frag.gColor = frag.color; + frag.gColor = vec4(waterReflectance, 0.0, 0.0, 1.0); // Normal is written in Camera Rig (OS Eye) Space //frag.gNormalReflectance = vec4(ellipsoidNormalCameraSpace, 1.0); - frag.gNormalReflectance = vec4(fs_normal, reflectance); + frag.gNormalReflectance = vec4(fs_normal, 1.0); frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space frag.depth = fs_position.w; diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index d0c12f7f46..661ed0037c 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -35,9 +35,10 @@ Fragment getFragment() { #endif // SHOW_CHUNK_EDGES // TODO: Change the color for the new deferred system (JCC) - frag.gColor = frag.color; + //frag.gColor = frag.color; + frag.gColor = vec4(waterReflectance, 0.0, 0.0, 1.0); // Normal is written in Camera Rig (OS Eye) Space - frag.gNormalReflectance = vec4(ellipsoidNormalCameraSpace, reflectance); + frag.gNormalReflectance = vec4(ellipsoidNormalCameraSpace, 1.0); //frag.gNormalReflectance = vec4(fs_normal, 1.0); // adding 1.0 to reflectance by now frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space diff --git a/modules/globebrowsing/shaders/texturetilemapping.hglsl b/modules/globebrowsing/shaders/texturetilemapping.hglsl index a735f2c42a..033040dcda 100644 --- a/modules/globebrowsing/shaders/texturetilemapping.hglsl +++ b/modules/globebrowsing/shaders/texturetilemapping.hglsl @@ -383,12 +383,12 @@ vec4 calculateWater( vec3 specularTotal = specularColor * cosineFactor * specularIntensity * waterColor.a; - reflectance = 1.0;//waterColor.a; + reflectance = waterColor.a; //return blendOver(currentColor, waterColor); - return currentColor + vec4(specularTotal, 1); + //return currentColor + vec4(specularTotal, 1); - //return currentColor; + return currentColor; } #endif // TEXTURETILEMAPPING_HGLSL diff --git a/modules/globebrowsing/shaders/tilefragcolor.hglsl b/modules/globebrowsing/shaders/tilefragcolor.hglsl index 51be093f04..bbd38a0386 100644 --- a/modules/globebrowsing/shaders/tilefragcolor.hglsl +++ b/modules/globebrowsing/shaders/tilefragcolor.hglsl @@ -67,6 +67,7 @@ uniform vec2 vertexResolution; #if USE_NIGHTTEXTURE || USE_WATERMASK || USE_ATMOSPHERE || PERFORM_SHADING uniform vec3 lightDirectionCameraSpace; + float waterReflectance = 0.0; #endif in vec4 fs_position; @@ -75,8 +76,6 @@ in vec2 fs_uv; in vec3 ellipsoidNormalCameraSpace; in vec3 positionCameraSpace; -float reflectance; - // levelInterpolationParameter is used to interpolate between a tile and its parent tiles // The value increases with the distance from the vertex (or fragment) to the camera in LevelWeights levelWeights; @@ -157,8 +156,7 @@ vec4 getTileFragColor(){ normalize(ellipsoidNormalCameraSpace), lightDirectionCameraSpace, // Should already be normalized positionCameraSpace, - reflectance); - + waterReflectance); #endif // USE_WATERMASK #if USE_NIGHTTEXTURE diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index d4ea52a9cf..6b78f3f2ab 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -289,7 +289,7 @@ void FramebufferRenderer::updateResolution() { glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _nAaSamples, - GL_RGBA, + GL_RGBA32F, GLsizei(_resolution.x), GLsizei(_resolution.y), true); @@ -627,6 +627,11 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainColorTexture); deferredcastProgram->setUniform("mainColorTexture", mainDColorTextureUnit); + ghoul::opengl::TextureUnit otherDataTextureUnit; + otherDataTextureUnit.activate(); + glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainDColorTexture); + deferredcastProgram->setUniform("otherDataTexture", otherDataTextureUnit); + ghoul::opengl::TextureUnit mainPositionTextureUnit; mainPositionTextureUnit.activate(); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainPositionTexture); @@ -650,6 +655,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure *deferredcastProgram); glDisable(GL_DEPTH_TEST); + //glDisable(GL_BLEND); glDepthMask(false); glBindVertexArray(_screenQuad); @@ -658,6 +664,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure glDepthMask(true); glEnable(GL_DEPTH_TEST); + //glEnable(GL_BLEND); deferredcaster->postRaycast(deferredcasterTask.renderData, _deferredcastData[deferredcaster],