mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Sonic Screwdriver added
This commit is contained in:
parent
d5ead46e24
commit
c3b9f6f816
@ -15,50 +15,48 @@ in vec3 fPosition;
|
|||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
|
|
||||||
|
|
||||||
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm, vec3 lightDir) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(lDirection);
|
vec3 LightDirection = normalize(lightDir);
|
||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
vec3 nfNormal;
|
vec3 nfNormal = normalize(fNorm);
|
||||||
|
|
||||||
// Compute diffuse component
|
// Compute diffuse component
|
||||||
float diff = 0.2*max(0.0, dot(nfNormal, -LightDirection));
|
float diff = max(0.0, dot(nfNormal, -LightDirection));
|
||||||
|
vec3 diffV = diff * Kd;
|
||||||
|
|
||||||
// Compute specular component
|
// Compute specular component
|
||||||
vec3 Rl = reflect(LightDirection, nfNormal);
|
vec3 Rl = reflect(LightDirection, nfNormal);
|
||||||
float spec = 0.2*pow(max(0.0, dot(/*normalMatrix */ Rl, nviewDirection)), 64);
|
float spec = pow(max(0.0, dot(/*normalMatrix */ Rl, nviewDirection)), Kn);
|
||||||
|
vec3 specV = spec * Ks;
|
||||||
|
|
||||||
// Compute ambient component
|
vec3 totalLight = diffV + specV;
|
||||||
float amb = 0.2;
|
//return vec4(Kd + Ks, 1)
|
||||||
|
return vec4(totalLight, 1);
|
||||||
float mult = 1;//max(0.0, -LightDirection.y+1.5);
|
|
||||||
|
|
||||||
//return vec4(0);
|
|
||||||
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) {
|
||||||
// Get lighting vectors
|
// Get lighting vectors
|
||||||
vec3 LightDirection = normalize(pointLight[i] + fPos);
|
vec3 LightDirection = normalize(pointLight[i] + fPos);
|
||||||
// vec3 nfNormal = normalize(fNorm);
|
vec3 nfNormal = normalize(fNorm);
|
||||||
vec3 nviewDirection = normalize(fPos);
|
vec3 nviewDirection = normalize(fPos);
|
||||||
vec3 nfNormal;
|
|
||||||
|
|
||||||
// Attenuation
|
// Attenuation
|
||||||
float distance = length(nviewDirection - pointLight[i] - fPos) / 3;
|
float distance = length(nviewDirection - pointLight[i] - fPos) / 3;
|
||||||
float attenuation = 0.5 + 1 / max(0.25, distance * distance);
|
float attenuation = 0.5 + 1 / max(0.25, distance * distance);
|
||||||
|
|
||||||
// Compute diffuse component
|
// Compute diffuse component
|
||||||
float diff = 0.3 * max(0.0, dot(nfNormal, LightDirection));
|
float diff = max(0.0, dot(nfNormal, LightDirection));
|
||||||
|
vec3 diffV = diff * Kd;
|
||||||
|
|
||||||
// Compute specular component
|
// Compute specular component
|
||||||
vec3 Rl = reflect(-LightDirection, /*normalMatrix */ nfNormal);
|
vec3 Rl = reflect(-LightDirection, /*normalMatrix */ nfNormal);
|
||||||
float spec = 0.5 * pow(max(0.0, dot(Rl, nviewDirection)), 32);
|
float spec = pow(max(0.0, dot(Rl, nviewDirection)), Kn);
|
||||||
|
vec3 specV = spec * Ks;
|
||||||
|
|
||||||
// Compute ambient component
|
// Compute ambient component
|
||||||
float amb = 0.2;
|
vec3 totalLight = attenuation * (diffV + specV);
|
||||||
|
return vec4(totalLight, 1);
|
||||||
return vec4(pointLightCol[i].xyz * attenuation * (amb + diff + spec) * tex.xyz, pointLightCol[i].w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -71,9 +69,7 @@ main()
|
|||||||
vec3 nfNormal = normalize(fNormal);
|
vec3 nfNormal = normalize(fNormal);
|
||||||
vec3 nviewDirection = normalize(fPosition);
|
vec3 nviewDirection = normalize(fPosition);
|
||||||
|
|
||||||
fColor = calcDirLight(texColor, fPosition, fNormal)
|
fColor = 0.3 * calcDirLight(texColor, fPosition, fNormal, lDirection)
|
||||||
+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
+ 0.6 * calcDirLight(texColor, fPosition, fNormal, vec3(0.0)-fPosition);
|
||||||
+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
|
||||||
+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
|
||||||
fColor.a = 1.0;
|
fColor.a = 1.0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -885,11 +885,14 @@ void Viewer::drawTool() {
|
|||||||
// Get projection and camera transformations
|
// Get projection and camera transformations
|
||||||
QMatrix4x4 modelViewMatrix;
|
QMatrix4x4 modelViewMatrix;
|
||||||
|
|
||||||
camera()->getModelViewMatrix(modelViewMatrix);
|
//camera()->getModelViewMatrix(modelViewMatrix);
|
||||||
|
|
||||||
QMatrix4x4 scale = QMatrix4x4();
|
QMatrix4x4 scale = QMatrix4x4();
|
||||||
// scale.translate(QVector3D(0,1.5,0));
|
//scale.translate(QVector3D(0,1.5,0));
|
||||||
scale.scale(2.0);
|
scale.translate(0.5, -0.25, -2);
|
||||||
|
scale.rotate(100, 1, 0, 0);
|
||||||
|
scale.rotate(-90, 0, 1, 0);
|
||||||
|
scale.scale(0.1);
|
||||||
|
|
||||||
objShader->setUniformValue(o_u_mvMatrix, modelViewMatrix * scale);
|
objShader->setUniformValue(o_u_mvMatrix, modelViewMatrix * scale);
|
||||||
objShader->setUniformValue(o_u_nmMatrix, modelViewMatrix.normalMatrix());
|
objShader->setUniformValue(o_u_nmMatrix, modelViewMatrix.normalMatrix());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user