Code cleanup
This commit is contained in:
parent
4d0d96e0af
commit
3c0f3e18cd
3 changed files with 5 additions and 37 deletions
|
|
@ -48,7 +48,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
glm::vec4 viewPos;
|
|
||||||
Light lights[NUM_LIGHTS];
|
Light lights[NUM_LIGHTS];
|
||||||
} uboLights;
|
} uboLights;
|
||||||
|
|
||||||
|
|
@ -766,7 +765,6 @@ public:
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
updateUniformBufferDeferredMatrices();
|
updateUniformBufferDeferredMatrices();
|
||||||
updateUniformBufferDeferredLights();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUniformBufferDeferredMatrices()
|
void updateUniformBufferDeferredMatrices()
|
||||||
|
|
@ -794,16 +792,11 @@ public:
|
||||||
|
|
||||||
for (auto& light : uboLights.lights)
|
for (auto& light : uboLights.lights)
|
||||||
{
|
{
|
||||||
light.position = glm::vec4(rndDist(rndGen) * 6.0f, 0.25f + std::abs(rndDist(rndGen)) * 4.0f, rndDist(rndGen) * 6.0f, 1.0f);
|
light.position = glm::vec4(rndDist(rndGen) * 8.0f, 0.25f + std::abs(rndDist(rndGen)) * 4.0f, rndDist(rndGen) * 8.0f, 1.0f);
|
||||||
light.color = colors[rndCol(rndGen)];
|
light.color = colors[rndCol(rndGen)];
|
||||||
light.radius = 1.0f + std::abs(rndDist(rndGen));
|
light.radius = 1.0f + std::abs(rndDist(rndGen));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Update fragment shader light position uniform block
|
|
||||||
void updateUniformBufferDeferredLights()
|
|
||||||
{
|
|
||||||
uboLights.viewPos = glm::vec4(camera.position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
|
||||||
memcpy(uniformBuffers.lights.mapped, &uboLights, sizeof(uboLights));
|
memcpy(uniformBuffers.lights.mapped, &uboLights, sizeof(uboLights));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -825,8 +818,8 @@ public:
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepare();
|
VulkanExampleBase::prepare();
|
||||||
loadAssets();
|
loadAssets();
|
||||||
initLights();
|
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
|
initLights();
|
||||||
setupDescriptorSetLayout();
|
setupDescriptorSetLayout();
|
||||||
preparePipelines();
|
preparePipelines();
|
||||||
setupDescriptorPool();
|
setupDescriptorPool();
|
||||||
|
|
@ -843,16 +836,9 @@ public:
|
||||||
draw();
|
draw();
|
||||||
if (camera.updated) {
|
if (camera.updated) {
|
||||||
updateUniformBufferDeferredMatrices();
|
updateUniformBufferDeferredMatrices();
|
||||||
updateUniformBufferDeferredLights();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void viewChanged()
|
|
||||||
{
|
|
||||||
updateUniformBufferDeferredMatrices();
|
|
||||||
updateUniformBufferDeferredLights();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Subpasses")) {
|
if (overlay->header("Subpasses")) {
|
||||||
|
|
@ -863,7 +849,6 @@ public:
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
if (overlay->button("Randomize lights")) {
|
if (overlay->button("Randomize lights")) {
|
||||||
initLights();
|
initLights();
|
||||||
updateUniformBufferDeferredLights();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ struct Light {
|
||||||
|
|
||||||
layout (binding = 3) uniform UBO
|
layout (binding = 3) uniform UBO
|
||||||
{
|
{
|
||||||
vec4 viewPos;
|
|
||||||
Light lights[NUM_LIGHTS];
|
Light lights[NUM_LIGHTS];
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
|
|
@ -30,40 +29,24 @@ void main()
|
||||||
vec3 normal = subpassLoad(samplerNormal).rgb;
|
vec3 normal = subpassLoad(samplerNormal).rgb;
|
||||||
vec4 albedo = subpassLoad(samplerAlbedo);
|
vec4 albedo = subpassLoad(samplerAlbedo);
|
||||||
|
|
||||||
#define ambient 0.15
|
#define ambient 0.05
|
||||||
|
|
||||||
// Ambient part
|
// Ambient part
|
||||||
vec3 fragcolor = albedo.rgb * ambient;
|
vec3 fragcolor = albedo.rgb * ambient;
|
||||||
|
|
||||||
for(int i = 0; i < NUM_LIGHTS; ++i)
|
for(int i = 0; i < NUM_LIGHTS; ++i)
|
||||||
{
|
{
|
||||||
// Vector to light
|
|
||||||
vec3 L = ubo.lights[i].position.xyz - fragPos;
|
vec3 L = ubo.lights[i].position.xyz - fragPos;
|
||||||
// Distance from light to fragment position
|
|
||||||
float dist = length(L);
|
float dist = length(L);
|
||||||
|
|
||||||
// Viewer to fragment
|
|
||||||
vec3 V = ubo.viewPos.xyz - fragPos;
|
|
||||||
V = normalize(V);
|
|
||||||
|
|
||||||
// Light to fragment
|
|
||||||
L = normalize(L);
|
L = normalize(L);
|
||||||
|
float atten = ubo.lights[i].radius / (pow(dist, 3.0) + 1.0);
|
||||||
|
|
||||||
// Attenuation
|
|
||||||
float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
|
|
||||||
|
|
||||||
// Diffuse part
|
|
||||||
vec3 N = normalize(normal);
|
vec3 N = normalize(normal);
|
||||||
float NdotL = max(0.0, dot(N, L));
|
float NdotL = max(0.0, dot(N, L));
|
||||||
vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
|
vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
|
||||||
|
|
||||||
// Specular part
|
fragcolor += diff;
|
||||||
// Specular map values are stored in alpha of albedo mrt
|
|
||||||
vec3 R = reflect(-L, N);
|
|
||||||
float NdotR = max(0.0, dot(R, V));
|
|
||||||
//vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 32.0) * atten;
|
|
||||||
|
|
||||||
fragcolor += diff;// + spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outColor = vec4(fragcolor, 1.0);
|
outColor = vec4(fragcolor, 1.0);
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue