Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/draw/engines/image/shaders')
-rw-r--r--source/blender/draw/engines/image/shaders/engine_image_frag.glsl94
-rw-r--r--source/blender/draw/engines/image/shaders/engine_image_vert.glsl34
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_color_frag.glsl38
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl11
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl16
-rw-r--r--source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl11
-rw-r--r--source/blender/draw/engines/image/shaders/infos/engine_image_info.hh30
7 files changed, 106 insertions, 128 deletions
diff --git a/source/blender/draw/engines/image/shaders/engine_image_frag.glsl b/source/blender/draw/engines/image/shaders/engine_image_frag.glsl
deleted file mode 100644
index 55a2f2a72f1..00000000000
--- a/source/blender/draw/engines/image/shaders/engine_image_frag.glsl
+++ /dev/null
@@ -1,94 +0,0 @@
-#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 IMAGE_DRAW_FLAG_DO_REPEAT (1 << 4)
-
-#ifdef TILED_IMAGE
-uniform sampler2DArray imageTileArray;
-uniform sampler1DArray imageTileData;
-#else
-uniform sampler2D imageTexture;
-#endif
-
-uniform bool imgPremultiplied;
-uniform int drawFlags;
-uniform vec2 farNearDistances;
-uniform vec4 color;
-uniform vec4 shuffle;
-
-#define FAR_DISTANCE farNearDistances.x
-#define NEAR_DISTANCE farNearDistances.y
-
-in vec2 uvs;
-
-out vec4 fragColor;
-
-#ifdef TILED_IMAGE
-/* TODO(fclem): deduplicate code. */
-bool node_tex_tile_lookup(inout vec3 co, sampler2DArray ima, sampler1DArray map)
-{
- vec2 tile_pos = floor(co.xy);
-
- if (tile_pos.x < 0 || tile_pos.y < 0 || tile_pos.x >= 10) {
- return false;
- }
-
- float tile = 10.0 * tile_pos.y + tile_pos.x;
- if (tile >= textureSize(map, 0).x) {
- return false;
- }
-
- /* Fetch tile information. */
- float tile_layer = texelFetch(map, ivec2(tile, 0), 0).x;
- if (tile_layer < 0.0) {
- return false;
- }
-
- vec4 tile_info = texelFetch(map, ivec2(tile, 1), 0);
-
- co = vec3(((co.xy - tile_pos) * tile_info.zw) + tile_info.xy, tile_layer);
- return true;
-}
-#endif
-
-void main()
-{
- vec4 tex_color;
- /* Read texture */
-#ifdef TILED_IMAGE
- vec3 co = vec3(uvs, 0.0);
- if (node_tex_tile_lookup(co, imageTileArray, imageTileData)) {
- tex_color = texture(imageTileArray, co);
- }
- else {
- tex_color = vec4(1.0, 0.0, 1.0, 1.0);
- }
-#else
- vec2 uvs_clamped = ((drawFlags & IMAGE_DRAW_FLAG_DO_REPEAT) != 0) ?
- fract(uvs) :
- clamp(uvs, vec2(0.0), vec2(1.0));
- tex_color = texture(imageTexture, uvs_clamped);
-#endif
-
- 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 = color * dot(tex_color, shuffle);
- }
- if ((drawFlags & IMAGE_DRAW_FLAG_SHOW_ALPHA) == 0) {
- tex_color.a = 1.0;
- }
-
- fragColor = tex_color;
-}
diff --git a/source/blender/draw/engines/image/shaders/engine_image_vert.glsl b/source/blender/draw/engines/image/shaders/engine_image_vert.glsl
deleted file mode 100644
index da2b1907c41..00000000000
--- a/source/blender/draw/engines/image/shaders/engine_image_vert.glsl
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma BLENDER_REQUIRE(common_view_lib.glsl)
-
-#define IMAGE_DRAW_FLAG_DO_REPEAT (1 << 4)
-#define IMAGE_DRAW_FLAG_USE_WORLD_POS (1 << 5)
-#define IMAGE_Z_DEPTH 0.75
-
-uniform int drawFlags;
-
-in vec3 pos;
-out vec2 uvs;
-
-void main()
-{
- /* `pos` contains the coordinates of a quad (-1..1). but we need the coordinates of an image
- * plane (0..1) */
- vec3 image_pos = pos * 0.5 + 0.5;
-
- if ((drawFlags & IMAGE_DRAW_FLAG_DO_REPEAT) != 0) {
- gl_Position = vec4(pos.xy, IMAGE_Z_DEPTH, 1.0);
- uvs = point_view_to_object(image_pos).xy;
- }
- else {
- vec3 world_pos = point_object_to_world(image_pos);
- vec4 position = point_world_to_ndc(world_pos);
- /* Move drawn pixels to the front. In the overlay engine the depth is used
- * to detect if a transparency texture or the background color should be drawn.
- * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4
- * actual pixels are at 0.75, 1.0 is used for the background. */
- position.z = IMAGE_Z_DEPTH;
- gl_Position = position;
- /* UDIM texture uses the world position for tile selection. */
- uvs = ((drawFlags & IMAGE_DRAW_FLAG_USE_WORLD_POS) != 0) ? world_pos.xy : image_pos.xy;
- }
-}
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;
+}
diff --git a/source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl b/source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl
new file mode 100644
index 00000000000..fb72a132613
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/image_engine_color_vert.glsl
@@ -0,0 +1,11 @@
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+void main()
+{
+ vec3 image_pos = vec3(pos, 0.0);
+ uv_screen = image_pos.xy;
+
+ vec3 world_pos = point_object_to_world(image_pos);
+ vec4 position = point_world_to_ndc(world_pos);
+ gl_Position = position;
+}
diff --git a/source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl b/source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl
new file mode 100644
index 00000000000..88610fb97fd
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/image_engine_depth_frag.glsl
@@ -0,0 +1,16 @@
+#pragma BLENDER_REQUIRE(common_colormanagement_lib.glsl)
+
+#define Z_DEPTH_BORDER 1.0
+#define Z_DEPTH_IMAGE 0.75
+
+bool is_border(vec2 uv)
+{
+ return (uv.x < min_max_uv.x || uv.y < min_max_uv.y || uv.x >= min_max_uv.z ||
+ uv.y >= min_max_uv.w);
+}
+
+void main()
+{
+ bool border = is_border(uv_image);
+ gl_FragDepth = border ? Z_DEPTH_BORDER : Z_DEPTH_IMAGE;
+}
diff --git a/source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl b/source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl
new file mode 100644
index 00000000000..3181a85ff55
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/image_engine_depth_vert.glsl
@@ -0,0 +1,11 @@
+#pragma BLENDER_REQUIRE(common_view_lib.glsl)
+
+void main()
+{
+ vec3 image_pos = vec3(pos, 0.0);
+ uv_image = uv;
+
+ vec3 world_pos = point_object_to_world(image_pos);
+ vec4 position = point_world_to_ndc(world_pos);
+ gl_Position = position;
+}
diff --git a/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh b/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh
new file mode 100644
index 00000000000..8b671686a5c
--- /dev/null
+++ b/source/blender/draw/engines/image/shaders/infos/engine_image_info.hh
@@ -0,0 +1,30 @@
+#include "gpu_shader_create_info.hh"
+
+GPU_SHADER_INTERFACE_INFO(image_engine_color_iface, "").smooth(Type::VEC2, "uv_screen");
+
+GPU_SHADER_CREATE_INFO(image_engine_color_shader)
+ .vertex_in(0, Type::VEC2, "pos")
+ .vertex_out(image_engine_color_iface)
+ .fragment_out(0, Type::VEC4, "fragColor")
+ .push_constant(Type::VEC4, "shuffle")
+ .push_constant(Type::VEC2, "farNearDistances")
+ .push_constant(Type::INT, "drawFlags")
+ .push_constant(Type::BOOL, "imgPremultiplied")
+ .sampler(0, ImageType::FLOAT_2D, "imageTexture")
+ .sampler(1, ImageType::DEPTH_2D, "depth_texture")
+ .vertex_source("image_engine_color_vert.glsl")
+ .fragment_source("image_engine_color_frag.glsl")
+ .additional_info("draw_modelmat")
+ .do_static_compilation(true);
+
+GPU_SHADER_INTERFACE_INFO(image_engine_depth_iface, "").smooth(Type::VEC2, "uv_image");
+
+GPU_SHADER_CREATE_INFO(image_engine_depth_shader)
+ .vertex_in(0, Type::VEC2, "pos")
+ .vertex_in(1, Type::VEC2, "uv")
+ .vertex_out(image_engine_depth_iface)
+ .push_constant(Type::VEC4, "min_max_uv")
+ .vertex_source("image_engine_depth_vert.glsl")
+ .fragment_source("image_engine_depth_frag.glsl")
+ .additional_info("draw_modelmat")
+ .do_static_compilation(true);