From 554cbcf32a8750721ad8b2bb0fa3b425d01fee74 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Wed, 24 May 2017 16:09:28 -0400 Subject: [PATCH] Added gBuffer filling from Globebrowsing. Changed Earth Radius for ATM calculations. Removed unsused code. --- data/scene/lodglobes/earth/earth.mod | 6 +- .../rendering/atmospheredeferredcaster.cpp | 2 +- .../rendering/atmospheredeferredcaster.h | 6 +- .../atmosphere/shaders/atmosphere_common.glsl | 24 ++++---- .../atmosphere/shaders/deferred_test_fs.glsl | 56 ++++++++----------- .../shaders/globalchunkedlodpatch_fs.glsl | 10 ++-- .../shaders/localchunkedlodpatch_fs.glsl | 10 ++-- 7 files changed, 55 insertions(+), 59 deletions(-) diff --git a/data/scene/lodglobes/earth/earth.mod b/data/scene/lodglobes/earth/earth.mod index 1c39b6df1b..da744a02bd 100644 --- a/data/scene/lodglobes/earth/earth.mod +++ b/data/scene/lodglobes/earth/earth.mod @@ -57,8 +57,10 @@ return { SegmentsPerPatch = 64, Atmosphere = { -- Atmosphere radius in Km - AtmoshereRadius = 6450, - PlanetRadius = 6378.1366, + --AtmoshereRadius = 6450, + AtmoshereRadius = 6420.0, + PlanetRadius = 6378.137, + --PlanetRadius = 6360.0, PlanetAverageGroundReflectance = 0.1, Rayleigh = { Coefficients = { diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index ac22f272af..7176fd789a 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -47,7 +47,7 @@ #define _USE_MATH_DEFINES #include -//#define _SAVE_ATMOSPHERE_TEXTURES +#define _SAVE_ATMOSPHERE_TEXTURES namespace { const std::string _loggerCat = "AtmosphereDeferredcaster"; diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.h b/modules/atmosphere/rendering/atmospheredeferredcaster.h index fcc9f80d02..c67272be76 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.h +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.h @@ -57,7 +57,7 @@ public: public: // See: Precomputed Atmospheric Scattering from Bruneton et al. // for explanation of the following parameters. - /* + const unsigned int TRANSMITTANCE_TABLE_WIDTH = 256; const unsigned int TRANSMITTANCE_TABLE_HEIGHT = 64; @@ -66,7 +66,8 @@ public: const unsigned int DELTA_E_TABLE_WIDTH = 64; const unsigned int DELTA_E_TABLE_HEIGHT = 16; - */ + + /* const unsigned int TRANSMITTANCE_TABLE_WIDTH = 512; const unsigned int TRANSMITTANCE_TABLE_HEIGHT = 128; @@ -75,6 +76,7 @@ public: const unsigned int DELTA_E_TABLE_WIDTH = 128; const unsigned int DELTA_E_TABLE_HEIGHT = 32; + */ const unsigned int R_SAMPLES = 32; const unsigned int MU_SAMPLES = 128; diff --git a/modules/atmosphere/shaders/atmosphere_common.glsl b/modules/atmosphere/shaders/atmosphere_common.glsl index 1b5a9e1d4c..3015420d5d 100644 --- a/modules/atmosphere/shaders/atmosphere_common.glsl +++ b/modules/atmosphere/shaders/atmosphere_common.glsl @@ -44,23 +44,23 @@ const int INSCATTER_SPHERICAL_INTEGRAL_SAMPLES = 16; const float M_PI = 3.141592657; -// const int TRANSMITTANCE_W = 256; -// const int TRANSMITTANCE_H = 64; +const int TRANSMITTANCE_W = 256; +const int TRANSMITTANCE_H = 64; -// const int SKY_W = 64; -// const int SKY_H = 16; +const int SKY_W = 64; +const int SKY_H = 16; -// const int OTHER_TEXTURES_W = 64; -// const int OTHER_TEXTURES_H = 16; +const int OTHER_TEXTURES_W = 64; +const int OTHER_TEXTURES_H = 16; -const int TRANSMITTANCE_W = 512; -const int TRANSMITTANCE_H = 128; +// const int TRANSMITTANCE_W = 512; +// const int TRANSMITTANCE_H = 128; -const int SKY_W = 128; -const int SKY_H = 32; +// const int SKY_W = 128; +// const int SKY_H = 32; -const int OTHER_TEXTURES_W = 128; -const int OTHER_TEXTURES_H = 32; +// const int OTHER_TEXTURES_W = 128; +// const int OTHER_TEXTURES_H = 32; // cosines sampling diff --git a/modules/atmosphere/shaders/deferred_test_fs.glsl b/modules/atmosphere/shaders/deferred_test_fs.glsl index d2445e534e..798e2944a1 100644 --- a/modules/atmosphere/shaders/deferred_test_fs.glsl +++ b/modules/atmosphere/shaders/deferred_test_fs.glsl @@ -249,8 +249,10 @@ void dCalculateRayRenderableGlobe(out dRay ray, out dvec4 planetPositionObjectCo //sgctEyeCoords /= sgctEyeCoords.w; sgctEyeCoords.w = 1.0; - // OS Eye to World coords + // SGCT Eye to OS Eye dvec4 tOSEyeCoordsInv = dSgctEyeToOSEyeTranform * sgctEyeCoords; + + // OS Eye to World coords dvec4 tmpRInv = dInverseCamRotTransform * tOSEyeCoordsInv; dvec4 worldCoords= dvec4(dvec3(tmpRInv) + dCampos, 1.0); @@ -258,6 +260,8 @@ void dCalculateRayRenderableGlobe(out dRay ray, out dvec4 planetPositionObjectCo dvec4 objectCoords = dInverseTransformMatrix * worldCoords; // Planet Position in Object Space + // JCC: Applying the inverse of the model transformation on the object postion in World + // space results in imprecision. planetPositionObjectCoords = dvec4(0.0,0.0,0.0,1.0);//dInverseTransformMatrix * dvec4(dObjpos.xyz, 1.0); // Camera Position in Object Space @@ -811,8 +815,6 @@ void main() { meanPosition /= nAaSamples; // geoDepth /= nAaSamples; - //meanPosition = texture2D(mainPositionTexture, vec2(gl_FragCoord)); - // Ray in object space dRay ray; dvec4 planetPositionObjectCoords = dvec4(0.0); @@ -912,21 +914,25 @@ void main() { // is occluded // Fragments positions into G-Buffer are written in OS Eye Space (Camera Rig Coords) // when using their positions later, one must convert them to the planet's coords - - // OS Eye to World coords - dvec4 tmpRInv = dInverseCamRotTransform * meanPosition; - dvec4 fragWorldCoords= dvec4(dvec3(tmpRInv) + dCampos, 1.0); - - // World to Object - dvec4 fragObjectCoords = dInverseTransformMatrix * fragWorldCoords; + // OS Eye to World coords + dvec4 tmpRInvPos = dInverseCamRotTransform * meanPosition; + dvec4 fragWorldCoords = dvec4(dvec3(tmpRInvPos) + dCampos, 1.0); + dvec4 tmpRInvNormal = dInverseCamRotTransform * meanNormal; + dvec4 fragNormalWorldCoords = dvec4(dvec3(tmpRInvNormal) + dCampos, 1.0); + + // World to Object + dvec4 fragObjectCoords = dInverseTransformMatrix * fragWorldCoords; + dvec4 fragNormalObjectCoords = dInverseTransformMatrix * fragNormalWorldCoords; + + // Distance of the pixel in the gBuffer to the observer double pixelDepth = distance(cameraPositionInObject.xyz, fragObjectCoords.xyz); - // TODO: Write the correct values in G-Buffer - // if (pixelDepth < offset) { - // renderTarget = meanColor; - // } else { - { + if (meanPosition.xyz != vec3(0.0) && (pixelDepth < offset)) { + renderTarget = meanColor; + renderTarget = vec4(1.0, 0.0, 0.0, 0.5); + } else { + //{ // Following paper nomenclature double t = offset; vec3 attenuation; @@ -949,11 +955,6 @@ void main() { vec3 groundColor = groundColor(x, tF, v, s, r, mu, attenuation, meanColor, meanNormal); vec3 sunColor = sunColor(x, tF, v, s, r, mu); - //renderTarget = vec4(HDR(inscatterColor), 1.0); - //renderTarget = vec4(HDR(groundColor), 1.0); - //renderTarget = vec4(groundColor, 1.0); - //renderTarget = vec4(HDR(sunColor), 1.0); - //renderTarget = vec4(HDR(sunColor), 1.0); //vec4 finalRadiance = vec4(HDR(inscatterColor + sunColor), 1.0); //finalRadiance = mix(finalRadiance, meanColor); //vec4 finalRadiance = vec4(inscatterColor, 1.0); @@ -966,22 +967,9 @@ void main() { // The meanColor is temporary here vec4 finalRadiance = vec4(HDR(inscatterColor + groundColor + sunColor + meanColor.xyz), 1.0); - //renderTarget = finalRadiance + meanColor; - renderTarget = finalRadiance; - //renderTarget = vec4(normalize(meanNormal.xyz), 1.0); - dvec4 ttmp = dInverseScaleTransformMatrix * meanPosition; - dvec3 ttmp2 = dmat3(dInverseCamRotTransform) * dvec3(ttmp); - dvec4 worldCoords = dvec4(dCampos + ttmp2, 1.0); - dvec4 positionInObject = dInverseTransformMatrix * dvec4(-dObjpos.xyz + worldCoords.xyz, 1.0); - //renderTarget = vec4(positionInObject.xyz, 1.0); - //renderTarget = vec4(meanColor.xyz, 1.0); - //renderTarget = meanColor; - //renderTarget = vec4(0.5, 0.0, 0.0, 0.5); - //renderTarget = vec4(0.0); + renderTarget = finalRadiance; } } else { - //renderTarget = vec4(1.0, 1.0, 0.0, 1.0); - //renderTarget = vec4(0.0); renderTarget = meanColor; } } else { diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl index 8c1626ed85..0c8f24a77c 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl @@ -32,11 +32,13 @@ Fragment getFragment() { #if SHOW_CHUNK_EDGES frag.color += patchBorderOverlay(fs_uv, vec3(0,1,0), 0.02); #endif // SHOW_CHUNK_EDGES - - // frag.gColor = frag.color; - // frag.gNormal = normal; - // frag.gPosition = p; + // TODO: Change the color for the new deferred system (JCC) + frag.gColor = frag.color; + // Normal is written in Camera Rig (OS Eye) Space + frag.gNormalReflectance = vec4(ellipsoidNormalCameraSpace, 1.0); // adding 1.0 to reflectance by now + frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space + frag.depth = fs_position.w; return frag; } diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index e5e40149a4..293417f9ae 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -34,11 +34,13 @@ Fragment getFragment() { frag.color += patchBorderOverlay(fs_uv, vec3(1,0,0), 0.005); #endif // SHOW_CHUNK_EDGES - // frag.gColor = frag.color; - // frag.gNormal = normal; - // frag.gPosition = p; + // TODO: Change the color for the new deferred system (JCC) + frag.gColor = frag.color; + // Normal is written in Camera Rig (OS Eye) Space + frag.gNormalReflectance = vec4(ellipsoidNormalCameraSpace, 1.0); // adding 1.0 to reflectance by now + frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space - frag.depth = fs_position.w; + frag.depth = fs_position.w; return frag; }