Shader: Creating a shader that acts like Photoshops 'Color' blendingmode

Hello there,

I am having trouble creating a shader that behaves like the ‘Color’ layer effect in Photoshop. I have Googled my ass of to find a decent shader for this but it lead to nowhere.

What I want to achieve is the following: I have gray-scaled images for my menu buttons and I want to colorize the gray areas in the image. The default shaders like ‘Transparent/Diffuse’ is almost what I want except that it also colorizes the white pixels, and I only need the gray areas to colorize.

I am stuck with this. Is there anybody who can help me? I basicly need a shader with one texture input and one colour input that automagicly combines the two into what I need.

In the following image you can see what I am trying to achieve:
alt text

Your codes are not giving me correct result for replicating the "Color" blending mode of Photoshop. I am Googling for a solution, and I have not found any yet. Somebody can help me?

3 Answers

3

Well I’m hope it’s not too late for you but I think I might have found the solution for this:

Just use this Shader that is a modified version of Unlit Transparent Colored and copies the Photoshop’s Overlay behavior on Layers.

Shader "Unlit/Photoshop Overlay"
{
    Properties
    {
        _MainTex ("Base (RGB), Alpha (A)", 2D) = "" {}
    }
    
    SubShader
    {
        LOD 100

        Tags
        {
            "Queue" = "Transparent"
            "IgnoreProjector" = "True"
            "RenderType" = "Transparent"
        }
        
        Pass
        {
            Cull Off
            Lighting Off
            ZWrite Off
            Fog { Mode Off }
            Offset -1, -1
            ColorMask RGB
            AlphaTest Greater .01
            Blend SrcAlpha OneMinusSrcAlpha
            ColorMaterial AmbientAndDiffuse
            
            SetTexture [_MainTex]
            {
                Combine Texture +- Primary, Texture * Primary
            }
            
            SetTexture [_MainTex]
            {
                Combine Texture +- previous, Texture * Primary
            }
        }
    }
}

Good luck.

Have a look at the code here: Photoshop math with GLSL shaders | Projects, Software, Programming, GLSL - Romz Blog - but essentially you convert to the HueSaturationLuminance (HSL)-colorspace, and replace the Hue with your input hue.

“Overlay” is not “color” these act very differently in Photoshop. Overlay is additive, it makes tings lighter (closer to white), color leaves sum RGB value the same.

For example I need a shader that makes things monochrome. In photoshop I create a white colour layer and issue blending mode “color”, this makes it grayscale. Next I make another color blending layer with a desired colour.

"I need" is not something we want to read on Unity Answers. Feel free to hire a Unity Expert on Unity Connect if you want someone to do the job for you without putting some effort into solving your own problem first of all.

The formula is like this: Input = int( (R + G + B)/3) = iR iG iB --- this gives approximated grayscale value Shader colour = sR sG sB --- simple rgb value input Now do for each color: R = iR + sR; iG - sR/2; iB - sR/2 G = iR - sG/2; iG + sG/2; iB - sG B = iR - sB/2; iG - sB/2; iB + sB Values capped to 255 of course.