shadows everywhere! lights must be moved elsewhere
This commit is contained in:
@@ -6,6 +6,7 @@ in layout(location = 2) vec3 worldPositions;
|
||||
|
||||
uniform vec3 lightPositions[3];
|
||||
uniform vec3 cameraPosition;
|
||||
uniform vec3 ballPosition;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
@@ -15,6 +16,9 @@ float rand(vec2 co) {
|
||||
float dither(vec2 uv) {
|
||||
return (rand(uv) * 2.0 - 1.0) / 256.0;
|
||||
}
|
||||
vec3 reject(vec3 from, vec3 onto) {
|
||||
return from - onto * dot(from, onto) / dot(onto, onto);
|
||||
}
|
||||
|
||||
const vec3 objectColor = vec3(1.0, 1.0, 1.0);
|
||||
const vec3 lightColor = vec3(0.5, 0.5, 0.5);
|
||||
@@ -25,6 +29,8 @@ const float shininess = 32.0;
|
||||
|
||||
const float la = 0.1, lb = 0.01, lc = 0.001;
|
||||
|
||||
const float ballRadius = 1.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(normal);
|
||||
@@ -36,8 +42,12 @@ void main()
|
||||
for (int i = 0; i < 3; i++) {
|
||||
vec3 lightVector = lightPositions[i] - worldPositions;
|
||||
vec3 lightDir = normalize(lightVector);
|
||||
|
||||
vec3 fragToBall = lightPositions[i] - ballPosition;
|
||||
|
||||
float d = length(lightVector);
|
||||
float attenuation = 1.0 / (la + d * lb + d * d * lc);
|
||||
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
@@ -45,7 +55,8 @@ void main()
|
||||
float spec = pow(max(dot(norm, halfwayDir), 0.0), shininess);
|
||||
vec3 specular = specularStrength * spec * lightColor;
|
||||
|
||||
result += attenuation * (diffuse + specular) * objectColor;
|
||||
if (length(lightVector) < length(fragToBall) && dot(lightVector, fragToBall) < 0.0)
|
||||
result += attenuation * (diffuse + specular) * objectColor;
|
||||
}
|
||||
|
||||
color = vec4(result + dither(textureCoordinates), 1.0);
|
||||
|
||||
@@ -409,6 +409,8 @@ void renderNode(SceneNode* node) {
|
||||
GLint cameraPosLoc = shader->getUniformFromName("cameraPosition");
|
||||
glUniform3fv(cameraPosLoc, 1, glm::value_ptr(cameraPosition));
|
||||
|
||||
GLint ballPosLoc = shader->getUniformFromName("ballPosition");
|
||||
glUniform3fv(ballPosLoc, 1, glm::value_ptr(ballPosition));
|
||||
|
||||
switch(node->nodeType) {
|
||||
case GEOMETRY:
|
||||
|
||||
Reference in New Issue
Block a user