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
|
||||
uniform vec3 lDirection;
|
||||
|
||||
in vec3 fNormal;
|
||||
in vec3 fPosition;
|
||||
in vec3 fNormal;
|
||||
in vec4 ifColor;
|
||||
|
||||
out vec4 fColor;
|
||||
@ -10,21 +10,22 @@ out vec4 fColor;
|
||||
void
|
||||
main()
|
||||
{
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(vec3(-1,-3,0)); // We assume light is at camera position
|
||||
vec3 nfNormal = normalize(fNormal);
|
||||
vec3 nviewDirection = normalize(fPosition);
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(vec3(0, 1, 0)); // We assume light is at camera position
|
||||
vec3 nfNormal = normalize(fNormal);
|
||||
vec3 nviewDirection = normalize(fPosition);
|
||||
|
||||
// Compute diffuse component
|
||||
float diffuse = max(0.0, dot(nfNormal, LightDirection));
|
||||
// Compute diffuse component
|
||||
float diffuse = max(0.0, dot(nfNormal, LightDirection));
|
||||
|
||||
// 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);
|
||||
// Compute specular component
|
||||
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
||||
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;
|
||||
// Fragment color (currently static, to be replaced with texture)
|
||||
vec3 color = ifColor.xyz;
|
||||
|
||||
// Compute final color
|
||||
fColor = vec4(color * (0.1 + diffuse + specular), 1);
|
||||
// Compute final color
|
||||
fColor = vec4(color * (0.1 + diffuse + specular), 1);
|
||||
// fColor = vec4(fNormal, 1);
|
||||
}
|
||||
|
||||
@ -15,10 +15,10 @@ out vec3 fNormal;
|
||||
void
|
||||
main()
|
||||
{
|
||||
vec4 vEyeCoord = mvMatrix * vPosition;
|
||||
gl_Position = projMatrix * vEyeCoord;
|
||||
fPosition = -vEyeCoord.xyz;
|
||||
fNormal = normalMatrix * vNormal;
|
||||
ifColor = color;
|
||||
vec4 vEyeCoord = mvMatrix * vPosition;
|
||||
gl_Position = projMatrix * vEyeCoord;
|
||||
fPosition = -vEyeCoord.xyz;
|
||||
fNormal = normalMatrix * vNormal;
|
||||
ifColor = color;
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,9 @@ uniform sampler2D skybox;
|
||||
|
||||
void main()
|
||||
{
|
||||
//fColor = vec4(1);
|
||||
fColor = texture(skybox, texCoords);
|
||||
//fColor = vec4(1);
|
||||
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);
|
||||
}
|
||||
skyboxRenderShaderProgram->release();
|
||||
}
|
||||
|
||||
void Viewer::draw()
|
||||
@ -148,7 +149,7 @@ void Viewer::draw()
|
||||
// Traverse the Scene in order to draw its components
|
||||
|
||||
modelStack.push(modelViewMatrix);
|
||||
root.accept(*this);
|
||||
root.accept(*this);
|
||||
frame++;
|
||||
update();
|
||||
}
|
||||
@ -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},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user