diff options
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl new file mode 100644 index 00000000000..e8323520af5 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_image_overlays_merge_frag.glsl @@ -0,0 +1,42 @@ + +/* Merge overlays texture on top of image texture and transform to display space (assume sRGB) */ + +uniform sampler2D image_texture; +uniform sampler2D overlays_texture; +uniform bool display_transform; + +in vec2 texCoord_interp; + +out vec4 fragColor; + +float linearrgb_to_srgb(float c) +{ + if (c < 0.0031308) { + return (c < 0.0) ? 0.0 : c * 12.92; + } + else { + return 1.055 * pow(c, 1.0 / 2.4) - 0.055; + } +} + +void linearrgb_to_srgb(vec4 col_from, out vec4 col_to) +{ + col_to.r = linearrgb_to_srgb(col_from.r); + col_to.g = linearrgb_to_srgb(col_from.g); + col_to.b = linearrgb_to_srgb(col_from.b); + col_to.a = col_from.a; +} + +void main() +{ + fragColor = texture(image_texture, texCoord_interp.st); + + vec4 overlay_col = texture(overlays_texture, texCoord_interp.st); + + fragColor *= 1.0 - overlay_col.a; + fragColor += overlay_col; + + if (display_transform) { + linearrgb_to_srgb(fragColor, fragColor); + } +} |