[Webkit-unassigned] [Bug 98504] [CSS Shaders] Implement overlay, color-dodge, color-burn, hard-light, soft-light blend modes.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Oct 8 11:48:18 PDT 2012


https://bugs.webkit.org/show_bug.cgi?id=98504





--- Comment #2 from Max Vujovic <mvujovic at adobe.com>  2012-10-08 11:48:53 PST ---
(From update of attachment 167299)
View in context: https://bugs.webkit.org/attachment.cgi?id=167299&action=review

> Source/WebCore/ChangeLog:3
> +        [CSS Shaders] Implement overlay, color-dodge, color-burn, hard-light, soft-light blend modes.

Thanks for the patch, Huang!

I have some ideas about how to factor this now that you're implementing the more complicated blend modes :)

Basically, I want to break up the GLSL css_Blend function into two functions, css_BlendColor and css_BlendComponent. If we need to do per component blending, css_BlendColor calls css_BlendComponent for each color component. I've provided the details below. Please let me know if something is not clear.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:189
>      const char* expression = 0;

Rename this blendColorExpression.

Give a default value of:
"Co = vec3(blendComponent(Cb.r, Cs.r), blendComponent(Cb.g, Cs.g), blendComponent(Cb.b, Cs.b));"

For the simpler blend modes that don't need to blend by component, we will overwrite this default value.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:190
> +    const char* auxiliaryExpression = "";

Rename this to blendComponentExpression.

Give a default value of:
"return 0.0;"

This default value is just so this function compiles when it is not used.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:193
>          expression = "Cs";

The existing blend mode expressions should change to this format:

blendColorExpression = "Co = Cs";
...

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:213
>      case BlendModeOverlay:

This entire case can be:

blendComponentExpression = SHADER(
    if (Cb <= 0.5)
        Co = Cs * (2.0 * Cb);
    else
        Co = Cs + (2.0 * Cb - 1.0) - (Cs * (2.0 * Cb - 1.0)); 
);

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:237
>      case BlendModeColorDodge:

This entire case can be:

blendComponentExpression = SHADER(
    float divisor = 1.0 - Cs;
    Co = (divisor != 0.0) ? (Cb / divisor) : 1.0;
);

Notice the divide by zero check I added. We need to make sure we don't ever divide by zero because different GPUs often behave differently in that case. I've seen some discard the entire fragment when a division by zero occurs in the shader.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:245
> +            mediump vec3 one = vec3(1.0, 1.0, 1.0);

Even though I'm asking you to remove this line, a nicer way to write it in GLSL is:
mediump vec3 one = vec3(1.0);

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:247
> +            if (Cs.r >= 1.0)

I think it's better to move this clamping operation to the css_BlendColor function below because we always want the blending result to be between 0.0 and 1.0. Check out the GLSL clamp function: http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:256
>      case BlendModeColorBurn:

The rest of the cases can also be written in the format I mentioned.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:265
> +            mediump vec3 B = one - min(one, (one - Cb) / Cs);

When you write this expression, be careful to avoid the divide by zero.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:341
>      return String::format(SHADER(

Add a function:

mediump vec3 css_BlendComponent(mediump float Cb, mediump float Cs)
{
    float Co;
    %s;
    return Co;
}

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:342
>          mediump vec3 css_Blend(mediump vec3 Cb, mediump vec3 Cs)

Rename this function to css_BlendColor.

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:345
>              return %s;

Replace this function body with:

vec3 Co;
%s
return clamp(Co, 0.0, 1.0);

> Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp:347
> +    ), auxiliaryExpression, expression);

Replace this with "blendComponentExpression, blendColorExpression".

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list