mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Spicy memeball
This commit is contained in:
parent
74e43e0294
commit
48e5889f60
@ -9,6 +9,7 @@ uniform bool isLightSource;
|
||||
uniform bool isPickingMode;
|
||||
uniform vec3 pointLight[3];
|
||||
uniform vec4 pointLightCol[3];
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
in vec3 fNormal;
|
||||
in vec3 fPosition;
|
||||
@ -28,15 +29,16 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
float diff = 0.4*max(0.0, dot(nfNormal, -LightDirection));
|
||||
|
||||
// Compute specular component
|
||||
//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);
|
||||
vec3 Rl = reflect(-LightDirection, fNorm);
|
||||
float spec = pow(max(0.0, dot(normalMatrix * Rl, nviewDirection)), 64);
|
||||
|
||||
// Compute ambient component
|
||||
float amb = 0.2;
|
||||
|
||||
float mult = 1; //max(0.0, -LightDirection.y);
|
||||
|
||||
//return vec4(0);
|
||||
return vec4(tex.xyz * (amb + diff + spec), tex.w);
|
||||
return vec4(tex.xyz * (diff + amb + spec) * mult, tex.w);
|
||||
}
|
||||
|
||||
vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||
@ -53,7 +55,7 @@ vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||
float diff = 0.3 * max(0.0, dot(nfNormal, LightDirection));
|
||||
|
||||
// Compute specular component
|
||||
vec3 Rl = reflect(-LightDirection, fNorm);
|
||||
vec3 Rl = reflect(-LightDirection, normalMatrix * fNorm);
|
||||
float spec = 0.5 * pow(max(0.0, dot(Rl, nviewDirection)), 32);
|
||||
|
||||
// Compute ambient component
|
||||
@ -87,10 +89,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;
|
||||
}
|
||||
|
||||
@ -20,18 +20,21 @@ out vec2 texCoords;
|
||||
out vec4 ifColor;
|
||||
out vec3 fPosition;
|
||||
out vec3 fNormal;
|
||||
out vec3 vfNormal;
|
||||
|
||||
vec4 calcDirLight(vec4 eye, vec3 fPos, vec3 fNorm) {
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(lDirection);
|
||||
vec3 nfNormal = normalize(fNorm - fPos);
|
||||
vec3 nfNormal = normalize(fNorm);
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
|
||||
// Compute diffuse component
|
||||
float diff = 0.65 * max(0.0, dot(nfNormal, LightDirection));
|
||||
|
||||
// Compute specular component
|
||||
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
||||
//vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
||||
|
||||
vec3 Rl = reflect(-LightDirection, fNorm);
|
||||
float spec = 0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
|
||||
|
||||
// Compute ambient component
|
||||
@ -75,7 +78,7 @@ main()
|
||||
vec4 vEyeCoord = mvMatrix * vPosition;
|
||||
gl_Position = projMatrix * vEyeCoord;
|
||||
fPosition = -vEyeCoord.xyz;
|
||||
fNormal = normalMatrix * vNormal;
|
||||
fNormal = /*normalMatrix **/ vNormal;
|
||||
|
||||
texCoords = vUv;
|
||||
|
||||
|
||||
@ -146,7 +146,7 @@ void Viewer::draw()
|
||||
camera()->getProjectionMatrix(projectionMatrix);
|
||||
camera()->getModelViewMatrix(modelViewMatrix);
|
||||
|
||||
modelViewMatrix.rotate(30,0,1,0);
|
||||
modelViewMatrix.rotate(30,1,0,0);
|
||||
|
||||
m_program->setUniformValue(m_projMatrixLocation, projectionMatrix);
|
||||
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
|
||||
@ -155,8 +155,9 @@ void Viewer::draw()
|
||||
|
||||
float rotAngle = std::fmod(angle_mult * frame, 360);
|
||||
sunRotate.rotate(rotAngle, 0, 0, 1);
|
||||
//sunRotate.rotate(15, 1, 0, 0);
|
||||
|
||||
m_program->setUniformValue(m_lDirLoc, (modelViewMatrix * sunRotate * sun));
|
||||
m_program->setUniformValue(m_lDirLoc, (sunRotate * sun));
|
||||
selection->transform.setToIdentity();
|
||||
selection->transform.rotate(rotAngle, 0, 1, 0);
|
||||
|
||||
@ -164,7 +165,7 @@ void Viewer::draw()
|
||||
|
||||
modelStack.push(modelViewMatrix);
|
||||
root.accept(*this);
|
||||
frame += 20;
|
||||
frame += 1;
|
||||
|
||||
sunRotate.setToIdentity();
|
||||
//float rotAngle = (frame * angle_mult) % 360;
|
||||
@ -233,9 +234,6 @@ void Viewer::init()
|
||||
initGeometries();
|
||||
initBuffers();
|
||||
|
||||
sunRotate.rotate(-15,0,0,1);
|
||||
sun = sunRotate * sun;
|
||||
|
||||
|
||||
{
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user