Normal computation in pre projection pass issue resolved.

This commit is contained in:
Michal Marcinkowski
2015-01-13 10:59:09 -05:00
parent f37958c24f
commit 812a9a48be
9 changed files with 49 additions and 100 deletions

View File

@@ -72,8 +72,8 @@ private:
ImageSequencer* _sequencer;
properties::StringProperty _colorTexturePath;
properties::StringProperty _projectionTexturePath;
properties::StringProperty _colorTexturePath;
properties::StringProperty _projectionTexturePath;
properties::TriggerProperty _imageTrigger;
ghoul::opengl::ProgramObject* _programObject;
@@ -106,8 +106,9 @@ private:
double lightTime;
std::string _target;
std::string _oldPath = "";
std::string _defaultProjImage;
std::string _next;
bool _capture;
// FBO stuff
GLuint _fboID;

View File

@@ -49,7 +49,7 @@ public:
public:
void createImage(double t1, double t2, std::string path = "dummypath");
bool getImagePath(double _currentTime, std::string& path);
bool getImagePath(double& _currentTime, std::string& path);
bool getImagePath(std::string _currentTime, std::string& path);
};

View File

@@ -32,7 +32,7 @@ uniform vec2 radius;
flat in uint vs_segments;
in vec4 vs_position;
in vec3 vs_boresight;
uniform vec3 boresight;
out vec4 color;
@@ -71,7 +71,7 @@ void main() {
vec3 normal = normalize((ModelTransform*vec4(vertex.xyz,0)).xyz);
vec3 v_b = normalize(vs_boresight);
vec3 v_b = normalize(boresight);
//color = 500*vec4(dot(v_b, normal),0,0,1);
// perspecitve division something with normals

View File

@@ -28,19 +28,17 @@ uniform mat4 ModelTransform;
uniform vec2 _scaling;
layout(location = 3) in vec4 in_position;
layout(location = 4) in vec3 boresight;
uniform vec3 boresight;
layout(location = 5) in int segments;
uniform vec2 radius;
out vec4 vs_position;
out vec3 vs_boresight;
flat out uint vs_segments;
#include "PowerScaling/powerScaling_vs.hglsl"
void main() {
vs_position = in_position;
vs_boresight = boresight;
vs_segments = segments;
gl_Position = vec4(in_position.xy, 0.0, 1.0);

View File

@@ -38,7 +38,7 @@ in vec4 vs_normal;
in vec4 vs_position;
in vec4 ProjTexCoord;
in vec3 vs_boresight;
uniform vec3 boresight;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
@@ -85,8 +85,9 @@ void main()
ProjTexCoord[0] < ProjTexCoord[2] ||
ProjTexCoord[1] < ProjTexCoord[2]){
diffuse = shaded;
}else if(dot(n,vs_boresight) < 0 ){// frontfacing
diffuse = projTexColor*0.5f + 0.5f*shaded;
}else if(dot(n,boresight) < 0 &&
(projTexColor.w != 0)){// frontfacing
diffuse = projTexColor;//*0.5f + 0.5f*shaded;
}else{
diffuse = shaded;
}

View File

@@ -36,20 +36,18 @@ layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
layout(location = 2) in vec3 in_normal;
layout(location = 3) in vec3 boresight;
uniform vec3 boresight;
out vec2 vs_st;
out vec4 vs_normal;
out vec4 vs_position;
out float s;
out vec3 vs_boresight;
out vec4 ProjTexCoord;
#include "PowerScaling/powerScaling_vs.hglsl"
void main(){
// Radius = 0.71492 *10^8;
vs_boresight = boresight;
// set variables
vs_st = in_st;
//vs_stp = in_position.xyz;

View File

@@ -57,11 +57,6 @@ namespace {
const std::string _mainFrame = "GALACTIC";
}
namespace openspace {
#ifdef WIN32
const char pathSeparator = '\\';
#else
const char pathSeparator = '/';
#endif
RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("planetTexture", "RGB Texture")
@@ -100,6 +95,8 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
success = dictionary.getValue(constants::scenegraph::keyPathModule, path);
assert(success);
_defaultProjImage = path + "/textures/3.jpg";
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(
constants::renderableplanet::keyGeometry, geometryDictionary);
@@ -132,7 +129,7 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
addProperty(_projectionTexturePath);
_projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadProjectionTexture, this));
std::string sPath = "C:/Users/michal/JupSequenceContrastCorrected";
std::string sPath = "C:/Users/michal/JupSequenceCrosshair";
_sequencer->loadSequence(sPath);
}
@@ -224,18 +221,7 @@ void RenderablePlanetProjection::imageProjectGPU(){
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
bool newImg = false;
std::string tmpProj = "C:/Users/michal/openspace/openspace-data/scene/jupiterprojection/textures/lor_0034817584_0x630_sci_1.fit.jpg";
boost::any s = _projectionTexturePath.get();
std::string *str;
str = boost::any_cast<std::string>(&s);
std::string newPath = tmpProj;
newImg = _sequencer->getImagePath(_time, newPath);
if (str[0] != newPath){ // every something frame for now..
_projectionTexturePath = newPath;
if (true){ // every something frame for now..
//counter = 0;
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
// set blend eq
@@ -249,11 +235,11 @@ void RenderablePlanetProjection::imageProjectGPU(){
ghoul::opengl::TextureUnit unitFbo;
unitFbo.activate();
_textureProj->bind();
_fboProgramObject->setUniform("texture1", unitFbo);
_fboProgramObject->setUniform("texture1" , unitFbo);
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
_fboProgramObject->setUniform("ModelTransform", _transform);
_fboProgramObject->setUniform("_scaling", _camScaling);
_fboProgramObject->setAttribute("boresight", _boresight);
_fboProgramObject->setUniform("ModelTransform" , _transform);
_fboProgramObject->setUniform("_scaling" , _camScaling);
_fboProgramObject->setUniform("boresight" , _boresight);
//TODO - needs target switching.
if (_geometry->hasProperty("radius")){
@@ -274,28 +260,6 @@ void RenderablePlanetProjection::imageProjectGPU(){
LERROR("Geometry object needs to provide segment count");
}
/*
if (_geometry->hasProperty("vaoID") &&
_geometry->hasProperty("vboID") &&
_geometry->hasProperty("iboID") ){
//int* vaoID, vboID, iboID;
boost::any id1 = _geometry->property("vaoID")->get();
boost::any id2 = _geometry->property("vboID")->get();
boost::any id3 = _geometry->property("iboID")->get();
if (GLuint vaoID = ((GLuint*)boost::any_cast<int>(&id1))[0]){
if (GLuint vboID = ((GLuint*)boost::any_cast<int>(&id2))[0]){
if (GLuint iboID = ((GLuint*)boost::any_cast<int>(&id3))[0]){
glBindVertexArray(vaoID); // select first VAO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
glDrawElements(GL_TRIANGLES, 240000, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
}
}
}
*/
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
_fboProgramObject->deactivate();
@@ -306,8 +270,6 @@ void RenderablePlanetProjection::imageProjectGPU(){
glViewport(m_viewport[0], m_viewport[1],
m_viewport[2], m_viewport[3]);
}
//counter++;
}
glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up){
@@ -368,15 +330,14 @@ void RenderablePlanetProjection::render(const RenderData& data){
#ifdef SEQUENCING
imageProjectGPU();
#endif
#endif
// Main renderpass
_programObject->activate();
// setup the data to the shader
_programObject->setUniform("ProjectorMatrix", _projectorMatrix);
_programObject->setUniform("ViewProjection" , data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform" , _transform);
_programObject->setAttribute("boresight" , _boresight);
_programObject->setUniform("boresight" , _boresight);
setPscUniforms(_programObject, &data.camera, data.position);
// Bind texture
@@ -396,8 +357,13 @@ void RenderablePlanetProjection::render(const RenderData& data){
void RenderablePlanetProjection::update(const UpdateData& data){
// set spice-orientation in accordance to timestamp
_time = data.time;
openspace::SpiceManager::ref().getPositionTransformMatrix(_target, _mainFrame, data.time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _mainFrame, data.time, _instrumentMatrix);
_next = _defaultProjImage;
//_capture = _sequencer->getImagePath(_time, _next);
_projectionTexturePath = _next;
openspace::SpiceManager::ref().getPositionTransformMatrix(_target, _mainFrame, _time, _stateMatrix);
openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _mainFrame, _time, _instrumentMatrix);
}
void RenderablePlanetProjection::loadProjectionTexture(){
@@ -406,13 +372,12 @@ void RenderablePlanetProjection::loadProjectionTexture(){
if (_colorTexturePath.value() != "") {
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
if (_textureProj) {
LDEBUG("Loaded texture from '" << absPath(_projectionTexturePath) << "'");
//LDEBUG("Loaded texture from '" << absPath(_projectionTexturePath) << "'");
_textureProj->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
}
}
@@ -423,7 +388,7 @@ void RenderablePlanetProjection::loadTexture(){
if (_colorTexturePath.value() != "") {
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
// LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);

View File

@@ -42,6 +42,7 @@ struct ImageParams{
double startTime;
double stopTime;
std::string path;
bool projected;
};
std::vector<ImageParams> _timeStamps;
@@ -64,6 +65,7 @@ void ImageSequencer::createImage(double t1, double t2, std::string path){
image.startTime = t1;
image.stopTime = t2;
image.path = path;
image.projected = false;
_timeStamps.push_back(image);
// sort
@@ -80,8 +82,8 @@ bool ImageSequencer::getImagePath(std::string _currentTime, std::string& path){
bool success = getImagePath(currentEt, path);
return success;
}
bool ImageSequencer::getImagePath(double _currentTime, std::string& path){
#define OPEN_INTERVAL
bool ImageSequencer::getImagePath(double& _currentTime, std::string& path){
auto cmp = [](const ImageParams &a, const ImageParams &b)->bool{
return a.startTime < b.startTime;
};
@@ -98,19 +100,22 @@ bool ImageSequencer::getImagePath(double _currentTime, std::string& path){
return end;
};
auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { _currentTime, 0, "" }, cmp);
//do this if check against [start, stop] intervals
/*
if (it == _timeStamps.end() || it->stopTime < _currentTime){
auto it = binary_find(_timeStamps.begin(), _timeStamps.end(), { _currentTime, 0, "", false }, cmp);
//check [start, stop]
#ifndef OPEN_INTERVAL
if (it == _timeStamps.end() || it->stopTime < _currentTime || it->projected){
return false;
}
*/
//do this if check against [start,) intervals
if (it == _timeStamps.end()){
#else
//check [start,)
if (it == _timeStamps.end() || it->projected){
return false;
}
#endif
it->projected = true;
path = it->path;
_currentTime = it->startTime;
return true;
}
@@ -118,7 +123,6 @@ bool ImageSequencer::loadSequence(const std::string dir){
ghoul::filesystem::Directory sequenceDir(dir, true);
std::vector<std::string> sequencePaths = sequenceDir.read(true, false); // check inputs
int count = 0;
std::cout.precision(15);
for (auto path : sequencePaths){
if (size_t position = path.find_last_of(".") + 1){
@@ -155,7 +159,6 @@ bool ImageSequencer::loadSequence(const std::string dir){
path.replace(path.begin() + position, path.end(), ext);
std::vector<std::string>::const_iterator it = std::find(sequencePaths.begin(), sequencePaths.end(), path);
if ( it != sequencePaths.end()){
// std::cout << "Creating image with time: " << timestamps[0] << "\ne_t: " << timestamps[1] << "\npath: " << path << std::endl;
createImage(timestamps[0], timestamps[1], path);
}
}
@@ -164,23 +167,6 @@ bool ImageSequencer::loadSequence(const std::string dir){
}
}
}
// testing _timeStamps
/*double currentEt = 0;
std::string currentTime = "2007-02-26T17:43:26.362";
openspace::SpiceManager::ref().getETfromDate(currentTime, currentEt);
std::cout << "\n Searching for s_t: " << currentEt << std::endl;
std::string storedpath = "";
currentEt -= 1;
for (int i = 0; i < 10000; i++){
bool success = getImagePath(currentEt, storedpath);
currentEt += ((float)i)/10000.f;
if (success) std::cout << "FOUND AT : "<< currentEt << " PATH "<< storedpath << std::endl;
}*/
return true;
}