Spicy memeball

This commit is contained in:
Dmitri K 2016-11-18 19:10:58 -05:00
parent 74e43e0294
commit 48e5889f60
3 changed files with 24 additions and 21 deletions

View File

@ -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;
@ -27,16 +28,17 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
// Compute diffuse component
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);
// Compute specular component
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;
}

View File

@ -20,19 +20,22 @@ 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));
float spec = 0.1*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 = 0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
// Compute ambient component
vec3 amb = vec3(0.1);
@ -40,7 +43,7 @@ vec4 calcDirLight(vec4 eye, vec3 fPos, vec3 fNorm) {
// Vertex color (currently static, to be replaced with texture)
vec4 color = ifColor;
return color * vec4(amb + diff + spec, 1);
return color * vec4(amb + diff + spec, 1);
}
vec4 calcPointLight(vec4 eye, vec3 fPos, vec3 fNorm, int i) {
@ -75,7 +78,7 @@ main()
vec4 vEyeCoord = mvMatrix * vPosition;
gl_Position = projMatrix * vEyeCoord;
fPosition = -vEyeCoord.xyz;
fNormal = normalMatrix * vNormal;
fNormal = /*normalMatrix **/ vNormal;
texCoords = vUv;

View File

@ -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;
{