Commit 43f1ed0f by Kai Westerkamp

first spell

parent a31ebbd8
File deleted
...@@ -12,7 +12,7 @@ class Camera: public QObject ...@@ -12,7 +12,7 @@ class Camera: public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
bool persp;
// QQuaternion *rotation; // QQuaternion *rotation;
// QVector3D *translation; // QVector3D *translation;
...@@ -25,6 +25,7 @@ public slots: ...@@ -25,6 +25,7 @@ public slots:
void home(); void home();
public: public:
bool persp;
QQuaternion *rotation; QQuaternion *rotation;
QVector3D *translation; QVector3D *translation;
......
...@@ -131,8 +131,30 @@ void Controler::setEditMode(){ ...@@ -131,8 +131,30 @@ void Controler::setEditMode(){
viewMode = EDIT; viewMode = EDIT;
} }
QImage* Controler::loadImage(QString Text)
{
QString fn = QFileDialog::getOpenFileName(NULL, Text,
QString("D:\\Projekte\\GraPa\\A4"), tr("Texture (*.jpg )"));
if(fn.isEmpty())
return NULL;
qDebug()<<"Opening Texture:"<<fn;
return new QImage(fn, "jpg");
}
void Controler::addLandscape() void Controler::addLandscape()
{ {
QImage *texture = loadImage("First Texture");
// for(int i = 0; i < 4; i++)
mainwindow->getViews()[0]->setLandscapeTexture(1,texture);
texture = loadImage("Second Texture");
// for(int i = 0; i < 4; i++)
mainwindow->getViews()[0]->setLandscapeTexture(2,texture);
QString fn = QFileDialog::getOpenFileName(NULL, tr("Open Volume..."), QString fn = QFileDialog::getOpenFileName(NULL, tr("Open Volume..."),
QString("D:\\Projekte\\GraPa\\A4"), tr("Portable Grayscale Map (*.pgm )")); QString("D:\\Projekte\\GraPa\\A4"), tr("Portable Grayscale Map (*.pgm )"));
...@@ -140,6 +162,7 @@ void Controler::addLandscape() ...@@ -140,6 +162,7 @@ void Controler::addLandscape()
return; return;
qDebug()<<"Opening File:"<<fn; qDebug()<<"Opening File:"<<fn;
addLandscape(fn); addLandscape(fn);
} }
void Controler::addLandscape(QString filePath) void Controler::addLandscape(QString filePath)
...@@ -176,7 +199,7 @@ void Controler::addLandscape(QString filePath) ...@@ -176,7 +199,7 @@ void Controler::addLandscape(QString filePath)
QByteArray rawdata = file.readAll(); QByteArray rawdata = file.readAll();
boolean shortNeeded = max < 256; boolean shortNeeded = max > 256;
char *data; char *data;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QObject> #include <QObject>
#include <QtGui> #include <QtGui>
#include <QImage>
class camera; class camera;
class GLView; class GLView;
...@@ -31,6 +32,8 @@ public slots: ...@@ -31,6 +32,8 @@ public slots:
void addLandscape(); void addLandscape();
void addLandscape(QString filePath); void addLandscape(QString filePath);
QImage *loadImage(QString Text);
private: private:
MainWindow *mainwindow; MainWindow *mainwindow;
Scene *scene; Scene *scene;
......
...@@ -15,6 +15,27 @@ GLView::GLView(Scene *scene,Camera * camera,Controler *controler ) ...@@ -15,6 +15,27 @@ GLView::GLView(Scene *scene,Camera * camera,Controler *controler )
MIP = false; MIP = false;
afterInit = false; afterInit = false;
landscape = false; landscape = false;
if(camera->persp)
setFocusPolicy(Qt::StrongFocus);
}
void GLView::keyPressEvent(QKeyEvent* event){
float stepsize = 0.15;
switch (event->key()) {
case Qt::Key_W:
camera->move(QVector3D(0.0,0.0,stepsize));
case Qt::Key_S:
camera->move(QVector3D(0.0,0.0,-stepsize));
case Qt::Key_A:
camera->move(QVector3D(stepsize,0.0,0.0));
case Qt::Key_D:
camera->move(QVector3D(-stepsize,0.0,0.0));
case Qt::SHIFT:
camera->move(QVector3D(0.0,stepsize,0.0));
default: QWidget::keyPressEvent(event);
};
updateGL();
} }
QSize GLView::minimumSizeHint() const QSize GLView::minimumSizeHint() const
...@@ -170,10 +191,33 @@ void GLView::paintGL () ...@@ -170,10 +191,33 @@ void GLView::paintGL ()
if(landscape){ if(landscape){
if(MIP)
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glLineWidth(1);
landscapeShader->bind(); landscapeShader->bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,heightmap);
landscapeShader->setUniformValue("HeightMap",0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,landscapeTexture1);
landscapeShader->setUniformValue("landTex1",1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D,landscapeTexture2);
landscapeShader->setUniformValue("landTex2",2);
landscapeShader->setUniformValue("heightScale",5);
landscapeShader->setUniformValue("horizontalScale",10);
QVector3D cam = QVector3D()-*camera->translation;
cam = camera->rotation->conjugate().rotatedVector(cam);
landscapeShader->setUniformValue("CamPos",cam);
glBindVertexArray(vertexArray); glBindVertexArray(vertexArray);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indices); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indices);
...@@ -182,6 +226,8 @@ void GLView::paintGL () ...@@ -182,6 +226,8 @@ void GLView::paintGL ()
glDrawElements(GL_PATCHES, IndexCount, GL_UNSIGNED_INT, 0); glDrawElements(GL_PATCHES, IndexCount, GL_UNSIGNED_INT, 0);
landscapeShader->release(); landscapeShader->release();
if(MIP)
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
} }
...@@ -487,6 +533,42 @@ void GLView::loadData(int width, int height, int depth, char* data, int type ) ...@@ -487,6 +533,42 @@ void GLView::loadData(int width, int height, int depth, char* data, int type )
GL_RED,type , data); // Imagedata as ByteBuffer GL_RED,type , data); // Imagedata as ByteBuffer
} }
void GLView::setLandscapeTexture(int number, QImage* texture){
if (texture == NULL){
return;
}
QImage textureImg = QGLWidget::convertToGLFormat( *texture );
if(number == 1){
glGenTextures( 1, &landscapeTexture1 );
glBindTexture( GL_TEXTURE_2D, landscapeTexture1 );
qDebug()<<"Load";
} else if(number == 2){
glGenTextures( 1, &landscapeTexture2 );
glBindTexture( GL_TEXTURE_2D, landscapeTexture2 );
} else
qDebug()<<"Error";
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureImg.width(), textureImg.height(), 0, GL_RGBA,
GL_UNSIGNED_BYTE, textureImg.bits());
// Filtering
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Wrap
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glBindTexture( GL_TEXTURE_2D, 0 );
}
void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char* data){ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char* data){
glGenTextures(1,&heightmap); glGenTextures(1,&heightmap);
glBindTexture(GL_TEXTURE_2D,heightmap); glBindTexture(GL_TEXTURE_2D,heightmap);
...@@ -512,7 +594,7 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char* ...@@ -512,7 +594,7 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char*
const int numberOfQuads = 50; const int numberOfQuads = 50;
const int numberOfVertecies = numberOfQuads+1; const int numberOfVertecies = numberOfQuads+1;
const float sizeOfQuads = 0.5; const float sizeOfQuads = 1.0;
float offset = (numberOfQuads)/2.0 * sizeOfQuads; float offset = (numberOfQuads)/2.0 * sizeOfQuads;
const int size = numberOfVertecies*numberOfVertecies * 3; const int size = numberOfVertecies*numberOfVertecies * 3;
...@@ -523,15 +605,15 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char* ...@@ -523,15 +605,15 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char*
int pos = (i*numberOfVertecies+j)*3; int pos = (i*numberOfVertecies+j)*3;
vertices[pos] = j*sizeOfQuads-offset; vertices[pos] = j*sizeOfQuads-offset;
vertices[pos+1] = i*sizeOfQuads-offset; vertices[pos+2] = i*sizeOfQuads-offset;
vertices[pos+2] = 0.0; vertices[pos+1] = 0.0;
} }
} }
// qDebug()<<"--------------------------------------"; // qDebug()<<"--------------------------------------";
// for (int var = 0; var < 51*3; var+=3) { // for (int var = 0; var < 51*3; var+=3) {
// qDebug()<<var/3<<vertices[var]<<vertices[var+1]<< vertices[var+2]; // qDebug()<<var/3<<vertices[var]<<vertices[var+1]<< vertices[var+2];
// } // }
IndexCount = numberOfQuads*numberOfQuads * 4; IndexCount = numberOfQuads*numberOfQuads * 4;
const int size2 = numberOfQuads*numberOfQuads * 4; const int size2 = numberOfQuads*numberOfQuads * 4;
...@@ -548,10 +630,10 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char* ...@@ -548,10 +630,10 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char*
} }
} }
// qDebug()<<"--------------------------------------"; // qDebug()<<"--------------------------------------";
// for (int var = 50*4*0; var < 50*4*2; var+=4) { // for (int var = 50*4*0; var < 50*4*2; var+=4) {
// qDebug()<<var/4<<"-"<<indicesI[var]<<indicesI[var+1]<< indicesI[var+2]<< indicesI[var+3]; // qDebug()<<var/4<<"-"<<indicesI[var]<<indicesI[var+1]<< indicesI[var+2]<< indicesI[var+3];
// } // }
// Create the vertexArray: // Create the vertexArray:
glGenVertexArrays(1, &vertexArray); glGenVertexArrays(1, &vertexArray);
...@@ -573,8 +655,8 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char* ...@@ -573,8 +655,8 @@ void GLView::setLandscape(int width,int height,int max,boolean shortNeeded,char*
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indicesI), indicesI, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indicesI), indicesI, GL_STATIC_DRAW);
// glDisableVertexAttribArray(0); // glDisableVertexAttribArray(0);
// glBindVertexArray(0); // glBindVertexArray(0);
landscape = true; landscape = true;
......
...@@ -21,6 +21,8 @@ protected : ...@@ -21,6 +21,8 @@ protected :
void mousePressEvent(QMouseEvent *event ) ; void mousePressEvent(QMouseEvent *event ) ;
void mouseMoveEvent(QMouseEvent *event ) ; void mouseMoveEvent(QMouseEvent *event ) ;
void wheelEvent(QWheelEvent *event ) ; void wheelEvent(QWheelEvent *event ) ;
void keyPressEvent(QKeyEvent* event);
public slots: public slots:
void home(); void home();
...@@ -29,9 +31,11 @@ public slots: ...@@ -29,9 +31,11 @@ public slots:
void showGrid(bool bo){isGridEnabled = bo;} void showGrid(bool bo){isGridEnabled = bo;}
void loadData(int width, int height, int depth, char* data, int type); void loadData(int width, int height, int depth, char* data, int type);
void setLandscape(int width,int height,int max,boolean shortNeeded,char* data); void setLandscape(int width,int height,int max,boolean shortNeeded,char* data);
void setLandscapeTexture(int number, QImage *texture);
void loadTransfer(uchar* data); void loadTransfer(uchar* data);
void setMIP(bool mip); void setMIP(bool mip);
public: public:
GLView(Scene *scene,Camera * camera,Controler *controler ); GLView(Scene *scene,Camera * camera,Controler *controler );
void setHome(QQuaternion *rotation, QVector3D *translation); void setHome(QQuaternion *rotation, QVector3D *translation);
...@@ -72,12 +76,16 @@ private: ...@@ -72,12 +76,16 @@ private:
GLuint transferFunction; GLuint transferFunction;
bool MIP; bool MIP;
bool wireframe;
int IndexCount; int IndexCount;
bool landscape; bool landscape;
GLuint heightmap; GLuint heightmap;
GLuint vertexArray; GLuint vertexArray;
GLuint indices; GLuint indices;
GLuint landscapeTexture1;
GLuint landscapeTexture2;
void drawGrid(); void drawGrid();
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2016-01-02T12:10:50. --> <!-- Written by QtCreator 3.5.1, 2016-01-04T16:24:23. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
#version 420 #version 420
out vec4 FragColor; out vec4 FragColor;
//in vec3 gFacetNormal;
//in vec3 gTriDistance; in vec3 tePosition;
//in vec3 gPatchDistance; in vec2 teUV;
//in float gPrimitive;
//uniform vec3 LightPosition; uniform sampler2D heightmap;
//uniform vec3 DiffuseMaterial; uniform sampler2D landTex1;
//uniform vec3 AmbientMaterial; uniform sampler2D landTex2;
//float amplify(float d, float scale, float offset)
//{
// d = scale * d + offset;
// d = clamp(d, 0, 1);
// d = 1 - exp2(-2*d*d);
// return d;
//}
void main() void main()
{ {
// vec3 N = normalize(gFacetNormal); //
// vec3 L = LightPosition;
// float df = abs(dot(N, L)); vec2 textureUV = teUV*8;
// vec3 color = AmbientMaterial + df * DiffuseMaterial; vec3 col1 = texture2D(landTex1,textureUV).xyz;
vec3 col2 = texture2D(landTex2,textureUV).xyz;
float height = tePosition.y/5;
float alpha = smoothstep(0.4f,0.6f,height);
//float alpha = clamp(height,0.0,1.0);
FragColor = vec4((1-alpha)*col2 + alpha *col1,1.0);
//FragColor = vec4(alpha);
//FragColor = vec4(col1,1.0);
//FragColor = clamp(vec4(vec3(textureLod(heightmap,teUV,0).x), 1.0)*10,0,1);
// float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
// float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z);
// color = amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5) * color;
FragColor = vec4(1.0,0.0,0.0, 1.0);
} }
#version 420 #version 420
layout(vertices = 4) out; layout(vertices = 4) out;
in vec3 vPosition[]; in vec3 vPosition[];
out vec3 tcPosition[]; out vec3 tcPosition[];
in vec2 vUV[];
out vec2 tcUV[];
uniform vec3 CamPos;
float calcTessellationLevel( const in float v1, const in float v2 )
{
float maxdist = min(v1,v2)/8;
float tesselationFactor = 5/(maxdist*maxdist);
return pow(min(tesselationFactor,5),2);
}
float computeDistance(in vec3 a)
{
return length(vec3(0.0,-CamPos.y,0.0)-a);
}
void main() void main()
{ {
tcPosition[gl_InvocationID] = vPosition[gl_InvocationID]; tcPosition[gl_InvocationID] = vPosition[gl_InvocationID];
tcUV[gl_InvocationID] = vUV[gl_InvocationID];
float tesselation = 1.0; float tesselation = 1.0;
gl_TessLevelInner[0] = tesselation;
gl_TessLevelInner[1] = tesselation;
gl_TessLevelOuter[0]= tesselation; float distances[4];
gl_TessLevelOuter[1]= tesselation; distances[0] = computeDistance(vPosition[0]);
gl_TessLevelOuter[2]= tesselation; distances[1] = computeDistance(vPosition[1]);
gl_TessLevelOuter[3]= tesselation; distances[2] = computeDistance(vPosition[2]);
distances[3] = computeDistance(vPosition[3]);
gl_TessLevelOuter[0] = calcTessellationLevel( distances[0], distances[3] );
gl_TessLevelOuter[2] = calcTessellationLevel( distances[1], distances[2] );
gl_TessLevelOuter[1] = calcTessellationLevel( distances[0], distances[1] );
gl_TessLevelOuter[3] = calcTessellationLevel( distances[2], distances[3] );
float tess = max( gl_TessLevelOuter[1], gl_TessLevelOuter[2] );
tess = max(tess, gl_TessLevelOuter[3]);
tess = max(tess, gl_TessLevelOuter[0]);
gl_TessLevelInner[0] = tess;
gl_TessLevelInner[1] = tess;
} }
#version 420 #version 420 compatibility
layout(quads, equal_spacing, cw) in; layout(quads, equal_spacing, cw) in;
in vec3 tcPosition[];
//out vec3 tePosition; in vec3 tcPosition[];
//out vec3 tePatchDistance; out vec3 tePosition;
//uniform mat4 Projection; in vec2 tcUV[];
//uniform mat4 Modelview; out vec2 teUV;
uniform sampler2D heightmap;
uniform vec3 CamPos;
vec3 pt_q(in vec3 p0,in vec3 p1,in vec3 p2,in vec3 p3,in float u,in float v){ vec3 pt_q(in vec3 p0,in vec3 p1,in vec3 p2,in vec3 p3,in float u,in float v){
return (1.0-u)*(1.0-v)*p0+u*(1.0-v)*p1+(1.0-u)*v*p3+u*v*p2; return (1.0-u)*(1.0-v)*p0+u*(1.0-v)*p1+(1.0-u)*v*p3+u*v*p2;
} }
vec2 pt_uv(in vec2 p0,in vec2 p1,in vec2 p2,in vec2 p3,in float u,in float v){
return (1.0-u)*(1.0-v)*p0+u*(1.0-v)*p1+(1.0-u)*v*p3+u*v*p2;
}
void main() void main()
{ {
...@@ -24,15 +28,21 @@ void main() ...@@ -24,15 +28,21 @@ void main()
vec3 p2 = tcPosition[2]; vec3 p2 = tcPosition[2];
vec3 p3 = tcPosition[3]; vec3 p3 = tcPosition[3];
float tess = gl_TessLevelInner[0];
teUV = pt_uv(tcUV[0],tcUV[1],tcUV[2],tcUV[3],u,v);
float height = textureLod(heightmap,teUV,0).x*50;
//tePatchDistance = gl_TessCoord; //tePatchDistance = gl_TessCoord;
vec3 tePosition = pt_q(p0,p1,p2,p3,u,v); tePosition = pt_q(p0,p1,p2,p3,u,v);
tePosition.y = height;
// tePosition =tePosition+ vec3(CamPos.x,0.0,CamPos.z);
float Angle = 1.5707;
mat4 RotationMatrix = mat4( cos( Angle ), -sin( Angle ), 0.0, 0.0,
sin( Angle ), cos( Angle ), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
gl_Position = RotationMatrix*vec4(tePosition, 1); gl_Position = gl_ModelViewProjectionMatrix*vec4(tePosition, 1);
} }
#version 420 #version 420
layout(location = 0) in vec4 Position; layout(location = 0) in vec4 Position;
out vec3 vPosition; out vec3 vPosition;
out vec2 vUV;
void main(void) void main(void)
{ {
vPosition.xyz = Position.xyz; vPosition.xyz = Position.xyz;
vUV = (Position.xz / 50)+0.5;
} }
File deleted
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