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
Commits
0cef46d9
Commit
0cef46d9
authored
3 years ago
by
Alexander Gauggel
Browse files
Options
Downloads
Patches
Plain Diff
[
#82
] Lets try moment shadow mapping
parent
a3001dec
No related branches found
No related tags found
1 merge request
!70
Resolve "Voxel cone tracing"
Pipeline
#25976
passed
3 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
projects/voxelization/resources/shaders/shadow.frag
+3
-3
3 additions, 3 deletions
projects/voxelization/resources/shaders/shadow.frag
projects/voxelization/resources/shaders/shadowMapping.inc
+38
-33
38 additions, 33 deletions
projects/voxelization/resources/shaders/shadowMapping.inc
with
41 additions
and
36 deletions
projects/voxelization/resources/shaders/shadow.frag
+
3
−
3
View file @
0cef46d9
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable
#extension GL_GOOGLE_include_directive : enable
#include
"
shadowMapping
.inc"
#include
"
lightInfo
.inc"
layout
(
set
=
0
,
binding
=
0
)
uniform
LightInfoBuffer
{
layout
(
set
=
0
,
binding
=
0
)
uniform
LightInfoBuffer
{
LightInfo
lightInfo
;
LightInfo
lightInfo
;
...
@@ -14,6 +14,6 @@ layout(location = 0) in vec4 passPos;
...
@@ -14,6 +14,6 @@ layout(location = 0) in vec4 passPos;
void
main
()
{
void
main
()
{
float
z
=
passPos
.
z
/
passPos
.
w
;
float
z
=
passPos
.
z
/
passPos
.
w
;
vec2
zWarped
=
applyDepthWarp
(
z
,
lightInfo
.
warps
);
float
z2
=
z
*
z
;
outMoments
=
vec4
(
z
Warped
,
zWarped
*
zWarped
);
outMoments
=
vec4
(
z
,
z2
,
z2
*
z
,
z2
*
z2
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
projects/voxelization/resources/shaders/shadowMapping.inc
+
38
−
33
View file @
0cef46d9
...
@@ -3,30 +3,39 @@
...
@@ -3,30 +3,39 @@
#include "lightInfo.inc"
#include "lightInfo.inc"
vec2
applyDepthWarp
(
float
z
,
vec2
warp
){
// nice math blob from the moment shadow mapping presentation
z
=
2
*
z
-
1
;
float
ComputeMSMShadowIntensity
(
vec4
_4Moments
,
float
FragmentDepth
,
float
DepthBias
,
float
MomentBias
)
float
positive
=
exp
(
z
*
warp
.
x
);
float
negative
=
-
exp
(
-
z
*
warp
.
y
);
return
vec2
(
positive
,
negative
);
}
float
rescale
(
float
a
,
float
b
,
float
v
)
{
{
return
clamp
((
v
-
a
)
/
(
b
-
a
),
0
,
1
);
vec4
b
=
mix
(
_4Moments
,
vec4
(
0.5
f
,
0.5
f
,
0.5
f
,
0.5
f
),
MomentBias
);
}
vec3
z
;
z
[
0
]
=
FragmentDepth
-
DepthBias
;
float
reduceVSMBleeding
(
float
shadowValue
,
float
newMin
)
float
L32D22
=-
b
[
0
]
*
b
[
1
]
+
b
[
2
];
{
float
D22
=
-
b
[
0
]
*
b
[
0
]
+
b
[
1
];
return
rescale
(
newMin
,
1.0
f
,
shadowValue
);
float
SquaredDepthVariance
=-
b
[
1
]
*
b
[
1
]
+
b
[
3
];
}
float
D33D22
=
dot
(
vec2
(
SquaredDepthVariance
,
-
L32D22
),
vec2
(
D22
,
L32D22
));
float
chebyshevInequality
(
float
mean
,
float
meanSquare
,
float
sampleIn
){
float
variance
=
meanSquare
-
mean
*
mean
;
float
InvD22
=
1.0
f
/
D22
;
float
d
=
sampleIn
-
mean
;
float
L32
=
L32D22
*
InvD22
;
float
pMax
=
clamp
(
variance
/
(
variance
+
d
*
d
),
0
,
1
);
vec3
c
=
vec3
(
1.0
f
,
z
[
0
],
z
[
0
]
*
z
[
0
]);
pMax
=
reduceVSMBleeding
(
pMax
,
0.1
);
c
[
1
]
-=
b
.
x
;
c
[
2
]
-=
b
.
y
+
L32
*
c
[
1
];
return
pMax
;
c
[
1
]
*=
InvD22
;
c
[
2
]
*=
D22
/
D33D22
;
c
[
1
]
-=
L32
*
c
[
2
];
c
[
0
]
-=
dot
(
c
.
yz
,
b
.
xy
);
float
p
=
c
[
1
]
/
c
[
2
];
float
q
=
c
[
0
]
/
c
[
2
];
float
r
=
sqrt
((
p
*
p
*
0.25
f
)
-
q
);
z
[
1
]
=-
p
*
0.5
f
-
r
;
z
[
2
]
=-
p
*
0.5
f
+
r
;
vec4
Switch
=
(
z
[
2
]
<
z
[
0
])
?
vec4
(
z
[
1
],
z
[
0
],
1.0
f
,
1.0
f
)
:
(
(
z
[
1
]
<
z
[
0
])
?
vec4
(
z
[
0
],
z
[
1
],
0.0
f
,
1.0
f
)
:
vec4
(
0.0
f
,
0.0
f
,
0.0
f
,
0.0
f
));
float
Quotient
=
(
Switch
[
0
]
*
z
[
2
]
-
b
[
0
]
*
(
Switch
[
0
]
+
z
[
2
])
+
b
[
1
])
/
((
z
[
2
]
-
Switch
[
1
])
*
(
z
[
0
]
-
z
[
1
]));
return
clamp
(
Switch
[
2
]
+
Switch
[
3
]
*
Quotient
,
0
,
1
);
}
}
float
shadowTest
(
vec3
worldPos
,
LightInfo
lightInfo
,
texture2D
shadowMap
,
sampler
shadowMapSampler
){
float
shadowTest
(
vec3
worldPos
,
LightInfo
lightInfo
,
texture2D
shadowMap
,
sampler
shadowMapSampler
){
...
@@ -39,17 +48,13 @@ float shadowTest(vec3 worldPos, LightInfo lightInfo, texture2D shadowMap, sample
...
@@ -39,17 +48,13 @@ float shadowTest(vec3 worldPos, LightInfo lightInfo, texture2D shadowMap, sample
}
}
lightPos
.
z
=
clamp
(
lightPos
.
z
,
0
,
1
);
lightPos
.
z
=
clamp
(
lightPos
.
z
,
0
,
1
);
vec2
warpedSample
=
applyDepthWarp
(
lightPos
.
z
,
lightInfo
.
warps
);
// using exponential variance shadow mapping
vec4
shadowMapSample
=
texture
(
sampler2D
(
shadowMap
,
shadowMapSampler
),
lightPos
.
xy
);
vec2
positiveMoments
=
shadowMapSample
.
rb
;
vec2
negativeMoments
=
shadowMapSample
.
ga
;
float
s1
=
chebyshevInequality
(
positiveMoments
.
r
,
positiveMoments
.
g
,
warpedSample
.
x
);
float
s2
=
chebyshevInequality
(
negativeMoments
.
r
,
negativeMoments
.
g
,
warpedSample
.
y
);
return
min
(
s1
,
s2
);
vec4
shadowMapSample
=
texture
(
sampler2D
(
shadowMap
,
shadowMapSampler
),
lightPos
.
xy
);
float
depthBias
=
0.
f
;
float
momentBias
=
0.000002
;
return
1
-
ComputeMSMShadowIntensity
(
shadowMapSample
,
lightPos
.
z
,
depthBias
,
momentBias
);
}
}
#endif // #ifndef SHADOW_MAPPING_INC
#endif // #ifndef SHADOW_MAPPING_INC
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment