mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
shaders interfering with one another... why?
This commit is contained in:
parent
1e0224ee52
commit
68799cbe44
@ -1,8 +1,8 @@
|
|||||||
#version 400 core
|
#version 400 core
|
||||||
uniform vec3 lDirection;
|
uniform vec3 lDirection;
|
||||||
|
|
||||||
in vec3 fNormal;
|
|
||||||
in vec3 fPosition;
|
in vec3 fPosition;
|
||||||
|
in vec3 fNormal;
|
||||||
in vec4 ifColor;
|
in vec4 ifColor;
|
||||||
|
|
||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
@ -10,21 +10,22 @@ out vec4 fColor;
|
|||||||
void
|
void
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
// Get lighting vectors
|
// 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 nfNormal = normalize(fNormal);
|
||||||
vec3 nviewDirection = normalize(fPosition);
|
vec3 nviewDirection = normalize(fPosition);
|
||||||
|
|
||||||
// Compute diffuse component
|
// Compute diffuse component
|
||||||
float diffuse = max(0.0, dot(nfNormal, LightDirection));
|
float diffuse = max(0.0, dot(nfNormal, LightDirection));
|
||||||
|
|
||||||
// Compute specular component
|
// Compute specular component
|
||||||
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
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)
|
// Fragment color (currently static, to be replaced with texture)
|
||||||
vec3 color = ifColor.xyz;
|
vec3 color = ifColor.xyz;
|
||||||
|
|
||||||
// Compute final color
|
// Compute final color
|
||||||
fColor = vec4(color * (0.1 + diffuse + specular), 1);
|
fColor = vec4(color * (0.1 + diffuse + specular), 1);
|
||||||
|
// fColor = vec4(fNormal, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,10 +15,10 @@ out vec3 fNormal;
|
|||||||
void
|
void
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
vec4 vEyeCoord = mvMatrix * vPosition;
|
vec4 vEyeCoord = mvMatrix * vPosition;
|
||||||
gl_Position = projMatrix * vEyeCoord;
|
gl_Position = projMatrix * vEyeCoord;
|
||||||
fPosition = -vEyeCoord.xyz;
|
fPosition = -vEyeCoord.xyz;
|
||||||
fNormal = normalMatrix * vNormal;
|
fNormal = normalMatrix * vNormal;
|
||||||
ifColor = color;
|
ifColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,9 @@ uniform sampler2D skybox;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//fColor = vec4(1);
|
//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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,6 +113,7 @@ void Viewer::drawSkybox()
|
|||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
||||||
}
|
}
|
||||||
|
skyboxRenderShaderProgram->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::draw()
|
void Viewer::draw()
|
||||||
@ -148,7 +149,7 @@ void Viewer::draw()
|
|||||||
// Traverse the Scene in order to draw its components
|
// Traverse the Scene in order to draw its components
|
||||||
|
|
||||||
modelStack.push(modelViewMatrix);
|
modelStack.push(modelViewMatrix);
|
||||||
root.accept(*this);
|
root.accept(*this);
|
||||||
frame++;
|
frame++;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -248,30 +249,50 @@ void Viewer::initShaders()
|
|||||||
qDebug() << m_program->log();
|
qDebug() << m_program->log();
|
||||||
}
|
}
|
||||||
m_program->link();
|
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
|
// Specify shader input paramters
|
||||||
// The strings "vPosition", "mvMatrix", etc. have to match an attribute name in the vertex shader.
|
// The strings "vPosition", "mvMatrix", etc. have to match an attribute name in the vertex shader.
|
||||||
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
|
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "vPosition";
|
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)
|
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "color";
|
cerr << "Unable to find shader location for " << "mvMatrix" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << m_program->log();
|
||||||
|
}
|
||||||
|
|
||||||
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0)
|
if ((m_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
cerr << "Unable to find shader location for " << "projMatrix" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << m_program->log();
|
||||||
|
}
|
||||||
|
|
||||||
if ((m_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0)
|
if ((m_lDirectionLocation = m_program->uniformLocation("lDirection")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "projMatrix";
|
cerr << "Unable to find shader location for " << "lDirection" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << m_program->log();
|
||||||
|
}
|
||||||
|
|
||||||
if ((m_lDirectionLocation = m_program->uniformLocation("lDirection")) < 0)
|
if ((m_normalMatrixLoc = m_program->uniformLocation("normalMatrix")) < 0){
|
||||||
qDebug() << "Unable to find m_shader location for" << "lDirection";
|
cerr << "Unable to find shader location for " << "normalMatrix" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << m_program->log();
|
||||||
|
}
|
||||||
|
|
||||||
if ((m_normalMatrixLoc = m_program->uniformLocation("normalMatrix")) < 0)
|
if ((m_vNormalLocation = m_program->attributeLocation("vNormal")) < 0){
|
||||||
qDebug() << "Unable to find m_shader location for" << "normalMatrix";
|
cerr << "Unable to find shader location for " << "vNormal" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
if ((m_vNormalLocation = m_program->attributeLocation("vNormal")) < 0)
|
qDebug() << m_program->log();
|
||||||
qDebug() << "Unable to find m_shader location for" << "vNormal";
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -313,19 +334,31 @@ void Viewer::initShaders()
|
|||||||
// if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
|
// if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
|
||||||
// qDebug() << "Unable to find shader location for " << "vPosition";
|
// qDebug() << "Unable to find shader location for " << "vPosition";
|
||||||
|
|
||||||
if ((s_vPositionLocation = skyboxRenderShaderProgram->attributeLocation("vPosition")) < 0)
|
if ((s_vPositionLocation = skyboxRenderShaderProgram->attributeLocation("vPosition")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "vPosition";
|
cerr << "Unable to find shader location for " << "vPosition" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << skyboxRenderShaderProgram->log();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((s_projMatrixLocation = skyboxRenderShaderProgram->uniformLocation("projMatrix")) < 0)
|
if ((s_projMatrixLocation = skyboxRenderShaderProgram->uniformLocation("projMatrix")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "projMatrix";
|
cerr << "Unable to find shader location for " << "projMatrix" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << skyboxRenderShaderProgram->log();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((s_mvMatrixLocation = skyboxRenderShaderProgram->uniformLocation("mvMatrix")) < 0)
|
if ((s_mvMatrixLocation = skyboxRenderShaderProgram->uniformLocation("mvMatrix")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
cerr << "Unable to find shader location for " << "mvMatrix" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << skyboxRenderShaderProgram->log();
|
||||||
|
}
|
||||||
|
|
||||||
if ((s_vUvLocation = skyboxRenderShaderProgram->attributeLocation("vUv")) < 0)
|
if ((s_vUvLocation = skyboxRenderShaderProgram->attributeLocation("vUv")) < 0){
|
||||||
qDebug() << "Unable to find shader location for " << "vUv";
|
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/skybox.jpg"));/*/
|
||||||
s_texture = new QOpenGLTexture(QImage("src/data/uvLayoutGrid.png"));//*/
|
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},
|
||||||
{ 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},
|
||||||
{ 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},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user