13
13
#endif // has_VK_KHR_multiview
14
14
#endif // MULTIVIEW
15
15
16
+ #define FLAG_FLIP_Y (1 << 0 )
17
+ #define FLAG_USE_SECTION (1 << 1 )
18
+ #define FLAG_FORCE_LUMINANCE (1 << 2 )
19
+ #define FLAG_ALPHA_TO_ZERO (1 << 3 )
20
+ #define FLAG_SRGB (1 << 4 )
21
+ #define FLAG_ALPHA_TO_ONE (1 << 5 )
22
+ #define FLAG_LINEAR (1 << 6 )
23
+
16
24
#ifdef MULTIVIEW
17
25
layout (location = 0 ) out vec3 uv_interp;
18
26
#else
@@ -22,13 +30,8 @@ layout(location = 0) out vec2 uv_interp;
22
30
layout (push_constant, std430) uniform Params {
23
31
vec4 section;
24
32
vec2 pixel_size;
25
- bool flip_y;
26
- bool use_section;
27
-
28
- bool force_luminance;
29
- bool alpha_to_zero;
30
- bool srgb;
31
- bool alpha_to_one;
33
+ float luminance_multiplier;
34
+ uint flags;
32
35
33
36
vec4 color;
34
37
}
@@ -41,13 +44,13 @@ void main() {
41
44
uv_interp.z = ViewIndex;
42
45
#endif
43
46
vec2 vpos = uv_interp.xy;
44
- if (params.use_section ) {
47
+ if (bool ( params.flags & FLAG_USE_SECTION) ) {
45
48
vpos = params.section.xy + vpos * params.section.zw;
46
49
}
47
50
48
51
gl_Position = vec4 (vpos * 2.0 - 1.0 , 0.0 , 1.0 );
49
52
50
- if (params.flip_y ) {
53
+ if (bool ( params.flags & FLAG_FLIP_Y) ) {
51
54
uv_interp.y = 1.0 - uv_interp.y;
52
55
}
53
56
}
@@ -67,16 +70,19 @@ void main() {
67
70
#endif // has_VK_KHR_multiview
68
71
#endif // MULTIVIEW
69
72
73
+ #define FLAG_FLIP_Y (1 << 0 )
74
+ #define FLAG_USE_SECTION (1 << 1 )
75
+ #define FLAG_FORCE_LUMINANCE (1 << 2 )
76
+ #define FLAG_ALPHA_TO_ZERO (1 << 3 )
77
+ #define FLAG_SRGB (1 << 4 )
78
+ #define FLAG_ALPHA_TO_ONE (1 << 5 )
79
+ #define FLAG_LINEAR (1 << 6 )
80
+
70
81
layout (push_constant, std430) uniform Params {
71
82
vec4 section;
72
83
vec2 pixel_size;
73
- bool flip_y;
74
- bool use_section;
75
-
76
- bool force_luminance;
77
- bool alpha_to_zero;
78
- bool srgb;
79
- bool alpha_to_one;
84
+ float luminance_multiplier;
85
+ uint flags;
80
86
81
87
vec4 color;
82
88
}
@@ -110,6 +116,10 @@ vec3 linear_to_srgb(vec3 color) {
110
116
return mix ((vec3 (1 .0f) + a) * pow (color.rgb, vec3 (1 .0f / 2 .4f)) - a, 12 .92f * color.rgb, lessThan (color.rgb, vec3 (0 .0031308f)));
111
117
}
112
118
119
+ vec3 srgb_to_linear(vec3 color) {
120
+ return mix (pow ((color.rgb + vec3 (0.055 )) * (1.0 / (1.0 + 0.055 )), vec3 (2.4 )), color.rgb * (1.0 / 12.92 ), lessThan (color.rgb, vec3 (0.04045 )));
121
+ }
122
+
113
123
void main() {
114
124
#ifdef MODE_SET_COLOR
115
125
frag_color = params.color;
@@ -165,19 +175,22 @@ void main() {
165
175
#endif /* MODE_TWO_SOURCES */
166
176
#endif /* MULTIVIEW */
167
177
168
- if (params.force_luminance ) {
178
+ if (bool ( params.flags & FLAG_FORCE_LUMINANCE) ) {
169
179
color.rgb = vec3 (max (max (color.r, color.g), color.b));
170
180
}
171
- if (params.alpha_to_zero ) {
181
+ if (bool ( params.flags & FLAG_ALPHA_TO_ZERO) ) {
172
182
color.rgb *= color.a;
173
183
}
174
- if (params.srgb ) {
184
+ if (bool ( params.flags & FLAG_SRGB) ) {
175
185
color.rgb = linear_to_srgb(color.rgb);
176
186
}
177
- if (params.alpha_to_one ) {
187
+ if (bool ( params.flags & FLAG_ALPHA_TO_ONE) ) {
178
188
color.a = 1.0 ;
179
189
}
190
+ if (bool (params.flags & FLAG_LINEAR)) {
191
+ color.rgb = srgb_to_linear(color.rgb);
192
+ }
180
193
181
- frag_color = color;
194
+ frag_color = color / params.luminance_multiplier ;
182
195
#endif // MODE_SET_COLOR
183
196
}
0 commit comments