Merge branch 'feature/FXAA' into feature/AALines2

This commit is contained in:
Jonathas Costa
2019-08-21 11:26:56 -04:00
5 changed files with 57 additions and 22 deletions

View File

@@ -1038,6 +1038,19 @@ void setSgctDelegateFunctions() {
sgct::SGCTWindow* w = sgct::Engine::instance()->getWindowPtr(0);
w->setHorizFieldOfView(hFovDeg);
};
sgctDelegate.frustumMode = []() {
using FM = sgct_core::Frustum::FrustumMode;
switch (sgct::Engine::instance()->getCurrentFrustumMode()) {
case FM::MonoEye: return WindowDelegate::Frustum::Mono;
case FM::StereoLeftEye: return WindowDelegate::Frustum::LeftEye;
case FM::StereoRightEye: return WindowDelegate::Frustum::RightEye;
}
};
sgctDelegate.swapGroupFrameNumber = []() {
unsigned int fn = 0;
sgct::Engine::instance()->getCurrentWindowPtr()->getSwapGroupFrameNumber(fn);
return static_cast<uint64_t>(fn);
};
}
int main(int argc, char** argv) {

View File

@@ -32,6 +32,8 @@
namespace openspace {
struct WindowDelegate {
enum class Frustum { Mono, LeftEye, RightEye };
void (*terminate)() = [](){};
void (*setBarrier)(bool enabled) = [](bool) {};
@@ -121,6 +123,10 @@ struct WindowDelegate {
GLProcAddress (*openGLProcedureAddress)(const char*) =
[](const char*) -> GLProcAddress { return []() {}; };
Frustum (*frustumMode)() = []() { return Frustum::Mono; };
uint64_t (*swapGroupFrameNumber)() = []() { return uint64_t(0); };
};
} // namespace openspace

View File

@@ -373,6 +373,8 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
glBindVertexArray(info._vaoID);
if (renderLines) {
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
p->setUniform(c.renderPhase, RenderPhaseLines);
// Subclasses of this renderer might be using the index array or might now be
// so we check if there is data available and if there isn't, we use the
@@ -392,6 +394,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
reinterpret_cast<void*>(info.first * sizeof(unsigned int))
);
}
glDisable(GL_LINE_SMOOTH);
}
if (renderPoints) {
// Subclasses of this renderer might be using the index array or might now be

View File

@@ -42,7 +42,7 @@ uniform sampler2D renderedTexture;
in vec2 texCoord;
// Relative luminance
float rgb2luma(vec3 rgb){
float getLum(vec3 rgb){
return dot(vec3(0.2126, 0.7152, 0.0722), rgb);
}
@@ -54,14 +54,14 @@ void main() {
// ============================
// Luma at the current fragment
float lumaCenter = rgb2luma(colorCenter.rgb);
float lumaCenter = getLum(colorCenter.rgb);
// Luma at the four direct neighbours of the current fragment.
float lumaDown = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(0,-1)).rgb);
float lumaUp = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(0,1)).rgb);
float lumaLeft = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(-1,0)).rgb);
float lumaRight = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(1,0)).rgb);
float lumaDown = getLum(textureOffset(renderedTexture, texCoord, ivec2(0,-1)).rgb);
float lumaUp = getLum(textureOffset(renderedTexture, texCoord, ivec2(0,1)).rgb);
float lumaLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,0)).rgb);
float lumaRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,0)).rgb);
// Find the maximum and minimum luma around the current fragment.
float lumaMin = min(lumaCenter, min(min(lumaDown, lumaUp), min(lumaLeft, lumaRight)));
float lumaMax = max(lumaCenter, max(max(lumaDown, lumaUp), max(lumaLeft, lumaRight)));
@@ -71,7 +71,7 @@ void main() {
// If the luma variation is lower that a threshold (or if we are in a really dark area),
// we are not on an edge, don't perform any AA.
if (lumaRange < max(EDGE_THRESHOLD_MIN,lumaMax * EDGE_THRESHOLD_MAX)) {
if (lumaRange < max(EDGE_THRESHOLD_MIN, lumaMax * EDGE_THRESHOLD_MAX)) {
aaFinalColor = colorCenter;
return;
}
@@ -80,10 +80,10 @@ void main() {
// Estimating the gradient:
// ============================
// Query the 4 remaining corners lumas.
float lumaDownLeft = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(-1,-1)).rgb);
float lumaUpRight = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(1,1)).rgb);
float lumaUpLeft = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(-1,1)).rgb);
float lumaDownRight = rgb2luma(textureOffset(renderedTexture, texCoord, ivec2(1,-1)).rgb);
float lumaDownLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,-1)).rgb);
float lumaUpRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,1)).rgb);
float lumaUpLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,1)).rgb);
float lumaDownRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,-1)).rgb);
// Combine the four edges lumas (using intermediary variables for future computations
// with the same values).
@@ -91,10 +91,10 @@ void main() {
float lumaLeftRight = lumaLeft + lumaRight;
// Same for corners
float lumaLeftCorners = lumaDownLeft + lumaUpLeft;
float lumaDownCorners = lumaDownLeft + lumaDownRight;
float lumaLeftCorners = lumaDownLeft + lumaUpLeft;
float lumaDownCorners = lumaDownLeft + lumaDownRight;
float lumaRightCorners = lumaDownRight + lumaUpRight;
float lumaUpCorners = lumaUpRight + lumaUpLeft;
float lumaUpCorners = lumaUpRight + lumaUpLeft;
// Compute an estimation of the gradient along the horizontal and vertical axis.
float edgeHorizontal = abs(-2.0 * lumaLeft + lumaLeftCorners) +
@@ -111,6 +111,7 @@ void main() {
// Select the two neighboring texels lumas in the opposite direction to the local edge.
float luma1 = isHorizontal ? lumaDown : lumaLeft;
float luma2 = isHorizontal ? lumaUp : lumaRight;
// Compute gradients in this direction.
float gradient1 = luma1 - lumaCenter;
float gradient2 = luma2 - lumaCenter;
@@ -156,8 +157,8 @@ void main() {
// Read the lumas at both current extremities of the exploration segment,
// and compute the delta wrt to the local average luma.
float lumaEnd1 = rgb2luma(texture(renderedTexture, uv1).rgb);
float lumaEnd2 = rgb2luma(texture(renderedTexture, uv2).rgb);
float lumaEnd1 = getLum(texture(renderedTexture, uv1).rgb);
float lumaEnd2 = getLum(texture(renderedTexture, uv2).rgb);
lumaEnd1 -= lumaLocalAverage;
lumaEnd2 -= lumaLocalAverage;
@@ -181,12 +182,12 @@ void main() {
for (int i = 2; i < ITERATIONS; i++) {
// If needed, read luma in 1st direction, compute delta.
if (!reached1) {
lumaEnd1 = rgb2luma(texture(renderedTexture, uv1).rgb);
lumaEnd1 = getLum(texture(renderedTexture, uv1).rgb);
lumaEnd1 = lumaEnd1 - lumaLocalAverage;
}
// If needed, read luma in opposite direction, compute delta.
if (!reached2) {
lumaEnd2 = rgb2luma(texture(renderedTexture, uv2).rgb);
lumaEnd2 = getLum(texture(renderedTexture, uv2).rgb);
lumaEnd2 = lumaEnd2 - lumaLocalAverage;
}
// If the luma deltas at the current extremities is larger than

View File

@@ -654,15 +654,25 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat
);
std::string fn = std::to_string(_frameNumber);
WindowDelegate::Frustum frustum = global::windowDelegate.frustumMode();
std::string fr = [](WindowDelegate::Frustum frustum) -> std::string {
switch (frustum) {
case WindowDelegate::Frustum::Mono: return "";
case WindowDelegate::Frustum::LeftEye: return "(left)";
case WindowDelegate::Frustum::RightEye: return "(right)";
}
}(frustum);
std::string sgFn = std::to_string(global::windowDelegate.swapGroupFrameNumber());
std::string dt = std::to_string(global::windowDelegate.deltaTime());
std::string avgDt = std::to_string(global::windowDelegate.averageDeltaTime());
std::string res = "Frame: " + fn + '\n' + "Dt: " + dt + '\n' + "Avg Dt: " + avgDt;
std::string res = "Frame: " + fn + ' ' + fr + '\n' +
"Swap group frame: " + sgFn + '\n' +
"Dt: " + dt + '\n' + "Avg Dt: " + avgDt;
RenderFont(*_fontFrameInfo, penPosition, res);
}
++_frameNumber;
if (masterEnabled && !delegate.isGuiWindow() && _globalBlackOutFactor > 0.f) {
std::vector<ScreenSpaceRenderable*> ssrs;
ssrs.reserve(global::screenSpaceRenderables.size());
@@ -844,6 +854,8 @@ void RenderEngine::renderDashboard() {
}
void RenderEngine::postDraw() {
++_frameNumber;
if (_shouldTakeScreenshot) {
// We only create the directory here, as we don't want to spam the users
// screenshot folder everytime we start OpenSpace even when we are not taking any