Revision: 44108
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44108
Author:   psy-fi
Date:     2012-02-14 13:25:23 +0000 (Tue, 14 Feb 2012)
Log Message:
-----------
Fix related to #30152, rainbow colours produced when loading hdr image to 3D 
viewport/ the Nyan cat bug.

Issue is caused by scaling for power of 2 dimensions and mipmapping that 
happens through GLU. It looks like the library cannot handle float colour 
values above 1.0 correctly. Since we are close to release I will just clamp the 
srgb result for now even though it will result in a small performance loss for 
16 bit textures only. 

I tried a few things before that, glGenerateMipmaps + no scaling (supported for 
2.0 GL hardware and up), or using our own scaling instead of glu among them 
which worked very nicely and gave a speedup too. However, since we are close to 
release and there may be issues with GPU mipmap generation, see:

http://www.gamedev.net/topic/495747-another-glgeneratemipmap-question/
(old discussion but better be sure than sorry)

I went for the most compatible solution. Maybe after release this can be tested 
if other devs agree.

Modified Paths:
--------------
    trunk/blender/source/blender/gpu/intern/gpu_draw.c
    trunk/blender/source/blender/imbuf/IMB_imbuf.h
    trunk/blender/source/blender/imbuf/intern/divers.c

Modified: trunk/blender/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_draw.c  2012-02-14 13:24:04 UTC 
(rev 44107)
+++ trunk/blender/source/blender/gpu/intern/gpu_draw.c  2012-02-14 13:25:23 UTC 
(rev 44108)
@@ -518,6 +518,8 @@
                                        IMB_buffer_float_from_float(srgb_frect, 
ibuf->rect_float,
                                                ibuf->channels, 
IB_PROFILE_SRGB, ibuf->profile, 0,
                                                ibuf->x, ibuf->y, ibuf->x, 
ibuf->x);
+                                       /* clamp buffer colours to 1.0 to avoid 
artifacts due to glu for hdr images */
+                                       IMB_buffer_float_clamp(srgb_frect, 
ibuf->x, ibuf->y);
                                        frect= srgb_frect + texwinsy*ibuf->x + 
texwinsx;
                                }
                                else
@@ -541,6 +543,8 @@
                                        IMB_buffer_float_from_float(srgb_frect, 
ibuf->rect_float,
                                                        ibuf->channels, 
IB_PROFILE_SRGB, ibuf->profile, 0,
                                                        ibuf->x, ibuf->y, 
ibuf->x, ibuf->x);
+                                       /* clamp buffer colours to 1.0 to avoid 
artifacts due to glu for hdr images */
+                                       IMB_buffer_float_clamp(srgb_frect, 
ibuf->x, ibuf->y);
                                }
                                else
                                        frect= ibuf->rect_float;
@@ -615,7 +619,7 @@
 
        if (!(gpu_get_mipmap() && mipmap)) {
                if(use_high_bit_depth)
-                       glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA16,  rectw, 
recth, 0, GL_RGBA, GL_FLOAT, frect);                 
+                       glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA16,  rectw, 
recth, 0, GL_RGBA, GL_FLOAT, frect);
                else
                        glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA,  rectw, recth, 
0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR);

Modified: trunk/blender/source/blender/imbuf/IMB_imbuf.h
===================================================================
--- trunk/blender/source/blender/imbuf/IMB_imbuf.h      2012-02-14 13:24:04 UTC 
(rev 44107)
+++ trunk/blender/source/blender/imbuf/IMB_imbuf.h      2012-02-14 13:25:23 UTC 
(rev 44108)
@@ -391,6 +391,7 @@
 void IMB_buffer_byte_from_byte(unsigned char *rect_to, const unsigned char 
*rect_from,
        int profile_to, int profile_from, int predivide,
        int width, int height, int stride_to, int stride_from);
+void IMB_buffer_float_clamp(float *buf, int width, int height);
 
 /**
  * Change the ordering of the color bytes pointed to by rect from

Modified: trunk/blender/source/blender/imbuf/intern/divers.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/divers.c  2012-02-14 13:24:04 UTC 
(rev 44107)
+++ trunk/blender/source/blender/imbuf/intern/divers.c  2012-02-14 13:25:23 UTC 
(rev 44108)
@@ -742,3 +742,10 @@
                        rct[0]= rct[1]= rct[2]= rgb_to_grayscale_byte(rct);
        }
 }
+
+void IMB_buffer_float_clamp(float *buf, int width, int height){
+       int i, total = width*height*4;
+       for(i = 0; i < total; i++){
+               buf[i] = MIN2(1.0, buf[i]);
+       }
+}

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to