Untitled
Loading...
Searching...
No Matches
depth_pre_pass_no_gbuffer.frag
Go to the documentation of this file.
1
2#extension GL_ARB_bindless_texture : require
3layout(location = 0)out vec2 gVel;
4
5layout(std140, binding = 0) uniform CameraData {
6 vec4 cam_pos;
7 vec4 cam_vel;
9 mat4 unjittered_projection;
10 mat4 view;
11 mat4 inv_projection;
12 mat4 unjittered_inv_projection;
13 mat4 inv_view;
14};
15struct Material
16{
17
18 vec4 ambient;
19 vec4 diffuse;
20 vec4 specular;
21 vec4 emissive;
23 uint pad0;
24 uint pad1;
26 uint pad2;
27 uint pad3;
28
29 sampler2D albedo_tex;
30 sampler2D normal_tex;
31 sampler2D arm_tex;
32 sampler2D emissive_tex;
33
34 float metallic;
35 float roughness;
36 float ao_strength;
37 float normal_scale;
38 uint alpha_mode;
39 float alpha_cutoff;
40 uint double_sided;
42
43};
44
45
46layout(std430, binding = 2) buffer MaterialData {
47
48 Material materials[];
49
50};
51
52
53
56flat in uint Mat;
58
63const float height_scale = 0.02f;
64uniform sampler2D uAlbedo;
65uniform sampler2D uARM;
66uniform sampler2D uNormal;
67
68vec2 ParallaxMapping(sampler2D normal_map, vec2 texCoords, vec3 viewDir, out float final_depth)
69{
70
71 vec2 dx = dFdx(texCoords);
72 vec2 dy = dFdy(texCoords);
73 const float minLayers = 2.0;
74 const float maxLayers = 16.0;
75
76 float tx_width = float(textureSize(normal_map, 0).x);
77
78 vec2 dx2 = max(dx * dx * tx_width * tx_width, dy * dy * tx_width * tx_width);
79 float mip_level = 0.5 * log2(max(dx2.x, dx2.y));
80
81 float fade = clamp(1.0 - (mip_level / 3.0), 0.0, 1.0);
82
83
84 float current_max_layers = mix(minLayers, maxLayers, fade);
85
86
87 float numLayers = mix(current_max_layers, minLayers, abs(dot(vec3(0.0, 0.0, 1.0), viewDir)));
88
89 float layerDepth = 1.0 / numLayers;
90 float currentLayerDepth = 0.0;
91
92
93
94 float uv_scale = length(fwidth(texCoords));
95 vec2 P = viewDir.xy *height_scale;
96 vec2 deltaTexCoords = vec2(P.x, -P.y) / numLayers;
97
98 vec2 currentTexCoords = texCoords;
99 float freq = 10;
100 float currentDepthMapValue = textureGrad(normal_map, currentTexCoords, dx, dy).a;
101
102 int safety = 20;
103 int cur = 0;
104 while(currentLayerDepth < currentDepthMapValue && safety > cur)
105 {
106 currentTexCoords -= deltaTexCoords;
107
108
109 currentDepthMapValue = textureGrad(normal_map, currentTexCoords, dx, dy).a;
110 currentLayerDepth += layerDepth;
111 cur++;
112 }
113
114 vec2 prevTexCoords = currentTexCoords + deltaTexCoords;
115 float afterDepth = currentLayerDepth - currentDepthMapValue;
116 float current_depth = textureGrad(normal_map, currentTexCoords, dx, dy).a;
117 float prev_depth = textureGrad(normal_map, prevTexCoords, dx, dy).a;
118 float beforeDepth = (prev_depth) - currentLayerDepth + layerDepth;
119
120 float weight = afterDepth / (afterDepth + beforeDepth);
121 vec2 finalTexCoords = mix(currentTexCoords, prevTexCoords, weight);
122 final_depth = mix(current_depth, prev_depth, weight);
123
124 return finalTexCoords;
125}
126void main()
127{
128
129 Material mat = materials[Mat];
130 vec3 viewDir = normalize(ViewDirTanSpace);
131 vec3 viewDirViewSpace = normalize(ViewPos.xyz);
132 float final_depth = 0.0;
133 vec2 uv = UV;
134 vec4 albedo = texture(mat.albedo_tex, uv) * mat.diffuse;
135 if (albedo.a < 1.0f) discard;
136
137 vec2 current_ndc = ClipPos.xy / ClipPos.w;
138 vec2 previous_ndc = PrevClipPos.xy / PrevClipPos.w;
139
140 vec2 current_uv = current_ndc * 0.5 + 0.5;
141 vec2 previous_uv = previous_ndc * 0.5 + 0.5;
142
143 gVel = (current_uv - previous_uv);
144}
layout(local_size_x=16, local_size_y=16) in
void main()
in vec3 Normal
in vec4 ClipPos
in vec3 ViewDirTanSpace
in vec2 UV
uniform sampler2D uAlbedo
flat in uint Mat
in vec3 ViewPos
uniform sampler2D uARM
const float height_scale
uniform sampler2D uNormal
vec2 ParallaxMapping(sampler2D normal_map, vec2 texCoords, vec3 viewDir, out float final_depth)
in mat3 TBN
in vec4 PrevClipPos
The GPU side SSBO structure.
in vec2 uv
sampler2D albedo_tex
float normal_scale
Unused - Used to determine how much of the texture normal to use.
sampler2D emissive_tex
float emissive_strength
sampler2D arm_tex
sampler2D normal_tex
float alpha_cutoff
Used to discard transparent Materials.
float absorption_coefficients[6]
How much audio is absorbed when hitting this Material.
float scattering_coefficients[6]
How much audio specularly reflects when hitting this Material.
The Materials parsed in from scene files that determine rendering pipeline setup, uploads,...
float clamp(float a, float b, float c)
Definition mathf.h:379
uniform sampler2D gVel
uniform mat4 projection
Definition shadow.vert:15
uniform mat4 view
Definition shadow.vert:16
float x
Definition types.h:11
float w
Definition types.h:13
float y
Definition types.h:11
Definition types.h:20
Definition types.h:21
Definition types.h:11
Definition types.h:12
Definition types.h:13