mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-20 03:49:31 -06:00
Get rid of MSAA GUI and updated framebuffer volume rendering (need more tests here).
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
asset.require('./base')
|
||||
asset.require('examples/volume/toyvolume')
|
||||
|
||||
local earthAsset = asset.require('scene/solarsystem/planets/earth/earth')
|
||||
|
||||
|
||||
@@ -136,14 +136,12 @@ public:
|
||||
void updateFXAA();
|
||||
|
||||
void setResolution(glm::ivec2 res) override;
|
||||
void setNAaSamples(int nAaSamples) override;
|
||||
void setHDRExposure(float hdrExposure) override;
|
||||
void setGamma(float gamma) override;
|
||||
void setHue(float hue) override;
|
||||
void setValue(float value) override;
|
||||
void setSaturation(float sat) override;
|
||||
|
||||
int nAaSamples() const override;
|
||||
void enableFXAA(bool enable) override;
|
||||
void disableHDR(bool disable) override;
|
||||
|
||||
@@ -164,7 +162,6 @@ public:
|
||||
DeferredcasterListener::IsAttached isAttached) override;
|
||||
|
||||
private:
|
||||
void resolveMSAA(float blackoutFactor);
|
||||
void applyTMO(float blackoutFactor);
|
||||
void applyFXAA();
|
||||
|
||||
@@ -182,9 +179,9 @@ private:
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _resolveProgram;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _fxaaProgram;
|
||||
|
||||
UniformCache(mainColorTexture, blackoutFactor, nAaSamples) _uniformCache;
|
||||
UniformCache(mainColorTexture, blackoutFactor) _uniformCache;
|
||||
UniformCache(hdrFeedingTexture, blackoutFactor, hdrExposure, gamma,
|
||||
Hue, Saturation, Value, nAaSamples) _hdrUniformCache;
|
||||
Hue, Saturation, Value) _hdrUniformCache;
|
||||
UniformCache(renderedTexture, inverseScreenSize) _fxaaUniformCache;
|
||||
|
||||
GLint _defaultFBO;
|
||||
|
||||
@@ -207,7 +207,6 @@ private:
|
||||
properties::BoolProperty _disableMasterRendering;
|
||||
|
||||
properties::FloatProperty _globalBlackOutFactor;
|
||||
properties::IntProperty _nAaSamples;
|
||||
|
||||
properties::BoolProperty _enableFXAA;
|
||||
|
||||
|
||||
@@ -49,13 +49,11 @@ public:
|
||||
virtual void deinitialize() = 0;
|
||||
|
||||
virtual void setResolution(glm::ivec2 res) = 0;
|
||||
virtual void setNAaSamples(int nAaSamples) = 0;
|
||||
virtual void setHDRExposure(float hdrExposure) = 0;
|
||||
virtual void setGamma(float gamma) = 0;
|
||||
virtual void setHue(float hue) = 0;
|
||||
virtual void setValue(float value) = 0;
|
||||
virtual void setSaturation(float sat) = 0;
|
||||
virtual int nAaSamples() const = 0;
|
||||
virtual void enableFXAA(bool enable) = 0;
|
||||
virtual void disableHDR(bool disable) = 0;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
uniform sampler2D exitColorTexture;
|
||||
uniform sampler2D exitDepthTexture;
|
||||
uniform sampler2DMS mainDepthTexture;
|
||||
uniform sampler2D mainDepthTexture;
|
||||
|
||||
uniform bool insideRaycaster;
|
||||
uniform vec3 cameraPosInRaycaster;
|
||||
@@ -46,9 +46,6 @@ out vec4 finalColor;
|
||||
|
||||
#define ALPHA_LIMIT 0.99
|
||||
#define RAYCAST_MAX_STEPS 1000
|
||||
#define MAX_AA_SAMPLES 8
|
||||
|
||||
uniform int nAaSamples;
|
||||
|
||||
#include <#{getEntryPath}>
|
||||
|
||||
@@ -76,25 +73,12 @@ void main() {
|
||||
vec3 direction = normalize(diff);
|
||||
float raycastDepth = length(diff);
|
||||
|
||||
float raycastDepths[MAX_AA_SAMPLES];
|
||||
|
||||
int i, j;
|
||||
float tmp;
|
||||
|
||||
for (i = 0; i < nAaSamples; i++) {
|
||||
float geoDepth = denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), i).x);
|
||||
float geoRatio = clamp((geoDepth - entryDepth) / (exitDepth - entryDepth), 0.0, 1.0);
|
||||
raycastDepths[i] = geoRatio * raycastDepth;
|
||||
}
|
||||
|
||||
for(i = 1; i < nAaSamples; ++i) {
|
||||
tmp = raycastDepths[i];
|
||||
for(j = i; j > 0 && tmp < raycastDepths[j - 1]; --j) {
|
||||
raycastDepths[j] = raycastDepths[j-1];
|
||||
}
|
||||
raycastDepths[j] = tmp;
|
||||
}
|
||||
|
||||
float geoDepth = denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), 0).x);
|
||||
float geoRatio = clamp((geoDepth - entryDepth) / (exitDepth - entryDepth), 0.0, 1.0);
|
||||
raycastDepth = geoRatio * raycastDepth;
|
||||
|
||||
float currentDepth = 0.0;
|
||||
// todo: shorten depth if geometry is intersecting!
|
||||
@@ -106,20 +90,20 @@ void main() {
|
||||
|
||||
float aaOpacity = 1.0;
|
||||
int sampleIndex = 0;
|
||||
float opacityDecay = 1.0 / nAaSamples;
|
||||
float opacityDecay = 1.0;
|
||||
|
||||
vec3 accumulatedColor = vec3(0.0);
|
||||
vec3 accumulatedAlpha = vec3(0.0);
|
||||
|
||||
|
||||
for (steps = 0; (accumulatedAlpha.r < ALPHA_LIMIT || accumulatedAlpha.g < ALPHA_LIMIT || accumulatedAlpha.b < ALPHA_LIMIT) && steps < RAYCAST_MAX_STEPS; ++steps) {
|
||||
while (sampleIndex < nAaSamples && currentDepth + nextStepSize * jitterFactor > raycastDepths[sampleIndex]) {
|
||||
sampleIndex++;
|
||||
for (steps = 0; (accumulatedAlpha.r < ALPHA_LIMIT || accumulatedAlpha.g < ALPHA_LIMIT ||
|
||||
accumulatedAlpha.b < ALPHA_LIMIT) && steps < RAYCAST_MAX_STEPS; ++steps) {
|
||||
if (currentDepth + nextStepSize * jitterFactor > raycastDepth) {
|
||||
aaOpacity -= opacityDecay;
|
||||
}
|
||||
bool shortStepSize = nextStepSize < raycastDepth / 10000000000.0;
|
||||
|
||||
if (sampleIndex >= nAaSamples || shortStepSize) {
|
||||
if (shortStepSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -139,7 +123,7 @@ void main() {
|
||||
|
||||
previousJitterDistance = currentStepSize - jitteredStepSize;
|
||||
|
||||
float maxStepSize = raycastDepths[nAaSamples - 1] - currentDepth;
|
||||
float maxStepSize = raycastDepth - currentDepth;
|
||||
|
||||
nextStepSize = min(nextStepSize, maxStepSize);
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "FramebufferRenderer";
|
||||
|
||||
constexpr const std::array<const char*, 3> UniformNames = {
|
||||
"mainColorTexture", "blackoutFactor", "nAaSamples"
|
||||
constexpr const std::array<const char*, 2> UniformNames = {
|
||||
"mainColorTexture", "blackoutFactor"
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 8> HDRUniformNames = {
|
||||
constexpr const std::array<const char*, 7> HDRUniformNames = {
|
||||
"hdrFeedingTexture", "blackoutFactor", "hdrExposure", "gamma",
|
||||
"Hue", "Saturation", "Value", "nAaSamples"
|
||||
"Hue", "Saturation", "Value"
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 2> FXAAUniformNames = {
|
||||
@@ -316,7 +316,6 @@ void FramebufferRenderer::initialize() {
|
||||
|
||||
// Default GL State for Blending
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
}
|
||||
|
||||
void FramebufferRenderer::deinitialize() {
|
||||
@@ -360,23 +359,6 @@ void FramebufferRenderer::deferredcastersChanged(Deferredcaster&,
|
||||
_dirtyDeferredcastData = true;
|
||||
}
|
||||
|
||||
void FramebufferRenderer::resolveMSAA(float blackoutFactor) {
|
||||
_resolveProgram->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit mainColorTextureUnit;
|
||||
mainColorTextureUnit.activate();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _gBuffers._colorTexture);
|
||||
_resolveProgram->setUniform(_uniformCache.mainColorTexture, mainColorTextureUnit);
|
||||
_resolveProgram->setUniform(_uniformCache.blackoutFactor, blackoutFactor);
|
||||
_resolveProgram->setUniform(_uniformCache.nAaSamples, _nAaSamples);
|
||||
glBindVertexArray(_screenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glBindVertexArray(0);
|
||||
|
||||
_resolveProgram->deactivate();
|
||||
}
|
||||
|
||||
void FramebufferRenderer::applyTMO(float blackoutFactor) {
|
||||
const bool doPerformanceMeasurements = global::performanceManager.isEnabled();
|
||||
std::unique_ptr<performance::PerformanceMeasurement> perfInternal;
|
||||
@@ -1005,7 +987,6 @@ void FramebufferRenderer::performRaycasterTasks(const std::vector<RaycasterTask>
|
||||
glBindTexture(GL_TEXTURE_2D, _gBuffers._depthTexture);
|
||||
raycastProgram->setUniform("mainDepthTexture", mainDepthTextureUnit);
|
||||
|
||||
raycastProgram->setUniform("nAaSamples", _nAaSamples);
|
||||
raycastProgram->setUniform("windowSize", static_cast<glm::vec2>(_resolution));
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@@ -1119,21 +1100,6 @@ void FramebufferRenderer::setResolution(glm::ivec2 res) {
|
||||
_dirtyResolution = true;
|
||||
}
|
||||
|
||||
void FramebufferRenderer::setNAaSamples(int nAaSamples) {
|
||||
ghoul_assert(
|
||||
nAaSamples >= 1 && nAaSamples <= 8,
|
||||
"Number of AA samples has to be between 1 and 8"
|
||||
);
|
||||
_nAaSamples = nAaSamples;
|
||||
if (_nAaSamples == 0) {
|
||||
_nAaSamples = 1;
|
||||
}
|
||||
if (_nAaSamples > 8) {
|
||||
LERROR("Framebuffer renderer does not support more than 8 MSAA samples.");
|
||||
_nAaSamples = 8;
|
||||
}
|
||||
}
|
||||
|
||||
void FramebufferRenderer::disableHDR(bool disable) {
|
||||
_disableHDR = std::move(disable);
|
||||
}
|
||||
@@ -1161,10 +1127,6 @@ void FramebufferRenderer::setSaturation(float sat) {
|
||||
_saturation = std::move(sat);
|
||||
}
|
||||
|
||||
int FramebufferRenderer::nAaSamples() const {
|
||||
return _nAaSamples;
|
||||
}
|
||||
|
||||
void FramebufferRenderer::enableFXAA(bool enable) {
|
||||
_enableFXAA = std::move(enable);
|
||||
}
|
||||
|
||||
@@ -192,13 +192,6 @@ namespace {
|
||||
"direction for tilted display systems in clustered immersive environments."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo AaSamplesInfo = {
|
||||
"AaSamples",
|
||||
"Number of Anti-aliasing samples",
|
||||
"This value determines the number of anti-aliasing samples to be used in the "
|
||||
"rendering for the MSAA method."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableHDRPipelineInfo = {
|
||||
"DisableHDRPipeline",
|
||||
"Disable HDR Rendering",
|
||||
@@ -279,8 +272,7 @@ RenderEngine::RenderEngine()
|
||||
#endif // OPENSPACE_WITH_INSTRUMENTATION
|
||||
, _disableMasterRendering(DisableMasterInfo, false)
|
||||
, _globalBlackOutFactor(GlobalBlackoutFactorInfo, 1.f, 0.f, 1.f)
|
||||
, _nAaSamples(AaSamplesInfo, 4, 1, 8)
|
||||
, _enableFXAA(FXAAInfo, false)
|
||||
, _enableFXAA(FXAAInfo, true)
|
||||
, _disableHDRPipeline(DisableHDRPipelineInfo, false)
|
||||
, _hdrExposure(HDRExposureInfo, 3.7f, 0.01f, 10.0f)
|
||||
, _gamma(GammaInfo, 0.86f, 0.01f, 5.0f)
|
||||
@@ -317,13 +309,6 @@ RenderEngine::RenderEngine()
|
||||
addProperty(_showVersionInfo);
|
||||
addProperty(_showCameraInfo);
|
||||
|
||||
_nAaSamples.onChange([this](){
|
||||
if (_renderer) {
|
||||
_renderer->setNAaSamples(_nAaSamples);
|
||||
}
|
||||
});
|
||||
addProperty(_nAaSamples);
|
||||
|
||||
_enableFXAA.onChange([this]() {
|
||||
if (_renderer) {
|
||||
_renderer->enableFXAA(_enableFXAA);
|
||||
@@ -471,8 +456,6 @@ void RenderEngine::initialize() {
|
||||
void RenderEngine::initializeGL() {
|
||||
LTRACE("RenderEngine::initializeGL(begin)");
|
||||
|
||||
_nAaSamples = global::windowDelegate.currentNumberOfAaSamples();
|
||||
|
||||
std::string renderingMethod = global::configuration.renderingMethod;
|
||||
if (renderingMethod == "ABuffer") {
|
||||
using Version = ghoul::systemcapabilities::Version;
|
||||
@@ -1080,7 +1063,7 @@ void RenderEngine::setRenderer(std::unique_ptr<Renderer> renderer) {
|
||||
|
||||
_renderer = std::move(renderer);
|
||||
_renderer->setResolution(renderingResolution());
|
||||
_renderer->setNAaSamples(_nAaSamples);
|
||||
_renderer->enableFXAA(true);
|
||||
_renderer->setHDRExposure(_hdrExposure);
|
||||
_renderer->initialize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user