Untitled
Toggle main menu visibility
Loading...
Searching...
No Matches
coc.frag
Go to the documentation of this file.
1
2
#version 430 core
3
4
layout
(std140, binding = 0) uniform CameraData {
5
vec4
cam_pos;
6
vec4
cam_vel;
7
mat4
projection
;
8
mat4
unjittered_projection;
9
mat4
view
;
10
mat4
inv_projection;
11
mat4
unjittered_inv_projection;
12
mat4
inv_view;
13
};
14
15
in
vec2
vUV
;
16
17
out
vec4
fragColor
;
18
19
uniform sampler2D
gDepth
;
20
uniform sampler2D
uScene
;
21
22
vec3
get_view_pos_from_depth
(
vec2
uv
,
float
depth,
mat4
invProjMatrix) {
23
vec4
ndc =
vec4
(
uv
* 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
24
25
vec4
viewSpacePos = invProjMatrix * ndc;
26
27
return
viewSpacePos.xyz / viewSpacePos.
w
;
28
}
29
30
float
linearize
(
float
z)
31
{
32
float
near = 0.1;
33
float
far = 100.0;
34
return
(2.0 * near) / (far + near - z * (far - near));
35
}
36
37
uniform
float
uFocalLength
;
38
uniform
float
uFStop
;
39
uniform
float
uSensorHeight
;
40
uniform
float
uMaxBlurRadius
;
41
42
struct
MeshNode
43
{
44
vec4
min
;
45
vec4
max
;
46
vec4
center
;
47
vec4
extents
;
48
uint
instance_count
;
49
uint
static_mesh
;
50
uint
lm_offset
;
51
uint
material
;
52
uint
first
;
53
uint
count
;
54
uint
pad0
;
55
uint
pad1
;
56
};
57
58
#define MAX_MESH_NODES 1024
59
layout
(std430, binding = 15) buffer MeshNodeData {
60
61
float
focal_distance;
62
uint pad0;
63
uint pad1;
64
uint pad2;
65
MeshNode
mns[
MAX_MESH_NODES
];
66
67
};
68
69
void
main
() {
70
float
rawDepth = texture(
gDepth
,
vUV
).r;
71
72
vec3
viewPos =
get_view_pos_from_depth
(
vUV
, rawDepth, unjittered_inv_projection);
73
74
float
pixelDistance = -(viewPos.
z
);
75
76
float
coeff = (
uFocalLength
*
uFocalLength
) / (
uFStop
* (focal_distance -
uFocalLength
));
77
float
cocMeters = coeff * ((pixelDistance - focal_distance) / pixelDistance);
78
79
float
cocUV = cocMeters /
uSensorHeight
;
80
81
float
finalCoC =
clamp
(cocUV, -
uMaxBlurRadius
,
uMaxBlurRadius
);
82
83
fragColor
=
vec4
(textureLod(
uScene
,
vUV
, 0).rgb, finalCoC);
84
85
86
}
layout
layout(local_size_x=16, local_size_y=16) in
main
void main()
Definition
audio_probe_bake.comp:465
uScene
uniform sampler2D uScene
Definition
bloom.frag:3
fragColor
out vec4 fragColor
Definition
bloom.frag:6
gDepth
uniform sampler2D gDepth
Definition
coc.frag:19
uFocalLength
uniform float uFocalLength
Definition
coc.frag:37
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
uSensorHeight
uniform float uSensorHeight
Definition
coc.frag:39
uMaxBlurRadius
uniform float uMaxBlurRadius
Definition
coc.frag:40
uFStop
uniform float uFStop
Definition
coc.frag:38
MAX_MESH_NODES
#define MAX_MESH_NODES
Maximum MeshNodes in a scene (used for SSBO sizing).
Definition
engine_types.h:108
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
vUV
in vec2 vUV
Definition
lightmap.frag:13
clamp
float clamp(float a, float b, float c)
Definition
mathf.h:379
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
mat4
Definition
types.h:21
vec2
Definition
types.h:11
vec3
Definition
types.h:12
vec4
Definition
types.h:13
src
render
coc.frag
Generated by
1.18.0