Untitled
Toggle main menu visibility
Loading...
Searching...
No Matches
depth_pre_pass.vert
Go to the documentation of this file.
1
2
#version 460
3
layout
(location = 0) in
vec3
aPosition;
4
layout
(location = 1) in
vec3
aNormal;
5
layout
(location = 2) in
vec4
aTangent;
6
layout
(location = 3) in
ivec4
aJointIndices;
7
layout
(location = 4) in
vec4
aWeights;
8
layout
(location = 5) in
vec2
aUV;
9
layout
(location = 6) in
mat4
aInstanceMatrix;
10
layout
(location = 10) in
ivec2
aPointLight;
11
layout
(location = 11) in
ivec2
aDirectionalLight;
12
layout
(location = 12) in
ivec2
aSpotLight;
13
layout
(location = 13) in
int
aSkinOffset;
14
15
16
struct
DrawArraysIndirectCommand
{
17
uint count;
18
uint instanceCount;
19
uint first;
20
uint baseInstance;
21
uint instanceOffset;
// the amount of instances pushed this frame
22
uint pad0;
23
};
24
25
26
layout
(std430, binding = 5) buffer DrawArraysData {
27
28
DrawArraysIndirectCommand
draw_arrays_commands[];
29
};
30
layout
(std140, binding = 0) uniform CameraData {
31
vec4
cam_pos;
32
vec4
cam_vel;
33
mat4
projection
;
34
mat4
unjittered_projection;
35
mat4
view
;
36
mat4
inv_projection;
37
mat4
unjittered_inv_projection;
38
mat4
inv_view;
39
};
40
layout
(std140, binding = 1) uniform RenderingData {
41
ivec4
resolution;
42
};
43
layout
(std140, binding = 2) uniform LightCameraData {
44
mat4
light_proj[4];
45
mat4
light_view[4];
46
};
47
48
layout
(std140, binding = 4) uniform PrevCameraData {
49
vec4
prev_cam_pos;
50
vec4
prev_cam_vel;
51
mat4
prev_projection;
52
mat4
prev_unjittered_projection;
53
mat4
prev_view;
54
mat4
prev_inv_projection;
55
mat4
prev_unjittered_inv_projection;
56
mat4
prev_inv_view;
57
};
58
struct
MeshNode
59
{
60
vec4
min
;
61
vec4
max
;
62
vec4
center
;
63
vec4
extents
;
64
uint
instance_count
;
65
uint
static_mesh
;
66
uint
lm_offset
;
67
uint
material
;
68
uint
first
;
69
uint
count
;
70
uint
pad0
;
71
uint
pad1
;
72
};
73
74
#define MAX_MESH_NODES 1024
75
layout
(std430, binding = 15) buffer MeshNodeData {
76
77
float
focal_distance;
78
uint pad0;
79
uint pad1;
80
uint pad2;
81
MeshNode
mns[
MAX_MESH_NODES
];
82
83
};
84
struct
Transform
85
{
86
uint
mn_id
;
87
uint
command_id
;
88
uvec2
directional_lights
;
89
uvec2
spot_lights
;
90
uint
skin_offset
;
91
uint
pad0
;
92
mat4
mat
;
93
};
94
95
layout
(std430, binding = 7) buffer TransformData {
96
97
Transform
trs[];
98
99
};
100
layout
(std430, binding = 9) buffer PrevTransformData {
101
102
Transform
prev_trs[];
103
104
};
105
layout
(std430, binding = 11) buffer JointData {
106
107
mat4
joint_mats[];
108
109
};
110
111
112
out
vec3
vWorldPos
;
113
uniform uint
uOffset
;
114
uniform uint
uDynamicPass
;
115
out
vec3
ViewPos
;
116
117
out
vec3
Normal
;
118
out
vec3
ViewDirTanSpace
;
119
out
mat3
TBN
;
120
flat out uint
Mat
;
121
out
vec2
UV
;
122
out
vec4
ClipPos
;
123
out
vec4
PrevClipPos
;
124
125
void
main
()
126
{
127
128
vec3
pos = aPosition;
129
UV
= aUV;
130
131
uint off = 0;
132
if
(
uDynamicPass
== 1)
133
{
134
135
DrawArraysIndirectCommand
com = draw_arrays_commands[
uOffset
-1];
136
off = com.
instanceCount
+ com.
baseInstance
;
137
}
138
Transform
tr = trs[off + gl_BaseInstance + gl_InstanceID];
139
Transform
prev_tr = prev_trs[off + gl_BaseInstance + gl_InstanceID];
140
MeshNode
mn = mns[tr.
mn_id
];
141
Mat
= mn.
material
;
142
143
mat4
skinMat =
144
joint_mats[aJointIndices.x] * aWeights.x +
145
joint_mats[aJointIndices.y] * aWeights.y +
146
joint_mats[aJointIndices.z] * aWeights.z +
147
joint_mats[aJointIndices.w] * aWeights.w;
148
149
// mat4 skinMat = mat4(1.0);
150
151
mat4
model = tr.
mat
;
152
vec4
skinned_pos = skinMat *
vec4
(pos, 1.0);
153
154
155
mat4
view_model =
view
* model;
156
mat3
normalMatrix = transpose(inverse(
mat3
(view_model) *
mat3
(skinMat)));
157
Normal
= normalize(normalMatrix * aNormal);
158
159
vec3
tangent;
160
int
tangent_sign;
161
vec3
up;
162
if
(aTangent.w == 2)
163
{
164
165
if
(abs(
Normal
.
z
) > 0.9f)
166
{
167
up =
vec3
(0,0,1);
168
}
169
else
170
{
171
up =
vec3
(1,0,0);
172
}
173
tangent = normalize(cross(up,
Normal
));
174
tangent_sign = 1;
175
}
176
else
177
{
178
179
tangent = normalize(
mat3
(model) * aTangent.xyz);
180
tangent_sign = int(aTangent.w);
181
}
182
183
vec3
T = (tangent - dot(tangent, aNormal) * aNormal);
184
vec3
B
= cross(aNormal, tangent) * tangent_sign;
185
T = normalize(
vec3
(view_model *
vec4
(T, 0.0)));
186
B
= normalize(
vec3
(view_model *
vec4
(
B
, 0.0)));
187
vec3
N = normalize(
vec3
(view_model *
vec4
(aNormal, 0.0)));
188
189
TBN
=
mat3
(T,
B
, N);
190
191
vec3
reg_Normal = normalize(
mat3
(inv_view) *
Normal
);
192
vec3
reg_T = normalize((tangent - dot(tangent, reg_Normal) * reg_Normal));
193
vec3
reg_B = normalize(cross(reg_Normal, tangent) * tangent_sign);
194
195
mat3
regular_TBN =
mat3
(reg_T, reg_B, reg_Normal);
196
197
vec4
wp = model *
vec4
(pos, 1.0);
198
199
ViewPos
= (
view
* model *
vec4
(pos, 1.0)).xyz;
200
ViewDirTanSpace
= transpose(regular_TBN) * (cam_pos.xyz - wp.xyz);
201
202
203
PrevClipPos
= prev_unjittered_projection * prev_view * prev_tr.
mat
* skinned_pos;
204
ClipPos
= unjittered_projection *
view
* model * skinned_pos;
205
206
207
gl_Position =
projection
*
view
* model * skinned_pos;
208
}
layout
layout(local_size_x=16, local_size_y=16) in
main
void main()
Definition
audio_probe_bake.comp:465
Normal
in vec3 Normal
Definition
depth_pre_pass.frag:67
ClipPos
in vec4 ClipPos
Definition
depth_pre_pass.frag:73
ViewDirTanSpace
in vec3 ViewDirTanSpace
Definition
depth_pre_pass.frag:75
UV
in vec2 UV
Definition
depth_pre_pass.frag:70
Mat
flat in uint Mat
Definition
depth_pre_pass.frag:69
ViewPos
in vec3 ViewPos
Definition
depth_pre_pass.frag:72
TBN
in mat3 TBN
Definition
depth_pre_pass.frag:68
PrevClipPos
in vec4 PrevClipPos
Definition
depth_pre_pass.frag:74
uDynamicPass
uniform uint uDynamicPass
Definition
depth_pre_pass.vert:114
uOffset
uniform uint uOffset
Definition
depth_pre_pass.vert:113
vWorldPos
out vec3 vWorldPos
Definition
depth_pre_pass.vert:112
MAX_MESH_NODES
#define MAX_MESH_NODES
Maximum MeshNodes in a scene (used for SSBO sizing).
Definition
engine_types.h:108
Transform::mat
mat4 mat
Definition
cull_draw_calls.comp:79
MeshNode::pad1
uint pad1
Definition
coc.frag:55
MeshNode::first
uint first
Definition
coc.frag:52
MeshNode::min
vec4 min
Definition
coc.frag:44
Transform::skin_offset
uint skin_offset
Definition
cull_draw_calls.comp:77
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
Transform::directional_lights
uvec2 directional_lights
Definition
cull_draw_calls.comp:75
Transform::mn_id
uint mn_id
Definition
cull_draw_calls.comp:73
Transform::command_id
uint command_id
Definition
cull_draw_calls.comp:74
DrawArraysIndirectCommand::instanceCount
uint32_t instanceCount
Definition
engine_types.h:845
DrawArraysIndirectCommand::baseInstance
uint32_t baseInstance
Definition
engine_types.h:847
Transform::pad0
uint pad0
Definition
cull_point_light_shadows.comp:70
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
Transform::spot_lights
uvec2 spot_lights
Definition
cull_draw_calls.comp:76
DrawArraysIndirectCommand
DrawArraysIndirect commands are used for static meshes (eg.
Definition
engine_types.h:842
MeshNode
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
Definition
audio_probe_bake.comp:85
Transform
Transforms for MeshNode models.
Definition
cull_draw_calls.comp:72
projection
uniform mat4 projection
Definition
shadow.vert:15
view
uniform mat4 view
Definition
shadow.vert:16
B
@ B
Definition
types.h:26
vec3::z
float z
Definition
types.h:12
ivec2
Definition
types.h:14
ivec4
Definition
types.h:16
mat3
Definition
types.h:20
mat4
Definition
types.h:21
vec2
Definition
types.h:11
vec3
Definition
types.h:12
vec4
Definition
types.h:13
src
render
depth_pre_pass.vert
Generated by
1.18.0