Cleanup in Renderers

This commit is contained in:
Alexander Bock
2018-04-22 09:15:42 +00:00
parent 7068637c9d
commit a881eef156
16 changed files with 287 additions and 431 deletions

View File

@@ -45,7 +45,7 @@ namespace ghoul::filesystem { class File; }
namespace ghoul::opengl {
class ProgramObject;
class Texture;
} // namespace opengl
} // namespace ghoul::opengl
namespace openspace {
@@ -61,8 +61,6 @@ public:
void initialize() override;
void deinitialize() override;
void setCamera(Camera* camera) override;
void setScene(Scene* scene) override;
void setResolution(glm::ivec2 res) override;
void setNAaSamples(int nAaSamples) override;
void setHDRExposure(float hdrExposure) override;
@@ -79,7 +77,8 @@ public:
void postRaycast(const RaycasterTask& raycasterTask);
void update() override;
void render(float blackoutFactor, bool doPerformanceMeasurements) override;
void render(Scene* scene, Camera* camera, float blackoutFactor,
bool doPerformanceMeasurements) override;
/**
* Update render data
@@ -97,8 +96,6 @@ private:
void saveTextureToMemory(const GLenum color_buffer_attachment,
const int width, const int height, std::vector<double> & memory) const;
Camera* _camera;
Scene* _scene;
glm::ivec2 _resolution;
bool _dirtyResolution;

View File

@@ -44,7 +44,7 @@ namespace ghoul::filesystem { class File; }
namespace ghoul::opengl {
class ProgramObject;
class Texture;
}
} // namespace ghoul::opengl
namespace openspace {
@@ -67,8 +67,6 @@ public:
void updateHDRData();
void updateMSAASamplingPattern();
void setCamera(Camera* camera) override;
void setScene(Scene* scene) override;
void setResolution(glm::ivec2 res) override;
void setNAaSamples(int nAaSamples) override;
void setHDRExposure(float hdrExposure) override;
@@ -81,7 +79,8 @@ public:
std::vector<double> mSSAPattern() const override;
void update() override;
void render(float blackoutFactor, bool doPerformanceMeasurements) override;
void render(Scene* scene, Camera* camera, float blackoutFactor,
bool doPerformanceMeasurements) override;
/**
* Update render data
@@ -132,8 +131,6 @@ private:
bool _dirtyRaycastData;
bool _dirtyResolution;
Camera* _camera;
Scene* _scene;
glm::vec2 _resolution;
int _nAaSamples;
float _hdrExposure;

View File

@@ -52,8 +52,6 @@ public:
virtual void initialize() = 0;
virtual void deinitialize() = 0;
virtual void setCamera(Camera* camera) = 0;
virtual void setScene(Scene* scene) = 0;
virtual void setResolution(glm::ivec2 res) = 0;
virtual void setNAaSamples(int nAaSamples) = 0;
virtual void setHDRExposure(float hdrExposure) = 0;
@@ -77,7 +75,8 @@ public:
virtual void update() = 0;
virtual void render(float blackoutFactor, bool doPerformanceMeasurements) = 0;
virtual void render(Scene* scene, Camera* camera, float blackoutFactor,
bool doPerformanceMeasurements) = 0;
/**
* Update render data
* Responsible for calling renderEngine::setRenderData

View File

@@ -1,31 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
out vec4 renderTableColor;
void main() {
renderTableColor = vec4(0.0);
}

View File

@@ -1,31 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
layout(location = 0) in vec3 in_position;
void main() {
gl_Position = vec4(in_position, 1.0);
}

View File

@@ -25,15 +25,14 @@
#ifndef _BLENDING_GLSL_
#define _BLENDING_GLSL_
/**
* Blend in src behind dst using normal blending
* dst is premultiplied
* src is expressed in straight RGBA
*/
void normalBlend(inout vec4 dst, vec4 src) {
dst.rgb = dst.rgb + (1.0 - dst.a) * src.a * src.rgb;
dst.a = dst.a + (1.0 - dst.a) * src.a;
dst.rgb = dst.rgb + (1.f - dst.a) * src.a * src.rgb;
dst.a = dst.a + (1.f - dst.a) * src.a;
}
/**
@@ -42,7 +41,7 @@ void normalBlend(inout vec4 dst, vec4 src) {
* src is expressed in straight RGBA
*/
void additiveBlend(inout vec4 dst, vec4 src) {
dst.rgb = dst.rgb + (1.0 - dst.a) * src.a * src.rgb;// dst.rgb = dst.rgb + src.a * src.rgb;
dst.rgb = dst.rgb + (1.f - dst.a) * src.a * src.rgb;// dst.rgb = dst.rgb + src.a * src.rgb;
//dst.a = dst.a + src.a;
}
@@ -55,7 +54,7 @@ void additiveBlend(inout vec4 dst, vec4 src) {
* stepSize = 1: alpha becomes src.a
*/
void normalBlendStep(inout vec4 dst, vec4 src, float stepSize) {
src.a = 1.0 - pow(1.0 - src.a, stepSize);
src.a = 1.f - pow(1.f - src.a, stepSize);
normalBlend(dst, src);
}
@@ -77,8 +76,8 @@ void additiveBlendStep(inout vec4 dst, vec4 src, float stepSize) {
* src is expressed in straight RGBA
*/
void blend(inout vec4 dst, vec4 src) {
dst.rgb = dst.rgb + (1.0 - dst.a) * src.a * src.rgb;
dst.a = dst.a + (1.0 - dst.a) * src.a;
dst.rgb = dst.rgb + (1.f - dst.a) * src.a * src.rgb;
dst.a = dst.a + (1.f - dst.a) * src.a;
}
/**
@@ -89,8 +88,8 @@ void blend(inout vec4 dst, vec4 src) {
* stepSize = 1: alpha becomes src.a
*/
void blendStep(inout vec4 dst, vec4 src, float stepSize) {
src.a = 1.0 - pow(1.0 - src.a, stepSize);
src.a = 1.0 - pow(1.f - src.a, stepSize);
blend(dst, src);
}
#endif
#endif // _BLENDING_GLSL_

View File

@@ -25,7 +25,6 @@
#ifndef _FLOATOPERATIONS_GLSL_
#define _FLOATOPERATIONS_GLSL_
/**
* Convert a positive floating point distance [0, 10^27]
* (size of observable universe)
@@ -51,43 +50,44 @@ float denormalizeFloat(float inpt) {
/**
* Compute the length of a vector.
* Supporting huge vectors, where the square of any of the components is too large to represent as a float.
* Supporting huge vectors, where the square of any of the components is too large to be
* represented as a float.
*/
float safeLength(vec4 v) {
float m = max(max(max(abs(v.x), abs(v.y)), abs(v.z)), abs(v.w));
if (m > 0.0) {
if (m > 0.f) {
return length(v / m) * m;
} else {
return 0;
return 0.f;
}
}
float safeLength(vec3 v) {
float m = max(max(abs(v.x), abs(v.y)), abs(v.z));
if (m > 0.0) {
if (m > 0.f) {
return length(v / m) * m;
} else {
return 0;
return 0.f;
}
}
float safeLength(vec2 v) {
float m = max(abs(v.x), abs(v.y));
if (m > 0.0) {
if (m > 0.f) {
return length(v / m) * m;
} else {
return 0;
return 0.f;
}
}
/**
* Normalize a vector
* Supporting huge vectors, where the square of any of the components is too large to represent as a float.
* Supporting huge vectors, where the square of any of the components is too large to be
* represent as a float.
*/
vec3 safeNormalize(vec3 v) {
float m = max(max(abs(v.x), abs(v.y)), abs(v.z));
return normalize(v / m);
}
#endif
#endif // _FLOATOPERATIONS_GLSL_

View File

@@ -36,11 +36,11 @@ uniform sampler2DMS mainColorTexture;
void main() {
vec4 color = vec4(0.0);
for (int i = 0; i < nAaSamples; i++) {
color += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
color += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
}
color /= nAaSamples;
//color.rgb *= blackoutFactor;
// color.rgb *= blackoutFactor;
finalColor = vec4(HDR(color.rgb * backgroundConstant, backgroundExposure), 1.0);
finalColor = vec4(HDR(color.rgb * backgroundConstant, backgroundExposure), 1.0);
}

View File

@@ -27,7 +27,7 @@
layout (location = 0) out vec4 finalColor;
in vec2 vTexCoord;
flat in vec3 vPosition;
// flat in vec3 vPosition;
uniform int currentSample;
uniform sampler2DMS pixelSizeTexture;

View File

@@ -28,11 +28,11 @@ layout(location = 0) in vec4 position;
layout(location = 1) in vec2 texCoord;
out vec2 vTexCoord;
flat out vec3 vPosition;
// flat out vec3 vPosition;
void main() {
vTexCoord = texCoord;
vPosition = position.xyz;
// vPosition = position.xyz;
gl_Position = position;
}

View File

@@ -28,6 +28,6 @@ layout (location = 0) out vec4 finalColor;
flat in vec3 vPosition;
void main() {
finalColor = vec4(0.5 * vPosition + 0.5, 1.0);
void main() {
finalColor = vec4(0.5 * vPosition + 0.5, 1.0);
}

View File

@@ -113,8 +113,6 @@ void main() {
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++;
aaOpacity -= opacityDecay;
@@ -132,7 +130,6 @@ void main() {
vec3 jitteredPosition = position + direction*jitteredStepSize;
position += direction * currentStepSize;
sample#{id}(jitteredPosition, direction, accumulatedColor, accumulatedAlpha, nextStepSize);
float sampleDistance = aaOpacity * (jitteredStepSize + previousJitterDistance);

View File

@@ -22,10 +22,9 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
//uniform float exposure;
uniform float gamma;
vec3 exponentialToneMapping(vec3 color, const float exposure) {
vec3 exponentialToneMapping(vec3 color, float exposure) {
color *= exposure;
color.r = color.r < 1.413 ? pow(color.r * 0.38317, 1.0 / gamma) : 1.0 - exp(-color.r);
@@ -35,62 +34,58 @@ vec3 exponentialToneMapping(vec3 color, const float exposure) {
return color;
}
vec3 linearToneMapping(vec3 color, const float exposure) {
vec3 linearToneMapping(vec3 color, float exposure) {
float tExposure = 0.08f;
color = clamp(tExposure * color, 0.0f, 1.0f);
color = pow(color, vec3(1.0f / gamma));
color = clamp(tExposure * color, 0.f, 1.f);
color = pow(color, vec3(1.f / gamma));
return color;
}
vec3 simpleReinhardToneMapping(vec3 color, const float exposure) {
vec3 simpleReinhardToneMapping(vec3 color, float exposure) {
float tExposure = 1.5f;
color *= tExposure/(1.0f + color / tExposure);
color = pow(color, vec3(1. / gamma));
color *= tExposure/(1.f + color / tExposure);
color = pow(color, vec3(1.f / gamma));
return color;
}
vec3 lumaBasedReinhardToneMapping(vec3 color, const float exposure)
{
vec3 lumaBasedReinhardToneMapping(vec3 color, float exposure) {
float luma = dot(color, vec3(0.2126f, 0.7152f, 0.0722f));
float toneMappedLuma = luma / (1.0f + luma);
float toneMappedLuma = luma / (1.f + luma);
color *= toneMappedLuma / luma;
color = pow(color, vec3(1.0f / gamma));
color = pow(color, vec3(1.f / gamma));
return color;
}
vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color, const float exposure)
{
float white = 4.0f;
vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color, float exposure) {
float white = 4.f;
//float luma = dot(color, vec3(0.2126f, 0.7152f, 0.0722f));
float luma = dot(color, vec3(0.4126f, 0.9152f, 0.2722f));
float toneMappedLuma = luma * (1.0f + luma / (white * white)) / (1.0f + luma);
float toneMappedLuma = luma * (1.f + luma / (white * white)) / (1.f + luma);
color *= toneMappedLuma / luma;
color = pow(color, vec3(1.0f / gamma));
color = pow(color, vec3(1.f / gamma));
return color;
}
vec3 RomBinDaHouseToneMapping(vec3 color, const float exposure)
{
color = exp( -1.0f / ( 2.72f * color + 0.15f ) );
color = pow(color, vec3(1.7 / gamma));
vec3 RomBinDaHouseToneMapping(vec3 color, float exposure) {
color = exp( -1.f / ( 2.72f * color + 0.15f ) );
color = pow(color, vec3(1.7f / gamma));
return color;
}
vec3 filmicToneMapping(vec3 color, const float exposure)
vec3 filmicToneMapping(vec3 color, float exposure)
{
color = max(vec3(0.0f), color - vec3(0.04f));
color = (color * (6.2f * color + 0.5f)) / (color * (6.2f * color + 20.0f) + 0.06f);
color = max(vec3(0.f), color - vec3(0.04f));
color = (color * (6.2f * color + 0.5f)) / (color * (6.2f * color + 20.f) + 0.06f);
return color;
}
vec3 Uncharted2ToneMapping(vec3 color, const float exposure)
{
vec3 Uncharted2ToneMapping(vec3 color, float exposure) {
float A = 0.15f;
float B = 0.50f;
float C = 0.10f;
float D = 0.20f;
float B = 0.5f;
float C = 0.1f;
float D = 0.2f;
float E = 0.02f;
float F = 0.30f;
float F = 0.3f;
float W = 11.2f;
float tExposure = 0.4f;
color *= tExposure;
@@ -101,7 +96,7 @@ vec3 Uncharted2ToneMapping(vec3 color, const float exposure)
return color;
}
vec3 jToneMapping(const vec3 color, const float exposure) {
vec3 jToneMapping(vec3 color, float exposure) {
return 1.0 - exp(-exposure * color);
}

View File

@@ -59,9 +59,7 @@ namespace {
namespace openspace {
ABufferRenderer::ABufferRenderer()
: _camera(nullptr)
, _scene(nullptr)
, _resolution(glm::ivec2(0))
: _resolution(glm::ivec2(0))
, _dirtyResolution(true)
, _dirtyRendererData(true)
, _dirtyRaycastData(true)
@@ -76,15 +74,15 @@ ABufferRenderer::~ABufferRenderer() {}
void ABufferRenderer::initialize() {
LINFO("Initializing ABufferRenderer");
const GLfloat size = 1.0f;
const GLfloat size = 1.f;
const GLfloat vertex_data[] = {
// x y s t
-size, -size, 0.0f, 1.0f,
size, size, 0.0f, 1.0f,
-size, size, 0.0f, 1.0f,
-size, -size, 0.0f, 1.0f,
size, -size, 0.0f, 1.0f,
size, size, 0.0f, 1.0f,
-size, -size, 0.f, 1.f,
size, size, 0.f, 1.f,
-size, size, 0.f, 1.f,
-size, -size, 0.f, 1.f,
size, -size, 0.f, 1.f,
size, size, 0.f, 1.f,
};
@@ -95,14 +93,7 @@ void ABufferRenderer::initialize() {
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 4,
nullptr
);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, nullptr);
glEnableVertexAttribArray(0);
glGenTextures(1, &_anchorPointerTexture);
@@ -230,8 +221,9 @@ void ABufferRenderer::update() {
LERRORC(error.component, error.message);
}
}
for (auto &program : _boundsPrograms) {
using K = VolumeRaycaster* const;
using V = std::unique_ptr<ghoul::opengl::ProgramObject>;
for (std::pair<K, V>& program : _boundsPrograms) {
if (program.second->isDirty()) {
try {
program.second->rebuildFromFile();
@@ -243,57 +235,59 @@ void ABufferRenderer::update() {
}
void ABufferRenderer::updateMSAASamplingPattern() {
// @CLEANUP(abock): This should probably be merged with the same code from the
// framebuffer renderer?
LINFO("Updating MSAA Sampling Pattern");
const int GRIDSIZE = 32;
GLfloat step = 2.0f / static_cast<GLfloat>(GRIDSIZE);
GLfloat sizeX = -1.0f,
sizeY = 1.0f;
constexpr const int GridSize = 32;
GLfloat step = 2.f / static_cast<GLfloat>(GridSize);
GLfloat sizeX = -1.0f;
GLfloat sizeY = 1.0f;
const int NVERTEX = 4 * 6;
constexpr const int NVertex = 4 * 6;
// openPixelSizeVertexData
GLfloat vertexData[GRIDSIZE * GRIDSIZE * NVERTEX];
GLfloat vertexData[GridSize * GridSize * NVertex];
for (int y = 0; y < GRIDSIZE; ++y) {
for (int x = 0; x < GRIDSIZE; ++x) {
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX] = sizeX;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 1] = sizeY - step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 2] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 3] = 1.0f;
for (int y = 0; y < GridSize; ++y) {
for (int x = 0; x < GridSize; ++x) {
vertexData[y * GridSize * NVertex + x * NVertex] = sizeX;
vertexData[y * GridSize * NVertex + x * NVertex + 1] = sizeY - step;
vertexData[y * GridSize * NVertex + x * NVertex + 2] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 3] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 4] = sizeX + step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 5] = sizeY;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 6] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 7] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 4] = sizeX + step;
vertexData[y * GridSize * NVertex + x * NVertex + 5] = sizeY;
vertexData[y * GridSize * NVertex + x * NVertex + 6] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 7] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 8] = sizeX;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 9] = sizeY;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 10] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 11] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 8] = sizeX;
vertexData[y * GridSize * NVertex + x * NVertex + 9] = sizeY;
vertexData[y * GridSize * NVertex + x * NVertex + 10] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 11] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 12] = sizeX;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 13] = sizeY - step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 14] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 15] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 12] = sizeX;
vertexData[y * GridSize * NVertex + x * NVertex + 13] = sizeY - step;
vertexData[y * GridSize * NVertex + x * NVertex + 14] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 15] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 16] = sizeX + step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 17] = sizeY - step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 18] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 19] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 16] = sizeX + step;
vertexData[y * GridSize * NVertex + x * NVertex + 17] = sizeY - step;
vertexData[y * GridSize * NVertex + x * NVertex + 18] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 19] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 20] = sizeX + step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 21] = sizeY;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 22] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 23] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 20] = sizeX + step;
vertexData[y * GridSize * NVertex + x * NVertex + 21] = sizeY;
vertexData[y * GridSize * NVertex + x * NVertex + 22] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 23] = 1.f;
sizeX += step;
}
sizeX = -1.0f;
sizeX = -1.f;
sizeY -= step;
}
GLuint pixelSizeQuadVAO = 0,
pixelSizeQuadVBO = 0;
GLuint pixelSizeQuadVAO = 0;
GLuint pixelSizeQuadVBO = 0;
glGenVertexArrays(1, &pixelSizeQuadVAO);
glBindVertexArray(pixelSizeQuadVAO);
@@ -303,20 +297,13 @@ void ABufferRenderer::updateMSAASamplingPattern() {
glBufferData(
GL_ARRAY_BUFFER,
sizeof(GLfloat) * GRIDSIZE * GRIDSIZE * NVERTEX,
sizeof(GLfloat) * GridSize * GridSize * NVertex,
vertexData,
GL_STATIC_DRAW
);
// Position
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
0,
nullptr
);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(0);
// Saves current state
@@ -366,17 +353,12 @@ void ABufferRenderer::updateMSAASamplingPattern() {
return;
}
std::unique_ptr<ghoul::opengl::ProgramObject> pixelSizeProgram = nullptr;
try {
pixelSizeProgram = ghoul::opengl::ProgramObject::Build(
std::unique_ptr<ghoul::opengl::ProgramObject> pixelSizeProgram =
ghoul::opengl::ProgramObject::Build(
"OnePixel MSAA",
"${SHADERS}/framebuffer/pixelSizeMSAA.vert",
"${SHADERS}/framebuffer/pixelSizeMSAA.frag"
);
}
catch (const ghoul::RuntimeError& e) {
LERRORC(e.component, e.message);
}
pixelSizeProgram->activate();
@@ -385,7 +367,7 @@ void ABufferRenderer::updateMSAASamplingPattern() {
glBindVertexArray(pixelSizeQuadVAO);
glDisable(GL_DEPTH_TEST);
glDepthMask(false);
glDrawArrays(GL_TRIANGLES, 0, GRIDSIZE * GRIDSIZE * 6);
glDrawArrays(GL_TRIANGLES, 0, GridSize * GridSize * 6);
glBindVertexArray(0);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
@@ -394,58 +376,58 @@ void ABufferRenderer::updateMSAASamplingPattern() {
pixelSizeProgram->deactivate();
// Now we render the Nx1 quad strip
GLuint nOneStripFramebuffer = 0,
nOneStripVAO = 0,
nOneStripVBO = 0,
nOneStripTexture = 0;
GLuint nOneStripFramebuffer = 0;
GLuint nOneStripVAO = 0;
GLuint nOneStripVBO = 0;
GLuint nOneStripTexture = 0;
sizeX = -1.0f;
step = 2.0f / static_cast<GLfloat>(_nAaSamples);
sizeX = -1.f;
step = 2.f / static_cast<GLfloat>(_nAaSamples);
GLfloat * nOneStripVertexData = new GLfloat[_nAaSamples * (NVERTEX + 12)];
std::vector<GLfloat> nOneStripVertexData(_nAaSamples * (NVertex + 12));
for (int x = 0; x < _nAaSamples; ++x) {
nOneStripVertexData[x * (NVERTEX + 12)] = sizeX;
nOneStripVertexData[x * (NVERTEX + 12) + 1] = -1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 2] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 3] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 4] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 5] = 0.0f;
nOneStripVertexData[x * (NVertex + 12)] = sizeX;
nOneStripVertexData[x * (NVertex + 12) + 1] = -1.0f;
nOneStripVertexData[x * (NVertex + 12) + 2] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 3] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 4] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 5] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 6] = sizeX + step;
nOneStripVertexData[x * (NVERTEX + 12) + 7] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 8] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 9] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 10] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 11] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 6] = sizeX + step;
nOneStripVertexData[x * (NVertex + 12) + 7] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 8] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 9] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 10] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 11] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 12] = sizeX;
nOneStripVertexData[x * (NVERTEX + 12) + 13] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 14] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 15] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 16] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 17] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 12] = sizeX;
nOneStripVertexData[x * (NVertex + 12) + 13] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 14] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 15] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 16] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 17] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 18] = sizeX;
nOneStripVertexData[x * (NVERTEX + 12) + 19] = -1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 20] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 21] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 22] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 23] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 18] = sizeX;
nOneStripVertexData[x * (NVertex + 12) + 19] = -1.0f;
nOneStripVertexData[x * (NVertex + 12) + 20] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 21] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 22] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 23] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 24] = sizeX + step;
nOneStripVertexData[x * (NVERTEX + 12) + 25] = -1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 26] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 27] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 28] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 29] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 24] = sizeX + step;
nOneStripVertexData[x * (NVertex + 12) + 25] = -1.0f;
nOneStripVertexData[x * (NVertex + 12) + 26] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 27] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 28] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 29] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 30] = sizeX + step;
nOneStripVertexData[x * (NVERTEX + 12) + 31] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 32] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 33] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 34] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 35] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 30] = sizeX + step;
nOneStripVertexData[x * (NVertex + 12) + 31] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 32] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 33] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 34] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 35] = 1.0f;
sizeX += step;
}
@@ -456,8 +438,8 @@ void ABufferRenderer::updateMSAASamplingPattern() {
glBindBuffer(GL_ARRAY_BUFFER, nOneStripVBO);
glBufferData(
GL_ARRAY_BUFFER,
sizeof(GLfloat) * _nAaSamples * (NVERTEX + 12),
nOneStripVertexData,
sizeof(GLfloat) * _nAaSamples * (NVertex + 12),
nOneStripVertexData.data(),
GL_STATIC_DRAW
);
@@ -482,7 +464,6 @@ void ABufferRenderer::updateMSAASamplingPattern() {
reinterpret_cast<GLvoid*>(sizeof(GLfloat) * 4)
);
glEnableVertexAttribArray(1);
delete[] nOneStripVertexData;
// fbo texture buffer
glGenTextures(1, &nOneStripTexture);
@@ -519,17 +500,12 @@ void ABufferRenderer::updateMSAASamplingPattern() {
glViewport(0, 0, _nAaSamples, ONEPIXEL);
std::unique_ptr<ghoul::opengl::ProgramObject> nOneStripProgram = nullptr;
try {
nOneStripProgram = ghoul::opengl::ProgramObject::Build(
std::unique_ptr<ghoul::opengl::ProgramObject> nOneStripProgram =
ghoul::opengl::ProgramObject::Build(
"OneStrip MSAA",
"${SHADERS}/framebuffer/nOneStripMSAA.vert",
"${SHADERS}/framebuffer/nOneStripMSAA.frag"
);
}
catch (const ghoul::RuntimeError& e) {
LERRORC(e.component, e.message);
}
nOneStripProgram->activate();
@@ -541,7 +517,7 @@ void ABufferRenderer::updateMSAASamplingPattern() {
// render strip
glDrawBuffers(1, textureBuffers);
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClearColor(0.f, 1.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(nOneStripVAO);
glDisable(GL_DEPTH_TEST);
@@ -584,10 +560,12 @@ void ABufferRenderer::updateMSAASamplingPattern() {
glDeleteVertexArrays(1, &nOneStripVAO);
}
void ABufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurements) {
void ABufferRenderer::render(Scene* scene, Camera* camera, float blackoutFactor,
bool doPerformanceMeasurements)
{
PerfMeasure("ABufferRenderer::render");
if (!_scene || !_camera) {
if (!scene || !camera) {
return;
}
@@ -626,7 +604,7 @@ void ABufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurement
Time time = OsEng.timeManager().time();
RenderData data {
*_camera,
*camera,
psc(),
time,
doPerformanceMeasurements,
@@ -634,7 +612,7 @@ void ABufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurement
{}
};
RendererTasks tasks;
_scene->render(data, tasks);
scene->render(data, tasks);
_blackoutFactor = blackoutFactor;
glBindFramebuffer(GL_FRAMEBUFFER, defaultFbo);
@@ -670,8 +648,8 @@ void ABufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurement
float logDistance = std::log(glm::length(cameraPos / maxComponent) * maxComponent)
/ std::log(10.f);
const float minLogDist = 15;
const float maxLogDist = 20;
const float minLogDist = 15.f;
const float maxLogDist = 20.f;
float t = (logDistance - minLogDist) / (maxLogDist - minLogDist);
t = glm::clamp(t, 0.0f, 1.0f);
@@ -703,7 +681,6 @@ void ABufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurement
_mainDepthTextureUnit = nullptr;
}
void ABufferRenderer::preRaycast(const RaycasterTask& raycasterTask) {
VolumeRaycaster& raycaster = *raycasterTask.raycaster;
const RaycastData& raycastData = _raycastData[&raycaster];
@@ -733,17 +710,9 @@ void ABufferRenderer::postRaycast(const RaycasterTask& raycasterTask) {
raycaster.postRaycast(raycastData, *_resolveProgram);
}
void ABufferRenderer::setScene(Scene* scene) {
_scene = scene;
}
void ABufferRenderer::setCamera(Camera* camera) {
_camera = camera;
}
void ABufferRenderer::setResolution(glm::ivec2 res) {
if (res != _resolution) {
_resolution = res;
_resolution = std::move(res);
_dirtyResolution = true;
}
}
@@ -893,8 +862,6 @@ void ABufferRenderer::updateResolution() {
_dirtyResolution = false;
}
void ABufferRenderer::updateResolveDictionary() {
ghoul::Dictionary dict;
ghoul::Dictionary raycastersDict;
@@ -1026,29 +993,27 @@ void ABufferRenderer::updateRendererData() {
}
void ABufferRenderer::saveTextureToMemory(const GLenum color_buffer_attachment,
const int width, const int height, std::vector<double> & memory) const {
const int width, const int height, std::vector<double>& memory) const {
if (!memory.empty()) {
memory.clear();
}
memory.reserve(width * height * 3);
float * tempMemory = new float[width * height * 3];
std::vector<float> tmpMemory(width * height * 3);
if (color_buffer_attachment != GL_DEPTH_ATTACHMENT) {
glReadBuffer(color_buffer_attachment);
glReadPixels(0, 0, width, height, GL_RGB, GL_FLOAT, tempMemory);
glReadPixels(0, 0, width, height, GL_RGB, GL_FLOAT, tmpMemory.data());
}
else {
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, tempMemory);
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, tmpMemory.data());
}
for (auto i = 0; i < width*height * 3; ++i) {
memory[i] = static_cast<double>(tempMemory[i]);
memory[i] = static_cast<double>(tmpMemory[i]);
}
delete[] tempMemory;
}
}
} // namespace openspace

View File

@@ -75,9 +75,7 @@ void saveTextureToMemory(const GLenum color_buffer_attachment,
FramebufferRenderer::FramebufferRenderer()
: _camera(nullptr)
, _scene(nullptr)
, _resolution(glm::vec2(0))
: _resolution(glm::vec2(0))
, _hdrExposure(0.4f)
, _hdrBackground(2.8f)
, _gamma(2.2f)
@@ -577,50 +575,54 @@ void FramebufferRenderer::updateHDRData() {
void FramebufferRenderer::updateMSAASamplingPattern() {
LDEBUG("Updating MSAA Sampling Pattern");
const int GRIDSIZE = 32;
GLfloat step = 2.0f / static_cast<GLfloat>(GRIDSIZE);
GLfloat sizeX = -1.0f,
sizeY = 1.0f;
constexpr const int GridSize = 32;
GLfloat step = 2.f / static_cast<GLfloat>(GridSize);
GLfloat sizeX = -1.f;
GLfloat sizeY = 1.0;
const int NVERTEX = 4 * 6;
constexpr const int NVertex = 4 * 6;
// openPixelSizeVertexData
GLfloat vertexData[GRIDSIZE * GRIDSIZE * NVERTEX];
GLfloat vertexData[GridSize * GridSize * NVertex];
for (int y = 0; y < GRIDSIZE; ++y) {
for (int x = 0; x < GRIDSIZE; ++x) {
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX] = sizeX;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 1] = sizeY - step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 2] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 3] = 1.0f;
// @CLEANUP(abock): Is this necessary? I was mucking about with the shader and it
// didn't make any visual difference. If it is necessary, the z and w
// components can be removed for sure since they are always 0, 1 and
// not used in the shader either
for (int y = 0; y < GridSize; ++y) {
for (int x = 0; x < GridSize; ++x) {
vertexData[y * GridSize * NVertex + x * NVertex] = sizeX;
vertexData[y * GridSize * NVertex + x * NVertex + 1] = sizeY - step;
vertexData[y * GridSize * NVertex + x * NVertex + 2] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 3] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 4] = sizeX + step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 5] = sizeY;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 6] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 7] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 4] = sizeX + step;
vertexData[y * GridSize * NVertex + x * NVertex + 5] = sizeY;
vertexData[y * GridSize * NVertex + x * NVertex + 6] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 7] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 8] = sizeX;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 9] = sizeY;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 10] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 11] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 8] = sizeX;
vertexData[y * GridSize * NVertex + x * NVertex + 9] = sizeY;
vertexData[y * GridSize * NVertex + x * NVertex + 10] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 11] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 12] = sizeX;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 13] = sizeY - step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 14] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 15] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 12] = sizeX;
vertexData[y * GridSize * NVertex + x * NVertex + 13] = sizeY - step;
vertexData[y * GridSize * NVertex + x * NVertex + 14] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 15] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 16] = sizeX + step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 17] = sizeY - step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 18] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 19] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 16] = sizeX + step;
vertexData[y * GridSize * NVertex + x * NVertex + 17] = sizeY - step;
vertexData[y * GridSize * NVertex + x * NVertex + 18] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 19] = 1.f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 20] = sizeX + step;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 21] = sizeY;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 22] = 0.0f;
vertexData[y * GRIDSIZE * NVERTEX + x * NVERTEX + 23] = 1.0f;
vertexData[y * GridSize * NVertex + x * NVertex + 20] = sizeX + step;
vertexData[y * GridSize * NVertex + x * NVertex + 21] = sizeY;
vertexData[y * GridSize * NVertex + x * NVertex + 22] = 0.f;
vertexData[y * GridSize * NVertex + x * NVertex + 23] = 1.f;
sizeX += step;
}
sizeX = -1.0f;
sizeX = -1.f;
sizeY -= step;
}
@@ -635,20 +637,13 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
glBufferData(
GL_ARRAY_BUFFER,
sizeof(GLfloat) * GRIDSIZE * GRIDSIZE * NVERTEX,
sizeof(GLfloat) * GridSize * GridSize * NVertex,
vertexData,
GL_STATIC_DRAW
);
// Position
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
0,
nullptr
);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(0);
// Saves current state
@@ -689,7 +684,7 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
GLenum textureBuffers[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, textureBuffers);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
@@ -698,17 +693,12 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
return;
}
std::unique_ptr<ghoul::opengl::ProgramObject> pixelSizeProgram = nullptr;
try {
pixelSizeProgram = ghoul::opengl::ProgramObject::Build(
std::unique_ptr<ghoul::opengl::ProgramObject> pixelSizeProgram =
ghoul::opengl::ProgramObject::Build(
"OnePixel MSAA",
absPath("${SHADERS}/framebuffer/pixelSizeMSAA.vert"),
absPath("${SHADERS}/framebuffer/pixelSizeMSAA.frag")
);
}
catch (const ghoul::RuntimeError& e) {
LERRORC(e.component, e.message);
}
pixelSizeProgram->activate();
@@ -717,7 +707,7 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
glBindVertexArray(pixelSizeQuadVAO);
glDisable(GL_DEPTH_TEST);
glDepthMask(false);
glDrawArrays(GL_TRIANGLES, 0, GRIDSIZE * GRIDSIZE * 6);
glDrawArrays(GL_TRIANGLES, 0, GridSize * GridSize * 6);
glBindVertexArray(0);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
@@ -731,53 +721,53 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
GLuint nOneStripVBO = 0;
GLuint nOneStripTexture = 0;
sizeX = -1.0f;
step = 2.0f / static_cast<GLfloat>(_nAaSamples);
sizeX = -1.f;
step = 2.f / static_cast<GLfloat>(_nAaSamples);
GLfloat * nOneStripVertexData = new GLfloat[_nAaSamples * (NVERTEX + 12)];
std::vector<GLfloat>nOneStripVertexData(_nAaSamples * (NVertex + 12));
for (int x = 0; x < _nAaSamples; ++x) {
nOneStripVertexData[x * (NVERTEX + 12)] = sizeX;
nOneStripVertexData[x * (NVERTEX + 12) + 1] = -1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 2] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 3] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 4] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 5] = 0.0f;
nOneStripVertexData[x * (NVertex + 12)] = sizeX;
nOneStripVertexData[x * (NVertex + 12) + 1] = -1.f;
nOneStripVertexData[x * (NVertex + 12) + 2] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 3] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 4] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 5] = 0.f;
nOneStripVertexData[x * (NVERTEX + 12) + 6] = sizeX + step;
nOneStripVertexData[x * (NVERTEX + 12) + 7] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 8] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 9] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 10] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 11] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 6] = sizeX + step;
nOneStripVertexData[x * (NVertex + 12) + 7] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 8] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 9] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 10] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 11] = 1.f;
nOneStripVertexData[x * (NVERTEX + 12) + 12] = sizeX;
nOneStripVertexData[x * (NVERTEX + 12) + 13] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 14] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 15] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 16] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 17] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 12] = sizeX;
nOneStripVertexData[x * (NVertex + 12) + 13] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 14] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 15] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 16] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 17] = 0.f;
nOneStripVertexData[x * (NVERTEX + 12) + 18] = sizeX;
nOneStripVertexData[x * (NVERTEX + 12) + 19] = -1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 20] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 21] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 22] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 23] = 0.0f;
nOneStripVertexData[x * (NVertex + 12) + 18] = sizeX;
nOneStripVertexData[x * (NVertex + 12) + 19] = -1.f;
nOneStripVertexData[x * (NVertex + 12) + 20] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 21] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 22] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 23] = 0.f;
nOneStripVertexData[x * (NVERTEX + 12) + 24] = sizeX + step;
nOneStripVertexData[x * (NVERTEX + 12) + 25] = -1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 26] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 27] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 28] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 29] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 24] = sizeX + step;
nOneStripVertexData[x * (NVertex + 12) + 25] = -1.f;
nOneStripVertexData[x * (NVertex + 12) + 26] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 27] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 28] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 29] = 1.f;
nOneStripVertexData[x * (NVERTEX + 12) + 30] = sizeX + step;
nOneStripVertexData[x * (NVERTEX + 12) + 31] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 32] = 0.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 33] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 34] = 1.0f;
nOneStripVertexData[x * (NVERTEX + 12) + 35] = 1.0f;
nOneStripVertexData[x * (NVertex + 12) + 30] = sizeX + step;
nOneStripVertexData[x * (NVertex + 12) + 31] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 32] = 0.f;
nOneStripVertexData[x * (NVertex + 12) + 33] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 34] = 1.f;
nOneStripVertexData[x * (NVertex + 12) + 35] = 1.f;
sizeX += step;
}
@@ -788,20 +778,13 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
glBindBuffer(GL_ARRAY_BUFFER, nOneStripVBO);
glBufferData(
GL_ARRAY_BUFFER,
sizeof(GLfloat) * _nAaSamples * (NVERTEX + 12),
nOneStripVertexData,
sizeof(GLfloat) * _nAaSamples * (NVertex + 12),
nOneStripVertexData.data(),
GL_STATIC_DRAW
);
// position
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
sizeof(GLfloat) * 6,
nullptr
);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, nullptr);
glEnableVertexAttribArray(0);
// texture coords
@@ -814,7 +797,6 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
reinterpret_cast<GLvoid*>(sizeof(GLfloat) * 4)
);
glEnableVertexAttribArray(1);
delete[] nOneStripVertexData;
// fbo texture buffer
glGenTextures(1, &nOneStripTexture);
@@ -851,17 +833,12 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
glViewport(0, 0, _nAaSamples, ONEPIXEL);
std::unique_ptr<ghoul::opengl::ProgramObject> nOneStripProgram = nullptr;
try {
nOneStripProgram = ghoul::opengl::ProgramObject::Build(
std::unique_ptr<ghoul::opengl::ProgramObject> nOneStripProgram =
ghoul::opengl::ProgramObject::Build(
"OneStrip MSAA",
absPath("${SHADERS}/framebuffer/nOneStripMSAA.vert"),
absPath("${SHADERS}/framebuffer/nOneStripMSAA.frag")
);
}
catch (const ghoul::RuntimeError& e) {
LERRORC(e.component, e.message);
}
nOneStripProgram->activate();
@@ -915,7 +892,9 @@ void FramebufferRenderer::updateMSAASamplingPattern() {
glDeleteVertexArrays(1, &nOneStripVAO);
}
void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurements) {
void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFactor,
bool doPerformanceMeasurements)
{
std::unique_ptr<performance::PerformanceMeasurement> perf;
if (doPerformanceMeasurements) {
perf = std::make_unique<performance::PerformanceMeasurement>(
@@ -924,7 +903,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
);
}
if (!_scene || !_camera) {
if (!scene || !camera) {
return;
}
@@ -933,7 +912,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
Time time = OsEng.timeManager().time();
RenderData data = { *_camera, psc(), time, doPerformanceMeasurements, 0, {} };
RenderData data = { *camera, psc(), time, doPerformanceMeasurements, 0, {} };
RendererTasks tasks;
// Capture standard fbo
@@ -965,7 +944,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
}
data.renderBinMask = static_cast<int>(Renderable::RenderBin::Background);
_scene->render(data, tasks);
scene->render(data, tasks);
}
{
std::unique_ptr<performance::PerformanceMeasurement> perfInternal;
@@ -977,7 +956,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
}
data.renderBinMask = static_cast<int>(Renderable::RenderBin::Opaque);
_scene->render(data, tasks);
scene->render(data, tasks);
}
{
std::unique_ptr<performance::PerformanceMeasurement> perfInternal;
@@ -989,7 +968,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
}
data.renderBinMask = static_cast<int>(Renderable::RenderBin::Transparent);
_scene->render(data, tasks);
scene->render(data, tasks);
}
{
std::unique_ptr<performance::PerformanceMeasurement> perfInternal;
@@ -1001,7 +980,7 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
}
data.renderBinMask = static_cast<int>(Renderable::RenderBin::Overlay);
_scene->render(data, tasks);
scene->render(data, tasks);
}
{
@@ -1125,18 +1104,17 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
bool firstPaint = true;
for (const DeferredcasterTask& deferredcasterTask : tasks.deferredcasterTasks) {
Deferredcaster* deferredcaster = deferredcasterTask.deferredcaster;
ghoul::opengl::ProgramObject* deferredcastProgram = nullptr;
if (deferredcastProgram != _deferredcastPrograms[deferredcaster].get()
|| deferredcastProgram == nullptr) {
|| deferredcastProgram == nullptr)
{
deferredcastProgram = _deferredcastPrograms[deferredcaster].get();
}
if (deferredcastProgram) {
deferredcastProgram->activate();
// adding G-Buffer
@@ -1188,9 +1166,11 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
deferredcaster->postRaycast(deferredcasterTask.renderData,
deferredcaster->postRaycast(
deferredcasterTask.renderData,
_deferredcastData[deferredcaster],
*deferredcastProgram);
*deferredcastProgram
);
deferredcastProgram->deactivate();
@@ -1225,14 +1205,6 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
}
}
void FramebufferRenderer::setScene(Scene* scene) {
_scene = scene;
}
void FramebufferRenderer::setCamera(Camera* camera) {
_camera = camera;
}
void FramebufferRenderer::setResolution(glm::ivec2 res) {
_resolution = res;
_dirtyResolution = true;

View File

@@ -562,7 +562,12 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat
bool masterEnabled = wrapper.isMaster() ? !_disableMasterRendering : true;
if (masterEnabled && !wrapper.isGuiWindow() && _globalBlackOutFactor > 0.f) {
_renderer->render(_globalBlackOutFactor, _performanceManager != nullptr);
_renderer->render(
_scene,
_camera,
_globalBlackOutFactor,
_performanceManager != nullptr
);
}
if (_showFrameNumber) {
@@ -742,16 +747,10 @@ DeferredcasterManager& RenderEngine::deferredcasterManager() {
void RenderEngine::setScene(Scene* scene) {
_scene = scene;
if (_renderer) {
_renderer->setScene(scene);
}
}
void RenderEngine::setCamera(Camera* camera) {
_camera = camera;
if (_renderer) {
_renderer->setCamera(camera);
}
}
const Renderer& RenderEngine::renderer() const {
@@ -912,8 +911,6 @@ void RenderEngine::setRenderer(std::unique_ptr<Renderer> renderer) {
_renderer->setNAaSamples(_nAaSamples);
_renderer->setHDRExposure(_hdrExposure);
_renderer->initialize();
_renderer->setCamera(_camera);
_renderer->setScene(_scene);
}
scripting::LuaLibrary RenderEngine::luaLibrary() {