mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
The rumour come out, does phong lighting is work?
This commit is contained in:
parent
fff57b7285
commit
eb4386ef23
@ -11,9 +11,9 @@ void
|
||||
main()
|
||||
{
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(vec3(0.0)-fPosition); // We assume light is at camera position
|
||||
vec3 LightDirection = normalize(vec3(-1,-3,0)); // We assume light is at camera position
|
||||
vec3 nfNormal = normalize(fNormal);
|
||||
vec3 nviewDirection = normalize(vec3(0.0)-fPosition);
|
||||
vec3 nviewDirection = normalize(fPosition);
|
||||
|
||||
// Compute diffuse component
|
||||
float diffuse = max(0.0, dot(nfNormal, LightDirection));
|
||||
@ -26,5 +26,5 @@ main()
|
||||
vec3 color = ifColor.xyz;
|
||||
|
||||
// Compute final color
|
||||
fColor = vec4(color * (diffuse + specular), 1);
|
||||
fColor = vec4(color * (0.1 + diffuse + specular), 1);
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ main()
|
||||
{
|
||||
vec4 vEyeCoord = mvMatrix * vPosition;
|
||||
gl_Position = projMatrix * vEyeCoord;
|
||||
fPosition = vEyeCoord.xyz;
|
||||
fPosition = -vEyeCoord.xyz;
|
||||
fNormal = normalMatrix * vNormal;
|
||||
ifColor = color;
|
||||
}
|
||||
|
||||
@ -6,6 +6,6 @@ uniform sampler2D skybox;
|
||||
|
||||
void main()
|
||||
{
|
||||
//fColor = texture(skybox, texCoords);
|
||||
//fColor = vec4(1);
|
||||
fColor = texture(skybox, texCoords);
|
||||
}
|
||||
|
||||
@ -142,6 +142,8 @@ void Viewer::draw()
|
||||
projectionMatrix.translate(0, -5, 0);
|
||||
projectionMatrix.rotate(15, 1, 0, 0);//*/
|
||||
|
||||
modelViewMatrix.rotate(30,0,1,0);
|
||||
|
||||
m_program->setUniformValue(m_projMatrixLocation, projectionMatrix);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
|
||||
@ -394,23 +396,23 @@ void Viewer::initGeometries()
|
||||
};
|
||||
|
||||
GLfloat normals[numVerticesCube][3] = {
|
||||
{ 0, 0, 1 }, {0, 0, 1}, {0, 0, 1},
|
||||
{ 0, 0, 1 }, {0, 0, 1}, {0, 0, 1},
|
||||
{ 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, -1 }, {0, 0, -1}, {0, 0, -1},
|
||||
{ 0, 0, -1 }, {0, 0, -1}, {0, 0, -1},
|
||||
{ 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 }, {1, 0, 0}, {1, 0, 0},
|
||||
{ 1, 0, 0 }, {1, 0, 0}, {1, 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 }, {-1, 0, 0}, {-1, 0, 0},
|
||||
{ -1, 0, 0 }, {-1, 0, 0}, {-1, 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, 1, 0 }, {0, 1, 0}, {0, 1, 0},
|
||||
{ 0, 1, 0 }, {0, 1, 0}, {0, 1, 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, -1, 0 }, {0, -1, 0}, {0, -1, 0},
|
||||
{ 0, -1, 0 }, {0, -1, 0}, {0, -1, 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}
|
||||
};
|
||||
|
||||
|
||||
@ -436,22 +438,19 @@ void Viewer::initGeometries()
|
||||
glEnableVertexAttribArray(s_vUvLocation);
|
||||
|
||||
glVertexAttribPointer(m_vNormalLocation, 3, GL_FLOAT,
|
||||
GL_FALSE, 0, BUFFER_OFFSET(sizeof(verticesCube) + sizeof(uvs)));
|
||||
GL_TRUE, 0, BUFFER_OFFSET(sizeof(verticesCube) + sizeof(uvs)));
|
||||
glEnableVertexAttribArray(m_vNormalLocation);
|
||||
}
|
||||
|
||||
void Viewer::visit(Cube &s)
|
||||
{
|
||||
QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform);
|
||||
QMatrix4x4 lookAt;
|
||||
|
||||
camera()->getProjectionMatrix(lookAt);
|
||||
|
||||
int faces = floor(numVerticesCube/6);
|
||||
for(int i = 0; i < faces; i++){ // 6 vertexes par face
|
||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
m_program->setUniformValue(m_normalMatrixLoc, lookAt.normalMatrix());
|
||||
m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix());
|
||||
m_program->setUniformValue(m_colorLocation, s.getColor());
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user