[Mesa-dev] [PATCH 12/16] Hack: Implement the older bogus HSL rules

Kenneth Graunke kenneth at whitecape.org
Sat Aug 13 03:13:04 UTC 2016


Prior to revision 9 of the NV extension or revision 16 of the KHR extension,
the rules for HSL conversion was different.  dEQP appears to be out of date.

Here's an old copy:
http://developer.download.nvidia.com/opengl/specs/GL_NV_blend_equation_advanced.txt

      // Take the base RGB color <cbase> and override its luminosity
      // with that of the RGB color <clum>.
      vec3 SetLum(vec3 cbase, vec3 clum) {
        float lbase = lumv3(cbase);
        float llum = lumv3(clum);
        float ldiff = llum - lbase;
        vec3 color = cbase + vec3(ldiff);
        if (minv3(color) < 0.0) {
          return llum + ((color-llum)*llum) / (llum-minv3(color));
        } else if (maxv3(color) > 1.0) {
          return llum + ((color-llum)*(1-llum)) / (maxv3(color)-llum);
        } else {
          return color;
        }
      }

versus the new copy:
https://www.opengl.org/registry/specs/KHR/blend_equation_advanced.txt

      // If any color components are outside [0,1], adjust the color to
      // get the components in range.
      vec3 ClipColor(vec3 color) {
        float lum = lumv3(color);
        float mincol = minv3(color);
        float maxcol = maxv3(color);
        if (mincol < 0.0) {
          color = lum + ((color-lum)*lum) / (lum-mincol);
        }
        if (maxcol > 1.0) {
          color = lum + ((color-lum)*lum) / (maxcol-lum);
        }
        return color;
      }

      // Take the base RGB color <cbase> and override its luminosity
      // with that of the RGB color <clum>.
      vec3 SetLum(vec3 cbase, vec3 clum) {
        float lbase = lumv3(cbase);
        float llum = lumv3(clum);
        float ldiff = llum - lbase;
        vec3 color = cbase + vec3(ldiff);
        return ClipColor(color);
      }

The revision history says:
"Fix incorrectly specified color clamping in the HSL blend modes."
so presumably the old rules are not what we want.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/compiler/glsl/lower_blend_equation_advanced.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/compiler/glsl/lower_blend_equation_advanced.cpp b/src/compiler/glsl/lower_blend_equation_advanced.cpp
index 91a11f3..58dfd2e 100644
--- a/src/compiler/glsl/lower_blend_equation_advanced.cpp
+++ b/src/compiler/glsl/lower_blend_equation_advanced.cpp
@@ -275,16 +275,18 @@ lower_blend_visitor::clip_color(ir_factory *f, ir_variable *color)
    ir_variable *lum = f->make_temp(glsl_type::float_type, "__blend_lum");
    ir_variable *mincol = f->make_temp(glsl_type::float_type, "__blend_mincol");
    ir_variable *maxcol = f->make_temp(glsl_type::float_type, "__blend_maxcol");
-   ir_variable *tmp = f->make_temp(glsl_type::vec3_type, "__blend_clip_tmp");
 
    f->emit(assign(lum, lumv3(color)));
    f->emit(assign(mincol, minv3(color)));
    f->emit(assign(maxcol, maxv3(color)));
-   f->emit(assign(tmp, mul(sub(color, lum), lum)));
+
    f->emit(if_tree(less(mincol, imm1(0)),
-                   assign(color, add(lum, div(tmp, sub(lum, mincol))))));
-   f->emit(if_tree(greater(maxcol, imm1(1)),
-                   assign(color, add(lum, div(tmp, sub(maxcol, lum))))));
+                   assign(color, add(lum, div(mul(sub(color, lum), lum),
+                                              sub(lum, mincol)))),
+                   if_tree(greater(maxcol, imm1(1)),
+                           assign(color, add(lum, div(mul(sub(color, lum),
+                                                          sub(imm3(1), lum)),
+                                                      sub(maxcol, lum)))))));
 }
 
 /* Take the base RGB color <cbase> and override its luminosity
-- 
2.9.0



More information about the mesa-dev mailing list