Search Unity

Blend Modes

Discussion in 'Assets and Asset Store' started by Elringus, Jan 16, 2015.

  1. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    176
    I upgraded to Unity 5.6 recently and upgraded Blend Modes as well and started getting this error:

    Code (CSharp):
    1. Error building Player: Shader error in 'BlendModes/Extra/UIBlured': unable to unroll loop, loop does not appear to terminate in a timely manner (683 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number at line 127 (on d3d9)
    2.  
    3. Compiling Fragment program with BmLinearLight
    4. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP
    5.  
    6. Shader error in 'BlendModes/Extra/UIBlured': unable to unroll loop, loop does not appear to terminate in a timely manner (683 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number at line 127 (on d3d9)
    7.  
    8. Compiling Fragment program with BmLinearLight
    9. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP
    10.  
    It only occurs when building. It only occurs sometimes it seems too. I tried to fix the issue by using the attribute it states but my limited shader knowledge caused this fix to fall through quickly for me. I deleted the shader UIBlured (which was added in the last update I believe) and it has solved the issue for me.
     
  2. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    If you are not using the UIBlured extra shader you can remove it from the project (just delete the BlendModes/Extra/UIBlured.shader file) and the error should disappear. I will investigate the issue further and update the package when the fix is ready. Thank you for reporting this and sorry for the inconvenience.
     
    Ghosthowl likes this.
  3. Dexyuzs

    Dexyuzs

    Joined:
    May 13, 2016
    Posts:
    3
    Hi! I just bought this asset pack and I'm running into some problems.

    I'm making a 2D game that works at 4k resolution. Without using any blend modes my game runs smoothly at 60 fps. After using them in a couple of sprites (they are big, 80~90% of the screen size) the frame rate drops to almost half (~35fps) and I get spammed by the following error in the editor console:

    GL.End requires material.SetPass before!

    Is this normal? Or i'm doing something wrong? I'm just adding the BlendModeEffect component to the sprites and selecting the blend mode (as you show in the documentation).

    Thank you in advance for your response ;)
     
  4. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi,

    The error you’re getting in the console is most likely caused by the following Unity regression issue: https://issuetracker.unity3d.com/is...if-a-cameras-clear-flags-is-set-to-depth-only Try updating the editor to the latest version (5.6.1) and installing the latest patch (5.6.1p1).

    As for the performance: default render mode of the blend mode effect uses GrabPass, which heavily depends on screen resolution. If you’re targeting mobile devices with framebuffer_fetch extension support, you can use Framebuffer render mode, which will work much faster. For other cases consider using Unified Grab mode: it will execute only one GrabPass for all the blend mode effects on the scene, which will also contribute to performance. You can find more on render modes and performance under the “Render mode” section of the docs: https://goo.gl/tSAmB7
     
  5. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    119
    Hi there.
    Our team decided to try Unity 2017.1 beta and it appeared that BlendModes works incorrectly.

    That's how they should look like (Unity 5.6.1f1)


    And this is how they look like in 2017.1b


    Any thoughts?
     
  6. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi,

    I was able to reproduce the issue on Unity 2017 beta. Looks like only sprites are affected (other objects work fine). I will investigate it further and provide fix as soon as possible. Thank you for reporting this!
     
  7. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    After investigating the issue further, it appears Unity 2017 has a regression bug with Stencil not working properly under SpriteRenderer. I’ve filed a bug report (case ID: 917247); hope it will be fixed before the final release.

    If you happen to need the sprites working with the current beta version asap, please contact me via the support email and we’ll try to manage a temp solution for this.
     
    Last edited: Jun 4, 2017
  8. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    119
    Hi. Thank for your investigation.
    This is not urgent for us. So let's wait for a bug fix from Unity officials.
     
  9. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    187
    Hi @Elringus
    I'd like to know if in your Blend Modes system I can execute only Color Blend Modes on the Sprite/UI elements instead of let the entire elements blending with other ones?

    What I want to do is apply any color to my grayed sprites, but keeping the highlight tone the same like it happens on the Photoshop (Blending Options > Color Overlay > Color Mode: Overlay).

    color_mode_example.jpg
     
  10. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi, that's possible with the UIColorBlend extra shader (included with the package): https://i.gyazo.com/a7e18ef25fe1eeb26ea649e30e93acbc.mp4
     
    sandolkakos likes this.
  11. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    228
    Can this asset use mask with alpha while blending?
     
  12. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Yes, it has a masking feature (implemented using stencil buffer) allowing to selectively blend or cutoff masked regions. You can find more in the docs: https://goo.gl/1MeKvb
     
  13. origaming

    origaming

    Joined:
    Nov 15, 2013
    Posts:
    1
    Hi! Can this be used to truly replicate Photoshop's blending modes?

    Say, I want to add a "ray of light" layer in my 2D project. This layer will use "Screen" blending mode and it must affect EVERY 2d sprites underneath it. If possible, I'd like to tween this ray of light layer as well, maybe animate it a little so it looks better

    Can this be done?
     
  14. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi,

    Blending algorithms themselves are either identical (all the ‘simple’ ones, including screen) or as close as possible (so called ‘component’ modes, which require translation between color spaces) to the ones used in Photoshop. The way they’re applied is also mostly identical to how Photoshop layers work: upper layer blends with anything that is drawn below.

    Here is a comparison of sprites rendered in Unity with BlendMode effect applied and the same sprites in Photoshop:

    Regarding ray of light effect: it should work the way you expect and look identical to what you get when using Photoshop blend modes. The sprite with the effect will blend with anything that is drawn before and you’ll be able to tween or transform it any way you need.
     
  15. FAAM

    FAAM

    Joined:
    Mar 23, 2016
    Posts:
    2
    Hi Elringus,

    Thanks for this plugin, it works very well and gives great results! I am using it a LOT.

    However, there is one thing that I would like to know if you could help me with. When I am using the framebuffer mode on Sprites 2D, the color that I put in the Sprite Renderer is completely ignored. Whereas in grab mode (so in the editor), I am able to apply a color on top of the Sprite.

    Is there any way to make it work? That way I wouldn't have to create a million different "Glow" sprites with different colors for exemple, I could just change the tint in the sprite renderer.

    If you have a solution that would be really helpful, thanks!
     
  16. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi,

    There was an issue with framebuffer shaders compilation when COLOR semantics is used (which is required to accept color from the sprite renderer component) in Unity 5.x, that’s why I had to remove it from the framebuffer shader variants. But seems like it’s now (partially) fixed in 2017.1: https://issuetracker.unity3d.com/issues/ios-framebuffer-fetch-not-working-with-gles3 At least I was able to make it work with Metal and GLE3 APIs (but not with GLES2).

    If you’re using Unity 2017 and not targeting GLES2, I can send you a patched version of the package; contact me via support email for that (don't forget to include invoice number). Otherwise, as a workaround, I can suggest using a custom material with "BlendModes/SpriteDefault/Framebuffer" shader and applying color tint to the sprites via the material instead of SpriteRenderer component.
     
  17. FAAM

    FAAM

    Joined:
    Mar 23, 2016
    Posts:
    2
    Thank you for the fast answer!
    I will update to Unity 2017 next week and contact you via email if the issue is not resolved.
     
  18. PMetcalf3

    PMetcalf3

    Joined:
    Oct 22, 2014
    Posts:
    2
    Thanks for this useful tool! however, I can't seem to get ui to hide using your shaders when nested in a mask object. Please tell me I'm doing something wrong...
     
  19. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Unity UI Mask feature is not compatible with the default Blend Modes shaders (they won't be hidden by the mask).
    You can however use BlendModes/Extra/MaskableUI shader to combine blend mode effect with UI masks. More info on using custom blend materials in the docs: Using custom blend materials.
     
  20. Yinmo

    Yinmo

    Joined:
    Apr 16, 2016
    Posts:
    20
    Hello,
    I checked your web demo and now I am wondering if it is possible to apply inverse alpha plending mode on 2d sprite?
     
  21. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi,

    You can apply any of the 25 blend modes (list of all the available blend modes is in the docs) to all the supported objects (sprites included). The plugin essentially simulates Photoshop's layer blending FX; it doesn't change the alpha blending mode of the objects. In case you want to manipulate the alpha blending (and not the colors), you may not need any plugins; take a look at this manual: https://docs.unity3d.com/Manual/SL-Blend.html
     
  22. Yinmo

    Yinmo

    Joined:
    Apr 16, 2016
    Posts:
    20
    I see, thanks a lot
     
  23. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Hi there,

    I'm considering purchasing your plugin but I'm hesitating to do so because I'm not sure it will do what I want as my case is a little unique. This is a little hard to explain so bear with me here. Basically what is happening currently is that I am refactoring my game to convert my sprite rendering from using Canvas Renderer to Sprite Renderer, and in this particularly scenario I am trying to blend two separate sprite images with a "Gradient" type blend:

    Fed_Ship_Lv9.png
    skin_iron_lines.png

    And the end result should be something like this(which is how it is in the Canvas Renderer solution):
    Screen Shot 2017-12-11 at 5.26.39 PM.png

    Unfortunately here's where it gets complicated. In the current solution that I'm using with Canvas, it is actually a simple C# script that is attached to the sprite object, which directly modifies the texture of the sprite without making any changes to the material of the sprite itself. This is important because I'm currently using a custom shader for the sprite that essentially converts the default color system to HSBC colors. Therefore, whatever new solution that I am converting to to address this issue needs to be one that does not replace the current material on the sprite(as seen in some other plugins I've purchased).

    So my question here is, would this plugin be able to help me with this issue?
     
    Last edited: Dec 11, 2017
  24. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Hi,

    By default the plugin will replace the material (the effect itself is achieved via shader).

    If you wish, I can make an extra shader, that will incorporate your custom shader and provide an option to apply a blend mode effect. But let me clarify one thing: do you actually need a blend mode effect here? As I can see on the screenshot, the images are just mixed using alpha channel. If you just want to 'crossfade' the sprites, the Blend Mode plugin won't really be necessary (it works with colors, not alpha).
     
  25. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Ah I think the screenshot I've shown here is not really a good example, but basically the "skin" needs to be able to blend with the ship texture, and still show the ship's outlines/contoues, if that makes sense? Don't think a crossfade can achieve that? (I'm pretty sure that the script i'm using also blends colors as well, judging from the code)

    This might probably be a better representation of what I'm looking for(It's not a perfect blend, i know, so if your plugin can do it better, that would be even more awesome!):

    Screen Shot 2017-12-12 at 11.49.07 AM.png
     
    Last edited: Dec 12, 2017
  26. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Ah, yeah, it looks like some blend mode is actually used here. Ok then, let's try it this way: send me (via support email or PM here) the custom shader you're using and I'll try to add blend mode effect for it. I'll then show you the result and if it will be ok -- you can purchase the plugin on the store and use it.
     
  27. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    I have no problems just posting the code here. It's mostly just what I managed to cobble up together based on other shader scripts I've seen and whatever meagre knowledge of shader programming i possess. I'll be happy if you can even see some ways of improving the shader itself since I'm almost certain I'm not doing everything right.

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. Shader "Unlit/Texture HSBC" {
    4.     Properties
    5.     {
    6.         //[PerRendererData] _MainTex ("Sprite Texture", 2D) = "black" {}
    7.         _MainTex("Base (RGB), Alpha (A)", 2D) = "black" {}
    8.         _Hue("Hue", Range(0.0, 1.0)) = 0
    9.         _Saturation("Saturation", Range(-1.0, 1.0)) = 0
    10.         _Brightness("Brightness", Range(-1.0, 1.0)) = 0
    11.         _Contrast("Contrast", Range(-1.0, 1.0)) = 0
    12.         _StencilComp ("Stencil Comparison", Float) = 8
    13.         _Stencil ("Stencil ID", Float) = 0
    14.         _StencilOp ("Stencil Operation", Float) = 0
    15.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    16.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    17.         _ColorMask ("Color Mask", Float) = 15
    18.         //[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    19.     }
    20.     SubShader
    21.     {
    22.         LOD 100
    23.         Tags
    24.         {
    25.             "Queue"="Transparent"
    26.             "IgnoreProjector"="True"
    27.             "RenderType"="Transparent"
    28.             "PreviewType"="Plane"
    29.             "CanUseSpriteAtlas"="True"
    30.         }
    31.         Cull Off
    32.         Lighting Off
    33.         ZWrite Off
    34.         Fog{ Mode Off }
    35.         Offset -1, -1
    36.         Blend SrcAlpha OneMinusSrcAlpha
    37.  
    38.         Stencil
    39.          {
    40.              Ref [_Stencil]
    41.              Comp [_StencilComp]
    42.              Pass [_StencilOp]
    43.              ReadMask [_StencilReadMask]
    44.              WriteMask [_StencilWriteMask]
    45.          }
    46.         ColorMask [_ColorMask]
    47.  
    48.         Pass
    49.         {
    50.             CGPROGRAM
    51.             #pragma vertex vert
    52.             #pragma fragment frag
    53.             #include "UnityCG.cginc"
    54.             // Function
    55.             inline float3 applyHue(float3 aColor, float aHue)
    56.             {
    57.                 float angle = radians(aHue);
    58.                 float3 k = float3(0.57735, 0.57735, 0.57735);
    59.                 float cosAngle = cos(angle);
    60.                 //Rodrigues' rotation formula
    61.                 return aColor * cosAngle + cross(k, aColor) * sin(angle) + k * dot(k, aColor) * (1 - cosAngle);
    62.             }
    63.             inline float4 applyHSBEffect(float4 startColor, fixed4 hsbc)
    64.             {
    65.                 float hue = 360 * hsbc.r;
    66.                 float saturation = hsbc.g + 1;
    67.                 float brightness = hsbc.b;
    68.                 float contrast = hsbc.a + 1;
    69.                 float4 outputColor = startColor;
    70.                 outputColor.rgb = applyHue(outputColor.rgb, hue);
    71.                 outputColor.rgb = (outputColor.rgb - 0.5f) * contrast + 0.5f + brightness;
    72.                 outputColor.rgb = lerp(Luminance(outputColor.rgb), outputColor.rgb, saturation);
    73.                
    74.                 return outputColor;
    75.             }
    76.             struct appdata_t
    77.             {
    78.                 float4 vertex : POSITION;
    79.                 float2 texcoord : TEXCOORD0;
    80.                 fixed4 color : COLOR;
    81.             };
    82.             struct v2f
    83.             {
    84.                 float4 vertex : SV_POSITION;
    85.                 half2 texcoord : TEXCOORD0;
    86.                 fixed4 hsbc : COLOR;
    87.                 fixed alpha : FLOAT;
    88.             };
    89.             sampler2D _MainTex;
    90.             fixed _Hue, _Saturation, _Brightness, _Contrast;
    91.             v2f vert(appdata_t v)
    92.             {
    93.                 v2f o;
    94.                 o.vertex = UnityObjectToClipPos(v.vertex);
    95.                 o.texcoord = v.texcoord;
    96.                 o.hsbc = fixed4(_Hue, _Saturation, _Brightness, _Contrast);
    97.                 o.alpha = v.color.a;
    98.                 return o;
    99.             }
    100.             fixed4 frag(v2f i) : COLOR
    101.             {
    102.                 float4 startColor = tex2D(_MainTex, i.texcoord);
    103.                 float4 hsbColor = applyHSBEffect(startColor, i.hsbc);
    104.                 hsbColor.a *= i.alpha;
    105.                 return hsbColor;
    106.             }
    107.             ENDCG
    108.         } // Pass
    109.     } // SubShader
    110.     SubShader
    111.     {
    112.         LOD 100
    113.         Tags
    114.         {
    115.             "Queue"="Transparent"
    116.             "IgnoreProjector"="True"
    117.             "RenderType"="Transparent"
    118.             "PreviewType"="Plane"
    119.             "CanUseSpriteAtlas"="True"
    120.         }
    121.  
    122.         Pass
    123.         {
    124.             Cull Off
    125.             Lighting Off
    126.             ZWrite Off
    127.             Fog{ Mode Off }
    128.             Offset -1, -1
    129.             ColorMask RGB
    130.             //AlphaTest Greater .01
    131.             Blend SrcAlpha OneMinusSrcAlpha
    132.             ColorMaterial AmbientAndDiffuse
    133.             SetTexture[_MainTex] { Combine Texture * Primary }
    134.         } // Pass
    135.     } // SubShader
    136. }
    NOTE: Keep in mind that this shader was created to use with UI Images instead of Sprites. It seems to work with Sprites the last I check, but it may not be properly optimized for it.
     
  28. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Got it. Can you please clarify, for which texture should HSBC apply (main, mask or both)? For example, when you blend ship texture with that gray texture, should HSBC params modify the ship, the mask or both of them? And should this modification happen before or after blend effect is applied?
     
  29. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Well the material with the shader is used by both the main and the "skin". Actually I should probably mention that the material is actually generated in runtime and shared across multiple game objects, not just the ship and skin in this case. Basically what this is being used for is for the feature in our game where we allow players to customize the colors of the ship(and components). I'm not sure what exactly happens with what the shader is doing(as i said i have little understanding of shader programming) in regards to your question, but i assume it should just apply to only the texture that the shader material is attached to? As for the other question, I assume it should be before the blend effect? Not really sure there as the blending was done purely through script that modifies the mesh directly. I'll attach the code for that script here just so can get a better idea of what it was doing:

    Code (CSharp):
    1. /// Credit Breyer
    2. /// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1780095
    3.  
    4. using System.Collections.Generic;
    5.  
    6. namespace UnityEngine.UI.Extensions
    7. {
    8.     [AddComponentMenu("UI/Effects/Extensions/Gradient")]
    9.     public class Gradient : BaseMeshEffect
    10.     {
    11.         public GradientMode gradientMode = GradientMode.Global;
    12.         public GradientDir gradientDir = GradientDir.Vertical;
    13.         public bool overwriteAllColor = false;
    14.         public Color vertex1 = Color.white;
    15.         public Color vertex2 = Color.black;
    16.         private Graphic targetGraphic;
    17.  
    18.         protected override void Start()
    19.         {
    20.             targetGraphic = GetComponent<Graphic>();
    21.         }
    22.  
    23.         public override void ModifyMesh(VertexHelper vh)
    24.         {
    25.             int count = vh.currentVertCount;
    26.             if (!IsActive() || count == 0)
    27.             {
    28.                 return;
    29.             }
    30.             var vertexList = new List<UIVertex>();
    31.             vh.GetUIVertexStream(vertexList);
    32.             UIVertex uiVertex = new UIVertex();
    33.             if (gradientMode == GradientMode.Global)
    34.             {
    35.                 if (gradientDir == GradientDir.DiagonalLeftToRight || gradientDir == GradientDir.DiagonalRightToLeft)
    36.                 {
    37. #if UNITY_EDITOR
    38.                     Debug.LogWarning("Diagonal dir is not supported in Global mode");
    39. #endif
    40.                     gradientDir = GradientDir.Vertical;
    41.                 }
    42.                 float bottomY = gradientDir == GradientDir.Vertical ? vertexList[vertexList.Count - 1].position.y : vertexList[vertexList.Count - 1].position.x;
    43.                 float topY = gradientDir == GradientDir.Vertical ? vertexList[0].position.y : vertexList[0].position.x;
    44.  
    45.                 float uiElementHeight = topY - bottomY;
    46.  
    47.                 for (int i = 0; i < count; i++)
    48.                 {
    49.                     vh.PopulateUIVertex(ref uiVertex, i);
    50.                     if (!overwriteAllColor && uiVertex.color != targetGraphic.color)
    51.                         continue;
    52.                     uiVertex.color *= Color.Lerp(vertex2, vertex1, ((gradientDir == GradientDir.Vertical ? uiVertex.position.y : uiVertex.position.x) - bottomY) / uiElementHeight);
    53.                     vh.SetUIVertex(uiVertex, i);
    54.                 }
    55.             }
    56.             else
    57.             {
    58.                 for (int i = 0; i < count; i++)
    59.                 {
    60.                     vh.PopulateUIVertex(ref uiVertex, i);
    61.                     if (!overwriteAllColor && !CompareCarefully(uiVertex.color, targetGraphic.color))
    62.                         continue;
    63.                     switch (gradientDir)
    64.                     {
    65.                         case GradientDir.Vertical:
    66.                             uiVertex.color *= (i % 4 == 0 || (i - 1) % 4 == 0) ? vertex1 : vertex2;
    67.                             break;
    68.                         case GradientDir.Horizontal:
    69.                             uiVertex.color *= (i % 4 == 0 || (i - 3) % 4 == 0) ? vertex1 : vertex2;
    70.                             break;
    71.                         case GradientDir.DiagonalLeftToRight:
    72.                             uiVertex.color *= (i % 4 == 0) ? vertex1 : ((i - 2) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f));
    73.                             break;
    74.                         case GradientDir.DiagonalRightToLeft:
    75.                             uiVertex.color *= ((i - 1) % 4 == 0) ? vertex1 : ((i - 3) % 4 == 0 ? vertex2 : Color.Lerp(vertex2, vertex1, 0.5f));
    76.                             break;
    77.  
    78.                     }
    79.                     vh.SetUIVertex(uiVertex, i);
    80.                 }
    81.             }
    82.         }
    83.         private bool CompareCarefully(Color col1, Color col2)
    84.         {
    85.             if (Mathf.Abs(col1.r - col2.r) < 0.003f && Mathf.Abs(col1.g - col2.g) < 0.003f && Mathf.Abs(col1.b - col2.b) < 0.003f && Mathf.Abs(col1.a - col2.a) < 0.003f)
    86.                 return true;
    87.             return false;
    88.         }
    89.     }
    90.  
    91.     public enum GradientMode
    92.     {
    93.         Global,
    94.         Local
    95.     }
    96.  
    97.     public enum GradientDir
    98.     {
    99.         Vertical,
    100.         Horizontal,
    101.         DiagonalLeftToRight,
    102.         DiagonalRightToLeft
    103.         //Free
    104.     }
    105.     //enum color mode Additive, Multiply, Overwrite
    106. }
     
  30. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Thanks for the detailed explanation!

    Here is a demo of the shader I've assembled:

    Feel free to ask for additional tweaks in case it's not exactly what you need.
     
  31. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Hi this demo video should demonstrate what is needed so as long as I can do the same thing (or better!) as shown here it would be great. :)

     
  32. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Ah, so the HSBC should apply only to the main texture, after all. Ok, I'll tweak it that way.

    All the other effects (and more) are achievable with the shader.
     
  33. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Haha yea wasn't entirely sure what you meant exactly but glad that got cleared up. Thanks!
     
  34. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    So i tried using the plugin. Everything seems fine, except for one thing. It doesn't seem to work with masks as seen in the screenshot below(the fire image is the skin). Note here I'm not using the way of using the plugin that was recommended in the documentation(due to some problems).

    Screen Shot 2017-12-21 at 3.49.23 PM.png

    I managed to fix it myself by re-adding some of the parts of the original shader script that you removed back into your HSBC shader. You might want to update that bit as well. Thanks!
     
    Last edited: Dec 21, 2017
  35. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Also another thing, with the changes you made to the shader, how much impact does it have on performance? It needs to be mobile friendly.
     
  36. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    I've actually wrote the shader from scratch and only looked for the params that was used and the HSBC functions. Didn't notice the mask feature, my bad. Will update the shader in the feature releases.

    The variant of the blend mode effect used in the shader is mobile friendly (doesn't use grab pass) and should not cause any issues on mobiles or any other platforms.
     
  37. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Alright, all good then! Thank you!
     
  38. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Actually there is one more issue. I'm not sure if it is because of the way I implemented it, but there seems to be some more "fade" on the bottom part of the texture compared to the top. Do you know if that is possible to be fixed?

    Screen Shot 2017-12-22 at 2.43.08 PM.png
     
  39. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    You can control the fade gradient with "Overlay Opacity Ramp" parameter. Setting it to 0 will completely hide the overlay and 1 will fill the overlay uniformly (so that bottom part will not be faded more than top).
     
  40. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Unfortunately if I use that the color changes will stop working.
     
  41. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Seems like I've got it a bit wrong; here is another iteration: https://gist.github.com/Elringus/57098d1e904e51b0f24e384965de29dc Just replace "Extra/SpriteGradientHSBC" shader file with this one.

    By default it won't apply opacity ramp now (any sort of fading of the overlay layer), but you'll be able to use an opacity mask in case you'll need it in the feature.
     
  42. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    I just tried it but it's still fading the bottom part of the texture. :/

    It is also no longer working with any parent masks anymore. I assume this has to do with the Opacity Masks you were referring to? How do I use it exactly? Screen Shot 2018-01-09 at 11.01.31 AM.png
     
  43. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    That’s strange. Please try to completely remove the old shader and any associated materials and add new one again.

    Not sure what you mean about the parent masks. The only thing I’ve changed is removed the opacity ramp (when bottom was fading) and added opacity mask texture instead. When opacity mask texture slot is empty it should behave exactly like before, but without the bottom fading effect.
     
  44. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Didn't work. Still the same thing. It also doesn't seem to change colors the same way as it did previously. That being said, I was actually directly using the shader in the same way I have been using my original shader previously. It worked fine with the previous iteration of your shader that's why I just kept it as is. Would that have been a factor?

    What I meant was that it was ignoring any parent object masks in the hierarchy. In the screenshot above, the "skin" is a child of the ship object, which has a mask.
     
  45. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    I didn't quite get how this additional masks (skins) should work. Are they using SpriteMask component? I didn't consider complex setup like this; the intent was to allow to use just one sprite material for all the effects you need (that would also be better for performance, which was the original objective, I believe).

    I've attached a demo scene that should make it clear on how to use the shader; please take a look and describe the features that the material is missing; I will try to add them to the shader (if possible) or think on how to make it work with other components.
     

    Attached Files:

  46. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Yea I wasn't using the Overlay Texture for the skin in my current system, but either way the shader needs to be able support accepting parent object Sprite/UI Masks as well. It was working previously when you were using the Opacity Ramp, but with the addition of the Opacity Mask seems to have removed that feature.

    EDIT: I just realized that there might have been some confusion because I am currently still using the Canvas Renderer system(along with the Gradient script that I was using) to test this, so the shader needs to work for both systems if possible.


    Also in the demo you uploaded above, the changes you've made to the shader seems to have adjusted the default Brightness result a little(when no Overlay Texture is applied). If I set everything to 0, the texture seems to have higher brightness than normal.

    Screen Shot 2018-01-10 at 11.03.35 AM.png


    EDIT 2: Actually, give me some time I'll update that demo scene to include all the different variants that I could be using this shader with, by including the current working shader that I'm using.
     
    Last edited: Jan 10, 2018
  47. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
    Ok I figured out what's going on. Basically I was mostly testing the shader using Canvas Renderer(which I am currently still using) as it was working with the previous iteration of your shader but I forgot that it was also still using the Gradient script for the blending(which was why it was working but was also causing the problem with opacity at the bottom). I've updated the demo scene to include the different test cases so you can have a clearer picture of what is needed. Let me know if the demo scene doesn't match the screenshot below in case I missed something.

    Screen Shot 2018-01-10 at 12.22.21 PM.png

    I'll be happy as long as you could get it working with the Sprite Renderer as I can just keep using the current working shader for the Canvas Renderer until i fully switch over to using Sprite Renderer, though it'd be great if it could also work for Canvas as well(in case I want to use the shader for the UI system).

    Essentially the issues that needs to be considered are:
    1) Getting it to work with parent Sprite Masks
    2) Getting the blending to work right, as the Overlay Texture method you are using doesn't seem to be blending it the way it should be? Compare 1st and the last test cases(minus the opacity issue) in the screenshot above to see what I mean.
     
    Last edited: Jan 10, 2018
  48. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    371
    Ok, I'll take a look, but lets continue our discussion in private. Please ping me via support email so I'll know where to respond.
     
  49. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    35
  50. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    793