mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
tweaking lights and shit
This commit is contained in:
parent
52d547bd1e
commit
9c79eca90d
@ -24,14 +24,14 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
|
||||
// Compute diffuse component
|
||||
float diff = 0.65 * 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.1*pow(max(0.0, dot(Rl, nviewDirection)), 16);
|
||||
float spec = 0.4*pow(max(0.0, dot(Rl, nviewDirection)), 16);
|
||||
|
||||
// Compute ambient component
|
||||
float amb = 0.05;
|
||||
float amb = 0.02;
|
||||
|
||||
//return vec4(0);
|
||||
return vec4(tex.xyz * (amb + diff + spec), tex.w);
|
||||
@ -39,25 +39,25 @@ vec4 calcDirLight(vec4 tex, vec3 fPos, vec3 fNorm) {
|
||||
|
||||
vec4 calcPointLight(vec4 tex, vec3 fPos, vec3 fNorm, int i) {
|
||||
// Get lighting vectors
|
||||
vec3 LightDirection = normalize(fPos - pointLight[i]);
|
||||
vec3 LightDirection = normalize(pointLight[i] + fPos);
|
||||
vec3 nfNormal = normalize(fNorm);
|
||||
vec3 nviewDirection = normalize(fPos);
|
||||
|
||||
// Attenuation
|
||||
float distance = length(pointLight[i] - nviewDirection);
|
||||
float attenuation = 1.0f;// / (distance * distance);
|
||||
float distance = length(nviewDirection - pointLight[i] - fPos) / 3;
|
||||
float attenuation = 0.5 + 1 / max(0.25, distance * distance);
|
||||
|
||||
// Compute diffuse component
|
||||
float diff = 0.5 * max(0.0, dot(nfNormal, LightDirection));
|
||||
float diff = 0.3 * max(0.0, dot(nfNormal, LightDirection));
|
||||
|
||||
// Compute specular component
|
||||
vec3 Rl = normalize(-LightDirection+2.0*nfNormal*dot(nfNormal,LightDirection));
|
||||
float spec = 0.5*pow(max(0.0, dot(Rl, nviewDirection)), 32);
|
||||
vec3 Rl = reflect(-LightDirection, fNorm);
|
||||
float spec = 0.5 * pow(max(0.0, dot(Rl, nviewDirection)), 32);
|
||||
|
||||
// Compute ambient component
|
||||
float amb = 0;
|
||||
float amb = 0.2;
|
||||
|
||||
return vec4(1 * pointLightCol[i].xyz * attenuation * (amb + diff + spec), pointLightCol[i].w);
|
||||
return vec4(pointLightCol[i].xyz * attenuation * (amb + diff + spec) * tex.xyz, pointLightCol[i].w);
|
||||
}
|
||||
|
||||
void
|
||||
@ -80,9 +80,9 @@ main()
|
||||
vec3 nviewDirection = normalize(fPosition);
|
||||
|
||||
fColor = calcDirLight(texColor, fPosition, fNormal)
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 0)
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 1)
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 2);
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 0)/4
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 1)/4
|
||||
+ calcPointLight(texColor, fPosition, fNormal, 2)/4;
|
||||
} else {
|
||||
fColor = texColor * ifColor;
|
||||
}
|
||||
|
||||
@ -259,16 +259,16 @@ void Viewer::init()
|
||||
Shape* s3 = new Sphere();
|
||||
|
||||
s1->transform.rotate(360 * 1/3,0,1,0);
|
||||
s1->transform.translate(0.5,1,0);
|
||||
s1->transform.scale(0.3);
|
||||
s1->transform.translate(1,0,0);
|
||||
s1->transform.scale(0.05);
|
||||
s1->setColor(*c1);
|
||||
s2->transform.rotate(360 * 2/3,0,1,0);
|
||||
s2->transform.translate(0.5,1,0);
|
||||
s2->transform.scale(0.3);
|
||||
s2->transform.translate(1,0,0);
|
||||
s2->transform.scale(0.05);
|
||||
s2->setColor(*c2);
|
||||
s3->transform.rotate(360 * 3/3,0,1,0);
|
||||
s3->transform.translate(0.5,1,0);
|
||||
s3->transform.scale(0.3);
|
||||
s3->transform.translate(1,0,0);
|
||||
s3->transform.scale(0.05);
|
||||
s3->setColor(*c3);
|
||||
|
||||
// uncomment this and the quaternion transformation in draw()
|
||||
@ -276,8 +276,8 @@ void Viewer::init()
|
||||
// cube->transform.translate(3, 0, 0);
|
||||
|
||||
selection = new SceneGroup();
|
||||
selection->addChild(s1);;
|
||||
selection->addChild(s2);;
|
||||
selection->addChild(s1);
|
||||
selection->addChild(s2);
|
||||
selection->addChild(s3);
|
||||
|
||||
SceneGroup *c = new SceneGroup();
|
||||
@ -370,7 +370,7 @@ void Viewer::initShaders()
|
||||
qDebug() << "Unable to find m_shader location for" << "pointLightCol[2]";
|
||||
|
||||
m_program->setUniformValue(m_isPhongLoc, true);
|
||||
m_program->setUniformValue(m_drawTextLoc, true);
|
||||
m_program->setUniformValue(m_drawTextLoc, false);
|
||||
|
||||
|
||||
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg"));/*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user