Untitled
Loading...
Searching...
No Matches
depth_pre_pass_no_gbuffer.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};
30#define MAX_INSTANCES 1024
31layout(std430, binding = 4) buffer VisibleData {
32
33 uint visible_indices[];
34
35};
36layout(std140, binding = 0) uniform CameraData {
37 vec4 cam_pos;
38 vec4 cam_vel;
40 mat4 unjittered_projection;
41 mat4 view;
42 mat4 inv_projection;
43 mat4 unjittered_inv_projection;
44 mat4 inv_view;
45};
46layout(std140, binding = 1) uniform RenderingData {
47 ivec4 resolution;
48};
49layout(std140, binding = 2) uniform LightCameraData {
50 mat4 light_proj[4];
51 mat4 light_view[4];
52};
53
54layout(std140, binding = 4) uniform PrevCameraData {
55 vec4 prev_cam_pos;
56 vec4 prev_cam_vel;
57 mat4 prev_projection;
58 mat4 prev_unjittered_projection;
59 mat4 prev_view;
60 mat4 prev_inv_projection;
61 mat4 prev_unjittered_inv_projection;
62 mat4 prev_inv_view;
63};
64struct MeshNode
65{
66 vec4 min;
67 vec4 max;
68 vec4 center;
69 vec4 extents;
70 uint instance_count;
71 uint static_mesh;
72 uint lm_offset;
73 uint material;
74 uint first;
75 uint count;
76 uint pad0;
77 uint pad1;
78};
79
80#define MAX_MESH_NODES 1024
81layout(std430, binding = 15) buffer MeshNodeData {
82
83 float focal_distance;
84 uint pad0;
85 uint pad1;
86 uint pad2;
88
89};
90struct Transform
91{
92 uint mn_id;
93 uint command_id;
95 uvec2 spot_lights;
96 uint skin_offset;
97 uint material;
98 mat4 mat;
99};
100
101layout(std430, binding = 7) buffer TransformData {
102
103 Transform trs[];
104
105};
106layout(std430, binding = 9) buffer PrevTransformData {
107
108 Transform prev_trs[];
109
110};
111layout(std430, binding = 11) buffer JointData {
112
113 mat4 joint_mats[];
114
115};
116
118uniform uint uOffset;
119uniform uint uDynamicPass;
121
125flat out uint Mat;
129uniform uint uStartArr;
130uniform uint uStartEle;
131
132void main()
133{
134
135 vec3 pos = aPosition;
136 UV = aUV;
137
138 uint off = 0;
139 uint index_offset = uStartArr + gl_DrawID;
140 if (uDynamicPass == 1)
141 {
142
143 index_offset = uStartEle + gl_DrawID;
145
146 }
147 uint visible_offset = index_offset * MAX_INSTANCES;
148 Transform tr = trs[visible_indices[visible_offset + gl_InstanceID]];
149 Transform prev_tr = prev_trs[visible_indices[visible_offset + gl_InstanceID]];
150 MeshNode mn = mns[tr.mn_id];
151 Mat = tr.material;
152
153 mat4 skinMat =
154 joint_mats[aJointIndices.x] * aWeights.x +
155 joint_mats[aJointIndices.y] * aWeights.y +
156 joint_mats[aJointIndices.z] * aWeights.z +
157 joint_mats[aJointIndices.w] * aWeights.w;
158
159 // mat4 skinMat = mat4(1.0);
160
161 mat4 model = tr.mat;
162 vec4 skinned_pos = skinMat * vec4(pos, 1.0);
163
164
165 mat4 view_model = view * model;
166 mat3 normalMatrix = transpose(inverse(mat3(view_model) * mat3(skinMat)));
167 Normal = normalize(normalMatrix * aNormal);
168
169 vec3 tangent;
170 int tangent_sign;
171 vec3 up;
172 if (aTangent.w == 2)
173 {
174
175 if (abs(Normal.z) > 0.9f)
176 {
177 up = vec3(0,0,1);
178 }
179 else
180 {
181 up = vec3(1,0,0);
182 }
183 tangent = normalize(cross(up, Normal));
184 tangent_sign = 1;
185 }
186 else
187 {
188
189 tangent = normalize(mat3(model) * aTangent.xyz);
190 tangent_sign = int(aTangent.w);
191 }
192
193 vec3 T = (tangent - dot(tangent, aNormal) * aNormal);
194 vec3 B = cross(aNormal, tangent) * tangent_sign;
195 T = normalize(vec3(view_model * vec4(T, 0.0)));
196 B = normalize(vec3(view_model * vec4(B, 0.0)));
197 vec3 N = normalize(vec3(view_model * vec4(aNormal, 0.0)));
198
199
200 TBN = mat3(T, B, N);
201
202 vec3 reg_Normal = normalize(mat3(inv_view) * Normal);
203 vec3 reg_T = normalize((tangent - dot(tangent, reg_Normal) * reg_Normal));
204 vec3 reg_B = normalize(cross(reg_Normal, tangent) * tangent_sign);
205
206
207
208 mat3 regular_TBN = mat3(reg_T, reg_B, reg_Normal);
209
210 vec4 wp = model * vec4(pos, 1.0);
211
212 ViewPos = (view * model * skinned_pos).xyz;
213 ViewDirTanSpace = transpose(regular_TBN) * (cam_pos.xyz - wp.xyz);
214
215
216
217
218 PrevClipPos = prev_unjittered_projection * prev_view * prev_tr.mat * skinned_pos;
219 ClipPos = unjittered_projection * view * model * skinned_pos;
220
221
222 gl_Position = projection * view * model * skinned_pos;
223}
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
uniform uint uStartArr
uniform uint uStartEle
uniform int index_offset
Definition dynamic.frag:234
#define MAX_INSTANCES
Maximum amount of TransformGPU instances to push in one frame (used for SSBO sizing).
#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