Blinn-Phong lighting
parent
6bd3bdecb8
commit
44b027c3e2
|
@ -1,12 +1,42 @@
|
|||
#version 330 core
|
||||
|
||||
in vec4 vColor;
|
||||
in vec3 vColor;
|
||||
in vec3 vNormal;
|
||||
in vec3 FragPos;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
vec3 lightColor = vec3(1.0);
|
||||
vec3 lightDir = -normalize(vec3(0.0, 100.0, 0.0) - vec3(32.0));
|
||||
|
||||
float ambientStrength = 0.5;
|
||||
float diffuseStrength = 0.3;
|
||||
float specularStrength = 0.2;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform float u_time;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vColor;
|
||||
// FragColor= vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
// offset the normal a tiny bit, so that the color of faces opposing lightDir is not completely
|
||||
// flat
|
||||
vec3 normal = normalize(vNormal);
|
||||
|
||||
// Blinn-Phong lighting
|
||||
// Ambient
|
||||
vec3 ambient = lightColor*vColor;
|
||||
|
||||
// Diffuse
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
vec3 diffuse = vColor * diff;
|
||||
|
||||
// Blinn Specular
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
vec3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(normal, halfwayDir), 0.0), 64.0);
|
||||
vec3 specular = lightColor * vColor * spec;
|
||||
|
||||
// Final color
|
||||
vec3 color = ambient * ambientStrength + diffuse * diffuseStrength + specular * specularStrength;
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
|
|
@ -8,13 +8,15 @@ uniform mat4 model;
|
|||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec4 vColor;
|
||||
out vec3 vColor;
|
||||
out vec3 vNormal;
|
||||
out vec3 FragPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vColor = vec4(aColor, 1.0f);
|
||||
vNormal = aNormal;
|
||||
vColor = aColor;
|
||||
vNormal = mat3(transpose(inverse(model))) * aNormal;
|
||||
|
||||
FragPos = vec3(model*vec4(aPos, 1.0));
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
}
|
||||
|
|
|
@ -124,7 +124,6 @@ namespace chunkmanager
|
|||
chunks_indices[index][0] = x;
|
||||
chunks_indices[index][1] = y;
|
||||
chunks_indices[index][2] = z;
|
||||
std::cout << index << "/" << chunks_volume << "\n";
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,21 +323,6 @@ void quad(Chunk::Chunk* chunk, glm::vec3 bottomLeft, glm::vec3 topLeft, glm::vec
|
|||
break;
|
||||
}
|
||||
|
||||
// Fake shadows
|
||||
if ((bottomLeft.z == bottomRight.z && bottomRight.z == topLeft.z && topLeft.z == topRight.z))
|
||||
{
|
||||
r += 0.1f;
|
||||
g += 0.1f;
|
||||
b += 0.1f;
|
||||
}
|
||||
|
||||
if ((bottomLeft.y == bottomRight.y && bottomRight.y == topLeft.y && topLeft.y == topRight.y))
|
||||
{
|
||||
r += 0.12f;
|
||||
g += 0.12f;
|
||||
b += 0.12f;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
chunk->colors.push_back(r);
|
||||
|
|
|
@ -88,6 +88,8 @@ int main()
|
|||
|
||||
// Camera
|
||||
theCamera.update(window, deltaTime);
|
||||
theShader->setFloat("u_time", currentFrame);
|
||||
theShader->setVec3("viewPos", theCamera.getPos());
|
||||
|
||||
// Reset blockping timeout if 200ms have passed
|
||||
if(glfwGetTime() - lastBlockPick > 0.1) blockpick = false;
|
||||
|
|
Loading…
Reference in New Issue