diff --git a/ADS/ADS.frag b/ADS/ADS.frag index d91d29c..8ddaf93 100644 --- a/ADS/ADS.frag +++ b/ADS/ADS.frag @@ -5,6 +5,8 @@ in vec3 LightIntensity; uniform sampler2D textureSampler; + + layout ( location = 0) out vec4 FragColor; void main() @@ -12,7 +14,7 @@ void main() vec4 texColor = texture2D(textureSampler, uv); //FragColor = texColor; - float blend = 0.5; + float blend = 1; FragColor = vec4(LightIntensity, 1.0) * blend + (1 - blend) * texColor; //FragColor = texColor; } diff --git a/ADS/ADS.vert b/ADS/ADS.vert index 417754a..db38e1c 100644 --- a/ADS/ADS.vert +++ b/ADS/ADS.vert @@ -23,6 +23,10 @@ uniform mat4 M_Matrix; uniform mat4 V_Matrix; uniform mat4 P_Matrix; +//uniform int isBumpMapping + +uniform sampler2D normalSampler; + void main() { uv = texCoord; @@ -41,6 +45,9 @@ void main() vec3 r = reflect( -s, tnorm ); vec3 ambient = La * Ka; +// if(isBumpMapping) + tnorm = normalize(texture2D(normalSampler, uv).rgb * 2.0 - 1.0); + float sDotN = max( dot( s, tnorm), 0.0 ); vec3 diffuse = Ld * Ka * sDotN; @@ -51,7 +58,8 @@ void main() } //Diffuse shading equation - LightIntensity = ambient + diffuse + specular; +// LightIntensity = ambient + diffuse + specular; + LightIntensity = texture2D(normalSampler, uv).rgb;//diffuse; gl_Position = MVP_Matrix * vec4(in_Position,1.0); } diff --git a/cs123-final.pro.user b/cs123-final.pro.user index b9d704a..f81d45a 100644 --- a/cs123-final.pro.user +++ b/cs123-final.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/scene/Basketball.h b/scene/Basketball.h index 66186ac..2b15c3a 100644 --- a/scene/Basketball.h +++ b/scene/Basketball.h @@ -4,7 +4,7 @@ #include "GL/glew.h" #include "glm/glm/glm.hpp" -#define GRAVITY 13.8 +#define GRAVITY 15.8 class Basketball { diff --git a/shape/Sphere.cpp b/shape/Sphere.cpp index 2ddba8e..8a469ab 100644 --- a/shape/Sphere.cpp +++ b/shape/Sphere.cpp @@ -884,10 +884,10 @@ glm::vec3 Sphere::getSphereNorm(float theta, float phi) float theta_i = 2.0 * M_PI / m_param2; - if(((int)(theta/theta_i))%5 ==0) - { - norm = glm::vec3(-1.0, 0.0, 0.0); - } +// if(((int)(theta/theta_i))%5 ==0) +// { +// norm = glm::vec3(-1.0, 0.0, 0.0); +// } return norm; diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 7e9c27b..b778099 100644 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -339,7 +339,7 @@ void GLWidget::initWall() m_wallList.push_back(tmpWall); //ground - Ka = glm::vec3(0.0f); + Ka = glm::vec3(0.0f, 0.5f, 0.0f); m_shader.setUniform( "Ka", Shader::VEC3, &Ka[0] ); modelMat = glm::mat4(1.0f); modelMat = glm::translate( modelMat, glm::vec3( 0.0f, 0.0f, 0.0f ) ); @@ -435,9 +435,13 @@ void GLWidget::renderWall() m_shader.setUniform( "Ka", Shader::VEC3, &Ka[0] ); m_shader.setUniform( "M_Matrix", Shader::MAT4, &modelMat[0][0]); if ( i == (m_wallList.size() - 1)){ + //glActiveTexture(GL_TEXTURE0); // Set the active texture to texture 0. + //m_shader.setUniform("textureSampler", Shader::INT, 0); + //glBindTexture(GL_TEXTURE_2D, m_textureId); + glActiveTexture(GL_TEXTURE0); // Set the active texture to texture 0. - m_shader.setUniform("textureSampler", Shader::INT, 0); - glBindTexture(GL_TEXTURE_2D, m_textureId); + m_shader.setUniform("normalSampler", Shader::INT, 0); + glBindTexture(GL_TEXTURE_2D, m_normalId); m_quad->draw(); glBindTexture(GL_TEXTURE_2D, 0); } @@ -617,12 +621,13 @@ void GLWidget::initializeGL() m_textureId = m_shader.loadTexture("../cs123_finalproj/textures/basketball_court2.jpg"); m_basketballTextureId = m_shader.loadTexture("../cs123_finalproj/textures/BasketballColor.jpg"); m_boardId = m_shader.loadTexture("../cs123_finalproj/textures/Board2.jpg"); + m_normalId = m_shader.loadTexture("../cs123_finalproj/textures/BasketballColor.jpg"); + // Set lighting properties. - glm::vec3 La = glm::vec3( 0.8f, 0.8f, 0.8f ); + glm::vec3 La = glm::vec3( 0.5f ); m_shader.setUniform( "La", Shader::VEC3, &La ); - - glm::vec3 Lpos = glm::vec3( 1.0f, 1.0f, 1.0f ); + glm::vec3 Lpos = glm::vec3( 5.0f, 5.0f, 5.0f ); m_shader.setUniform( "Lpos", Shader::VEC3, &Lpos ); glm::vec3 Ld = glm::vec3( 1.0f, 1.0f, 1.0f ); m_shader.setUniform( "Ld", Shader::VEC3, &Ld ); @@ -661,11 +666,11 @@ void GLWidget::paintGL() // renderArrow(); - glActiveTexture(GL_TEXTURE0); // Set the active texture to texture 0. - m_shader.setUniform("textureSampler", Shader::INT, 0); - glBindTexture(GL_TEXTURE_2D, m_basketballTextureId); +// glActiveTexture(GL_TEXTURE0); // Set the active texture to texture 0. +// m_shader.setUniform("textureSampler", Shader::INT, 0); +// glBindTexture(GL_TEXTURE_2D, m_basketballTextureId); renderBasketball(); - glBindTexture(GL_TEXTURE_2D, 0); +// glBindTexture(GL_TEXTURE_2D, 0); renderWall(); renderHoop(); @@ -693,7 +698,7 @@ void GLWidget::renderBasketball() // std::cout<getRadius() * 2; @@ -782,7 +787,7 @@ void GLWidget::renderBasketball() } - glm::vec3 Ka = glm::vec3(0.2f); + glm::vec3 Ka = glm::vec3(1.0f, 0.0f, 0.0f); m_shader.setUniform( "Ka", Shader::VEC3, &Ka ); m_shader.setUniform( "M_Matrix", Shader::MAT4, &basketballModelMat0[ 0 ][ 0 ] ); @@ -798,8 +803,8 @@ void GLWidget::processScoring(Basketball *cur_basketball) { glm::vec3 hoop_pos = glm::vec3(m_hoop.modelMat * glm::vec4(0.0, 0.0, 0.0, 1.0)); glm::vec3 cur_pos = cur_basketball->getPos(); - if((point2PointDist(hoop_pos, cur_pos) < m_hoopsize - 0.05) - && fabs(cur_pos.y - hoop_pos.y) < 0.1) + if((point2PointDist(hoop_pos, cur_pos) < m_hoopsize * 0.45 - 0.15) + && fabs(cur_pos.y - hoop_pos.y) < 0.05) { glm::vec3 cur_vel = cur_basketball->getVel(); cur_vel.x = 0.5 * rand()/RAND_MAX; diff --git a/src/glwidget.h b/src/glwidget.h index 5012d6b..0c86631 100644 --- a/src/glwidget.h +++ b/src/glwidget.h @@ -139,6 +139,7 @@ protected slots: GLuint m_textureId; GLuint m_basketballTextureId; GLuint m_boardId; + GLuint m_normalId; glm::vec3 arrow_vel; diff --git a/textures/testNormalMap.png b/textures/testNormalMap.png new file mode 100644 index 0000000..fc6354d Binary files /dev/null and b/textures/testNormalMap.png differ