Commit 4685d45b by Kai Westerkamp

shader start

parent 53b97ddc
...@@ -176,6 +176,8 @@ void Controler::addVolume(QString filePath){ ...@@ -176,6 +176,8 @@ void Controler::addVolume(QString filePath){
int count = 0; int count = 0;
// std::cout<<std::hex; // std::cout<<std::hex;
int printLine = 150;
for(int k = 0; k < z; k++) for(int k = 0; k < z; k++)
{ {
data[k] = new char*[y]; data[k] = new char*[y];
...@@ -186,14 +188,13 @@ void Controler::addVolume(QString filePath){ ...@@ -186,14 +188,13 @@ void Controler::addVolume(QString filePath){
for(int i = 0; i < x; i++) for(int i = 0; i < x; i++)
{ {
data[k][j][i] = rawdata.at(count++); data[k][j][i] = rawdata.at(count++);
if(k == 150 ){ if(k == printLine ){
int temp = ((uchar)data[k][j][i])*9/256; int temp = ((uchar)data[k][j][i])*9/256;
std::cout<<temp; std::cout<<temp;
// std::cout<<((uint)data[k][j][i]);
} }
} }
if(k == 150){ if(k == printLine){
//std::cout<<std::endl; std::cout<<std::endl;
} }
} }
} }
......
...@@ -110,6 +110,9 @@ void GLView::paintGL () ...@@ -110,6 +110,9 @@ void GLView::paintGL ()
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D,texture3D);
displayShader->setUniformValue("volumeData",0);
shader->setUniformValue("shaded",true); shader->setUniformValue("shaded",true);
......
...@@ -290,9 +290,10 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -290,9 +290,10 @@ MainWindow::MainWindow(QWidget *parent)
//Assemble Tool Bar //Assemble Tool Bar
initToolbar(); initToolbar();
scene->simpleScene(); timer= new QTimer(this);
//controler->addVolume("D:/Projekte/GraPa/A3/lobster.raw");
connect(timer, SIGNAL(timeout()),this,SLOT(initScene()));
timer->start(1000);
setStatusBar(statusBar); setStatusBar(statusBar);
initDoc(); initDoc();
...@@ -300,6 +301,13 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -300,6 +301,13 @@ MainWindow::MainWindow(QWidget *parent)
} }
void MainWindow::initScene(){
//scene->simpleScene();
controler->addVolume("D:/Projekte/GraPa/A3/lobster.raw");
timer->stop();
}
void MainWindow::initDoc() void MainWindow::initDoc()
{ {
......
...@@ -77,6 +77,8 @@ private: ...@@ -77,6 +77,8 @@ private:
QSpinBox* gridStepInput; QSpinBox* gridStepInput;
QToolButton* showGridButton; QToolButton* showGridButton;
QTimer *timer;
void initDoc(); void initDoc();
...@@ -104,6 +106,7 @@ public slots: ...@@ -104,6 +106,7 @@ public slots:
void showSingle(); void showSingle();
void showDual(); void showDual();
void showQuad(); void showQuad();
void initScene();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
uniform bool shaded; uniform bool shaded;
uniform bool volume;
uniform sampler3D volumeData;
varying vec4 pick; varying vec4 pick;
varying vec3 position; varying vec3 position;
...@@ -7,35 +10,39 @@ varying vec3 normal; ...@@ -7,35 +10,39 @@ varying vec3 normal;
void main(void) void main(void)
{ {
vec3 N = normalize(normal); vec3 V = normalize(-position);
vec3 L = normalize(gl_LightSource[0].position.xyz-position);
vec4 diffuse = vec4(max(dot(L,N),0.0)); if(volume){
vec4 Iamb = gl_FrontLightProduct[0].ambient; // gl_FragData[0] = vec4(gl_TexCoord[0].xyz,1);
vec4 Idiff = gl_FrontLightProduct[0].diffuse*diffuse;
Idiff = clamp(Idiff, 0.0, 1.0);
vec3 V = normalize(-position); gl_FragData[0] = vec4(texture3D(volumeData,gl_TexCoord[0].xyz).x);
}
else if(shaded){
vec3 N = normalize(normal);
vec3 L = normalize(gl_LightSource[0].position.xyz-position);
vec4 diffuse = vec4(max(dot(L,N),0.0));
vec4 Iamb = gl_FrontLightProduct[0].ambient;
vec4 Idiff = gl_FrontLightProduct[0].diffuse*diffuse;
Idiff = clamp(Idiff, 0.0, 1.0);
vec3 R = normalize(reflect(-L,N)); vec3 R = normalize(reflect(-L,N));
float specular = pow(max(dot(R,V),0.0),gl_FrontMaterial.shininess);//); float specular = pow(max(dot(R,V),0.0),gl_FrontMaterial.shininess);//);
vec4 Ispec = gl_FrontLightProduct[0].specular * specular; vec4 Ispec = gl_FrontLightProduct[0].specular * specular;
Ispec = clamp(Ispec, 0.0, 1.0); Ispec = clamp(Ispec, 0.0, 1.0);
vec4 color = ( vec4 color = (Iamb + Idiff + Ispec );
Iamb
+ Idiff
+ Ispec
);
if(shaded)
gl_FragData[0] = color; gl_FragData[0] = color;
}
else else
gl_FragData[0] = vec4(1,1,0,1); gl_FragData[0] = vec4(1,1,0,1);
gl_FragData[1] = pick; gl_FragData[1] = pick;
gl_FragData[1] = vec4(abs(normal),1); //gl_FragData[1] = vec4(abs(normal),1);
} }
...@@ -12,6 +12,7 @@ varying vec3 position; ...@@ -12,6 +12,7 @@ varying vec3 position;
varying vec3 normal; varying vec3 normal;
varying vec4 pick; varying vec4 pick;
void main(void) void main(void)
{ {
normal = normalize(gl_NormalMatrix * gl_Normal); normal = normalize(gl_NormalMatrix * gl_Normal);
...@@ -20,6 +21,8 @@ void main(void) ...@@ -20,6 +21,8 @@ void main(void)
pick = vec4(pickID); pick = vec4(pickID);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
} }
...@@ -17,6 +17,7 @@ Scene::~Scene( ) ...@@ -17,6 +17,7 @@ Scene::~Scene( )
int Scene::simpleScene() int Scene::simpleScene()
{ {
/*
addCube(); addCube();
moveActive(QVector3D(4,0,0)); moveActive(QVector3D(4,0,0));
...@@ -33,7 +34,7 @@ int Scene::simpleScene() ...@@ -33,7 +34,7 @@ int Scene::simpleScene()
addCone(); addCone();
moveActive(QVector3D(0,-1.5,-1.5)); moveActive(QVector3D(0,-1.5,-1.5));
*/
return active->getID(); return active->getID();
......
...@@ -35,23 +35,12 @@ void SceneVolume::draw(QGLShaderProgram *shader){ ...@@ -35,23 +35,12 @@ void SceneVolume::draw(QGLShaderProgram *shader){
glPushMatrix(); glPushMatrix();
applyTransformation(); applyTransformation();
shader->setUniformValue("volume", true);
float color[] = {0.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,white);
GLfloat mShininess[] = {128};
glMaterialfv(GL_FRONT,GL_SHININESS,mShininess);
float x = lx/2; float x = lx/2;
float y = ly/2; float y = ly/2;
float z = lz/2; float z = lz/2;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glNormal3f(0,1,0); glNormal3f(0,1,0);
glTexCoord3i(1,1,0); glTexCoord3i(1,1,0);
...@@ -124,9 +113,9 @@ void SceneVolume::draw(QGLShaderProgram *shader){ ...@@ -124,9 +113,9 @@ void SceneVolume::draw(QGLShaderProgram *shader){
glVertex3f( x, -y, -z); glVertex3f( x, -y, -z);
glEnd(); glEnd();
glPopMatrix(); glPopMatrix();
shader->setUniformValue("volume", false);
} }
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