shaders interfering with one another... why?

This commit is contained in:
Dmitri K 2016-11-09 23:21:20 -05:00
parent 1e0224ee52
commit 68799cbe44
4 changed files with 87 additions and 50 deletions

View File

@ -1,8 +1,8 @@
#version 400 core
uniform vec3 lDirection;
in vec3 fNormal;
in vec3 fPosition;
in vec3 fNormal;
in vec4 ifColor;
out vec4 fColor;
@ -11,7 +11,7 @@ void
main()
{
// Get lighting vectors
vec3 LightDirection = normalize(vec3(-1,-3,0)); // We assume light is at camera position
vec3 LightDirection = normalize(vec3(0, 1, 0)); // We assume light is at camera position
vec3 nfNormal = normalize(fNormal);
vec3 nviewDirection = normalize(fPosition);
@ -20,11 +20,12 @@ main()
// Compute specular component
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
float specular = 0.0;//0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
float specular = 0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
// Fragment color (currently static, to be replaced with texture)
vec3 color = ifColor.xyz;
// Compute final color
fColor = vec4(color * (0.1 + diffuse + specular), 1);
// fColor = vec4(fNormal, 1);
}

View File

@ -7,5 +7,8 @@ uniform sampler2D skybox;
void main()
{
//fColor = vec4(1);
fColor = texture(skybox, texCoords);
vec4 c = texture(skybox, texCoords);
c = c*c*c*2/1.414;
fColor = vec4(1, 1, 1, 1) /2;
//fColor = normalize(c)*2;
}

View File

@ -113,6 +113,7 @@ void Viewer::drawSkybox()
glDrawArrays(GL_TRIANGLES, i*6, 6);
}
skyboxRenderShaderProgram->release();
}
void Viewer::draw()
@ -248,30 +249,50 @@ void Viewer::initShaders()
qDebug() << m_program->log();
}
m_program->link();
m_program->bind(); // Note: This is equivalent to glUseProgram(programId());
//m_program->bind(); // Note: This is equivalent to glUseProgram(programId());
// Specify shader input paramters
// The strings "vPosition", "mvMatrix", etc. have to match an attribute name in the vertex shader.
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
qDebug() << "Unable to find shader location for " << "vPosition";
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0){
cerr << "Unable to find shader location for " << "vPosition" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
if ((m_colorLocation = m_program->uniformLocation("color")) < 0){
cerr << "Unable to find shader location for " << "color" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
if ((m_colorLocation = m_program->uniformLocation("color")) < 0)
qDebug() << "Unable to find shader location for " << "color";
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0){
cerr << "Unable to find shader location for " << "mvMatrix" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0)
qDebug() << "Unable to find shader location for " << "mvMatrix";
if ((m_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0){
cerr << "Unable to find shader location for " << "projMatrix" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
if ((m_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0)
qDebug() << "Unable to find shader location for " << "projMatrix";
if ((m_lDirectionLocation = m_program->uniformLocation("lDirection")) < 0){
cerr << "Unable to find shader location for " << "lDirection" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
if ((m_lDirectionLocation = m_program->uniformLocation("lDirection")) < 0)
qDebug() << "Unable to find m_shader location for" << "lDirection";
if ((m_normalMatrixLoc = m_program->uniformLocation("normalMatrix")) < 0){
cerr << "Unable to find shader location for " << "normalMatrix" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
if ((m_normalMatrixLoc = m_program->uniformLocation("normalMatrix")) < 0)
qDebug() << "Unable to find m_shader location for" << "normalMatrix";
if ((m_vNormalLocation = m_program->attributeLocation("vNormal")) < 0)
qDebug() << "Unable to find m_shader location for" << "vNormal";
if ((m_vNormalLocation = m_program->attributeLocation("vNormal")) < 0){
cerr << "Unable to find shader location for " << "vNormal" << endl
<< "Log file:" << endl;
qDebug() << m_program->log();
}
/*
@ -313,19 +334,31 @@ void Viewer::initShaders()
// if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
// qDebug() << "Unable to find shader location for " << "vPosition";
if ((s_vPositionLocation = skyboxRenderShaderProgram->attributeLocation("vPosition")) < 0)
qDebug() << "Unable to find shader location for " << "vPosition";
if ((s_vPositionLocation = skyboxRenderShaderProgram->attributeLocation("vPosition")) < 0){
cerr << "Unable to find shader location for " << "vPosition" << endl
<< "Log file:" << endl;
qDebug() << skyboxRenderShaderProgram->log();
}
if ((s_projMatrixLocation = skyboxRenderShaderProgram->uniformLocation("projMatrix")) < 0)
qDebug() << "Unable to find shader location for " << "projMatrix";
if ((s_projMatrixLocation = skyboxRenderShaderProgram->uniformLocation("projMatrix")) < 0){
cerr << "Unable to find shader location for " << "projMatrix" << endl
<< "Log file:" << endl;
qDebug() << skyboxRenderShaderProgram->log();
}
if ((s_mvMatrixLocation = skyboxRenderShaderProgram->uniformLocation("mvMatrix")) < 0)
qDebug() << "Unable to find shader location for " << "mvMatrix";
if ((s_mvMatrixLocation = skyboxRenderShaderProgram->uniformLocation("mvMatrix")) < 0){
cerr << "Unable to find shader location for " << "mvMatrix" << endl
<< "Log file:" << endl;
qDebug() << skyboxRenderShaderProgram->log();
}
if ((s_vUvLocation = skyboxRenderShaderProgram->attributeLocation("vUv")) < 0)
qDebug() << "Unable to find shader location for " << "vUv";
if ((s_vUvLocation = skyboxRenderShaderProgram->attributeLocation("vUv")) < 0){
cerr << "Unable to find shader location for " << "vUv" << endl
<< "Log file:" << endl;
qDebug() << skyboxRenderShaderProgram->log();
}
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
s_texture = new QOpenGLTexture(QImage("src/data/uvLayoutGrid.png"));//*/
@ -399,11 +432,11 @@ void Viewer::initGeometries()
{ 0.0, 0.0, -1.0 }, {0.0, 0.0, -1.0}, {0.0, 0.0, -1.0},
{ 0.0, 0.0, -1.0 }, {0.0, 0.0, -1.0}, {0.0, 0.0, -1.0},
{ 1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
{ 1.0, 0.0, 0.0 }, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
{ -1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0},
{ -1.0, 0.0, 0.0 }, {-1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0},
{ -1.0, 0.0, 0.0 }, {-1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0},
{ -1.0, 0.0, 0.0 }, {-1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0},
{ 1.0, 0.0, 0.0 }, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
{ 1.0, 0.0, 0.0 }, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
{ 0.0, 1.0, 0.0 }, {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
{ 0.0, 1.0, 0.0 }, {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0},