1
0
Fork 0
forked from wry/wry

vulkan: rewrite shaders in terms of eotf and oetf

This commit is contained in:
Julian Orth 2025-02-25 14:52:43 +01:00
parent cb9dc4c182
commit b7f93b37a6
8 changed files with 52 additions and 14 deletions

View file

@ -3,6 +3,7 @@
layout(constant_id = 0) const bool src_has_alpha = false;
layout(constant_id = 1) const bool has_alpha_multiplier = false;
layout(constant_id = 2) const bool color_management = false;
layout(constant_id = 2) const uint eotf = 0;
layout(constant_id = 3) const uint oetf = 0;
#endif

View file

@ -10,8 +10,11 @@ layout(location = 0) out vec4 out_color;
void main() {
vec4 c = texelFetch(in_color, ivec2(gl_FragCoord.xy), 0);
c.rgb /= mix(c.a, 1.0, c.a == 0.0);
c.rgb = oetf_srgb(c.rgb);
c.rgb *= c.a;
if (eotf != oetf) {
c.rgb /= mix(c.a, 1.0, c.a == 0.0);
c.rgb = apply_eotf(c.rgb);
c.rgb = apply_oetf(c.rgb);
c.rgb *= c.a;
}
out_color = c;
}

View file

@ -10,11 +10,12 @@ layout(location = 0) out vec4 out_color;
void main() {
vec4 c = textureLod(tex, tex_pos, 0);
if (color_management) {
if (eotf != oetf) {
if (src_has_alpha) {
c.rgb /= mix(c.a, 1.0, c.a == 0.0);
}
c.rgb = eotf_srgb(c.rgb);
c.rgb = apply_eotf(c.rgb);
c.rgb = apply_oetf(c.rgb);
if (src_has_alpha) {
c.rgb *= c.a;
}

View file

@ -1,6 +1,11 @@
#ifndef TRANSFER_FUNCTIONS_GLSL
#define TRANSFER_FUNCTIONS_GLSL
#include "frag_spec_const.glsl"
#define SRGB 0
#define LINEAR 1
vec3 eotf_srgb(vec3 c) {
return mix(
c * vec3(1.0 / 12.92),
@ -18,4 +23,20 @@ vec3 oetf_srgb(vec3 c) {
);
}
vec3 apply_eotf(vec3 c) {
switch (eotf) {
case SRGB: return eotf_srgb(c);
case LINEAR: return c;
default: return c;
}
}
vec3 apply_oetf(vec3 c) {
switch (oetf) {
case SRGB: return oetf_srgb(c);
case LINEAR: return c;
default: return c;
}
}
#endif