diff --git a/src/shaders/basicShader.frag b/src/shaders/basicShader.frag index 7b19083..ad0f0a0 100644 --- a/src/shaders/basicShader.frag +++ b/src/shaders/basicShader.frag @@ -5,6 +5,7 @@ uniform bool isPhong; uniform sampler2D tex; uniform float skyMult; uniform bool drawTextures; +uniform bool isLightSource; in vec3 fNormal; in vec3 fPosition; @@ -22,7 +23,9 @@ main() } else { texColor = ifColor; } - if(isSky) { + if(isLightSource) { + fColor = texColor; + } else if(isSky) { fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2; } else if(isPhong) { // Get lighting vectors diff --git a/src/shaders/basicShader.vert b/src/shaders/basicShader.vert index 8f741cb..8515ade 100644 --- a/src/shaders/basicShader.vert +++ b/src/shaders/basicShader.vert @@ -3,6 +3,7 @@ uniform mat4 mvMatrix; uniform mat4 projMatrix; uniform mat3 normalMatrix; uniform vec3 lDirection; +uniform bool isLightSource; uniform vec4 color; @@ -30,7 +31,7 @@ main() ifColor = color; - if(!isPhong && !isSky) { + if(!isPhong && !isSky && !isLightSource) { // Get lighting vectors vec3 LightDirection = normalize(lDirection); vec3 nfNormal = normalize(fNormal); diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index 1247ec3..9b0f507 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -69,7 +69,7 @@ class SkyboxCamera : public qglviewer::Camera Viewer::Viewer() { - activeColor = new QColor(255, 255, 255, 255); + activeColor = new QColor(255, 255, 255, 255); activeCell = nullptr; activeShape = 0; angle_mult = 0.1; @@ -117,6 +117,7 @@ void Viewer::drawSkybox() m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_isSkyLoc, true); m_program->setUniformValue(m_drawTextLoc, true); + m_program->setUniformValue(m_isLightLoc, false); int faces = floor(numVerticesCube/6); for(int i = 0; i < faces; i++){ // 6 vertexes par face @@ -162,6 +163,8 @@ void Viewer::draw() sunRotate.rotate(rotAngle, 1, 0, 0); m_program->setUniformValue(m_lDirLoc, (sun * sunRotate)); + selection->transform.setToIdentity(); + selection->transform.rotate(rotAngle, 0, 1, 0); // Traverse the Scene in order to draw its components @@ -333,6 +336,9 @@ void Viewer::initShaders() if ((m_drawTextLoc = m_program->uniformLocation("drawTextures")) < 0) qDebug() << "Unable to find m_shader location for" << "drawTextures"; + if ((m_isLightLoc = m_program->uniformLocation("isLightSource")) < 0) + qDebug() << "Unable to find m_shader location for" << "isLightSource"; + m_program->setUniformValue(m_isPhongLoc, true); m_program->setUniformValue(m_drawTextLoc, true); @@ -619,6 +625,7 @@ void Viewer::visit(Cube &s) m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); m_program->setUniformValue(m_colorLocation, s.getColor()); m_program->setUniformValue(m_drawTextLoc, true); + m_program->setUniformValue(m_isLightLoc, false); glDrawArrays(GL_TRIANGLES, i*6, 6); } @@ -634,8 +641,9 @@ void Viewer::visit(Sphere &s) m_program->setUniformValue(m_isSkyLoc, false); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); - m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255)); + m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 200)); m_program->setUniformValue(m_drawTextLoc, false); + m_program->setUniformValue(m_isLightLoc, true); glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0); } diff --git a/src/viewer/simpleViewer.h b/src/viewer/simpleViewer.h index 46f5152..5f8a2c6 100644 --- a/src/viewer/simpleViewer.h +++ b/src/viewer/simpleViewer.h @@ -100,6 +100,7 @@ private: int m_lDirLoc; int m_skyMultLoc; int m_drawTextLoc; + int m_isLightLoc; float angle_mult;