mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
rip
This commit is contained in:
parent
968f0761a2
commit
52d547bd1e
@ -53,9 +53,7 @@ HEADERS += QGLViewer/camera.h \
|
|||||||
|
|
||||||
DISTFILES += src/shaders/basicShader.vert \
|
DISTFILES += src/shaders/basicShader.vert \
|
||||||
src/shaders/basicShader.frag \
|
src/shaders/basicShader.frag \
|
||||||
src/data/skybox.jpg \
|
src/data/skybox.jpg
|
||||||
src/shaders/skyboxShader.frag \
|
|
||||||
src/shaders/skyboxShader.vert
|
|
||||||
|
|
||||||
FORMS += QGLViewer/ImageInterface.ui mainwindow.ui
|
FORMS += QGLViewer/ImageInterface.ui mainwindow.ui
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ uniform float skyMult;
|
|||||||
uniform bool drawTextures;
|
uniform bool drawTextures;
|
||||||
uniform bool isLightSource;
|
uniform bool isLightSource;
|
||||||
uniform vec3 pointLight[3];
|
uniform vec3 pointLight[3];
|
||||||
|
uniform vec4 pointLightCol[3];
|
||||||
|
|
||||||
in vec3 fNormal;
|
in vec3 fNormal;
|
||||||
in vec3 fPosition;
|
in vec3 fPosition;
|
||||||
@ -30,7 +31,7 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
|||||||
float spec = 0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
|
float spec = 0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
|
||||||
|
|
||||||
// Compute ambient component
|
// Compute ambient component
|
||||||
float amb = 0.1;
|
float amb = 0.05;
|
||||||
|
|
||||||
//return vec4(0);
|
//return vec4(0);
|
||||||
return vec4(tex.xyz * (amb + diff + spec), tex.w);
|
return vec4(tex.xyz * (amb + diff + spec), tex.w);
|
||||||
@ -38,7 +39,7 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
|||||||
|
|
||||||
vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 LightDirection = normalize(fPos - pointLight[i]);
|
||||||
vec3 nfNormal = normalize(fNorm);
|
vec3 nfNormal = normalize(fNorm);
|
||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
|||||||
// Compute ambient component
|
// Compute ambient component
|
||||||
float amb = 0;
|
float amb = 0;
|
||||||
|
|
||||||
return vec4(tex.xyz * attenuation * (amb + diff + spec), tex.w);
|
return vec4(1 * pointLightCol[i].xyz * attenuation * (amb + diff + spec), pointLightCol[i].w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@ -44,7 +44,7 @@ vec4 calcDirLight(vec4 eye, vec3 fPos, vec3 fNorm) {
|
|||||||
|
|
||||||
vec4 calcPointLight(vec4 eye, vec3 fPos, vec3 fNorm, int i) {
|
vec4 calcPointLight(vec4 eye, vec3 fPos, vec3 fNorm, int i) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 LightDirection = normalize(pointLight[i] - fPos);
|
||||||
vec3 nfNormal = normalize(fNorm);
|
vec3 nfNormal = normalize(fNorm);
|
||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
#version 400 core
|
|
||||||
in vec2 texCoords;
|
|
||||||
out vec4 fColor;
|
|
||||||
|
|
||||||
uniform sampler2D skybox;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
//fColor = vec4(1);
|
|
||||||
//fColor = texture(skybox, texCoords);
|
|
||||||
}
|
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -162,9 +162,9 @@ void Viewer::draw()
|
|||||||
// Adjust sun position
|
// Adjust sun position
|
||||||
|
|
||||||
float rotAngle = std::fmod(angle_mult * frame, 360);
|
float rotAngle = std::fmod(angle_mult * frame, 360);
|
||||||
sunRotate.rotate(rotAngle, 1, 0, 0);
|
//sunRotate.rotate(rotAngle, 1, 0, 0);
|
||||||
|
|
||||||
m_program->setUniformValue(m_lDirLoc, (sunRotate * sun));
|
m_program->setUniformValue(m_lDirLoc, (modelViewMatrix * sunRotate * sun));
|
||||||
selection->transform.setToIdentity();
|
selection->transform.setToIdentity();
|
||||||
selection->transform.rotate(rotAngle, 0, 1, 0);
|
selection->transform.rotate(rotAngle, 0, 1, 0);
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ void Viewer::draw()
|
|||||||
|
|
||||||
modelStack.push(modelViewMatrix);
|
modelStack.push(modelViewMatrix);
|
||||||
root.accept(*this);
|
root.accept(*this);
|
||||||
frame++;
|
frame += 2;
|
||||||
|
|
||||||
sunRotate.setToIdentity();
|
sunRotate.setToIdentity();
|
||||||
//float rotAngle = (frame * angle_mult) % 360;
|
//float rotAngle = (frame * angle_mult) % 360;
|
||||||
@ -250,16 +250,26 @@ void Viewer::init()
|
|||||||
Shape* cube = new Cube();
|
Shape* cube = new Cube();
|
||||||
cube->setColor(*activeColor);
|
cube->setColor(*activeColor);
|
||||||
|
|
||||||
|
QColor* c1 = new QColor(255, 0, 255, 255);
|
||||||
|
QColor* c2 = new QColor(0, 255, 255, 255);
|
||||||
|
QColor* c3 = new QColor(255, 255, 0, 255);
|
||||||
|
|
||||||
Shape* s1 = new Sphere();
|
Shape* s1 = new Sphere();
|
||||||
Shape* s2 = new Sphere();
|
Shape* s2 = new Sphere();
|
||||||
Shape* s3 = new Sphere();
|
Shape* s3 = new Sphere();
|
||||||
|
|
||||||
s1->transform.rotate(360 * 1/3,0,1,0);
|
s1->transform.rotate(360 * 1/3,0,1,0);
|
||||||
s1->transform.translate(1.5,0,0);
|
s1->transform.translate(0.5,1,0);
|
||||||
|
s1->transform.scale(0.3);
|
||||||
|
s1->setColor(*c1);
|
||||||
s2->transform.rotate(360 * 2/3,0,1,0);
|
s2->transform.rotate(360 * 2/3,0,1,0);
|
||||||
s2->transform.translate(1.5,0,0);
|
s2->transform.translate(0.5,1,0);
|
||||||
|
s2->transform.scale(0.3);
|
||||||
|
s2->setColor(*c2);
|
||||||
s3->transform.rotate(360 * 3/3,0,1,0);
|
s3->transform.rotate(360 * 3/3,0,1,0);
|
||||||
s3->transform.translate(1.5,0,0);
|
s3->transform.translate(0.5,1,0);
|
||||||
|
s3->transform.scale(0.3);
|
||||||
|
s3->setColor(*c3);
|
||||||
|
|
||||||
// uncomment this and the quaternion transformation in draw()
|
// uncomment this and the quaternion transformation in draw()
|
||||||
// to see the cube rotate. This is how we can easily make the sun.
|
// to see the cube rotate. This is how we can easily make the sun.
|
||||||
@ -350,58 +360,18 @@ void Viewer::initShaders()
|
|||||||
if ((m_point3Loc = m_program->uniformLocation("pointLight[2]")) < 0)
|
if ((m_point3Loc = m_program->uniformLocation("pointLight[2]")) < 0)
|
||||||
qDebug() << "Unable to find m_shader location for" << "pointLight[2]";
|
qDebug() << "Unable to find m_shader location for" << "pointLight[2]";
|
||||||
|
|
||||||
|
if ((m_c1Loc = m_program->uniformLocation("pointLightCol[0]")) < 0)
|
||||||
|
qDebug() << "Unable to find m_shader location for" << "pointLightCol[0]";
|
||||||
|
|
||||||
|
if ((m_c2Loc = m_program->uniformLocation("pointLightCol[1]")) < 0)
|
||||||
|
qDebug() << "Unable to find m_shader location for" << "pointLightCol[1]";
|
||||||
|
|
||||||
|
if ((m_c3Loc = m_program->uniformLocation("pointLightCol[2]")) < 0)
|
||||||
|
qDebug() << "Unable to find m_shader location for" << "pointLightCol[2]";
|
||||||
|
|
||||||
m_program->setUniformValue(m_isPhongLoc, true);
|
m_program->setUniformValue(m_isPhongLoc, true);
|
||||||
m_program->setUniformValue(m_drawTextLoc, true);
|
m_program->setUniformValue(m_drawTextLoc, true);
|
||||||
/*
|
|
||||||
* Adding Texture Shader
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
textureRenderShaderprogram = new QOpenGLShaderProgram;
|
|
||||||
if (!textureRenderShaderprogram->addShaderFromSourceFile(QOpenGLShader::Vertex, "src/shaders/textureShader.vert")) {
|
|
||||||
cerr << "Unable to load Shader" << endl
|
|
||||||
<< "Log file:" << endl;
|
|
||||||
qDebug() << textureRenderShaderprogram->log();
|
|
||||||
}
|
|
||||||
if (!textureRenderShaderprogram->addShaderFromSourceFile(QOpenGLShader::Fragment, "src/shaders/textureShader.frag")) {
|
|
||||||
cerr << "Unable to load Shader" << endl
|
|
||||||
<< "Log file:" << endl;
|
|
||||||
qDebug() << textureRenderShaderprogram->log();
|
|
||||||
}
|
|
||||||
|
|
||||||
textureRenderShaderprogram->link();
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Adding Skybox Shaders
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
skyboxRenderShaderProgram = new QOpenGLShaderProgram;
|
|
||||||
if (!skyboxRenderShaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, "src/shaders/skyboxShader.vert")) {
|
|
||||||
cerr << "Unable to load Shader" << endl
|
|
||||||
<< "Log file:" << endl;
|
|
||||||
qDebug() << skyboxRenderShaderProgram->log();
|
|
||||||
}
|
|
||||||
if (!skyboxRenderShaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, "src/shaders/skyboxShader.frag")) {
|
|
||||||
cerr << "Unable to load Shader" << endl
|
|
||||||
<< "Log file:" << endl;
|
|
||||||
qDebug() << skyboxRenderShaderProgram->log();
|
|
||||||
}
|
|
||||||
|
|
||||||
skyboxRenderShaderProgram->link();
|
|
||||||
|
|
||||||
// if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
|
|
||||||
// qDebug() << "Unable to find shader location for " << "vPosition";
|
|
||||||
|
|
||||||
if ((s_vPositionLocation = skyboxRenderShaderProgram->attributeLocation("vPosition")) < 0)
|
|
||||||
qDebug() << "Unable to find shader location for " << "vPosition";
|
|
||||||
|
|
||||||
|
|
||||||
if ((s_projMatrixLocation = skyboxRenderShaderProgram->uniformLocation("projMatrix")) < 0)
|
|
||||||
qDebug() << "Unable to find shader location for " << "projMatrix";
|
|
||||||
|
|
||||||
|
|
||||||
if ((s_mvMatrixLocation = skyboxRenderShaderProgram->uniformLocation("mvMatrix")) < 0)
|
|
||||||
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
|
||||||
|
|
||||||
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
||||||
s_texture = new QOpenGLTexture(QImage("src/data/uvLayoutGrid.png"));//*/
|
s_texture = new QOpenGLTexture(QImage("src/data/uvLayoutGrid.png"));//*/
|
||||||
@ -652,25 +622,23 @@ void Viewer::visit(Sphere &s)
|
|||||||
m_program->setUniformValue(m_isSkyLoc, false);
|
m_program->setUniformValue(m_isSkyLoc, false);
|
||||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||||
m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 200));
|
m_program->setUniformValue(m_colorLocation, s.getColor());
|
||||||
m_program->setUniformValue(m_drawTextLoc, false);
|
m_program->setUniformValue(m_drawTextLoc, false);
|
||||||
m_program->setUniformValue(m_isLightLoc, true);
|
m_program->setUniformValue(m_isLightLoc, true);
|
||||||
|
|
||||||
// This will save the current position of this light ball as the next point
|
// This will save the current position of this light ball as the next point
|
||||||
// This means point lights are technically 1 frame behind
|
// This means point lights are technically 1 frame behind
|
||||||
|
|
||||||
QVector3D point = QVector3D(1,0,0);
|
QVector3D point = QVector3D(0,0,0);
|
||||||
|
|
||||||
point = modelViewMatrix * point
|
point = modelViewMatrix * point;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
int pointLocs[3] = {m_point1Loc, m_point2Loc, m_point3Loc};
|
int pointLocs[3] = {m_point1Loc, m_point2Loc, m_point3Loc};
|
||||||
|
int pointCLocs[3] = {m_c1Loc, m_c2Loc, m_c3Loc};
|
||||||
|
|
||||||
std::cout << "Point " << currentPoint << " x:" << point.x() << " y:" << point.y() << " z:" << point.z() << "\n";
|
m_program->setUniformValue(pointLocs[currentPoint], point);
|
||||||
|
m_program->setUniformValue(pointCLocs[currentPoint], s.getColor());
|
||||||
m_program->setUniformValue(pointLocs[currentPoint], point * modelViewMatrix);
|
|
||||||
|
|
||||||
currentPoint = (currentPoint + 1) % 3;
|
currentPoint = (currentPoint + 1) % 3;
|
||||||
|
|
||||||
|
|||||||
@ -106,6 +106,10 @@ private:
|
|||||||
int m_point2Loc;
|
int m_point2Loc;
|
||||||
int m_point3Loc;
|
int m_point3Loc;
|
||||||
|
|
||||||
|
int m_c1Loc;
|
||||||
|
int m_c2Loc;
|
||||||
|
int m_c3Loc;
|
||||||
|
|
||||||
float angle_mult;
|
float angle_mult;
|
||||||
|
|
||||||
QOpenGLTexture *s_texture;
|
QOpenGLTexture *s_texture;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user