-
Notifications
You must be signed in to change notification settings - Fork 1
/
notexture.frag
executable file
·79 lines (66 loc) · 2.34 KB
/
notexture.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#version 450
#extension GL_ARB_separate_shader_objects : enable
#define SELECT_BOX_DEPTH_2D 1024
#define SELECT_BOX_DEPTH_3D 1024
#define MAX_LIGHTS 10
struct light { // not used
vec4 position;
vec4 spotDirection;
uint diffuse;
uint specular;
float constantAttenuation, linearAttenuation, quadraticAttenuation;
float spotCutoff, spotExponent, padding;
};
layout(set = 0, binding = 1) uniform uniformBuffer { // not used
light lights[MAX_LIGHTS];
uint num_lights;
uint scene_ambient;
uint padding1;
uint padding2;
} ub;
layout(set = 1, binding = 0) buffer select_buffers {
uint selected_objects_2d[][SELECT_BOX_DEPTH_2D];
} ;
layout(set = 1, binding = 1) buffer select_buffer_3d {
uint selected_objects_3d[][SELECT_BOX_DEPTH_3D];
} ;
layout(push_constant) uniform pushConstant {
layout(offset = 80) vec4 selectBox;
layout(offset = 96) float pxRange; // not used
layout(offset = 100) uint uint_ambient; // not used
layout(offset = 104) uint uint_diffuse; // not used
layout(offset = 108) uint uint_specular; // not used
layout(offset = 112) float shininess; // not used
} pc;
layout(location = 0) flat in uint inObjectId;
layout(location = 1) in vec4 fragColor;
layout(location = 6) flat in uint is2d;
layout(location = 0) out vec4 outColor;
void main () {
outColor = fragColor;
if (pc.selectBox.x <= gl_FragCoord.x &&
pc.selectBox.y <= gl_FragCoord.y &&
gl_FragCoord.x <= pc.selectBox.z &&
gl_FragCoord.y <= pc.selectBox.w) {
if ( is2d == 1) {
uint zIndex = uint(round((1.0 - gl_FragCoord.z) * SELECT_BOX_DEPTH_2D) + 0.5);
uint row_size = uint(pc.selectBox.z) - uint(pc.selectBox.x);
uint offset = uint(gl_FragCoord.y - pc.selectBox.y) * row_size
+ uint(gl_FragCoord.x - pc.selectBox.x);
if (selected_objects_2d[offset][zIndex] == 0) {
selected_objects_2d[offset][zIndex] = inObjectId;
}
} else {
float near = 0.1;
float far = 3000.0;
float z = (2.0 * near) / (far + near - gl_FragCoord.z * (far - near));
uint zIndex = uint(z * SELECT_BOX_DEPTH_3D);
uint row_size = uint(pc.selectBox.z) - uint(pc.selectBox.x);
uint offset = uint(gl_FragCoord.y - pc.selectBox.y) * row_size
+ uint(gl_FragCoord.x - pc.selectBox.x);
if (selected_objects_3d[offset][zIndex] == 0) {
selected_objects_3d[offset][zIndex] = inObjectId;
}
}
}
}