Untitled
Toggle main menu visibility
Loading...
Searching...
No Matches
focal_distance.comp
Go to the documentation of this file.
1
#version 430 core
2
3
layout
(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
4
5
6
layout
(std140, binding = 0) uniform CameraData {
7
vec4
cam_pos;
8
vec4
cam_vel;
9
mat4
projection
;
10
mat4
unjittered_projection;
11
mat4
view
;
12
mat4
inv_projection;
13
mat4
unjittered_inv_projection;
14
mat4
inv_view;
15
};
16
17
struct
MeshNode
18
{
19
vec4
min
;
20
vec4
max
;
21
vec4
center
;
22
vec4
extents
;
23
uint
instance_count
;
24
uint
static_mesh
;
25
uint
lm_offset
;
26
uint
material
;
27
uint
first
;
28
uint
count
;
29
uint
pad0
;
30
uint
pad1
;
31
};
32
33
#define MAX_MESH_NODES 1024
34
layout
(std430, binding = 15) buffer MeshNodeData {
35
36
float
focal_distance;
37
uint pad0;
38
uint pad1;
39
uint pad2;
40
MeshNode
mns[
MAX_MESH_NODES
];
41
42
};
43
44
uniform sampler2D
gDepth
;
45
uniform
vec2
uTexelSize
;
46
uniform
vec2
uResolution
;
47
uniform
float
uDT
;
48
49
vec3
get_view_pos_from_depth
(
vec2
uv
,
float
depth,
mat4
invProjMatrix) {
50
vec4
ndc =
vec4
(
uv
* 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
51
52
vec4
viewSpacePos = invProjMatrix * ndc;
53
54
return
viewSpacePos.xyz / viewSpacePos.
w
;
55
}
56
57
58
float
linearize
(
float
z)
59
{
60
float
near = 0.1;
61
float
far = 1000.0;
62
return
(2.0 * near) / (far + near - z * (far - near));
63
}
64
65
void
main
()
66
{
67
if
(gl_GlobalInvocationID.x > 0)
return
;
68
69
ivec2
uv
=
ivec2
(
uResolution
/2.0f);
70
vec2
suv =
vec2
(0.5, 0.5);
71
float
old_focal_distance = focal_distance;
72
float
acc = 0.0;
73
for
(
int
y = -4; y <= 4; y++)
74
{
75
for
(
int
x = -4; x <= 4; x++)
76
{
77
78
vec2
tuv =
vec2
(x, y) *
uTexelSize
;
79
ivec2
current_uv =
uv
+
ivec2
(
uTexelSize
*
ivec2
(x, y));
80
float
depth = texelFetch(
gDepth
, current_uv, 0).r;
81
vec3
viewPos =
get_view_pos_from_depth
(suv + tuv, depth, unjittered_inv_projection);
82
83
float
pixelDistance = -(viewPos.
z
);
84
85
acc += pixelDistance;
86
87
}
88
}
89
90
91
float
d = acc / 81;
92
93
float
targetDiopter = 1.0 / max(d, 0.05);
94
float
currentDiopter = 1.0 / max(focal_distance, 0.05);
95
96
float
blend = 1.0 - exp(-5.0 *
uDT
);
97
98
currentDiopter = mix(currentDiopter, targetDiopter, blend);
99
100
focal_distance = 1.0 / currentDiopter;
101
102
103
104
}
layout
layout(local_size_x=16, local_size_y=16) in
main
void main()
Definition
audio_probe_bake.comp:465
uTexelSize
uniform vec2 uTexelSize
Definition
bokeh.frag:18
gDepth
uniform sampler2D gDepth
Definition
coc.frag:19
get_view_pos_from_depth
vec3 get_view_pos_from_depth(vec2 uv, float depth, mat4 invProjMatrix)
Definition
coc.frag:22
linearize
float linearize(float z)
Definition
coc.frag:30
MAX_MESH_NODES
#define MAX_MESH_NODES
Maximum MeshNodes in a scene (used for SSBO sizing).
Definition
engine_types.h:108
uDT
uniform float uDT
Definition
focal_distance.comp:47
uResolution
uniform vec2 uResolution
Definition
focal_distance.comp:46
uv
in vec2 uv
Definition
fullscreen.frag:4
MeshNode::pad1
uint pad1
Definition
coc.frag:55
MeshNode::first
uint first
Definition
coc.frag:52
MeshNode::min
vec4 min
Definition
coc.frag:44
MeshNode::material
uint material
Definition
coc.frag:51
MeshNode::max
vec4 max
Definition
coc.frag:45
MeshNode::lm_offset
uint lm_offset
Definition
coc.frag:50
MeshNode::pad0
uint pad0
Definition
coc.frag:54
MeshNode::center
vec4 center
Definition
coc.frag:46
MeshNode::instance_count
uint instance_count
Definition
coc.frag:48
MeshNode::static_mesh
bool static_mesh
If this mesh is static (DrawArrays) or dynamic (DrawElements), used to indicate Lightmap status.
Definition
engine_types.h:2399
MeshNode::count
size_t count
Count of vertices pushed into the MAIN_VBO.
Definition
engine_types.h:2402
MeshNode::extents
vec4 extents
Definition
coc.frag:47
MeshNode
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
Definition
audio_probe_bake.comp:85
projection
uniform mat4 projection
Definition
shadow.vert:15
view
uniform mat4 view
Definition
shadow.vert:16
vec4::w
float w
Definition
types.h:13
vec3::z
float z
Definition
types.h:12
ivec2
Definition
types.h:14
mat4
Definition
types.h:21
vec2
Definition
types.h:11
vec3
Definition
types.h:12
vec4
Definition
types.h:13
src
render
focal_distance.comp
Generated by
1.18.0