Clean up: Remove targetBody from Renderable

This commit is contained in:
Erik Broberg
2016-08-12 16:39:26 -04:00
parent 0f21217f38
commit 7fc31151ea
10 changed files with 24 additions and 330 deletions

View File

@@ -157,8 +157,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
dictionary.getValue(keyFrame, _frame);
dictionary.getValue(keyBody, _target);
if (_target != "")
setBody(_target);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
@@ -618,26 +617,7 @@ void RenderablePlanet::render(const RenderData& data)
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
transform = transform * rot * roty * rotProp;
// setup the data to the shader
double lt;
glm::dvec3 sunPosFromPlanet =
SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt);
sunPosFromPlanet *= 1000.0; // from Km to m
psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(sunPosFromPlanet.x, sunPosFromPlanet.y, sunPosFromPlanet.z);
glm::dvec3 planetPosFromSun =
SpiceManager::ref().targetPosition(_target, "SUN", "GALACTIC", {}, _time, lt);
psc tmppos = PowerScaledCoordinate::CreatePowerScaledCoordinate(planetPosFromSun.x, planetPosFromSun.y, planetPosFromSun.z);
glm::vec3 cam_dir = glm::normalize(data.camera.position().vec3() - tmppos.vec3());
// This is camera position vector (camera direction) in world coordinates.
//_programObject->setUniform("cam_dir", cam_dir);
//glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix();
//glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz;
//_programObject->setUniform("camdir", camSpaceEye);
transform = transform * rot * roty * rotProp;
_programObject->setUniform("transparency", _alpha);
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
@@ -649,9 +629,7 @@ void RenderablePlanet::render(const RenderData& data)
float scaleFactor = data.camera.scaling().x * powf(10.0, data.camera.scaling().y);
glm::mat4 scaleCamTrans = glm::scale(glm::mat4(1.0), glm::vec3(scaleFactor));
// Is it wright not considering the camera rotation matrix here?
/*glm::mat4 ModelViewTrans = data.camera.viewMatrix() * scaleCamTrans *
data.camera.viewRotationMatrix() * translateCamTrans * translateObjTrans * transform;*/
glm::mat4 ModelViewTrans = data.camera.viewMatrix() * scaleCamTrans *
translateCamTrans * translateObjTrans * transform;
if (_atmosphereEnabled)
@@ -692,6 +670,8 @@ void RenderablePlanet::render(const RenderData& data)
glCullFace(GL_BACK);
// TODO: Move Calculations to VIEW SPACE (precision problems avoidance...)
double lt;
// Shadow calculations..
if (!_shadowConfArray.empty()) {
std::vector<ShadowRenderingStruct> shadowDataArray;
@@ -848,232 +828,15 @@ void RenderablePlanet::render(const RenderData& data)
// HDR
_programObject->setUniform("exposure", 0.4f);
/*std::stringstream ss;
ss << "atmosphere-" << count++ << ".ppm";
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, ss.str(), m_viewport[2], m_viewport[3]);*/
}
// render
_geometry->render();
// disable shader
_programObject->deactivate();
//
//
//// Render Atmosphere to a texture:
//if (_atmosphereEnabled) {
// /*std::cout << "\nTestes..." << std::endl;
// glm::dvec3 sunPosSun = SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt);
// glm::dvec3 earthPosSun = SpiceManager::ref().targetPosition("EARTH", "SUN", "GALACTIC", {}, _time, lt);
// std::cout << "\n\nSun in Sun: " << sunPosSun.x << ", " << sunPosSun.y << ", " << sunPosSun.z << std::endl;
// std::cout << "\n\nEarth in Sun: " << earthPosSun.x << ", " << earthPosSun.y << ", " << earthPosSun.z << std::endl;
// std::cout << "\n\nCam Position in Sun: " << data.camera.position().vec3().x << ", " << data.camera.position().vec3().y << ", " << data.camera.position().vec3().z << std::endl;
// std::cout << "\n\nCam Position from Earth in Sun: " << cam_dir.x << ", " << cam_dir.y << ", " << cam_dir.z << std::endl;
//
// glm::dmat3 sun2earthMat = SpiceManager::ref().frameTransformationMatrix("GALACTIC", "IAU_EARTH", _time);
// glm::dvec3 sunPosEarth = sun2earthMat * sunPosSun;
// glm::dvec3 earthPosEarth = sun2earthMat * earthPosSun;
// glm::dvec3 camDirEarth = sun2earthMat * cam_dir;
// glm::dvec3 camPosEarth = sun2earthMat * data.camera.position().vec3();
// std::cout << "\n\nSun in Earth: " << sunPosEarth.x << ", " << sunPosEarth.y << ", " << sunPosEarth.z << std::endl;
// std::cout << "\n\nEarth in Earth: " << earthPosEarth.x << ", " << earthPosEarth.y << ", " << earthPosEarth.z << std::endl;
// std::cout << "\n\nCam Position in Earth: " << camPosEarth.x << ", " << camPosEarth.y << ", " << camPosEarth.z << std::endl;
// std::cout << "\n\nCam Position from Earth in Earth: " << camDirEarth.x << ", " << camDirEarth.y << ", " << camDirEarth.z << std::endl;
// glm::dvec3 sunPosView = glm::dvec3(data.camera.viewMatrix() * glm::dvec4(sunPosSun.x, sunPosSun.y, sunPosSun.z, 1.0));
// glm::dvec3 earthPosView = glm::dvec3(data.camera.viewMatrix() * glm::dvec4(earthPosSun.x, earthPosSun.y, earthPosSun.z, 1.0));
// glm::dvec3 camDirView = glm::dvec3(data.camera.viewMatrix() * glm::dvec4(cam_dir.x, cam_dir.y, cam_dir.z, 0.0));
// glm::dvec3 camPosView = glm::dvec3(data.camera.viewMatrix() * glm::dvec4(data.camera.position().vec3().x, data.camera.position().vec3().y, data.camera.position().vec3().z, 1.0));
// std::cout << "\n\nSun in View: " << sunPosView.x << ", " << sunPosView.y << ", " << sunPosView.z << std::endl;
// std::cout << "\n\nEarth in View: " << earthPosView.x << ", " << earthPosView.y << ", " << earthPosView.z << std::endl;
// std::cout << "\n\nCam Position in View: " << camPosView.x << ", " << camPosView.y << ", " << camPosView.z << std::endl;
// std::cout << "\n\nCam Position from Earth in View: " << camDirView.x << ", " << camDirView.y << ", " << camDirView.z << std::endl;*/
// GLint defaultFBO;
// glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
// GLint m_viewport[4];
// glGetIntegerv(GL_VIEWPORT, m_viewport);
// glBindFramebuffer(GL_FRAMEBUFFER, _atmosphereFBO);
// glReadBuffer(GL_COLOR_ATTACHMENT1);
// GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
// glDrawBuffers(2, drawBuffers);
// if (!glIsTexture(_dummyTexture)) {
// _dummyTextureUnit.activate();
// glGenTextures(1, &_dummyTexture);
// //glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _dummyTexture);
// glBindTexture(GL_TEXTURE_2D, _dummyTexture);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_viewport[2],
// m_viewport[3], 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
// /*glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 8, GL_RGBA,
// m_viewport[2], m_viewport[3], true);*/
// }
// glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _dummyTexture, 0);
// glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, _atmosphereTexture, 0);
// //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, _dummyTexture, 0);
// //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, _atmosphereTexture, 0);
// if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
// LERROR("Atmosphere Framework not built.");
// GLenum fbErr = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// switch (fbErr) {
// case GL_FRAMEBUFFER_UNDEFINED:
// LERROR("Indefined framebuffer.");
// break;
// case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
// LERROR("Incomplete, missing attachement.");
// break;
// case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
// LERROR("Framebuffer doesn't have at least one image attached to it.");
// break;
// case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
// LERROR("Returned if the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for any color attachment point(s) named by GL_DRAW_BUFFERi.");
// break;
// case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
// LERROR("Returned if GL_READ_BUFFER is not GL_NONE and the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment point named by GL_READ_BUFFER.");
// break;
// case GL_FRAMEBUFFER_UNSUPPORTED:
// LERROR("Returned if the combination of internal formats of the attached images violates an implementation - dependent set of restrictions.");
// break;
// case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
// LERROR("Returned if the value of GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is the not same for all attached textures; or , if the attached images are a mix of renderbuffers and textures, the value of GL_RENDERBUFFER_SAMPLES does not match the value of GL_TEXTURE_SAMPLES.");
// LERROR("Returned if the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not the same for all attached textures; or , if the attached images are a mix of renderbuffers and textures, the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not GL_TRUE for all attached textures.");
// break;
// case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
// LERROR("Returned if any framebuffer attachment is layered, and any populated attachment is not layered, or if all populated color attachments are not from textures of the same target.");
// break;
// }
// }
// GLenum err;
// while ((err = glGetError()) != GL_NO_ERROR) {
// const GLubyte * errorString = gluErrorString(err);
// std::stringstream ss;
// ss << "Error setting up atmosphere framebuffer. OpenGL error: "
// << err << " - " << errorString << std::endl;
// LERROR(ss.str());
// }
// glClearColor(1.0, 0.0, 0.0, 1.0);
// glClear(GL_COLOR_BUFFER_BIT);
//
// _atmosphereProgramObject->activate();
// //glm::vec2 camScaling = data.camera.scaling();
// ///*glm::mat4 invScaling = glm::scale(glm::mat4(1.0), glm::vec3(1.0 / (camScaling.x * pow(10.0, camScaling.y))));
// //glm::mat4 invCamRot = glm::inverse(data.camera.viewRotationMatrix());
// //glm::mat4 invTrans = glm::translate(glm::mat4(1.0), glm::vec3(-data.camera.position().vec4()));*/
// //glm::mat4 camScaleTrans = glm::scale(glm::mat4(1.0), glm::vec3(camScaling.x * pow(10.0, camScaling.y)));
// //glm::mat4 camRotationTrans = glm::mat4(glm::mat3(data.camera.viewRotationMatrix()));
// //glm::mat4 camTranslationTrans = glm::translate(glm::mat4(1.0), glm::vec3(-data.camera.position().vec4()));
// //glm::mat4 completeInverse = glm::inverse(data.camera.viewProjectionMatrix() * camScaleTrans *
// // camRotationTrans * camTranslationTrans);
// // Object Space (in Km)
// glm::mat4 obj2World = glm::translate(glm::mat4(1.0), data.position.vec3() / 1000.0f);
// glm::mat4 M = data.camera.viewMatrix() * scaleCamTrans * data.camera.viewRotationMatrix() *
// translateCamTrans * obj2World * transform;
// // World Space
// /*glm::mat4 M = data.camera.viewMatrix() * scaleCamTrans * data.camera.viewRotationMatrix() *
// translateCamTrans;*/
// //glm::mat4 completeInverse = glm::inverse(data.camera.projectionMatrix() * M);
// glm::mat4 completeInverse = glm::inverse(M);
// //glm::mat4 completeInverse = glm::inverse(data.camera.projectionMatrix() * ModelViewTrans);
// _atmosphereProgramObject->setUniform("completeInverse", completeInverse);
// _atmosphereProgramObject->setUniform("projInverse", glm::inverse(data.camera.projectionMatrix()));
//
// //// This is camera position and planet position vector in world coordinates, in Km.
// //glm::vec4 cameraPosWorld = glm::vec4(data.camera.position().vec3() / 1000.0f, 1.0);
// //glm::vec4 planetPositionWorld = glm::vec4(data.position.vec3() / 1000.0f, 1.0);
// //_atmosphereProgramObject->setUniform("cameraPosWorld", cameraPosWorld);
// //_atmosphereProgramObject->setUniform("planetPosition", planetPositionWorld);
// //// I know it is (0,0,0). It is here just for sake of sanity. :-p
// //glm::dvec3 sunPosWorld =
// // SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt);
// //_atmosphereProgramObject->setUniform("sunPositionWorld", sunPosWorld);
// // This is camera position and planet position vector in object coordinates, in Km.
// glm::mat4 world2Obj = glm::inverse(obj2World * transform);
// glm::vec4 cameraPosObj = world2Obj * glm::vec4(data.camera.position().vec3() / 1000.0f, 1.0);
// glm::vec4 planetPositionObj = world2Obj * glm::vec4(data.position.vec3() / 1000.0f, 1.0);
// _atmosphereProgramObject->setUniform("cameraPosObj", cameraPosObj);
// _atmosphereProgramObject->setUniform("planetPositionObj", planetPositionObj);
//
// // I know it is (0,0,0). It is here just for sake of sanity. :-p
// glm::dvec3 sunPosWorld =
// SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt);
// glm::vec4 sunPosObj = world2Obj * glm::vec4(sunPosWorld.x, sunPosWorld.y, sunPosWorld.z, 1.0);
// _atmosphereProgramObject->setUniform("sunPositionObj", glm::vec3(sunPosObj));
// //// DEBUG:
// //std::cout << "\n\nSun in Obj Space: " << sunPosObj.x << ", " << sunPosObj.y << ", " << sunPosObj.z << std::endl;
// //std::cout << "\n\nEarth in Obj Space: " << planetPositionObj.x << ", " << planetPositionObj.y << ", " << planetPositionObj.z << std::endl;
// //std::cout << "\n\nCam in Obj Space: " << cameraPosObj.x << ", " << cameraPosObj.y << ", " << cameraPosObj.z << std::endl;
//
// _transmittanceTableTextureUnit.activate();
// //glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
// _atmosphereProgramObject->setUniform("transmittanceSampler", _transmittanceTableTextureUnit);
// _irradianceTableTextureUnit.activate();
// //glBindTexture(GL_TEXTURE_2D, _irradianceTableTexture);
// _atmosphereProgramObject->setUniform("irradianceSampler", _irradianceTableTextureUnit);
// _inScatteringTableTextureUnit.activate();
// //glBindTexture(GL_TEXTURE_3D, _inScatteringTableTexture);
// _atmosphereProgramObject->setUniform("inscatterSampler", _inScatteringTableTextureUnit);
//
// if (_hasReflectanceTexture) {
// ghoul::opengl::TextureUnit reflectanceUnit;
// reflectanceUnit.activate();
// _reflectanceTexture->bind();
// _atmosphereProgramObject->setUniform("reflectanceSampler", reflectanceUnit);
// }
// // HDR
// _atmosphereProgramObject->setUniform("exposure", 0.4f);
// setPscUniforms(*_atmosphereProgramObject.get(), data.camera, data.position);
// // check OpenGL error
// while ((err = glGetError()) != GL_NO_ERROR) {
// const GLubyte * errorString = gluErrorString(err);
// std::cout << "\n\nBefore Rendering Planet. OpenGL error: "
// << err << " - " << errorString << std::endl;
// }
// renderQuadForCalc(_atmosphereRenderVAO, 6);
// std::stringstream ss;
// ss << "atmosphere-" << count++ << ".ppm";
// saveTextureToPPMFile(GL_COLOR_ATTACHMENT1, ss.str(), m_viewport[2], m_viewport[3]);
// _atmosphereProgramObject->deactivate();
// glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
// glViewport(m_viewport[0], m_viewport[1],
// m_viewport[2], m_viewport[3]);
//}
}
void RenderablePlanet::update(const UpdateData& data) {