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 bool isPickingMode;
uniform vec3 pointLight[3]; uniform vec3 pointLight[3];
uniform vec4 pointLightCol[3]; uniform vec4 pointLightCol[3];
uniform mat3 normalMatrix;
in vec3 fNormal; in vec3 fNormal;
in vec3 fPosition; 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)); float diff = 0.4*max(0.0, dot(nfNormal, -LightDirection));
// Compute specular component // Compute specular component
//vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection)); vec3 Rl = reflect(-LightDirection, fNorm);
vec3 Rl = reflect(LightDirection, fNorm); float spec = pow(max(0.0, dot(normalMatrix * Rl, nviewDirection)), 64);
float spec = pow(max(0.0, dot(Rl, nviewDirection)), 64);
// Compute ambient component // Compute ambient component
float amb = 0.2; float amb = 0.2;
float mult = 1; //max(0.0, -LightDirection.y);
//return vec4(0); //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) { 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)); float diff = 0.3 * max(0.0, dot(nfNormal, LightDirection));
// Compute specular component // 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); float spec = 0.5 * pow(max(0.0, dot(Rl, nviewDirection)), 32);
// Compute ambient component // Compute ambient component
@ -87,10 +89,10 @@ main()
vec3 nfNormal = normalize(fNormal); vec3 nfNormal = normalize(fNormal);
vec3 nviewDirection = normalize(fPosition); vec3 nviewDirection = normalize(fPosition);
fColor = calcDirLight(texColor, fPosition, fNormal); fColor = calcDirLight(texColor, fPosition, fNormal)
//+ calcPointLight(texColor, fPosition, fNormal, 0)/4 + calcPointLight(texColor, fPosition, fNormal, 0)/4
//+ calcPointLight(texColor, fPosition, fNormal, 1)/4 + calcPointLight(texColor, fPosition, fNormal, 1)/4
//+ calcPointLight(texColor, fPosition, fNormal, 2)/4; + calcPointLight(texColor, fPosition, fNormal, 2)/4;
} else { } else {
fColor = texColor + ifColor; fColor = texColor + ifColor;
} }

View File

@ -20,18 +20,21 @@ out vec2 texCoords;
out vec4 ifColor; out vec4 ifColor;
out vec3 fPosition; out vec3 fPosition;
out vec3 fNormal; out vec3 fNormal;
out vec3 vfNormal;
vec4 calcDirLight(vec4 eye, vec3 fPos, vec3 fNorm) { vec4 calcDirLight(vec4 eye, vec3 fPos, vec3 fNorm) {
// Get lighting vectors // Get lighting vectors
vec3 LightDirection = normalize(lDirection); vec3 LightDirection = normalize(lDirection);
vec3 nfNormal = normalize(fNorm - fPos); vec3 nfNormal = normalize(fNorm);
vec3 nviewDirection = normalize(fPos); vec3 nviewDirection = normalize(fPos);
// Compute diffuse component // Compute diffuse component
float diff = 0.65 * max(0.0, dot(nfNormal, LightDirection)); float diff = 0.65 * max(0.0, dot(nfNormal, LightDirection));
// Compute specular component // 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); float spec = 0.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
// Compute ambient component // Compute ambient component
@ -75,7 +78,7 @@ main()
vec4 vEyeCoord = mvMatrix * vPosition; vec4 vEyeCoord = mvMatrix * vPosition;
gl_Position = projMatrix * vEyeCoord; gl_Position = projMatrix * vEyeCoord;
fPosition = -vEyeCoord.xyz; fPosition = -vEyeCoord.xyz;
fNormal = normalMatrix * vNormal; fNormal = /*normalMatrix **/ vNormal;
texCoords = vUv; texCoords = vUv;

View File

@ -146,7 +146,7 @@ void Viewer::draw()
camera()->getProjectionMatrix(projectionMatrix); camera()->getProjectionMatrix(projectionMatrix);
camera()->getModelViewMatrix(modelViewMatrix); 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_projMatrixLocation, projectionMatrix);
m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix);
@ -155,8 +155,9 @@ void Viewer::draw()
float rotAngle = std::fmod(angle_mult * frame, 360); float rotAngle = std::fmod(angle_mult * frame, 360);
sunRotate.rotate(rotAngle, 0, 0, 1); 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.setToIdentity();
selection->transform.rotate(rotAngle, 0, 1, 0); selection->transform.rotate(rotAngle, 0, 1, 0);
@ -164,7 +165,7 @@ void Viewer::draw()
modelStack.push(modelViewMatrix); modelStack.push(modelViewMatrix);
root.accept(*this); root.accept(*this);
frame += 20; frame += 1;
sunRotate.setToIdentity(); sunRotate.setToIdentity();
//float rotAngle = (frame * angle_mult) % 360; //float rotAngle = (frame * angle_mult) % 360;
@ -233,9 +234,6 @@ void Viewer::init()
initGeometries(); initGeometries();
initBuffers(); initBuffers();
sunRotate.rotate(-15,0,0,1);
sun = sunRotate * sun;
{ {