diff options
author | Antonis Ryakiotakis <kalast@gmail.com> | 2022-02-07 21:37:15 +0300 |
---|---|---|
committer | Antonis Ryakiotakis <kalast@gmail.com> | 2022-02-07 21:37:15 +0300 |
commit | d8c05502272990173381bfd2590884bbc95aa5f5 (patch) | |
tree | 8bd65efacbe6484b838d4550597d0f4a54ddddd9 /source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl | |
parent | b64d551f3b2fa409b4eeefb641fc581eb6cd0bd6 (diff) | |
parent | fe1816f67fbc6aaf383ec77847d668367335d093 (diff) |
Merge branch 'master' into KTX_supportKTX_support
Diffstat (limited to 'source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl')
-rw-r--r-- | source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl new file mode 100644 index 00000000000..0edc18836f0 --- /dev/null +++ b/source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl @@ -0,0 +1,38 @@ +#pragma BLENDER_REQUIRE(common_colormanagement_lib.glsl) + +/* Keep in sync with image_engine.c */ +#define IMAGE_DRAW_FLAG_SHOW_ALPHA (1 << 0) +#define IMAGE_DRAW_FLAG_APPLY_ALPHA (1 << 1) +#define IMAGE_DRAW_FLAG_SHUFFLING (1 << 2) +#define IMAGE_DRAW_FLAG_DEPTH (1 << 3) + +#define FAR_DISTANCE farNearDistances.x +#define NEAR_DISTANCE farNearDistances.y + +void main() +{ + ivec2 uvs_clamped = ivec2(uv_screen); + float depth = texelFetch(depth_texture, uvs_clamped, 0).r; + if (depth == 1.0) { + discard; + } + + vec4 tex_color = texelFetch(imageTexture, uvs_clamped, 0); + + if ((drawFlags & IMAGE_DRAW_FLAG_APPLY_ALPHA) != 0) { + if (!imgPremultiplied) { + tex_color.rgb *= tex_color.a; + } + } + if ((drawFlags & IMAGE_DRAW_FLAG_DEPTH) != 0) { + tex_color = smoothstep(FAR_DISTANCE, NEAR_DISTANCE, tex_color); + } + + if ((drawFlags & IMAGE_DRAW_FLAG_SHUFFLING) != 0) { + tex_color = vec4(dot(tex_color, shuffle)); + } + if ((drawFlags & IMAGE_DRAW_FLAG_SHOW_ALPHA) == 0) { + tex_color.a = 1.0; + } + fragColor = tex_color; +} |