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
|
#version 400 core
|
||||||
|
uniform sampler2D texCol;
|
||||||
|
uniform sampler2D texNormal;
|
||||||
|
|
||||||
uniform vec3 lDirection;
|
uniform vec3 lDirection;
|
||||||
uniform bool isSky;
|
uniform bool isSky;
|
||||||
uniform bool isPhong;
|
uniform bool isPhong;
|
||||||
uniform sampler2D tex;
|
|
||||||
uniform float skyMult;
|
uniform float skyMult;
|
||||||
uniform bool drawTextures;
|
uniform bool drawTextures;
|
||||||
uniform bool isLightSource;
|
uniform bool isLightSource;
|
||||||
@ -10,6 +12,7 @@ uniform bool isPickingMode;
|
|||||||
uniform vec3 pointLight[3];
|
uniform vec3 pointLight[3];
|
||||||
uniform vec4 pointLightCol[3];
|
uniform vec4 pointLightCol[3];
|
||||||
uniform mat3 normalMatrix;
|
uniform mat3 normalMatrix;
|
||||||
|
uniform bool useNormalMap;
|
||||||
|
|
||||||
in vec3 fNormal;
|
in vec3 fNormal;
|
||||||
in vec3 fPosition;
|
in vec3 fPosition;
|
||||||
@ -22,8 +25,15 @@ out vec4 fColor;
|
|||||||
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 LightDirection = normalize(lDirection);
|
||||||
vec3 nfNormal = normalize(fNorm);
|
|
||||||
vec3 nviewDirection = normalize(fPos);
|
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
|
// Compute diffuse component
|
||||||
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
|
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
|
||||||
@ -44,8 +54,16 @@ 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(pointLight[i] + fPos);
|
vec3 LightDirection = normalize(pointLight[i] + fPos);
|
||||||
vec3 nfNormal = normalize(fNorm);
|
// vec3 nfNormal = normalize(fNorm);
|
||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
|
vec3 nfNormal;
|
||||||
|
|
||||||
|
if(useNormalMap) {
|
||||||
|
vec3 vNorm = texture(texNormal, texCoords).rgb;
|
||||||
|
nfNormal = normalize(normalMatrix * vNorm);
|
||||||
|
} else {
|
||||||
|
nfNormal = normalize(fNorm);
|
||||||
|
}
|
||||||
|
|
||||||
// Attenuation
|
// Attenuation
|
||||||
float distance = length(nviewDirection - pointLight[i] - fPos) / 3;
|
float distance = length(nviewDirection - pointLight[i] - fPos) / 3;
|
||||||
@ -74,7 +92,7 @@ main()
|
|||||||
fColor = ifColor;
|
fColor = ifColor;
|
||||||
}else{
|
}else{
|
||||||
if(drawTextures) {
|
if(drawTextures) {
|
||||||
texColor = texture(tex, texCoords);
|
texColor = texture(texCol, texCoords);
|
||||||
} else {
|
} else {
|
||||||
texColor = ifColor;
|
texColor = ifColor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,6 +103,8 @@ void Viewer::cleanup()
|
|||||||
void Viewer::drawSkybox()
|
void Viewer::drawSkybox()
|
||||||
{
|
{
|
||||||
// Use the Skybox Shaders
|
// Use the Skybox Shaders
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
s_texture->bind();
|
s_texture->bind();
|
||||||
// Get projection and camera transformations
|
// Get projection and camera transformations
|
||||||
@ -195,6 +197,7 @@ void Viewer::drawUi(){
|
|||||||
uiViewMatrix.translate(-TEX_LENGTH/2.0, 0, 0);
|
uiViewMatrix.translate(-TEX_LENGTH/2.0, 0, 0);
|
||||||
for(int i = 0; i<TEX_LENGTH; i++)
|
for(int i = 0; i<TEX_LENGTH; i++)
|
||||||
{
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
TexturePrograms[i]->bind();
|
TexturePrograms[i]->bind();
|
||||||
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
|
m_program->setUniformValue(m_mvMatrixLocation, uiViewMatrix);
|
||||||
uiViewMatrix.translate(1.2, 0, 0);
|
uiViewMatrix.translate(1.2, 0, 0);
|
||||||
@ -374,6 +377,15 @@ void Viewer::initShaders()
|
|||||||
if ((m_colorLocation = m_program->uniformLocation("color")) < 0)
|
if ((m_colorLocation = m_program->uniformLocation("color")) < 0)
|
||||||
qDebug() << "Unable to find shader location for " << "color";
|
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)
|
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0)
|
||||||
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
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_isPhongLoc, true);
|
||||||
m_program->setUniformValue(m_drawTextLoc, false);
|
m_program->setUniformValue(m_drawTextLoc, false);
|
||||||
m_program->setUniformValue(m_isPickingModeLoc, 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"));/*/
|
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
||||||
@ -447,6 +463,11 @@ void Viewer::initShaders()
|
|||||||
TexturePrograms[i] = new QOpenGLTexture(QImage(TexturePaths[i]));
|
TexturePrograms[i] = new QOpenGLTexture(QImage(TexturePaths[i]));
|
||||||
TexturePrograms[i]->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
|
TexturePrograms[i]->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
|
||||||
TexturePrograms[i]->setMagnificationFilter(QOpenGLTexture::Linear);
|
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);
|
||||||
}//*/
|
}//*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,7 +724,11 @@ void Viewer::visit(Cube &s)
|
|||||||
QColor* faceColor = new QColor;
|
QColor* faceColor = new QColor;
|
||||||
|
|
||||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
TexturePrograms[s.getType()]->bind();
|
TexturePrograms[s.getType()]->bind();
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
TexturePrograms[TEX_LENGTH + s.getType()]->bind();
|
||||||
|
|
||||||
m_program->setUniformValue(m_isSkyLoc, false);
|
m_program->setUniformValue(m_isSkyLoc, false);
|
||||||
m_program->setUniformValue(m_drawTextLoc, true);
|
m_program->setUniformValue(m_drawTextLoc, true);
|
||||||
|
|||||||
@ -100,7 +100,10 @@ private:
|
|||||||
QOpenGLShaderProgram *skyboxRenderShaderProgram;
|
QOpenGLShaderProgram *skyboxRenderShaderProgram;
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program;
|
||||||
int m_vPositionLocation;
|
int m_vPositionLocation;
|
||||||
|
int m_texColor;
|
||||||
|
int m_texNormal;
|
||||||
int m_colorLocation;
|
int m_colorLocation;
|
||||||
|
int m_useNormalMap;
|
||||||
int m_projMatrixLocation;
|
int m_projMatrixLocation;
|
||||||
int m_mvMatrixLocation;
|
int m_mvMatrixLocation;
|
||||||
|
|
||||||
@ -182,6 +185,14 @@ private:
|
|||||||
"src/data/pierre_bouchardee.jpg",
|
"src/data/pierre_bouchardee.jpg",
|
||||||
"src/data/wood_floor.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] = {
|
int sideColors[6] = {
|
||||||
0xFF0000,
|
0xFF0000,
|
||||||
@ -192,7 +203,7 @@ private:
|
|||||||
0xFFFF00,
|
0xFFFF00,
|
||||||
};
|
};
|
||||||
|
|
||||||
QOpenGLTexture *TexturePrograms[TEX_LENGTH];
|
QOpenGLTexture *TexturePrograms[TEX_LENGTH * 2];
|
||||||
QMatrix4x4 identityMatrix;
|
QMatrix4x4 identityMatrix;
|
||||||
|
|
||||||
QQuaternion rot;
|
QQuaternion rot;
|
||||||
|
|||||||