Normal Maps
BIN
src/data/assets/dry_ground_normals.jpg
Normal file
|
After Width: | Height: | Size: 518 KiB |
BIN
src/data/assets/granite_floor_normals.jpg
Normal file
|
After Width: | Height: | Size: 580 KiB |
BIN
src/data/assets/grass_normals.jpg
Normal file
|
After Width: | Height: | Size: 477 KiB |
BIN
src/data/assets/limestone_wall_normals.jpg
Normal file
|
After Width: | Height: | Size: 534 KiB |
BIN
src/data/assets/pierre_bouchardee_normals.jpg
Normal file
|
After Width: | Height: | Size: 472 KiB |
BIN
src/data/assets/wood_floor_normals.jpg
Normal file
|
After Width: | Height: | Size: 483 KiB |
BIN
src/data/dry_ground_normals.jpg
Normal file
|
After Width: | Height: | Size: 518 KiB |
BIN
src/data/granite_floor_normals.jpg
Normal file
|
After Width: | Height: | Size: 580 KiB |
BIN
src/data/grass_normals.jpg
Normal file
|
After Width: | Height: | Size: 477 KiB |
BIN
src/data/limestone_wall_normals.jpg
Normal file
|
After Width: | Height: | Size: 534 KiB |
BIN
src/data/pierre_bouchardee_normals.jpg
Normal file
|
After Width: | Height: | Size: 472 KiB |
BIN
src/data/wood_floor_normals.jpg
Normal file
|
After Width: | Height: | Size: 483 KiB |
@ -1,8 +1,10 @@
|
||||
#version 400 core
|
||||
uniform sampler2D texCol;
|
||||
uniform sampler2D texNormal;
|
||||
|
||||
uniform vec3 lDirection;
|
||||
uniform bool isSky;
|
||||
uniform bool isPhong;
|
||||
uniform sampler2D tex;
|
||||
uniform float skyMult;
|
||||
uniform bool drawTextures;
|
||||
uniform bool isLightSource;
|
||||
@ -10,6 +12,7 @@ uniform bool isPickingMode;
|
||||
uniform vec3 pointLight[3];
|
||||
uniform vec4 pointLightCol[3];
|
||||
uniform mat3 normalMatrix;
|
||||
uniform bool useNormalMap;
|
||||
|
||||
in vec3 fNormal;
|
||||
in vec3 fPosition;
|
||||
@ -21,9 +24,16 @@ out vec4 fColor;
|
||||
|
||||
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(lDirection);
|
||||
vec3 nfNormal = normalize(fNorm);
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
vec3 LightDirection = normalize(lDirection);
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
vec3 nfNormal;
|
||||
|
||||
if(useNormalMap) {
|
||||
vec3 vNorm = texture(texNormal, texCoords).rgb;
|
||||
nfNormal = normalize(normalMatrix * vNorm);
|
||||
} else {
|
||||
nfNormal = normalize(fNorm);
|
||||
}
|
||||
|
||||
// Compute diffuse component
|
||||
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
|
||||
@ -38,14 +48,22 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
float mult = 1;//max(0.0, -LightDirection.y+1.5);
|
||||
|
||||
//return vec4(0);
|
||||
return vec4(tex.xyz * (diff + amb + spec) * mult, tex.w);
|
||||
return vec4(tex.xyz * (diff + amb + spec) * mult, tex.w);
|
||||
}
|
||||
|
||||
vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(pointLight[i] + fPos);
|
||||
vec3 nfNormal = normalize(fNorm);
|
||||
// vec3 nfNormal = normalize(fNorm);
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
vec3 nfNormal;
|
||||
|
||||
if(useNormalMap) {
|
||||
vec3 vNorm = texture(texNormal, texCoords).rgb;
|
||||
nfNormal = normalize(normalMatrix * vNorm);
|
||||
} else {
|
||||
nfNormal = normalize(fNorm);
|
||||
}
|
||||
|
||||
// Attenuation
|
||||
float distance = length(nviewDirection - pointLight[i] - fPos) / 3;
|
||||
@ -61,7 +79,7 @@ vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||
// Compute ambient component
|
||||
float amb = 0.2;
|
||||
|
||||
return vec4(pointLightCol[i].xyz * attenuation * (amb + diff + spec) * tex.xyz, pointLightCol[i].w);
|
||||
return vec4(pointLightCol[i].xyz * attenuation * (amb + diff + spec) * tex.xyz, pointLightCol[i].w);
|
||||
}
|
||||
|
||||
void
|
||||
@ -74,12 +92,12 @@ main()
|
||||
fColor = ifColor;
|
||||
}else{
|
||||
if(drawTextures) {
|
||||
texColor = texture(tex, texCoords);
|
||||
texColor = texture(texCol, texCoords);
|
||||
} else {
|
||||
texColor = ifColor;
|
||||
texColor = ifColor;
|
||||
}
|
||||
|
||||
if(isLightSource) {
|
||||
if(isLightSource) {
|
||||
fColor = texColor;
|
||||
} else if(isSky) {
|
||||
fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2;
|
||||
@ -89,7 +107,7 @@ main()
|
||||
vec3 nfNormal = normalize(fNormal);
|
||||
vec3 nviewDirection = normalize(fPosition);
|
||||
|
||||
fColor = calcDirLight(texColor, fPosition, fNormal)
|
||||
fColor = calcDirLight(texColor, fPosition, fNormal)
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
||||
|
||||
@ -103,6 +103,8 @@ void Viewer::cleanup()
|
||||
void Viewer::drawSkybox()
|
||||
{
|
||||
// Use the Skybox Shaders
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_program->bind();
|
||||
s_texture->bind();
|
||||
// Get projection and camera transformations
|
||||
@ -194,7 +196,8 @@ void Viewer::drawUi(){
|
||||
uiViewMatrix.scale(.25, .25, .01);
|
||||
uiViewMatrix.translate(-TEX_LENGTH/2.0, 0, 0);
|
||||
for(int i = 0; i<TEX_LENGTH; i++)
|
||||
{
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
TexturePrograms[i]->bind();
|
||||
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
|
||||
uiViewMatrix.translate(1.2, 0, 0);
|
||||
@ -371,8 +374,17 @@ void Viewer::initShaders()
|
||||
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "vPosition";
|
||||
|
||||
if ((m_colorLocation = m_program->uniformLocation("color")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "color";
|
||||
if ((m_colorLocation = m_program->uniformLocation("color")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "color";
|
||||
|
||||
if ((m_useNormalMap = m_program->uniformLocation("useNormalMap")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "useNormalMap";
|
||||
|
||||
if ((m_texNormal = m_program->uniformLocation("texNormal")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "texNormal";
|
||||
|
||||
if ((m_texColor = m_program->uniformLocation("texCol")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "texCol";
|
||||
|
||||
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0)
|
||||
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
||||
@ -434,6 +446,10 @@ void Viewer::initShaders()
|
||||
m_program->setUniformValue(m_isPhongLoc, true);
|
||||
m_program->setUniformValue(m_drawTextLoc, false);
|
||||
m_program->setUniformValue(m_isPickingModeLoc, false);
|
||||
m_program->setUniformValue(m_useNormalMap, true);
|
||||
|
||||
m_program->setUniformValue(m_texColor, 0);
|
||||
m_program->setUniformValue(m_texNormal, 1);
|
||||
|
||||
|
||||
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
||||
@ -442,11 +458,16 @@ void Viewer::initShaders()
|
||||
s_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||
|
||||
// load remaining textures
|
||||
for(int i = 0; i<TEX_LENGTH; i++){
|
||||
std::cout << "Binding " << TexturePaths[i].toStdString() << endl;
|
||||
TexturePrograms[i] = new QOpenGLTexture(QImage(TexturePaths[i]));
|
||||
TexturePrograms[i]->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
|
||||
TexturePrograms[i]->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||
for(int i = 0; i<TEX_LENGTH; i++){
|
||||
std::cout << "Binding " << TexturePaths[i].toStdString() << endl;
|
||||
TexturePrograms[i] = new QOpenGLTexture(QImage(TexturePaths[i]));
|
||||
TexturePrograms[i]->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
|
||||
TexturePrograms[i]->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||
|
||||
std::cout << "Binding " << NormalPaths[i].toStdString() << endl;
|
||||
TexturePrograms[TEX_LENGTH + i] = new QOpenGLTexture(QImage(NormalPaths[i]));
|
||||
TexturePrograms[TEX_LENGTH + i]->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
|
||||
TexturePrograms[TEX_LENGTH + i]->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||
}//*/
|
||||
}
|
||||
|
||||
@ -702,8 +723,12 @@ void Viewer::visit(Cube &s)
|
||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||
QColor* faceColor = new QColor;
|
||||
|
||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||
TexturePrograms[s.getType()]->bind();
|
||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
TexturePrograms[s.getType()]->bind();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
TexturePrograms[TEX_LENGTH + s.getType()]->bind();
|
||||
|
||||
m_program->setUniformValue(m_isSkyLoc, false);
|
||||
m_program->setUniformValue(m_drawTextLoc, true);
|
||||
|
||||
@ -100,7 +100,10 @@ private:
|
||||
QOpenGLShaderProgram *skyboxRenderShaderProgram;
|
||||
QOpenGLShaderProgram *m_program;
|
||||
int m_vPositionLocation;
|
||||
int m_texColor;
|
||||
int m_texNormal;
|
||||
int m_colorLocation;
|
||||
int m_useNormalMap;
|
||||
int m_projMatrixLocation;
|
||||
int m_mvMatrixLocation;
|
||||
|
||||
@ -174,14 +177,22 @@ private:
|
||||
|
||||
unsigned int selectedTexture = TEX_WOODFLOOR;
|
||||
|
||||
QString TexturePaths[TEX_LENGTH] = {
|
||||
"src/data/dry_ground.jpg",
|
||||
"src/data/granite_floor.jpg",
|
||||
"src/data/grass.jpg",
|
||||
"src/data/limestone_wall.jpg",
|
||||
"src/data/pierre_bouchardee.jpg",
|
||||
"src/data/wood_floor.jpg"
|
||||
};
|
||||
QString TexturePaths[TEX_LENGTH] = {
|
||||
"src/data/dry_ground.jpg",
|
||||
"src/data/granite_floor.jpg",
|
||||
"src/data/grass.jpg",
|
||||
"src/data/limestone_wall.jpg",
|
||||
"src/data/pierre_bouchardee.jpg",
|
||||
"src/data/wood_floor.jpg"
|
||||
};
|
||||
QString NormalPaths[TEX_LENGTH] = {
|
||||
"src/data/dry_ground_normals.jpg",
|
||||
"src/data/granite_floor_normals.jpg",
|
||||
"src/data/grass_normals.jpg",
|
||||
"src/data/limestone_wall_normals.jpg",
|
||||
"src/data/pierre_bouchardee_normals.jpg",
|
||||
"src/data/wood_floor_normals.jpg"
|
||||
};
|
||||
|
||||
int sideColors[6] = {
|
||||
0xFF0000,
|
||||
@ -192,7 +203,7 @@ private:
|
||||
0xFFFF00,
|
||||
};
|
||||
|
||||
QOpenGLTexture *TexturePrograms[TEX_LENGTH];
|
||||
QOpenGLTexture *TexturePrograms[TEX_LENGTH * 2];
|
||||
QMatrix4x4 identityMatrix;
|
||||
|
||||
QQuaternion rot;
|
||||
|
||||