Skip to content

Commit

Permalink
bumpmapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jrenzhile committed Dec 10, 2014
1 parent 006b7c2 commit 8aac1fd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 22 deletions.
4 changes: 3 additions & 1 deletion ADS/ADS.frag
Expand Up @@ -5,14 +5,16 @@ in vec3 LightIntensity;

uniform sampler2D textureSampler;



layout ( location = 0) out vec4 FragColor;

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;
}
10 changes: 9 additions & 1 deletion ADS/ADS.vert
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion cs123-final.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.0, 2014-12-09T23:13:55. -->
<!-- Written by QtCreator 3.0.0, 2014-12-10T16:41:18. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down
2 changes: 1 addition & 1 deletion scene/Basketball.h
Expand Up @@ -4,7 +4,7 @@
#include "GL/glew.h"
#include "glm/glm/glm.hpp"

#define GRAVITY 13.8
#define GRAVITY 15.8

class Basketball
{
Expand Down
8 changes: 4 additions & 4 deletions shape/Sphere.cpp
Expand Up @@ -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;
Expand Down
33 changes: 19 additions & 14 deletions src/glwidget.cpp
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -693,7 +698,7 @@ void GLWidget::renderBasketball()
// std::cout<<m_basketballList.size()<<std::endl;
for(unsigned int i = 0; i<m_basketballList.size();i++)
{
float delta_t = 1.0f/(float)m_fps;
float delta_t = 0.5f/(float)m_fps;
Basketball *cur_basketball = m_basketballList[i];
float scale = cur_basketball->getRadius() * 2;

Expand Down Expand Up @@ -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 ] );

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/glwidget.h
Expand Up @@ -139,6 +139,7 @@ protected slots:
GLuint m_textureId;
GLuint m_basketballTextureId;
GLuint m_boardId;
GLuint m_normalId;

glm::vec3 arrow_vel;

Expand Down
Binary file added textures/testNormalMap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8aac1fd

Please sign in to comment.