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:
authorJeroen Bakker <j.bakker@atmind.nl>2019-04-02 17:05:22 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2019-06-21 10:53:51 +0300
commitfed6c1a970f1df14da7c5fd4dfaf84371efcbe5d (patch)
treecab4653b8d57d41bca6f1c45ef94b2601f8ea97c /source/blender/draw/modes/shaders
parenta3a6cda8fb678432e0552d23b0226e8617f26e5f (diff)
Fix T62876: Camera Background Images
Migrate old legacy code to the draw mamager/object mode. The old legacy version did not work with wireframe. By migrating the code to modern draw manager code we have mode control on the drawing process. Still background images do not work with OIT, the cause seems to be that the transparent pixels are treated as background pixels. Also There are some artifacts when working with Holdouts and DoF, this is because the draw engines do not pass the correct alpha values. Reviewers: fclem, brecht Differential Revision: https://developer.blender.org/D4638
Diffstat (limited to 'source/blender/draw/modes/shaders')
-rw-r--r--source/blender/draw/modes/shaders/common_colormanagement_lib.glsl30
-rw-r--r--source/blender/draw/modes/shaders/object_camera_image_frag.glsl23
-rw-r--r--source/blender/draw/modes/shaders/object_camera_image_vert.glsl18
-rw-r--r--source/blender/draw/modes/shaders/object_empty_image_frag.glsl25
-rw-r--r--source/blender/draw/modes/shaders/paint_texture_frag.glsl25
5 files changed, 71 insertions, 50 deletions
diff --git a/source/blender/draw/modes/shaders/common_colormanagement_lib.glsl b/source/blender/draw/modes/shaders/common_colormanagement_lib.glsl
new file mode 100644
index 00000000000..45f711296f3
--- /dev/null
+++ b/source/blender/draw/modes/shaders/common_colormanagement_lib.glsl
@@ -0,0 +1,30 @@
+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;
+ }
+}
+
+vec4 texture_read_as_linearrgb(sampler2D tex, bool premultiplied, vec2 co)
+{
+ /* By convention image textures return scene linear colors, but
+ * overlays still assume srgb. */
+ vec4 color = texture(tex, co);
+ /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
+ if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
+ color.rgb = color.rgb / color.a;
+ }
+ return color;
+}
+
+vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
+{
+ vec4 color = texture_read_as_linearrgb(tex, premultiplied, co);
+ color.r = linearrgb_to_srgb(color.r);
+ color.g = linearrgb_to_srgb(color.g);
+ color.b = linearrgb_to_srgb(color.b);
+ return color;
+}
diff --git a/source/blender/draw/modes/shaders/object_camera_image_frag.glsl b/source/blender/draw/modes/shaders/object_camera_image_frag.glsl
new file mode 100644
index 00000000000..5d8ad3c79ea
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_camera_image_frag.glsl
@@ -0,0 +1,23 @@
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform sampler2D image;
+uniform float alpha;
+uniform bool imagePremultiplied;
+
+void main()
+{
+#ifdef DRW_STATE_DO_COLOR_MANAGEMENT
+ /* render engine has already applied the view transform. We sample the
+ * camera images as srgb*/
+ vec4 color = texture_read_as_srgb(image, imagePremultiplied, texCoord_interp);
+
+#else
+ /* Render engine renders in linearrgb. We sample the camera images as
+ * linearrgb */
+ vec4 color = texture_read_as_linearrgb(image, imagePremultiplied, texCoord_interp);
+#endif
+
+ color.a *= alpha;
+ fragColor = color;
+}
diff --git a/source/blender/draw/modes/shaders/object_camera_image_vert.glsl b/source/blender/draw/modes/shaders/object_camera_image_vert.glsl
new file mode 100644
index 00000000000..61b88c013aa
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_camera_image_vert.glsl
@@ -0,0 +1,18 @@
+uniform mat4 TransformMat;
+uniform float flipX;
+uniform float flipY;
+uniform float depth;
+
+in vec2 texCoord;
+in vec2 pos;
+
+out vec2 texCoord_interp;
+
+void main()
+{
+ vec4 position = TransformMat * vec4((pos - 0.5) * 2.0, 1.0, 1.0);
+ gl_Position = vec4(position.xy, depth, 1.0);
+
+ vec2 uv_mul = vec2(flipX, flipY);
+ texCoord_interp = texCoord * uv_mul;
+}
diff --git a/source/blender/draw/modes/shaders/object_empty_image_frag.glsl b/source/blender/draw/modes/shaders/object_empty_image_frag.glsl
index 88220140aec..7dfbf469adc 100644
--- a/source/blender/draw/modes/shaders/object_empty_image_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_empty_image_frag.glsl
@@ -15,31 +15,6 @@ uniform bool imagePremultiplied;
uniform int depthMode;
uniform bool useAlphaTest;
-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;
- }
-}
-
-vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
-{
- /* By convention image textures return scene linear colors, but
- * overlays still assume srgb. */
- vec4 color = texture(tex, co);
- /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
- if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
- color.rgb = color.rgb / color.a;
- }
- color.r = linearrgb_to_srgb(color.r);
- color.g = linearrgb_to_srgb(color.g);
- color.b = linearrgb_to_srgb(color.b);
- return color;
-}
-
void main()
{
#ifdef USE_WIRE
diff --git a/source/blender/draw/modes/shaders/paint_texture_frag.glsl b/source/blender/draw/modes/shaders/paint_texture_frag.glsl
index af7ea99e6a1..e8722590802 100644
--- a/source/blender/draw/modes/shaders/paint_texture_frag.glsl
+++ b/source/blender/draw/modes/shaders/paint_texture_frag.glsl
@@ -18,31 +18,6 @@ uniform vec3 maskingColor;
uniform bool maskingInvertStencil;
#endif
-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;
- }
-}
-
-vec4 texture_read_as_srgb(sampler2D tex, bool premultiplied, vec2 co)
-{
- /* By convention image textures return scene linear colors, but
- * overlays still assume srgb. */
- vec4 color = texture(tex, co);
- /* Unpremultiply if stored multiplied, since straight alpha is expected by shaders. */
- if (premultiplied && !(color.a == 0.0 || color.a == 1.0)) {
- color.rgb = color.rgb / color.a;
- }
- color.r = linearrgb_to_srgb(color.r);
- color.g = linearrgb_to_srgb(color.g);
- color.b = linearrgb_to_srgb(color.b);
- return color;
-}
-
void main()
{
vec2 uv = uv_interp;