Untitled
Loading...
Searching...
No Matches
depth_pre_pass.vert
Go to the documentation of this file.
1
2#version 460
3layout(location = 0) in vec3 aPosition;
4layout(location = 1) in vec3 aNormal;
5layout(location = 2) in vec4 aTangent;
6layout(location = 3) in ivec4 aJointIndices;
7layout(location = 4) in vec4 aWeights;
8layout(location = 5) in vec2 aUV;
9layout(location = 6) in mat4 aInstanceMatrix;
10layout(location = 10) in ivec2 aPointLight;
11layout(location = 11) in ivec2 aDirectionalLight;
12layout(location = 12) in ivec2 aSpotLight;
13layout(location = 13) in int aSkinOffset;
14
15
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
26layout(std430, binding = 5) buffer DrawArraysData {
27
28 DrawArraysIndirectCommand draw_arrays_commands[];
29};
30layout(std140, binding = 0) uniform CameraData {
31 vec4 cam_pos;
32 vec4 cam_vel;
34 mat4 unjittered_projection;
35 mat4 view;
36 mat4 inv_projection;
37 mat4 unjittered_inv_projection;
38 mat4 inv_view;
39};
40layout(std140, binding = 1) uniform RenderingData {
41 ivec4 resolution;
42};
43layout(std140, binding = 2) uniform LightCameraData {
44 mat4 light_proj[4];
45 mat4 light_view[4];
46};
47
48layout(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};
58struct 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
75layout(std430, binding = 15) buffer MeshNodeData {
76
77 float focal_distance;
78 uint pad0;
79 uint pad1;
80 uint pad2;
82
83};
84struct Transform
85{
86 uint mn_id;
87 uint command_id;
89 uvec2 spot_lights;
90 uint skin_offset;
91 uint pad0;
92 mat4 mat;
93};
94
95layout(std430, binding = 7) buffer TransformData {
96
97 Transform trs[];
98
99};
100layout(std430, binding = 9) buffer PrevTransformData {
101
102 Transform prev_trs[];
103
104};
105layout(std430, binding = 11) buffer JointData {
106
107 mat4 joint_mats[];
108
109};
110
111
113uniform uint uOffset;
114uniform uint uDynamicPass;
116
120flat out uint Mat;
124
125void 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(local_size_x=16, local_size_y=16) in
void main()
in vec3 Normal
in vec4 ClipPos
in vec3 ViewDirTanSpace
in vec2 UV
flat in uint Mat
in vec3 ViewPos
in mat3 TBN
in vec4 PrevClipPos
uniform uint uDynamicPass
uniform uint uOffset
out vec3 vWorldPos
#define MAX_MESH_NODES
Maximum MeshNodes in a scene (used for SSBO sizing).
uint pad1
Definition coc.frag:55
uint first
Definition coc.frag:52
vec4 min
Definition coc.frag:44
uint material
Definition coc.frag:51
vec4 max
Definition coc.frag:45
uint lm_offset
Definition coc.frag:50
uvec2 directional_lights
uint pad0
Definition coc.frag:54
vec4 center
Definition coc.frag:46
uint instance_count
Definition coc.frag:48
bool static_mesh
If this mesh is static (DrawArrays) or dynamic (DrawElements), used to indicate Lightmap status.
size_t count
Count of vertices pushed into the MAIN_VBO.
vec4 extents
Definition coc.frag:47
DrawArraysIndirect commands are used for static meshes (eg.
MeshNodes that describe the position of Meshes, GLTF nodes for GLTFAnimations, or hold references to ...
Transforms for MeshNode models.
uniform mat4 projection
Definition shadow.vert:15
uniform mat4 view
Definition shadow.vert:16
@ B
Definition types.h:26
float z
Definition types.h:12
Definition types.h:14
Definition types.h:16
Definition types.h:20
Definition types.h:21
Definition types.h:11
Definition types.h:12
Definition types.h:13