Skip to content

Commit 34ba6ab

Browse files
committed
cleanup
1 parent 2ecafa0 commit 34ba6ab

File tree

3 files changed

+0
-152
lines changed

3 files changed

+0
-152
lines changed

HelloVulkan/Header/Pipelines/PipelineShadow.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,9 @@ class PipelineShadow final : public PipelineBase
2323
const LightData* light,
2424
ShadowMapUBO* ubo);
2525

26-
void CalculateCascade2(VulkanContext& ctx,
27-
const Camera* camera,
28-
const LightData* light,
29-
ShadowMapUBO* ubo);
30-
31-
glm::mat4 GetLightSpaceMatrix(const Camera* camera, float near, float far, glm::vec3 normLightPos);
32-
33-
std::vector<glm::vec4> GetFrustumCornersWorldSpace(glm::mat4& proj, glm::mat4& view);
34-
3526
virtual void FillCommandBuffer(VulkanContext& ctx, VkCommandBuffer commandBuffer) override;
3627

3728
void OnWindowResized(VulkanContext& ctx) override;
38-
39-
public:
40-
float zMult = 10.f;
4129

4230
private:
4331
void CreateDescriptor(VulkanContext& ctx);

HelloVulkan/Source/Apps/AppPBRShadow.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ void AppPBRShadow::UpdateUI()
192192
};
193193
static float staticLightPos[3] = { -5.f, 30.0f, 5.0f};
194194
static int staticPCFIteration = 2;
195-
static float zMult = 10.f;
196195

197196
imguiPtr_->ImGuiStart();
198197
imguiPtr_->ImGuiSetWindow("Bindless Shadow Mapping", 525, 650);
@@ -210,7 +209,6 @@ void AppPBRShadow::UpdateUI()
210209
ImGui::SliderFloat("Far Plane", &staticShadowUBO.shadowFarPlane, 10.0f, 150.0f);
211210
ImGui::SliderFloat("PCF Scale", &staticShadowUBO.pcfScale, 0.1f, 1.0f);
212211
ImGui::SliderInt("PCF Iteration", &staticPCFIteration, 1, 10);
213-
ImGui::SliderFloat("Z Mult", &zMult, 0.0f, 50.f);
214212

215213
ImGui::SeparatorText("Light position");
216214
ImGui::SliderFloat("X", &(staticLightPos[0]), -10.0f, 10.0f);
@@ -231,8 +229,6 @@ void AppPBRShadow::UpdateUI()
231229
shadowUBO_.shadowFarPlane = staticShadowUBO.shadowFarPlane;
232230
shadowUBO_.pcfScale = staticShadowUBO.pcfScale;
233231
shadowUBO_.pcfIteration = staticPCFIteration;
234-
235-
shadowPtr_->zMult = zMult;
236232
}
237233

238234
// This is called from main.cpp

HelloVulkan/Source/Pipelines/PipelineShadow.cpp

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -203,142 +203,6 @@ void PipelineShadow::CalculateCascade(
203203
shadowMapUBOBuffers_[frameIndex].UploadBufferData(ctx, ubo, sizeof(ShadowMapUBO));
204204
}
205205

206-
void PipelineShadow::CalculateCascade2(VulkanContext& ctx,
207-
const Camera* camera,
208-
const LightData* light,
209-
ShadowMapUBO* ubo)
210-
{
211-
float far = CameraConfig::Far;
212-
const glm::vec3 normLightPos = normalize(glm::vec3(light->position_.x, light->position_.y, light->position_.z));
213-
std::vector<float> shadowCascadeLevels{ far / 50.0f, far / 25.0f, far / 10.0f, far / 2.0f };
214-
215-
for (uint32_t i = 0; i < ShadowConfig::CascadeCount; i++)
216-
{
217-
glm::mat4 lightspaceMatrix(1.0f);
218-
if (i == 0)
219-
{
220-
lightspaceMatrix = GetLightSpaceMatrix(camera, CameraConfig::Near, shadowCascadeLevels[i], normLightPos);
221-
}
222-
else if (i < shadowCascadeLevels.size())
223-
{
224-
lightspaceMatrix = GetLightSpaceMatrix(camera, shadowCascadeLevels[i - 1], shadowCascadeLevels[i], normLightPos);
225-
}
226-
else
227-
{
228-
lightspaceMatrix = GetLightSpaceMatrix(camera, shadowCascadeLevels[i - 1], CameraConfig::Far, normLightPos);
229-
}
230-
231-
// Store split distance and matrix in cascade
232-
ubo->lightSpaceMatrices[i] = lightspaceMatrix;
233-
ubo->orthoMatrices[i] = glm::mat4(1.0f);
234-
ubo->viewMatrices[i] = glm::mat4(1.0f);
235-
ubo->splitValues[i] = -1.0f * shadowCascadeLevels[i];
236-
}
237-
238-
ubo->lightPosition = light->position_;
239-
240-
// Copy UBO to the buffer
241-
const uint32_t frameIndex = ctx.GetFrameIndex();
242-
shadowMapUBOBuffers_[frameIndex].UploadBufferData(ctx, ubo, sizeof(ShadowMapUBO));
243-
}
244-
245-
std::vector<glm::vec4> PipelineShadow::GetFrustumCornersWorldSpace(glm::mat4& proj, glm::mat4& view)
246-
{
247-
const auto inv = glm::inverse(proj * view);
248-
249-
std::vector<glm::vec4> frustumCorners;
250-
for (unsigned int x = 0; x < 2; ++x)
251-
{
252-
for (unsigned int y = 0; y < 2; ++y)
253-
{
254-
for (unsigned int z = 0; z < 2; ++z)
255-
{
256-
const glm::vec4 pt = inv * glm::vec4(2.0f * x - 1.0f, 2.0f * y - 1.0f, 2.0f * z - 1.0f, 1.0f);
257-
frustumCorners.push_back(pt / pt.w);
258-
}
259-
}
260-
}
261-
262-
return frustumCorners;
263-
}
264-
265-
glm::mat4 PipelineShadow::GetLightSpaceMatrix(const Camera* camera, float near, float far, glm::vec3 normLightPos)
266-
{
267-
glm::mat4 proj = glm::perspective(glm::radians(camera->zoom_), 1.0f, near, far);
268-
proj[1][1] *= -1;
269-
glm::mat4 view = camera->GetViewMatrix();
270-
271-
const auto corners = GetFrustumCornersWorldSpace(proj, view);
272-
273-
glm::vec3 center = glm::vec3(0, 0, 0);
274-
for (const auto& v : corners)
275-
{
276-
center += glm::vec3(v);
277-
}
278-
center /= static_cast<float>(corners.size());
279-
280-
const auto lightView = glm::lookAt(center + normLightPos, center, glm::vec3(0.0f, 1.0f, 0.0f));
281-
282-
float minX = std::numeric_limits<float>::max();
283-
float maxX = std::numeric_limits<float>::lowest();
284-
float minY = std::numeric_limits<float>::max();
285-
float maxY = std::numeric_limits<float>::lowest();
286-
float minZ = std::numeric_limits<float>::max();
287-
float maxZ = std::numeric_limits<float>::lowest();
288-
for (const auto& v : corners)
289-
{
290-
glm::vec4 trf = lightView * v;
291-
minX = std::min(minX, trf.x);
292-
maxX = std::max(maxX, trf.x);
293-
minY = std::min(minY, trf.y);
294-
maxY = std::max(maxY, trf.y);
295-
minZ = std::min(minZ, trf.z);
296-
maxZ = std::max(maxZ, trf.z);
297-
}
298-
299-
// Tune this parameter according to the scene
300-
if (minZ < 0)
301-
{
302-
minZ *= zMult;
303-
}
304-
else
305-
{
306-
minZ /= zMult;
307-
}
308-
309-
if (maxZ < 0)
310-
{
311-
maxZ /= zMult;
312-
}
313-
else
314-
{
315-
maxZ *= zMult;
316-
}
317-
318-
const glm::mat4 lightProjection = glm::ortho(minX, maxX, minY, maxY, minZ, maxZ);
319-
320-
/*float radius = 0.0f;
321-
for (uint32_t i = 0; i < 8; i++)
322-
{
323-
float distance = glm::length(glm::vec3(corners[i]) - center);
324-
radius = glm::max(radius, distance);
325-
}
326-
radius = std::ceil(radius * 16.0f) / 16.0f;
327-
328-
glm::vec3 eye = center + normLightPos * radius;
329-
glm::vec3 target = center;
330-
glm::mat4 lightView = glm::lookAt(eye, target, glm::vec3(0.0f, 1.0f, 0.0f));
331-
glm::mat4 lightProjection = glm::ortho(
332-
-radius,
333-
radius,
334-
-radius,
335-
radius,
336-
0.0f,
337-
radius * 2.0f);*/
338-
339-
return lightProjection * lightView;
340-
}
341-
342206
void PipelineShadow::FillCommandBuffer(VulkanContext& ctx, VkCommandBuffer commandBuffer)
343207
{
344208
uint32_t frameIndex = ctx.GetFrameIndex();

0 commit comments

Comments
 (0)