Commit f1cc9984 authored by Ruben Garcia Hernndez's avatar Ruben Garcia Hernndez
Browse files

Add support for isosurfaces in CAVE.

Transparencies not implemented yet, but it can be used for fermi surfaces.
parent fe1cbf8c
...@@ -60,8 +60,10 @@ set(SOURCES ...@@ -60,8 +60,10 @@ set(SOURCES
src/NOMADVRLib/atoms.cpp src/NOMADVRLib/CompileGLShader.cpp src/NOMADVRLib/atoms.cpp src/NOMADVRLib/CompileGLShader.cpp
src/NOMADVRLib/polyhedron.cpp src/NOMADVRLib/UnitCellShaders.cpp src/NOMADVRLib/polyhedron.cpp src/NOMADVRLib/UnitCellShaders.cpp
src/NOMADVRLib/atomsGL.cpp src/NOMADVRLib/ConfigFile.cpp src/NOMADVRLib/atomsGL.cpp src/NOMADVRLib/ConfigFile.cpp
src/NOMADVRLib/TessShaders.cpp src/NOMADVRLib/TessShaders.cpp src/NOMADVRLib/IsosurfacesGL.cpp
src/NOMADVRLib/IsoShaders.cpp
src/happyhttp/happyhttp.cpp src/happyhttp/happyhttp.cpp
src/rply/rply.c
) )
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "NOMADVRLib/CompileGLShader.h" #include "NOMADVRLib/CompileGLShader.h"
#include "NOMADVRLib/IsosurfacesGL.h"
#include "defines.h" #include "defines.h"
#define TESSSUB 16 #define TESSSUB 16
...@@ -57,7 +59,7 @@ public: ...@@ -57,7 +59,7 @@ public:
void displayFunction(); void displayFunction();
void keyboardFunction(char key, int x, int y); void keyboardFunction(char key, int x, int y);
void keyReleaseFunction(char key, int x, int y); void keyReleaseFunction(char key, int x, int y);
void setCDPSyncher(std::shared_ptr<synchlib::SynchObject<int> > sy){m_pCurrentDataPosSyncher = sy; m_pCurrentDataPosSyncher->setData(0);} void setCDPSyncher(std::shared_ptr<synchlib::SynchObject<int> > sy){m_pCurrentDataPosSyncher = sy; m_pCurrentDataPosSyncher->setData(-1);}
void setCDTPSyncher(std::shared_ptr<synchlib::SynchObject<int> > sy){m_pCurrentDataTimeSyncher = sy; m_pCurrentDataTimeSyncher->setData(0);} void setCDTPSyncher(std::shared_ptr<synchlib::SynchObject<int> > sy){m_pCurrentDataTimeSyncher = sy; m_pCurrentDataTimeSyncher->setData(0);}
void setCDPtSyncher(std::shared_ptr<synchlib::SynchObject<SelectedPoints> > sy) void setCDPtSyncher(std::shared_ptr<synchlib::SynchObject<SelectedPoints> > sy)
{ {
...@@ -102,16 +104,24 @@ configFile=f; ...@@ -102,16 +104,24 @@ configFile=f;
int error=0; int error=0;
GLuint textures[2]; // white, atoms GLuint textures[2]; // white, atoms
//if no tesselation is available, we still need the tess atoms for the trajectories! //if no tesselation is available, we still need the tess atoms for the trajectories!
GLuint *AtomTVAO=0, *AtomTBuffer=0, *AtomVAO=0, *AtomBuffer=0, *AtomIndices=0,//[2], atoms, extraatoms GLuint *AtomTVAO=nullptr, *AtomTBuffer=nullptr,
*AtomVAO=nullptr, *AtomBuffer=nullptr, *AtomIndices=nullptr,//[2], atoms, extraatoms
UnitCellVAO, UnitCellBuffer, UnitCellIndexBuffer; UnitCellVAO, UnitCellBuffer, UnitCellIndexBuffer;
GLuint AtomsP, UnitCellP; // framework does not provide support for tesselation and provides many things we don't need. GLuint AtomsP, UnitCellP; // framework does not provide support for tesselation and provides many things we don't need.
GLint AtomMatrixLoc, UnitCellMatrixLoc, UnitCellColourLoc; GLint AtomMatrixLoc, UnitCellMatrixLoc, UnitCellColourLoc;
bool hasTess=true; bool hasTess=true;
GLuint *ISOVAO=nullptr/*[ISOS*TIMESTEPS]*/, *ISOBuffer=nullptr/*[ISOS*TIMESTEPS]*/,
*ISOIndices=nullptr/*[ISOS*TIMESTEPS]*/;
GLuint ISOP;
GLint ISOMatrixLoc;
int *numISOIndices=nullptr/*[ISOS*TIMESTEPS]*/;
void RenderAtoms(const float *m); void RenderAtoms(const float *m);
void RenderUnitCell(const glm::mat4 eyeViewProjection); void RenderUnitCell(const glm::mat4 eyeViewProjection);
void RenderAtomTrajectoriesUnitCell(); void RenderAtomTrajectoriesUnitCell();
void RenderAtomTrajectories(const glm::mat4 eyeViewProjection); void RenderAtomTrajectories(const glm::mat4 eyeViewProjection);
void RenderIsos(const glm::mat4 eyeViewProjection, int curDataPos);
}; };
...@@ -205,6 +215,73 @@ glGenTextures(2, textures); ...@@ -205,6 +215,73 @@ glGenTextures(2, textures);
error=-406; error=-406;
} }
//now isosurfaces
if (ISOS) {
PrepareISOShader(&ISOP, &ISOMatrixLoc);
std::vector<float> vertices;
#ifndef INDICESGL32
std::vector<short> indices;
#else
std::vector<GLuint> indices;
#endif
numISOIndices=new int[TIMESTEPS*ISOS];
ISOVAO=new GLuint[TIMESTEPS*ISOS];
ISOBuffer=new GLuint[TIMESTEPS*ISOS];
ISOIndices=new GLuint[TIMESTEPS*ISOS];
glGenBuffers(TIMESTEPS*ISOS, ISOBuffer);
glGenVertexArrays(TIMESTEPS*ISOS, ISOVAO);
glGenBuffers(TIMESTEPS*ISOS, ISOIndices);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("opengl error %d, glGenBuffers\n", e);
char tmpname[250];
int timestep=1;
for (int p = 0; p < TIMESTEPS*ISOS; p++) {
sprintf(tmpname, "%s%d-%s.ply", PATH, timestep,
plyfiles[p % ISOS]);
//add the rotateX(-90)
glm::mat4 trans;
trans=glm::rotate(trans, (float)-M_PI_2, glm::vec3(1.f,0.f,0.f));
glm::mat4 matFinal;
matFinal=glm::translate(matFinal,
glm::vec3(translations[p%ISOS][0],
translations[p%ISOS][1],
translations[p%ISOS][2]));
matFinal=trans*matFinal;
float mat[16];
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
mat[j*4+i]=matFinal[j][i];
if (!AddModelToScene(mat, vertices, indices,
tmpname, false, isocolours[p%ISOS][0]<0, p%ISOS))
{
eprintf("Error loading ply file %s\n", tmpname);
//return;
}
#ifndef INDICESGL32
if (vertices.size() > 65535 * numComponents)
{
eprintf("Mesh has more than 64k vertices (%d), unsupported\n", vertdataarray[currentlod][p].size() / numComponents);
return;
}
#endif
numISOIndices[p] = indices.size();
if (GL_NO_ERROR!=PrepareGLiso(ISOVAO[p], ISOBuffer[p],
vertices, ISOIndices[p], indices))
eprintf ("PrepareGLiso, GL error");
vertices.clear();
indices.clear();
if (p % ISOS == ISOS - 1) {
eprintf ("timestep %d", timestep);
timestep++;
}
}
}
//for painting selected points //for painting selected points
glGenVertexArrays(1, &PointVAO); glGenVertexArrays(1, &PointVAO);
glGenBuffers(1, &PointVBO); glGenBuffers(1, &PointVBO);
...@@ -305,6 +382,9 @@ if (has_abc) { ...@@ -305,6 +382,9 @@ if (has_abc) {
RenderAtomTrajectories(pvmat*st); RenderAtomTrajectories(pvmat*st);
} }
if (ISOS)
RenderIsos(pvmat*st, curDataPos);
} }
void sceneManager::displayFunction(){ void sceneManager::displayFunction(){
...@@ -320,6 +400,9 @@ void sceneManager::displayFunction(){ ...@@ -320,6 +400,9 @@ void sceneManager::displayFunction(){
m_node->getSceneTrafo(viewMat); m_node->getSceneTrafo(viewMat);
int curDataPos; int curDataPos;
m_pCurrentDataPosSyncher->getData(curDataPos); m_pCurrentDataPosSyncher->getData(curDataPos);
curDataPos=curDataPos%(ISOS+1);
if (curDataPos<0)
curDataPos+=ISOS+1;
int timePos; int timePos;
m_pCurrentDataTimeSyncher->getData(timePos); m_pCurrentDataTimeSyncher->getData(timePos);
if(m_oldTime != timePos){ if(m_oldTime != timePos){
...@@ -729,6 +812,29 @@ for (unsigned int i=0;i<atomtrajectories.size();i++) { ...@@ -729,6 +812,29 @@ for (unsigned int i=0;i<atomtrajectories.size();i++) {
} //sceneManager::RenderAtomTrajectoriesUnitCell() } //sceneManager::RenderAtomTrajectoriesUnitCell()
void sceneManager::RenderIsos(const glm::mat4 eyeViewProjection, int curDataPos)
{
GLenum e;
float t[16];
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
t[j*4+i]=eyeViewProjection[j][i];
glUseProgram(ISOP);
glUniformMatrix4fv(ISOMatrixLoc, 1, GL_FALSE, t);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error after glUniform4fv 1 RenderUnitCell: %d\n", e);
if (curDataPos!=ISOS) {
glBindVertexArray(ISOVAO[m_oldTime*ISOS+curDataPos]);
glDrawElements(GL_TRIANGLES,numISOIndices[m_oldTime*ISOS+curDataPos] , GL_UNSIGNED_INT, 0);
} else {
for (int i=0;i<ISOS;i++) {
glBindVertexArray(ISOVAO[m_oldTime*ISOS+i]);
glDrawElements(GL_TRIANGLES,numISOIndices[m_oldTime*ISOS+i] , GL_UNSIGNED_INT, 0);
}
}
}
void sceneManager::RenderUnitCell(const glm::mat4 eyeViewProjection) void sceneManager::RenderUnitCell(const glm::mat4 eyeViewProjection)
{ {
//eprintf ("eyeViewProjection"); //eprintf ("eyeViewProjection");
......
...@@ -62,7 +62,7 @@ private: ...@@ -62,7 +62,7 @@ private:
bool m_stop = false; bool m_stop = false;
int m_swapIsoSurface = 0; int m_swapIsoSurface = 0;
int m_curData = 0; //ISOS; int m_curData = -1; //ISOS;
std::thread* m_updateButtonsThread; std::thread* m_updateButtonsThread;
int m_mode = 0; //0 both, 1 negative and 2 positive iso swap int m_mode = 0; //0 both, 1 negative and 2 positive iso swap
bool m_pressB0 = false; bool m_pressB0 = false;
...@@ -133,7 +133,7 @@ bool longpress=false; ...@@ -133,7 +133,7 @@ bool longpress=false;
{//ms //rgh: change isos in a more discrete manner. {//ms //rgh: change isos in a more discrete manner.
std::cout << "Changing iso!!\n"; std::cout << "Changing iso!!\n";
m_curData += m_swapIsoSurface; m_curData += m_swapIsoSurface;
//rgh: unused for now //rgh: isos only in clients
// m_curData = (m_curData > ISOS) ? 0 : m_curData; // m_curData = (m_curData > ISOS) ? 0 : m_curData;
// m_curData = (m_curData < 0) ? ISOS : m_curData; // m_curData = (m_curData < 0) ? ISOS : m_curData;
synch(); synch();
......
#include "IsoShaders.h"
const char * const IsoShaders [] = {"Iso Renderer",
//vertex
#if defined(WIN32) || defined(CAVE)
"#version 410\n"
#else
"#version 300 es\n"
#endif
"uniform mat4 matrix;\n"
"layout(location = 0) in vec3 pos;\n"
"layout(location = 1) in vec3 normal;\n"
"layout(location = 2) in vec4 color;\n"
"out vec4 vcolor;\n"
"out vec3 vnormal;\n"
"void main()\n"
"{\n"
"gl_Position = matrix * vec4(pos, 1);\n"
"vcolor=color;\n"
"vnormal=normalize(normal);\n"
"}\n"
,
//fragment
#if defined(WIN32) || defined(CAVE)
"#version 410\n"
#else
"#version 300 es\n"
#endif
"in vec4 vcolor;\n"
"in vec3 vnormal;\n"
"out lowp vec4 outputColor;\n"
"void main()\n"
"{\n"
"lowp vec3 nn=normalize(vnormal);"
"lowp float a=max(0.0, dot(nn, vec3(0,sqrt(2.0)/2.0,sqrt(2.0)/2.0)));\n"
"lowp float b=max(0.0, dot(nn, vec3(0,0,1)));\n"
"highp vec4 res=vcolor;\n"
" outputColor = vec4 ((res.rgb) * (0.2 + 0.2*a + 0.3*b), vcolor.a);\n"
"}\n"
,
//tess
nullptr
};
extern const char * const IsoShaders[];
//#if 0 //#if 0
#include <vector> #include <vector>
#include <math.h>
#include "MyGL.h" #include "MyGL.h"
#include "eprintf.h" #include "eprintf.h"
#include "ConfigFile.h" //for isocolours #include "ConfigFile.h" //for isocolours
#include "TessShaders.h" //for SHADERNAME, etc
#include "IsosurfacesGL.h" #include "IsosurfacesGL.h"
#include "IsoShaders.h"
#include "CompileGLShader.h"
float *CubeVertices=0; float *CubeVertices=0;
int *CubeIndices=0; int *CubeIndices=0;
...@@ -219,4 +224,18 @@ GLenum PrepareGLiso (GLuint vao, GLuint vertbuffer, const std::vector<float> &ve ...@@ -219,4 +224,18 @@ GLenum PrepareGLiso (GLuint vao, GLuint vertbuffer, const std::vector<float> &ve
return e; return e;
} }
//#endif GLenum PrepareISOShader (GLuint *p, GLint *mat) {
\ No newline at end of file *p= CompileGLShader(
IsoShaders[SHADERNAME],
IsoShaders[SHADERVERTEX],
IsoShaders[SHADERFRAGMENT],
IsoShaders[SHADERTESSEVAL]
);
*mat=glGetUniformLocation(*p, "matrix");
if( *mat == -1 )
{
eprintf( "Unable to find matrix uniform in ISO shader\n" );
}
return glGetError();
}
...@@ -22,4 +22,7 @@ GLenum PrepareGLiso (GLuint vao, GLuint vertbuffer, const std::vector<float> &ve ...@@ -22,4 +22,7 @@ GLenum PrepareGLiso (GLuint vao, GLuint vertbuffer, const std::vector<float> &ve
#endif #endif
); );
#endif GLenum PrepareISOShader (GLuint *p, GLint *mat);
\ No newline at end of file
#endif // __ISOSURFACESGL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment