How to write shader for hard light blend mode in unity

Hi.

I’m trying to implement hard light blend mode similar to photoshop hard light blend mode. Bellow you can see example output from photoshop and output from my shader. As you can see outputs aren’t equal. I know that I’m doing something wrong but I don’t know what because I’m newbie in shader programming. For hard light blend mode I used formula from here. So I will be very thankful for any help or idea. Thanks.

Source code of my shader:
https://bitbucket.org/maho125/hardlight/src/ca0db7486768e0e157cde48c1cd590ff43fe1bb8/Assets/Shaders/Hard%20Light.shader

Hard Light in Photoshop:

​IMG

Output from my shader:

​IMG

I recently wrote an overlay shader. According to Wikipedia, it’s the same as hard light, except a and b are swapped.

My fragment is as follows…

 fixed4 frag(vertexOutput input) : COLOR
 {
    fixed4 output = 0;

    fixed4 inputA = tex2D(_MainTex, input.tex);
    fixed4 inputB = _Color;

    output = (inputA < 0.5) ? 2*inputA*inputB : 1-2*(1-inputA)*(1 - inputB);
    output = lerp(inputA, output, _Blend);
    output.a  = inputA.a * inputB.a * _Transparency;

    output.a  = inputA.a * inputB.a * _Transparency;
 }

Note, I’m doing a couple things different here than what you’ll ultimately need. First, this is an “Overlay” not “Hard Light” blend mode, but it should be a matter of swapping which color is assigned to “a” and “b” Blend modes - Wikipedia. Second, I’m blending a texture and a color. It sounds like you want to blend a texture with the scene, so your use of a grab pass appears necessary.

As @tanoshimi mentioned, you don’t have a blend mode specified. Since the blending has already happened in the shader,…

Blend SrcAlpha OneMinusSrcAlpha 

…should work (it did for me).

Lastly, this line…

output = lerp(inputA, output, _Blend);

…functions the same as the “Opacity” property of a layer in photoshop.

The “_Transparency” property…

output.a  = inputA.a * inputB.a * _Transparency;

…was just to allow me to fade out the object being rendered altogether.