This commit is contained in:
Dmitri K 2016-11-10 15:36:22 -05:00
parent d1ed0a00dd
commit 89c2187f7f
6 changed files with 724 additions and 731 deletions

View File

@ -2,6 +2,7 @@
uniform vec3 lDirection; uniform vec3 lDirection;
uniform bool isSky; uniform bool isSky;
uniform bool isPhong; uniform bool isPhong;
uniform bool isPickerColor;
uniform sampler2D tex; uniform sampler2D tex;
uniform float skyMult; uniform float skyMult;
@ -16,7 +17,10 @@ void
main() main()
{ {
vec4 texColor = texture(tex, texCoords); vec4 texColor = texture(tex, texCoords);
if(isSky) {
if(isPickerColor){
fColor = ifColor;
} else if(isSky) {
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2; fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
} else if(isPhong) { } else if(isPhong) {
// Get lighting vectors // Get lighting vectors
@ -40,5 +44,5 @@ main()
//fColor = vec4(fNormal, 1); //fColor = vec4(fNormal, 1);
} else { } else {
fColor = texColor * ifColor; fColor = texColor * ifColor;
} }
} }

View File

@ -8,6 +8,7 @@ uniform vec4 color;
uniform bool isSky; uniform bool isSky;
uniform bool isPhong; uniform bool isPhong;
uniform bool isPickerColor;
in vec4 vPosition; in vec4 vPosition;
in vec3 vNormal; in vec3 vNormal;
@ -30,7 +31,7 @@ main()
ifColor = color; ifColor = color;
if(!isPhong && !isSky) { if(!isPickerColor && !isPhong && !isSky) {
// Get lighting vectors // Get lighting vectors
vec3 LightDirection = normalize(lDirection); vec3 LightDirection = normalize(lDirection);
vec3 nfNormal = normalize(fNormal); vec3 nfNormal = normalize(fNormal);
@ -50,5 +51,6 @@ main()
ifColor = vec4(color * (0.1 + diffuse + specular), 1); ifColor = vec4(color * (0.1 + diffuse + specular), 1);
//ifColor = vec4(fNormal, 1); //ifColor = vec4(fNormal, 1);
} }
} }

View File

@ -9,7 +9,7 @@ in vec4 vPosition;
void void
main() main()
{ {
gl_Position = projMatrix * mvMatrix * vPosition; gl_Position = projMatrix * mvMatrix * vPosition;
texCoords = vUv; texCoords = vUv;
} }

View File

@ -1,15 +0,0 @@
#version 400 core
uniform mat4 mvMatrix;
uniform mat4 projMatrix;
out vec2 texCoords;
in vec2 vUv;
in vec4 vPosition;
void
main()
{
gl_Position = projMatrix * mvMatrix * vPosition;
texCoords = vUv;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,122 +1,123 @@
/**************************************************************************** /****************************************************************************
Copyright (C) 2002-2008 Gilles Debunne. All rights reserved. Copyright (C) 2002-2008 Gilles Debunne. All rights reserved.
This file is part of the QGLViewer library version 2.3.6. This file is part of the QGLViewer library version 2.3.6.
http://www.libqglviewer.com - contact@libqglviewer.com http://www.libqglviewer.com - contact@libqglviewer.com
This file may be used under the terms of the GNU General Public License This file may be used under the terms of the GNU General Public License
versions 2.0 or 3.0 as published by the Free Software Foundation and versions 2.0 or 3.0 as published by the Free Software Foundation and
appearing in the LICENSE file included in the packaging of this file. appearing in the LICENSE file included in the packaging of this file.
In addition, as a special exception, Gilles Debunne gives you certain In addition, as a special exception, Gilles Debunne gives you certain
additional rights, described in the file GPL_EXCEPTION in this package. additional rights, described in the file GPL_EXCEPTION in this package.
libQGLViewer uses dual licensing. Commercial/proprietary software must libQGLViewer uses dual licensing. Commercial/proprietary software must
purchase a libQGLViewer Commercial License. purchase a libQGLViewer Commercial License.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*****************************************************************************/ *****************************************************************************/
#ifndef SIMPLEVIEWER_H #ifndef SIMPLEVIEWER_H
#define SIMPLEVIEWER_H #define SIMPLEVIEWER_H
#include <QOpenGLFunctions_4_0_Core> #include <QOpenGLFunctions_4_0_Core>
#include <QOpenGLVertexArrayObject> #include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
#include <QOpenGLTexture> #include <QOpenGLTexture>
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QGLViewer/qglviewer.h> #include <QGLViewer/qglviewer.h>
#include "../interfaces/visitor.h" #include "../interfaces/visitor.h"
#include "../glnodes/glnode.h" #include "../glnodes/glnode.h"
#include "../glnodes/scenegroup.h" #include "../glnodes/scenegroup.h"
#include "../glnodes/shapes.h" #include "../glnodes/shapes.h"
#include <stack> #include <stack>
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram) QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
class Viewer : public QGLViewer, class Viewer : public QGLViewer,
protected QOpenGLFunctions_4_0_Core, protected QOpenGLFunctions_4_0_Core,
public Visitor public Visitor
{ {
Q_OBJECT Q_OBJECT
public: public:
Viewer(); Viewer();
~Viewer(); ~Viewer();
virtual void visit(SceneGroup &s); virtual void visit(SceneGroup &s);
virtual void visit(Cube &s); virtual void visit(Cube &s);
public slots: public slots:
void cleanup(); void cleanup();
void changeColor(QColor); void changeColor(QColor);
void setPhong(bool); void setPhong(bool);
signals: signals:
int shapeSelected(int); int shapeSelected(int);
protected : protected :
virtual void draw(); virtual void draw();
virtual void drawSkybox(); virtual void drawSkybox();
virtual void init(); virtual void init();
virtual void mouseMoveEvent(QMouseEvent* e); virtual void mouseMoveEvent(QMouseEvent* e);
virtual void mouseReleaseEvent(QMouseEvent* e); virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void mousePressEvent(QMouseEvent *e); virtual void mousePressEvent(QMouseEvent *e);
SceneGroup root; SceneGroup root;
std::stack<QMatrix4x4> modelStack; std::stack<QMatrix4x4> modelStack;
private: private:
void initShaders(); void initShaders();
void initGeometries(); void initGeometries();
void deselect(); void deselect();
Shape* pickGeom(int, int); Shape* pickGeom(int, int);
// shader switching variables and constants; // shader switching variables and constants;
QOpenGLShaderProgram *colorPickerShaderProgram; QOpenGLShaderProgram *colorPickerShaderProgram;
QOpenGLShaderProgram *textureRenderShaderprogram; QOpenGLShaderProgram *textureRenderShaderprogram;
QOpenGLShaderProgram *skyboxRenderShaderProgram; QOpenGLShaderProgram *skyboxRenderShaderProgram;
QOpenGLShaderProgram *m_program; QOpenGLShaderProgram *m_program;
int m_vPositionLocation; int m_vPositionLocation;
int m_colorLocation; int m_colorLocation;
int m_projMatrixLocation; int m_projMatrixLocation;
int m_mvMatrixLocation; int m_mvMatrixLocation;
int s_texCoordsLocation; int s_texCoordsLocation;
int s_vPositionLocation; int s_vPositionLocation;
int s_mvMatrixLocation; int s_mvMatrixLocation;
int s_colorLocation; int s_colorLocation;
int s_projMatrixLocation; int s_projMatrixLocation;
int s_skyboxCubemapLocation; int s_skyboxCubemapLocation;
int s_vUvLocation; int s_vUvLocation;
int m_vNormalLocation; int m_vNormalLocation;
int m_isPhongLoc; int m_isPhongLoc;
int m_isSkyLoc; int m_isSkyLoc;
int m_lDirLoc; int m_lDirLoc;
int m_skyMultLoc; int m_skyMultLoc;
bool m_pickerColor;
float angle_mult;
float angle_mult;
QOpenGLTexture *s_texture;
QOpenGLTexture *s_texture;
SceneGroup* activeCell;
QColor* activeColor; SceneGroup* activeCell;
int activeShape; QColor* activeColor;
int activeShape;
enum VAO_IDs { VAO_Cube, NumVAOs };
enum Buffer_IDs { VBO_Cube, NumBuffers }; enum VAO_IDs { VAO_Cube, NumVAOs };
enum Buffer_IDs { VBO_Cube, NumBuffers };
GLuint m_VAOs[NumVAOs];
GLuint m_Buffers[NumBuffers]; GLuint m_VAOs[NumVAOs];
GLuint m_Buffers[NumBuffers];
Shape* generateShapeFromIndex(int);
Shape* generateShapeFromIndex(int);
QQuaternion rot;
unsigned int frame; QQuaternion rot;
}; unsigned int frame;
};
#endif // SIMPLEVIEWER_H
#endif // SIMPLEVIEWER_H