diff --git a/maps/test_map.json b/maps/test_map.json index f5ebfc2..bf7c648 100644 --- a/maps/test_map.json +++ b/maps/test_map.json @@ -22,7 +22,7 @@ "lights":[ { - "type":"directional", + "type":"point", "intensity": 1, "position": { "x":30, diff --git a/shaders/fragment/lighting.glsl b/shaders/fragment/lighting.glsl index c9bf298..2559f4b 100644 --- a/shaders/fragment/lighting.glsl +++ b/shaders/fragment/lighting.glsl @@ -12,7 +12,18 @@ flat in Light outLight[1]; uniform sampler2D diffuse, position, texcoord, normal, depth; vec4 directionalLight(Light light) { - return vec4(0,0,0,1); + vec3 norm = normalize(texture(normal, outTexCoords).rgb); + vec3 diffuse_color = texture(diffuse, outTexCoords).rgb; + vec3 fragPos = texture(position, outTexCoords).rgb; + + vec3 lightDir = normalize(light.position - fragPos); + float diff = max(dot(norm, lightDir), 0); + + vec3 _ambient = light.ambient; + vec3 _diffuse = light.diffuse * diff; + vec3 _specular = light.specular; + + return vec4(_diffuse + _ambient + _specular, 1.0); } vec4 pointLight(Light light) { @@ -24,7 +35,7 @@ vec4 spotLight(Light light) { } vec4 calculateLighting(Light light) { - vec4 result = vec4(0,0,0,0); + vec4 result; switch(light.type) { case DIRECTIONAL: { @@ -37,7 +48,8 @@ vec4 calculateLighting(Light light) { result = spotLight(light); } default: { - result = vec4(1,1,1,1); + // result = vec4(1,1,1,1); + result = directionalLight(light); } }