Correct specular highlights, light colors

This commit is contained in:
saschawillems 2016-07-17 15:14:52 +02:00
parent f3a86c292c
commit 94d8f7b94a
5 changed files with 21 additions and 26 deletions

View file

@ -73,7 +73,6 @@ float filterPCF(vec4 sc, float layer)
return shadowFactor / count; return shadowFactor / count;
} }
void main() void main()
{ {
// Get G-Buffer values // Get G-Buffer values
@ -112,18 +111,19 @@ void main()
float spotEffect = smoothstep(lightCosOuterAngle, lightCosInnerAngle, cosDir); float spotEffect = smoothstep(lightCosOuterAngle, lightCosInnerAngle, cosDir);
float heightAttenuation = smoothstep(lightRange, 0.0f, dist); float heightAttenuation = smoothstep(lightRange, 0.0f, dist);
// Diffuse lighting. // Diffuse lighting
float NdotL = max(0.0, dot(N, L)); float NdotL = max(0.0, dot(N, L));
vec3 diff = vec3(NdotL); vec3 diff = vec3(NdotL);
// Specular lighting. // Specular lighting
vec3 R = reflect(-L, N); vec3 R = reflect(-L, N);
float NdotR = max(0.0, dot(R, V)); float NdotR = max(0.0, dot(R, V));
vec3 spec = vec3(pow(NdotR, 16.0)); vec3 spec = vec3(pow(NdotR, 16.0) * albedo.a * 2.5);
fragcolor += vec3((diff + spec) * spotEffect * heightAttenuation) * ubo.lights[i].color.rgb * albedo.rgb ; fragcolor += vec3((diff + spec) * spotEffect * heightAttenuation) * ubo.lights[i].color.rgb * albedo.rgb;
} }
// Shadow calculations in a separate pass
for(int i = 0; i < LIGHT_COUNT; ++i) for(int i = 0; i < LIGHT_COUNT; ++i)
{ {
vec4 shadowClip = ubo.lights[i].viewMatrix * vec4(fragPos, 1.0); vec4 shadowClip = ubo.lights[i].viewMatrix * vec4(fragPos, 1.0);

View file

@ -14,23 +14,14 @@ layout (binding = 0) uniform UBO
} ubo; } ubo;
layout (location = 0) out vec2 outUV; layout (location = 0) out vec2 outUV;
//layout (location = 1) out vec4 outShadowCoord;
out gl_PerVertex out gl_PerVertex
{ {
vec4 gl_Position; vec4 gl_Position;
}; };
/*
const mat4 biasMat = mat4(
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.5, 0.5, 0.0, 1.0 );
*/
void main() void main()
{ {
outUV = inUV; outUV = inUV;
gl_Position = ubo.projection * ubo.modelview * vec4(inPos.xyz, 1.0); gl_Position = ubo.projection * ubo.modelview * vec4(inPos.xyz, 1.0);
//outShadowCoord = (biasMat * ubo.lightMVP * ubo.modelview) * vec4(inPos, 1.0);
} }

View file

@ -540,7 +540,7 @@ public:
vkMeshLoader::MeshCreateInfo meshCreateInfo; vkMeshLoader::MeshCreateInfo meshCreateInfo;
meshCreateInfo.scale = glm::vec3(15.0f); meshCreateInfo.scale = glm::vec3(15.0f);
meshCreateInfo.uvscale = glm::vec2(2.0f); meshCreateInfo.uvscale = glm::vec2(1.0f, 1.5f);
meshCreateInfo.center = glm::vec3(0.0f, 2.3f, 0.0f); meshCreateInfo.center = glm::vec3(0.0f, 2.3f, 0.0f);
loadMesh(getAssetPath() + "models/openbox.dae", &meshes.background, vertexLayout, &meshCreateInfo); loadMesh(getAssetPath() + "models/openbox.dae", &meshes.background, vertexLayout, &meshCreateInfo);
} }
@ -1079,7 +1079,8 @@ public:
}; };
std::vector<glm::vec4> lightColors = std::vector<glm::vec4> lightColors =
{ {
glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), // glm::vec4(1.0f),
glm::vec4(1.0f, 0.5f, 0.5f, 0.0f),
glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::vec4(0.0f, 0.0f, 1.0f, 0.0f),
glm::vec4(1.0f, 1.0f, 1.0f, 0.0f), glm::vec4(1.0f, 1.0f, 1.0f, 0.0f),
}; };
@ -1091,15 +1092,17 @@ public:
}; };
// Animate // Animate
// todo: wip if (!paused)
lightPositions[0].x = -14.0f + abs(sin(glm::radians(timer * 360.0f)) * 20.0f); {
lightPositions[0].z = 15.0f + cos(glm::radians(timer *360.0f)) * 1.0f; lightPositions[0].x = -14.0f + abs(sin(glm::radians(timer * 360.0f)) * 20.0f);
lightPositions[0].z = 15.0f + cos(glm::radians(timer *360.0f)) * 1.0f;
lightPositions[1].x = 14.0f - abs(sin(glm::radians(timer * 360.0f)) * 2.5f); lightPositions[1].x = 14.0f - abs(sin(glm::radians(timer * 360.0f)) * 2.5f);
lightPositions[1].z = 13.0f + cos(glm::radians(timer *360.0f)) * 4.0f; lightPositions[1].z = 13.0f + cos(glm::radians(timer *360.0f)) * 4.0f;
lightPositions[2].x = 0.0f + sin(glm::radians(timer *360.0f)) * 4.0f; lightPositions[2].x = 0.0f + sin(glm::radians(timer *360.0f)) * 4.0f;
lightPositions[2].z = 4.0f + cos(glm::radians(timer *360.0f)) * 2.0f; lightPositions[2].z = 4.0f + cos(glm::radians(timer *360.0f)) * 2.0f;
}
for (uint32_t i = 0; i < static_cast<uint32_t>(lightPositions.size()); i++) for (uint32_t i = 0; i < static_cast<uint32_t>(lightPositions.size()); i++)
{ {
@ -1127,6 +1130,7 @@ public:
vkUnmapMemory(device, uniformData.uboShadowGS.memory); vkUnmapMemory(device, uniformData.uboShadowGS.memory);
uboFragmentLights.viewPos = glm::vec4(uboOffscreenVS.view[3]); uboFragmentLights.viewPos = glm::vec4(uboOffscreenVS.view[3]);
uboFragmentLights.viewPos = glm::vec4(camera.position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);;
VK_CHECK_RESULT(vkMapMemory(device, uniformData.fsLights.memory, 0, sizeof(uboFragmentLights), 0, (void **)&pData)); VK_CHECK_RESULT(vkMapMemory(device, uniformData.fsLights.memory, 0, sizeof(uboFragmentLights), 0, (void **)&pData));
memcpy(pData, &uboFragmentLights, sizeof(uboFragmentLights)); memcpy(pData, &uboFragmentLights, sizeof(uboFragmentLights));
@ -1189,7 +1193,7 @@ public:
if (!prepared) if (!prepared)
return; return;
draw(); draw();
if (!paused) //if (!paused)
updateUniformBufferDeferredLights(); updateUniformBufferDeferredLights();
} }