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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

BlendOp functionality and usage questions

Discussion in 'Shaders' started by brn, Oct 12, 2012.

  1. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    I've been wanting to use the BlendOp functionality that was added to 3.5. I think it should be possible to do something like this.

    Code (csharp):
    1.  
    2. BlendOp  Max
    3. Blend DstAlpha One
    4.  
    I presumed this would result in something like max(SrcColor * DstAlpha, DstColor * One)

    Unfortunately the result always produces this max(SrcColor * One, DstColor * One)

    Am I mistaken in thinking that the BlendOp should only change the combine operation of the Blend?
    Is this a Bug I should be submitting to be fixed in a future release?

    Cheers
    Brn
     
  2. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    This is not a bug; it's just how the Min and Max blend operations work, i.e. they don't take the factors into account that you specify with "Blend", see: http://www.opengl.org/wiki/Blending#Blend_Equations
     
    NeatWolf likes this.
  3. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Thanks Martin

    Pity though, it would be incredibly helpful if it did.
     
    Last edited: Oct 12, 2012
  4. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    This will probably not solve your problem now but it might be interesting: on iOS 6 you can use GL_EXT_shader_framebuffer_fetch to implement this and on many Tegra-based Android devices you can use GL_NV_shader_framebuffer_fetch .
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    The operation is what happens to the two parts of the blending .... source color is operated on, dest color is operated on, then the results of those two operations are combined in some way - usually it's by adding them together, but with BlendOp it can be subtracted, subtracted in reverse, the minimum of the two results or the maximum of the two results.
     
  6. brn

    brn

    Joined:
    Feb 8, 2011
    Posts:
    320
    Thats what I thought would have been the case, But Martin pointed out that when using Min or Max the first part of the blend, the "SrcFactor the DstFactor", will always be the SrcColor and DstColor because the Min and Max BlendOp doesn't take definable Src and Dst Factors. Interestingly this is not the case for Subtractive or Reverse Subtractive BlendOps. It had certainly caught me out, but again as Martin pointed out it is in the opengl wiki fine print.
     
  7. samy99

    samy99

    Joined:
    Mar 4, 2020
    Posts:
    7
    So,How can i get the expect result like max(SrcColor * DstAlpha, DstColor * One)