Improved RendedrablePlanesCloud rendering times.

This commit is contained in:
Jonathas Costa
2017-11-22 11:55:37 -05:00
parent 0264a3026c
commit cd1c695944
5 changed files with 56 additions and 25 deletions

View File

@@ -832,26 +832,45 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
//glm::vec3 lookup = data.camera.lookUpVectorWorldSpace();
//glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace();
//glm::vec3 right = glm::cross(viewDirection, lookup);
//glm::vec3 up = glm::cross(right, viewDirection);
//glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)));
//glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0)));
/*glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() *
glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3()));
glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix);
glm::vec3 lookup = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0);
glm::vec3 viewDirection = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0);
glm::vec3 right = glm::cross(viewDirection, lookup);
glm::vec3 up = glm::cross(right, viewDirection);
glm::vec3 orthoRight = glm::normalize(right);
glm::vec3 orthoUp = glm::normalize(up);*/
//glm::dmat4 invMVP = glm::inverse(modelViewProjectionMatrix);
/*
glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() *
glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3()));
glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix);
glm::dvec4 lookup = worldToModelTransform * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0);
glm::dvec4 viewDirection = worldToModelTransform * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0);
glm::vec3 right = glm::cross(glm::vec3(viewDirection), glm::vec3(lookup));
glm::vec3 up = glm::cross(right, glm::vec3(viewDirection));
glm::vec3 orthoRight = glm::normalize(right);
glm::vec3 orthoUp = glm::normalize(up);
*/
// Almost Working
glm::dmat4 invMVPParts = glm::inverse(modelMatrix) * glm::inverse(data.camera.combinedViewMatrix()) *
glm::inverse(glm::dmat4(projectionMatrix));
glm::dvec3 orthoRight = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0))));
glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0))));
glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0))));
if (_hasSpeckFile) {
renderBillboards(data, modelViewMatrix, worldToModelTransform, orthoRight, orthoUp, fadeInVariable);
}
if (_drawLabels && _hasLabel) {
renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp, fadeInVariable);
}
}
}
void RenderableBillboardsCloud::update(const UpdateData&) {

View File

@@ -486,9 +486,9 @@ void RenderablePlanesCloud::initializeGL() {
void RenderablePlanesCloud::deleteDataGPU() {
for (auto pair : _renderingPlanesMap) {
glDeleteVertexArrays(1, &pair.second.vao);
glDeleteBuffers(1, &pair.second.vbo);
for (auto renderingPlane : _renderingPlanesArray) {
glDeleteVertexArrays(1, &renderingPlane.vao);
glDeleteBuffers(1, &renderingPlane.vbo);
}
}
@@ -555,13 +555,16 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
// glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//}
for (auto pair : _renderingPlanesMap) {
ghoul::opengl::TextureUnit unit;
unit.activate();
_textureMap[pair.second.planeIndex]->bind();
_program->setUniform("galaxyTexture", unit);
glBindVertexArray(pair.second.vao);
ghoul::opengl::TextureUnit unit;
unit.activate();
_program->setUniform("galaxyTexture", unit);
int currentTextureIndex = -1;
for (auto renderingPlane : _renderingPlanesArray) {
if (currentTextureIndex != renderingPlane.planeIndex) {
_textureMap[renderingPlane.planeIndex]->bind();
currentTextureIndex = renderingPlane.planeIndex;
}
glBindVertexArray(renderingPlane.vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
@@ -1240,7 +1243,7 @@ void RenderablePlanesCloud::createPlanes() {
reinterpret_cast<GLvoid*>(sizeof(GLfloat) * 4)
);
_renderingPlanesMap.insert({planeNumber++, plane});
_renderingPlanesArray.push_back(plane);
}
glBindVertexArray(0);
@@ -1252,6 +1255,15 @@ void RenderablePlanesCloud::createPlanes() {
_labelDataIsDirty = false;
}
// Sort planes by texture index
if (!_renderingPlanesArray.empty()) {
std::sort(_renderingPlanesArray.begin(), _renderingPlanesArray.end(),
[](const RenderingPlane& planeA, const RenderingPlane& planeB) {
return planeA.planeIndex < planeB.planeIndex;
});
}
}
} // namespace openspace

View File

@@ -149,7 +149,7 @@ namespace openspace {
glm::dmat4 _transformationMatrix;
std::unordered_map<int, RenderingPlane> _renderingPlanesMap;
std::vector<RenderingPlane> _renderingPlanesArray;
};

View File

@@ -9,10 +9,10 @@ return {
-- A regular 1280x720 window
SGCTConfig = sgct.config.single{1280, 720},
-- SGCTConfig = sgct.config.single{1280, 720, scene={orientation = { yaw = 120, pitch = 15, roll = 0.0 }}},
-- SGCTConfig = "${CONFIG}/single_two_win.xml",
--SGCTConfig = "${CONFIG}/single_two_win.xml",
-- A regular 1920x1080 window
-- SGCTConfig = sgct.config.single{1920, 1080},
--SGCTConfig = sgct.config.single{1920, 1080},
-- A windowed 1920x1080 fullscreen
-- SGCTConfig = sgct.config.single{1920, 1080, border=false, windowPos={0,0}, shared=true, name="WV_OBS_SPOUT1"},