diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index 5b5e173566..c7d2204276 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -204,8 +204,7 @@ private: bool _dirtyDeferredcastData; bool _dirtyRaycastData; bool _dirtyResolution; - bool _dirtyMsaaSamplingPattern; - + glm::ivec2 _resolution = glm::ivec2(0); int _nAaSamples; bool _enableFXAA = false; diff --git a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl index d8d1d4e28b..920e278a4d 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl @@ -65,15 +65,16 @@ out vec4 renderTarget; in vec3 interpolatedNDCPos; +in vec2 texCoord; uniform int nAaSamples; uniform int cullAtmosphere; uniform sampler2D irradianceTexture; uniform sampler3D inscatterTexture; -uniform sampler2DMS mainPositionTexture; -uniform sampler2DMS mainNormalTexture; -uniform sampler2DMS mainColorTexture; +uniform sampler2D mainPositionTexture; +uniform sampler2D mainNormalTexture; +uniform sampler2D mainColorTexture; uniform dmat4 dInverseModelTransformMatrix; uniform dmat4 dModelTransformMatrix; @@ -230,7 +231,7 @@ bool dAtmosphereIntersection(const dvec3 planetPosition, const dRay ray, const d * This method avoids matrices multiplications * wherever is possible. */ -void dCalculateRayRenderableGlobe(in int mssaSample, out dRay ray, +void dCalculateRayRenderableGlobe(out dRay ray, out dvec4 planetPositionObjectCoords, out dvec4 cameraPositionInObject) { dvec4 clipCoords = dvec4(interpolatedNDCPos.xy, 1.0, 1.0); @@ -529,8 +530,6 @@ vec3 sunColor(const vec3 x, const float t, const vec3 v, const vec3 s, const flo } void main() { - ivec2 fragCoords = ivec2(gl_FragCoord); - if (cullAtmosphere == 0) { vec4 atmosphereFinalColor = vec4(0.0f); int nSamples = 1; @@ -538,153 +537,141 @@ void main() { // First we determine if the pixel is complex (different fragments on it) bool complex = false; vec4 oldColor, currentColor; - vec4 colorArray[16]; + vec4 colorTexture; - colorArray[0] = texelFetch(mainColorTexture, fragCoords, 0); - for (int i = 1; i < nAaSamples; i++) { - colorArray[i] = texelFetch(mainColorTexture, fragCoords, i); - if (colorArray[i] != colorArray[i-1]) { - complex = true; - } - } - nSamples = complex ? nAaSamples / 2 : 1; + colorTexture = texture(mainColorTexture, texCoord); - for (int i = 0; i < nSamples; i++) { - // Color from G-Buffer - vec4 color = colorArray[i]; - // Ray in object space - dRay ray; - dvec4 planetPositionObjectCoords = dvec4(0.0); - dvec4 cameraPositionInObject = dvec4(0.0); + // Color from G-Buffer + vec4 color = colorTexture; + // Ray in object space + dRay ray; + dvec4 planetPositionObjectCoords = dvec4(0.0); + dvec4 cameraPositionInObject = dvec4(0.0); + + // Get the ray from camera to atm in object space + dCalculateRayRenderableGlobe(ray, planetPositionObjectCoords, + cameraPositionInObject); + + bool insideATM = false; + double offset = 0.0; // in Km + double maxLength = 0.0; // in Km + + bool intersectATM = false; + + intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray, + Rt - (ATM_EPSILON * 0.001), insideATM, offset, maxLength); - // Get the ray from camera to atm in object space - dCalculateRayRenderableGlobe(i * 3, ray, planetPositionObjectCoords, - cameraPositionInObject); - - bool insideATM = false; - double offset = 0.0; // in Km - double maxLength = 0.0; // in Km + if ( intersectATM ) { + // Now we check is if the atmosphere is occluded, i.e., if the distance to the pixel + // in the G-Buffer positions is less than the distance to the atmosphere then the atmosphere + // is occluded + // Fragments positions into G-Buffer are written in SGCT Eye Space (View plus Camera Rig Coords) + // when using their positions later, one must convert them to the planet's coords + + // Get data from G-Buffer + vec4 normal = texture(mainNormalTexture, texCoord); + // Data in the mainPositionTexture are written in view space (view plus camera rig) + vec4 position = texture(mainPositionTexture, texCoord); - bool intersectATM = false; + // OS Eye to World coords + dvec4 positionWorldCoords = dSGCTViewToWorldMatrix * position; - intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray, - Rt - (ATM_EPSILON * 0.001), insideATM, offset, maxLength); - - if ( intersectATM ) { - // Now we check is if the atmosphere is occluded, i.e., if the distance to the pixel - // in the G-Buffer positions is less than the distance to the atmosphere then the atmosphere - // is occluded - // Fragments positions into G-Buffer are written in SGCT Eye Space (View plus Camera Rig Coords) - // when using their positions later, one must convert them to the planet's coords - - // Get data from G-Buffer - vec4 normal = texelFetch(mainNormalTexture, fragCoords, i); - // Data in the mainPositionTexture are written in view space (view plus camera rig) - vec4 position = texelFetch(mainPositionTexture, fragCoords, i); + // World to Object (Normal and Position in meters) + dvec4 positionObjectsCoords = dInverseModelTransformMatrix * positionWorldCoords; - // OS Eye to World coords - dvec4 positionWorldCoords = dSGCTViewToWorldMatrix * position; + + // Distance of the pixel in the gBuffer to the observer + // JCC (12/12/2017): AMD distance function is buggy. + //double pixelDepth = distance(cameraPositionInObject.xyz, positionObjectsCoords.xyz); + double pixelDepth = length(cameraPositionInObject.xyz - positionObjectsCoords.xyz); + + // JCC (12/13/2017): Trick to remove floating error in texture. + // We see a squared noise on planet's surface when seeing the planet + // from far away. + float dC = float(length(cameraPositionInObject.xyz)); + float x1 = 1e8; + if (dC > x1) { + pixelDepth += 1000.0; + float alpha = 1000.0; + float beta = 1000000.0; + float x2 = 1e9; + float diffGreek = beta - alpha; + float diffDist = x2 - x1; + float varA = diffGreek/diffDist; + float varB = (alpha - varA * x1); + pixelDepth += double(varA * dC + varB); + } - // World to Object (Normal and Position in meters) - dvec4 positionObjectsCoords = dInverseModelTransformMatrix * positionWorldCoords; - - - // Distance of the pixel in the gBuffer to the observer - // JCC (12/12/2017): AMD distance function is buggy. - //double pixelDepth = distance(cameraPositionInObject.xyz, positionObjectsCoords.xyz); - double pixelDepth = length(cameraPositionInObject.xyz - positionObjectsCoords.xyz); - - // JCC (12/13/2017): Trick to remove floating error in texture. - // We see a squared noise on planet's surface when seeing the planet - // from far away. - float dC = float(length(cameraPositionInObject.xyz)); - float x1 = 1e8; - if (dC > x1) { - pixelDepth += 1000.0; - float alpha = 1000.0; - float beta = 1000000.0; - float x2 = 1e9; - float diffGreek = beta - alpha; - float diffDist = x2 - x1; - float varA = diffGreek/diffDist; - float varB = (alpha - varA * x1); - pixelDepth += double(varA * dC + varB); - } - - // All calculations are done in Km: - pixelDepth *= 0.001; - positionObjectsCoords.xyz *= 0.001; - - if (pixelDepth < offset) { - // ATM Occluded - Something in fron of ATM. - atmosphereFinalColor += color; - } else { - // Following paper nomenclature - double t = offset; - vec3 attenuation; - - // Moving observer from camera location to top atmosphere - // If the observer is already inside the atm, offset = 0.0 - // and no changes at all. - vec3 x = vec3(ray.origin.xyz + t*ray.direction.xyz); - float r = 0.0f;//length(x); - vec3 v = vec3(ray.direction.xyz); - float mu = 0.0f;//dot(x, v) / r; - vec3 s = vec3(sunDirectionObj); - float tF = float(maxLength - t); - - // Because we may move the camera origin to the top of atmosphere - // we also need to adjust the pixelDepth for tdCalculateRayRenderableGlobe' offset so the - // next comparison with the planet's ground make sense: - pixelDepth -= offset; - - dvec4 onATMPos = dModelTransformMatrix * dvec4(x * 1000.0, 1.0); - vec4 eclipseShadowATM = calcShadow(shadowDataArray, onATMPos.xyz, false); - float sunIntensityInscatter = sunRadiance * eclipseShadowATM.x; - - float irradianceFactor = 0.0; - - bool groundHit = false; - vec3 inscatterColor = inscatterRadiance(x, tF, irradianceFactor, v, - s, r, mu, attenuation, - vec3(positionObjectsCoords.xyz), - groundHit, maxLength, pixelDepth, - color, sunIntensityInscatter); - vec3 groundColorV = vec3(0.0); - vec3 sunColorV = vec3(0.0); - if (groundHit) { - vec4 eclipseShadowPlanet = calcShadow(shadowDataArray, positionWorldCoords.xyz, true); - float sunIntensityGround = sunRadiance * eclipseShadowPlanet.x; - groundColorV = groundColor(x, tF, v, s, r, mu, attenuation, - color, normal.xyz, irradianceFactor, - normal.a, sunIntensityGround); - } else { - // In order to get better performance, we are not tracing - // multiple rays per pixel when the ray doesn't intersect - // the ground. - sunColorV = sunColor(x, tF, v, s, r, mu, irradianceFactor); - } - - // Final Color of ATM plus terrain: - vec4 finalRadiance = vec4(inscatterColor + groundColorV + sunColorV, 1.0); - - atmosphereFinalColor += finalRadiance; - } - } - else { // no intersection - // Buffer color + // All calculations are done in Km: + pixelDepth *= 0.001; + positionObjectsCoords.xyz *= 0.001; + + if (pixelDepth < offset) { + // ATM Occluded - Something in fron of ATM. atmosphereFinalColor += color; - } - } + } else { + // Following paper nomenclature + double t = offset; + vec3 attenuation; - renderTarget = atmosphereFinalColor / float(nSamples); + // Moving observer from camera location to top atmosphere + // If the observer is already inside the atm, offset = 0.0 + // and no changes at all. + vec3 x = vec3(ray.origin.xyz + t*ray.direction.xyz); + float r = 0.0f;//length(x); + vec3 v = vec3(ray.direction.xyz); + float mu = 0.0f;//dot(x, v) / r; + vec3 s = vec3(sunDirectionObj); + float tF = float(maxLength - t); + + // Because we may move the camera origin to the top of atmosphere + // we also need to adjust the pixelDepth for tdCalculateRayRenderableGlobe' offset so the + // next comparison with the planet's ground make sense: + pixelDepth -= offset; + + dvec4 onATMPos = dModelTransformMatrix * dvec4(x * 1000.0, 1.0); + vec4 eclipseShadowATM = calcShadow(shadowDataArray, onATMPos.xyz, false); + float sunIntensityInscatter = sunRadiance * eclipseShadowATM.x; + + float irradianceFactor = 0.0; + + bool groundHit = false; + vec3 inscatterColor = inscatterRadiance(x, tF, irradianceFactor, v, + s, r, mu, attenuation, + vec3(positionObjectsCoords.xyz), + groundHit, maxLength, pixelDepth, + color, sunIntensityInscatter); + vec3 groundColorV = vec3(0.0); + vec3 sunColorV = vec3(0.0); + if (groundHit) { + vec4 eclipseShadowPlanet = calcShadow(shadowDataArray, positionWorldCoords.xyz, true); + float sunIntensityGround = sunRadiance * eclipseShadowPlanet.x; + groundColorV = groundColor(x, tF, v, s, r, mu, attenuation, + color, normal.xyz, irradianceFactor, + normal.a, sunIntensityGround); + } else { + // In order to get better performance, we are not tracing + // multiple rays per pixel when the ray doesn't intersect + // the ground. + sunColorV = sunColor(x, tF, v, s, r, mu, irradianceFactor); + } + + // Final Color of ATM plus terrain: + vec4 finalRadiance = vec4(inscatterColor + groundColorV + sunColorV, 1.0); + + atmosphereFinalColor += finalRadiance; + } + } + else { // no intersection + // Buffer color + atmosphereFinalColor += color; + } + + + renderTarget = atmosphereFinalColor; } else { // culling - vec4 bColor = vec4(0.0f); - for (int f = 0; f < nAaSamples; f++) { - bColor += texelFetch(mainColorTexture, fragCoords, f); - } - bColor /= float(nAaSamples); + vec4 bColor = texture(mainColorTexture, texCoord); renderTarget = bColor; } } diff --git a/modules/atmosphere/shaders/atmosphere_deferred_vs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_vs.glsl index 52cd01cb6e..33f0eb1651 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_vs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_vs.glsl @@ -27,9 +27,11 @@ layout(location = 0) in vec4 in_position; out vec3 interpolatedNDCPos; +out vec2 texCoord; void main() { + texCoord = 0.5 + in_position.xy * 0.5; interpolatedNDCPos = in_position.xyz; gl_Position = in_position; } diff --git a/openspace.cfg b/openspace.cfg index 85daf27146..c7e7bb63a0 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -166,7 +166,7 @@ LoadingScreen = { ShowNodeNames = true, ShowProgressbar = false } -CheckOpenGLState = false +CheckOpenGLState = true LogEachOpenGLCall = false ShutdownCountdown = 3 diff --git a/shaders/framebuffer/hdrAndFiltering.frag b/shaders/framebuffer/hdrAndFiltering.frag index cd943e2e14..997c68780a 100644 --- a/shaders/framebuffer/hdrAndFiltering.frag +++ b/shaders/framebuffer/hdrAndFiltering.frag @@ -40,19 +40,12 @@ uniform float Value; uniform float Lightness; uniform int nAaSamples; -uniform sampler2DMS hdrFeedingTexture; +uniform sampler2D hdrFeedingTexture; in vec2 texCoord; void main() { - vec4 color = vec4(0.0); - - // Resolving... - for (int i = 0; i < nAaSamples; i++) { - color += texelFetch(hdrFeedingTexture, ivec2(gl_FragCoord), i); - } - - color /= nAaSamples; + vec4 color = texture(hdrFeedingTexture, texCoord); color.rgb *= blackoutFactor; // Applies TMO diff --git a/shaders/framebuffer/renderframebuffer.frag b/shaders/framebuffer/renderframebuffer.frag index e7e18698b5..a20d685f4e 100644 --- a/shaders/framebuffer/renderframebuffer.frag +++ b/shaders/framebuffer/renderframebuffer.frag @@ -33,7 +33,6 @@ layout(location = 0) out vec4 _out_color_; layout(location = 1) out vec4 gPosition; layout(location = 2) out vec4 gNormal; -layout(location = 3) out vec4 filterBuffer; void main() { Fragment f = getFragment(); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 00f9f4f9e7..aebdab6991 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -167,31 +167,27 @@ void FramebufferRenderer::initialize() { //===== GBuffers Buffers =====// //==============================// glBindFramebuffer(GL_FRAMEBUFFER, _gBuffers._framebuffer); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._colorTexture, 0 ); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, - GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._positionTexture, 0 ); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, - GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._normalTexture, 0 ); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._depthTexture, 0 ); @@ -205,24 +201,21 @@ void FramebufferRenderer::initialize() { //===== PingPong Buffers =====// //==============================// glBindFramebuffer(GL_FRAMEBUFFER, _pingPongBuffers.framebuffer); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D_MULTISAMPLE, _pingPongBuffers.colorTexture[0], 0 ); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, - GL_TEXTURE_2D_MULTISAMPLE, _pingPongBuffers.colorTexture[1], 0 ); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._depthTexture, 0 ); @@ -237,17 +230,15 @@ void FramebufferRenderer::initialize() { //======================================// // Builds Exit Framebuffer glBindFramebuffer(GL_FRAMEBUFFER, _exitFramebuffer); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, _exitColorTexture, 0 ); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_TEXTURE_2D, _exitDepthTexture, 0 ); @@ -261,10 +252,9 @@ void FramebufferRenderer::initialize() { //===== HDR/Filtering Buffers =====// //===================================// glBindFramebuffer(GL_FRAMEBUFFER, _hdrBuffers._hdrFilteringFramebuffer); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, _hdrBuffers._hdrFilteringTexture, 0 ); @@ -278,10 +268,9 @@ void FramebufferRenderer::initialize() { //========== FXAA Buffers =========// //===================================// glBindFramebuffer(GL_FRAMEBUFFER, _fxaaBuffers._fxaaFramebuffer); - glFramebufferTexture2D( + glFramebufferTexture( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, _fxaaBuffers._fxaaTexture, 0 ); @@ -297,8 +286,6 @@ void FramebufferRenderer::initialize() { updateFXAA(); updateDeferredcastData(); - _dirtyMsaaSamplingPattern = true; - // Sets back to default FBO glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO); @@ -404,7 +391,7 @@ void FramebufferRenderer::applyTMO(float blackoutFactor) { ghoul::opengl::TextureUnit hdrFeedingTextureUnit; hdrFeedingTextureUnit.activate(); glBindTexture( - GL_TEXTURE_2D_MULTISAMPLE, + GL_TEXTURE_2D, _pingPongBuffers.colorTexture[_pingPongIndex] ); @@ -420,8 +407,6 @@ void FramebufferRenderer::applyTMO(float blackoutFactor) { _hdrFilteringProgram->setUniform(_hdrUniformCache.Hue, _hue); _hdrFilteringProgram->setUniform(_hdrUniformCache.Saturation, _saturation); _hdrFilteringProgram->setUniform(_hdrUniformCache.Value, _value); - _hdrFilteringProgram->setUniform(_hdrUniformCache.nAaSamples, _nAaSamples); - glBindVertexArray(_screenQuad); glDrawArrays(GL_TRIANGLES, 0, 6); @@ -558,61 +543,7 @@ void FramebufferRenderer::update() { } void FramebufferRenderer::updateResolution() { - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._colorTexture); - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_RGBA32F, - _resolution.x, - _resolution.y, - GL_TRUE - ); - - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._positionTexture); - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_RGBA32F, - _resolution.x, - _resolution.y, - GL_TRUE - ); - - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._normalTexture); - - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_RGBA32F, - _resolution.x, - _resolution.y, - GL_TRUE - ); - - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._depthTexture); - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_DEPTH_COMPONENT32F, - _resolution.x, - _resolution.y, - GL_TRUE - ); - - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _pingPongBuffers.colorTexture[1]); - glTexImage2DMultisample( - GL_TEXTURE_2D_MULTISAMPLE, - _nAaSamples, - GL_RGBA32F, - _resolution.x, - _resolution.y, - GL_TRUE - ); - - - // HDR / Filtering - glBindTexture(GL_TEXTURE_2D, _hdrBuffers._hdrFilteringTexture); - + glBindTexture(GL_TEXTURE_2D, _gBuffers._colorTexture); glTexImage2D( GL_TEXTURE_2D, 0, @@ -624,13 +555,87 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, _gBuffers._positionTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + _resolution.x, + _resolution.y, + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, _gBuffers._normalTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + _resolution.x, + _resolution.y, + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, _gBuffers._depthTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_DEPTH_COMPONENT32F, + _resolution.x, + _resolution.y, + 0, + GL_DEPTH_COMPONENT, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glBindTexture(GL_TEXTURE_2D, _pingPongBuffers.colorTexture[1]); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + _resolution.x, + _resolution.y, + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + // HDR / Filtering + glBindTexture(GL_TEXTURE_2D, _hdrBuffers._hdrFilteringTexture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + GL_RGBA32F, + _resolution.x, + _resolution.y, + 0, + GL_RGBA, + GL_FLOAT, + nullptr + ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // FXAA glBindTexture(GL_TEXTURE_2D, _fxaaBuffers._fxaaTexture); - glTexImage2D( GL_TEXTURE_2D, 0, @@ -642,7 +647,6 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -928,13 +932,8 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac glViewport(0, 0, _resolution.x, _resolution.y); - if (_disableHDR) { - resolveMSAA(blackoutFactor); - } - else { - // Apply the selected TMO on the results and resolve the result for the default FBO - applyTMO(blackoutFactor); - } + // Apply the selected TMO on the results and resolve the result for the default FBO + applyTMO(blackoutFactor); if (_enableFXAA) { glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO); @@ -1003,7 +1002,7 @@ void FramebufferRenderer::performRaycasterTasks(const std::vector ghoul::opengl::TextureUnit mainDepthTextureUnit; mainDepthTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._depthTexture); + glBindTexture(GL_TEXTURE_2D, _gBuffers._depthTexture); raycastProgram->setUniform("mainDepthTexture", mainDepthTextureUnit); raycastProgram->setUniform("nAaSamples", _nAaSamples); @@ -1058,9 +1057,8 @@ void FramebufferRenderer::performDeferredTasks( // adding G-Buffer ghoul::opengl::TextureUnit mainDColorTextureUnit; mainDColorTextureUnit.activate(); - //glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._colorTexture); glBindTexture( - GL_TEXTURE_2D_MULTISAMPLE, + GL_TEXTURE_2D, _pingPongBuffers.colorTexture[fromIndex] ); deferredcastProgram->setUniform( @@ -1070,7 +1068,7 @@ void FramebufferRenderer::performDeferredTasks( ghoul::opengl::TextureUnit mainPositionTextureUnit; mainPositionTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._positionTexture); + glBindTexture(GL_TEXTURE_2D, _gBuffers._positionTexture); deferredcastProgram->setUniform( "mainPositionTexture", mainPositionTextureUnit @@ -1078,14 +1076,12 @@ void FramebufferRenderer::performDeferredTasks( ghoul::opengl::TextureUnit mainNormalTextureUnit; mainNormalTextureUnit.activate(); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._normalTexture); + glBindTexture(GL_TEXTURE_2D, _gBuffers._normalTexture); deferredcastProgram->setUniform( "mainNormalTexture", mainNormalTextureUnit ); - deferredcastProgram->setUniform("nAaSamples", _nAaSamples); - deferredcaster->preRaycast( deferredcasterTask.renderData, _deferredcastData[deferredcaster], @@ -1136,7 +1132,6 @@ void FramebufferRenderer::setNAaSamples(int nAaSamples) { LERROR("Framebuffer renderer does not support more than 8 MSAA samples."); _nAaSamples = 8; } - _dirtyMsaaSamplingPattern = true; } void FramebufferRenderer::disableHDR(bool disable) {