mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
fucking around with lighting shaders and the speed of sound
This commit is contained in:
parent
b985770871
commit
489578ba10
@ -25,14 +25,15 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
|
||||
// Compute diffuse component
|
||||
float diff = 0.4 * max(0.0, dot(nfNormal, LightDirection));
|
||||
float diff = 0.4*max(0.0, dot(nfNormal, -LightDirection));
|
||||
|
||||
// Compute specular component
|
||||
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
||||
float spec = 0.4*pow(max(0.0, dot(Rl, nviewDirection)), 16);
|
||||
//vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
||||
vec3 Rl = reflect(LightDirection, fNorm);
|
||||
float spec = pow(max(0.0, dot(Rl, nviewDirection)), 64);
|
||||
|
||||
// Compute ambient component
|
||||
float amb = 0.02;
|
||||
float amb = 0.2;
|
||||
|
||||
//return vec4(0);
|
||||
return vec4(tex.xyz * (amb + diff + spec), tex.w);
|
||||
@ -86,10 +87,10 @@ main()
|
||||
vec3 nfNormal = normalize(fNormal);
|
||||
vec3 nviewDirection = normalize(fPosition);
|
||||
|
||||
fColor = calcDirLight(texColor, fPosition, fNormal)
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
||||
fColor = calcDirLight(texColor, fPosition, fNormal);
|
||||
//+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
||||
//+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
||||
//+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
||||
} else {
|
||||
fColor = texColor + ifColor;
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ out vec3 fNormal;
|
||||
vec4 calcDirLight(vec4 eye, vec3 fPos, vec3 fNorm) {
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(lDirection);
|
||||
vec3 nfNormal = normalize(fNorm);
|
||||
vec3 nfNormal = normalize(fNorm - fPos);
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
|
||||
// Compute diffuse component
|
||||
|
||||
@ -146,7 +146,7 @@ void Viewer::draw()
|
||||
camera()->getProjectionMatrix(projectionMatrix);
|
||||
camera()->getModelViewMatrix(modelViewMatrix);
|
||||
|
||||
//modelViewMatrix.rotate(30,0,1,0);
|
||||
modelViewMatrix.rotate(30,0,1,0);
|
||||
|
||||
m_program->setUniformValue(m_projMatrixLocation, projectionMatrix);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
@ -154,7 +154,7 @@ void Viewer::draw()
|
||||
// Adjust sun position
|
||||
|
||||
float rotAngle = std::fmod(angle_mult * frame, 360);
|
||||
sunRotate.rotate(rotAngle, 1, 0, 0);
|
||||
sunRotate.rotate(rotAngle, 0, 0, 1);
|
||||
|
||||
m_program->setUniformValue(m_lDirLoc, (modelViewMatrix * sunRotate * sun));
|
||||
selection->transform.setToIdentity();
|
||||
@ -164,7 +164,7 @@ void Viewer::draw()
|
||||
|
||||
modelStack.push(modelViewMatrix);
|
||||
root.accept(*this);
|
||||
frame += 2;
|
||||
frame += 20;
|
||||
|
||||
sunRotate.setToIdentity();
|
||||
//float rotAngle = (frame * angle_mult) % 360;
|
||||
@ -196,8 +196,7 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
|
||||
container->transform = selectedPosition;
|
||||
container->addChild(c);
|
||||
root.addChild(container);
|
||||
}
|
||||
QGLViewer::mousePressEvent(e);
|
||||
} else QGLViewer::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void Viewer::mouseReleaseEvent(QMouseEvent* e) {
|
||||
@ -259,15 +258,15 @@ void Viewer::init()
|
||||
root.addChild(selection);
|
||||
|
||||
s1->transform.rotate(360 * 1/3,0,1,0);
|
||||
s1->transform.translate(1,0,0);
|
||||
s1->transform.translate(0.3,1,0);
|
||||
s1->transform.scale(0.05);
|
||||
s1->setColor(*c1);
|
||||
s2->transform.rotate(360 * 2/3,0,1,0);
|
||||
s2->transform.translate(1,0,0);
|
||||
s2->transform.translate(0.3,1,0);
|
||||
s2->transform.scale(0.05);
|
||||
s2->setColor(*c2);
|
||||
s3->transform.rotate(360 * 3/3,0,1,0);
|
||||
s3->transform.translate(1,0,0);
|
||||
s3->transform.translate(0.3,1,0);
|
||||
s3->transform.scale(0.05);
|
||||
s3->setColor(*c3);
|
||||
|
||||
@ -279,24 +278,10 @@ void Viewer::init()
|
||||
cube->setColor(*c1);
|
||||
cube->setType(1);
|
||||
sc->addChild(cube);
|
||||
sc->transform.translate(-5+i, -5, -5+j);
|
||||
sc->transform.translate(-5+i, 0, -5+j);
|
||||
root.addChild(sc);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Shape* cube1 = new Cube();
|
||||
Shape* cube2 = new Cube();
|
||||
Shape* cube3 = new Cube();
|
||||
cube1->setColor(*c1);
|
||||
cube2->setColor(*c2);
|
||||
cube3->setColor(*c3);
|
||||
cube2->transform.translate(3, 0, 0);
|
||||
cube3->transform.translate(-3, 0, 0);
|
||||
//*/
|
||||
|
||||
// uncomment this and the quaternion transformation in draw()
|
||||
// to see the cube rotate. This is how we can easily make the sun.
|
||||
// cube->transform.translate(3, 0, 0);
|
||||
|
||||
}
|
||||
}
|
||||
@ -568,10 +553,10 @@ void Viewer::initGeometries()
|
||||
glGenBuffers(NumBuffers, m_Buffers);
|
||||
|
||||
// Fill cube vertex VBO
|
||||
|
||||
GLsizeiptr offsetVertices = 0;
|
||||
GLsizeiptr offsetNormals = sizeof(verticesCube);
|
||||
GLsizeiptr offsetUV = offsetNormals + sizeof(normals);
|
||||
|
||||
GLsizeiptr dataSize = offsetUV + sizeof(uvs);
|
||||
|
||||
|
||||
@ -593,6 +578,29 @@ void Viewer::initGeometries()
|
||||
glVertexAttribPointer(s_vUvLocation, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(offsetUV));
|
||||
glEnableVertexAttribArray(s_vUvLocation);
|
||||
|
||||
/*GLsizeiptr offsetVertices = 0;
|
||||
GLsizeiptr offsetNormals = sizeof(verticesCube);
|
||||
GLsizeiptr offsetUV = offsetNormals + sizeof(normals);
|
||||
GLsizeiptr dataSize = offsetUV + sizeof(uvs);
|
||||
|
||||
|
||||
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[VBO_Cube]);
|
||||
glBufferData(GL_ARRAY_BUFFER, dataSize, NULL, GL_STATIC_DRAW);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, offsetVertices, sizeof(verticesCube), verticesCube);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, offsetNormals, sizeof(normals), normals);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, offsetUV, sizeof(uvs), uvs);
|
||||
|
||||
glVertexAttribPointer(m_vPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
glEnableVertexAttribArray(m_vPositionLocation);
|
||||
|
||||
glVertexAttribPointer(m_vNormalLocation, 3, GL_FLOAT, GL_TRUE, 0, BUFFER_OFFSET(sizeof(offsetNormals)));
|
||||
glEnableVertexAttribArray(m_vNormalLocation);
|
||||
|
||||
glVertexAttribPointer(s_vUvLocation, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(offsetUV)));
|
||||
glEnableVertexAttribArray(s_vUvLocation);//*/
|
||||
|
||||
// Fill Sphere VBO
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user