Commit d6f5692c authored by Dario Seyb's avatar Dario Seyb

added specular lighting

parent cccedf7a
......@@ -14,6 +14,7 @@ uniform mat4 uLightProjMatrix;
uniform float uNear;
uniform float uFar;
uniform vec3 cameraPosition;
uniform mat4 uViewProjectionInverseMatrix;
in vec2 vTexCoord;
......@@ -72,11 +73,17 @@ void main()
float lightDistance = length(lightDir);
lightDir /= lightDistance;
float diffuseFactor = dot(lightDir, normal) * uLightColor.a/(lightDistance*lightDistance) ;
float diffuseFactor = dot(lightDir, normal);
if(diffuseFactor < 0) diffuseFactor = 0;
vec3 diffuseColor = diffuseFactor * uLightColor.rgb * color.rgb * shadowFactor(worldPosition);;
vec3 diffuseColor = diffuseFactor * uLightColor.rgb * color.rgb;
vec3 viewDir = normalize(cameraPosition - worldPosition);
float specularFactor = dot( reflect(lightDir, -normal), -viewDir);
if(specularFactor < 0) specularFactor = 0;
vec3 specularColor = pow(specularFactor, 210) * color.rgb;
oColor = vec4(diffuseColor, 1);
oColor = vec4((diffuseColor + specularColor) * uLightColor.a/(lightDistance*lightDistance) * shadowFactor(worldPosition), 1);
}
......@@ -94,11 +94,11 @@ bool RendererSystem::startup() {
}
ImGui::End();
ImGui::Begin("ShadowMap", 0, ImGuiWindowFlags_AlwaysAutoResize);
/*ImGui::Begin("ShadowMap", 0, ImGuiWindowFlags_AlwaysAutoResize);
for (auto light : m_lights) {
//ImGui::Image((void*)light.shadowMap->getObjectName(), { 256, 256 });
ImGui::Image((void*)light.shadowMap->getObjectName(), { 256, 256 });
}
ImGui::End();
ImGui::End();*/
});
......@@ -211,6 +211,9 @@ void RendererSystem::frame(double interp, double totalTime) {
m_deferredCombineProgram->setUniform("uNear", cam->near);
m_deferredCombineProgram->setUniform("uFar", cam->far);
auto camPos = camTransform * glm::vec4{ 0, 0, 0, 1 };
m_deferredCombineProgram->setUniform("cameraPosition", glm::vec3{ camPos.x, camPos.y, camPos.z });
m_deferredCombineProgram->setUniform("uViewProjectionInverseMatrix",
glm::inverse(projectionMatrix));
......
......@@ -47,7 +47,7 @@ int main(int argc, char *argv[]) {
SceneGraphSystem sceneGraph(&context);
AudioSystem audio(&context);
UISystem ui(&context);
GameLoopSystem gameLoop(&context, 10, 250);
GameLoopSystem gameLoop(&context, 60, 250);
// Call the startup functions of the systems above in the order they are listed.
// This means it's safe to access other systems in a startup function as long
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment