74 lines
1.6 KiB
GLSL
74 lines
1.6 KiB
GLSL
#version 330
|
|
|
|
// Input vertex attributes (from vertex shader)
|
|
in vec3 vertexPos;
|
|
in vec2 fragTexCoord;
|
|
in vec4 fragColor;
|
|
|
|
// Input uniform values
|
|
uniform sampler2D texture0;
|
|
uniform sampler2D texture1;
|
|
uniform vec4 colDiffuse;
|
|
|
|
uniform float divider = 0.5;
|
|
|
|
out vec4 finalColor;
|
|
|
|
float float_to_srgb(float l) {
|
|
if (l < 0.0031308) {
|
|
return l * 12.92;
|
|
} else {
|
|
return 1.055 * pow(l, 0.41666) - 0.055;
|
|
}
|
|
}
|
|
|
|
vec4 linear_to_srgb(vec4 linear) {
|
|
vec4 srgb;
|
|
|
|
if (linear.r < 0.0031308) {
|
|
srgb.r = linear.r * 12.92;
|
|
} else {
|
|
srgb.r = 1.055 * pow(linear.r, 0.41666) - 0.055;
|
|
}
|
|
|
|
if (linear.g < 0.0031308) {
|
|
srgb.g = linear.g * 12.92;
|
|
} else {
|
|
srgb.g = 1.055 * pow(linear.g, 0.41666) - 0.055;
|
|
}
|
|
|
|
if (linear.b < 0.0031308) {
|
|
srgb.b = linear.b * 12.92;
|
|
} else {
|
|
srgb.b = 1.055 * pow(linear.b, 0.41666) - 0.055;
|
|
}
|
|
|
|
srgb.a = linear.a;
|
|
|
|
return srgb;
|
|
}
|
|
|
|
float float_to_linear(float s) {
|
|
if (s <= 0.04045) {
|
|
return s / 12.92;
|
|
} else {
|
|
return pow((s + 0.055) / 1.055, 2.4);
|
|
}
|
|
}
|
|
|
|
vec4 srgb_to_linear(vec4 srgb) {
|
|
return vec4(float_to_linear(srgb.r), float_to_linear(srgb.g), float_to_linear(srgb.b), srgb.a);
|
|
}
|
|
|
|
void main() {
|
|
// // Texel color fetching from texture sampler
|
|
vec4 texelColor0 = texture(texture0, fragTexCoord);
|
|
// vec4 texelColor1 = texture(texture1, fragTexCoord);
|
|
|
|
// float x = fract(fragTexCoord.s);
|
|
// float final = smoothstep(divider - 0.1, divider + 0.1, x);
|
|
|
|
finalColor = vec4(1, 1, 1, float_to_srgb(texelColor0.r)); //xelColor0;
|
|
// finalColor = vec4(1, 1, 0.0, 1.0);
|
|
}
|