Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Merge requests
!70
Resolve "Voxel cone tracing"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Voxel cone tracing"
82-voxel-cone-tracing
into
develop
Overview
7
Commits
95
Pipelines
67
Changes
1
Merged
Ghost User
requested to merge
82-voxel-cone-tracing
into
develop
3 years ago
Overview
7
Commits
95
Pipelines
67
Changes
1
Expand
Closes
#82 (closed)
Edited
3 years ago
by
Tobias Frisch
0
0
Merge request reports
Viewing commit
eb723db1
Prev
Next
Show latest version
1 file
+
16
−
9
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
eb723db1
[
#82
] Stabilize shadows
· eb723db1
Alexander Gauggel
authored
3 years ago
projects/voxelization/src/ShadowMapping.cpp
+
16
−
9
Options
#include
"ShadowMapping.hpp"
#include
<vkcv/shader/GLSLCompiler.hpp>
const
vk
::
Format
shadowMapFormat
=
vk
::
Format
::
eR32G32B32A32Sfloat
;
const
vk
::
Format
shadowMapDepthFormat
=
vk
::
Format
::
eD32Sfloat
;
const
uint32_t
shadowMapResolution
=
2048
;
const
vkcv
::
Multisampling
msaa
=
vkcv
::
Multisampling
::
MSAA8X
;
vkcv
::
ShaderProgram
loadShadowShader
()
{
vkcv
::
ShaderProgram
shader
;
vkcv
::
shader
::
GLSLCompiler
compiler
;
@@ -114,13 +119,20 @@ glm::mat4 computeShadowViewProjectionMatrix(
getMinMaxView
(
viewFrustumCorners
);
getMinMaxView
(
voxelVolumeCorners
);
glm
::
vec3
scale
=
glm
::
vec3
(
2
)
/
(
maxView
-
minView
);
// rotationaly invariant to avoid swimming when moving camera
scale
=
glm
::
vec3
(
glm
::
max
(
glm
::
max
(
scale
.
x
,
scale
.
y
),
scale
.
z
));
// rotationaly invariant to avoid shadow swimming when moving camera
// could potentially be wasteful, but guarantees stability, regardless of camera and voxel volume
glm
::
vec3
scale
=
glm
::
vec3
(
1.
f
/
glm
::
max
(
far
,
voxelVolumeExtent
));
glm
::
vec3
offset
=
-
0.5
f
*
(
maxView
+
minView
)
*
scale
;
// snap to texel to avoid shadow swimming when moving
glm
::
vec2
offset2D
=
glm
::
vec2
(
offset
);
glm
::
vec2
frustumExtent2D
=
glm
::
vec2
(
1
)
/
glm
::
vec2
(
scale
);
glm
::
vec2
texelSize
=
glm
::
vec2
(
frustumExtent2D
/
static_cast
<
float
>
(
shadowMapResolution
));
offset2D
=
glm
::
ceil
(
offset2D
/
texelSize
)
*
texelSize
;
offset
.
x
=
offset2D
.
x
;
offset
.
y
=
offset2D
.
y
;
glm
::
mat4
crop
(
1
);
crop
[
0
][
0
]
=
scale
.
x
;
crop
[
1
][
1
]
=
scale
.
y
;
@@ -137,11 +149,6 @@ glm::mat4 computeShadowViewProjectionMatrix(
return
vulkanCorrectionMatrix
*
crop
*
view
;
}
const
vk
::
Format
shadowMapFormat
=
vk
::
Format
::
eR32G32B32A32Sfloat
;
const
vk
::
Format
shadowMapDepthFormat
=
vk
::
Format
::
eD32Sfloat
;
const
uint32_t
shadowMapResolution
=
2048
;
const
vkcv
::
Multisampling
msaa
=
vkcv
::
Multisampling
::
MSAA8X
;
ShadowMapping
::
ShadowMapping
(
vkcv
::
Core
*
corePtr
,
const
vkcv
::
VertexLayout
&
vertexLayout
)
:
m_corePtr
(
corePtr
),
m_shadowMap
(
corePtr
->
createImage
(
shadowMapFormat
,
shadowMapResolution
,
shadowMapResolution
,
1
,
true
,
true
)),
Loading