Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Photoshop Fill Opacity blend mode.

Discussion in 'Shaders' started by FoxyShadow, Feb 20, 2018.

  1. FoxyShadow

    FoxyShadow

    Joined:
    Aug 14, 2016
    Posts:
    41
    I'm trying to figure out how Fill Opacity in Photoshop works. I know there are 8 special blending modes which works differently with Opacity and Fill Opacity. Assuming source color is S and background color is B I need a formula to count a pixel if opacity for S is set to 100% but Fill Opacity is not 100%. For now I need a formula for Color Dodge blend when source color's Fill Opacity is not 100%.
    Color Dodge formula is B/(1-S) if Fill Opacity is 100% as I know.

    Thanks for any help!
     
  2. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    314
    In the past I played with photoshop blends in Unity shader, link to source code:
    Code (CSharp):
    1. https://github.com/przemyslawzaworski/Unity3D-CG-programming/blob/master/photoshop_blends.shader
    To emulate opacity you need add transparency, as I understand.
     
  3. FoxyShadow

    FoxyShadow

    Joined:
    Aug 14, 2016
    Posts:
    41
    Wait, wait, wait. It's a shader with photoshop blend modes where alpha is not taken into account. I know formulae I need for this. My problem is to find a blend formula for Fill Opacity, there are 8 blend modes which work with Opacity differently than with Fill Opacity. May be question in my first post wasn't pretty clear so I'll provide a screenshot explaining what I'm looking for.



    I'm blending that diffused sphere with backdrop. To the left is an initial sphere. Up-Right is a result of ColorDodge blending with 60% opacity and 100% Fill Opacity. Bottom-Right is ColorDodge blending with 100% opacity and 60% FillOpacity. I know how to count a pixel when it is a regular opacity goes in, but how to count a pixel when Fill is not 100% is my problem here.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    To me it looks like it's doing this:

    color = lerp(B, BlendFunc(B, S, Fill), Opacity)

    If I was to guess, for color dodge this is:

    color = lerp(B, B / (1 - S * Fill), Opacity)
     
    FoxyShadow likes this.
  5. FoxyShadow

    FoxyShadow

    Joined:
    Aug 14, 2016
    Posts:
    41
    Bgolus.. you have saved my day again! I don't know how to thank you, really :) It worked as I wanted.
     
  6. FoxyShadow

    FoxyShadow

    Joined:
    Aug 14, 2016
    Posts:
    41
    Bgolus. Do you even happen to know why this formula is exact copy of PS's only when a channel is not very near to FF. For example for FA it is exactly the same, but for FF in a channel it differs (a value is a little less than in PS). I upgraded my formula to this (Opacity 100%)

    Code (CSharp):
    1.  
    2. fixed ColorDodge(fixed _b, fixed _s, fixed _fill) {
    3.     if(_s * _fill < 1) {
    4.         return min(1, _b / (1 - _s * _fill));
    5.     }
    6.     return 1;
    7. }
    8.  
    May be I'm missing smth? :)
     
    Last edited: Feb 24, 2018
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    1 - 1 = 0
    x / 0 = badness

    I suspect Photoshop is doing the same test for 1 you are.
     
  8. FoxyShadow

    FoxyShadow

    Joined:
    Aug 14, 2016
    Posts:
    41
    I mean I have a slight difference near to FF from Photoshop when using this upgraded formula above...)
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,230
    Oh, yeah, no idea. Could be some factor of floating point math, or photoshop could be doing some different kind of blend when near 1.
     
  10. FoxyShadow

    FoxyShadow

    Joined:
    Aug 14, 2016
    Posts:
    41
    I tried to figure out what kind of math near 1 PS uses but did not figure it out. Anyway the difference is small so this formula is ok. Let it be as it is. You helped me a lot anyway! :)