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. Dismiss Notice

Question How to implement blend mode "Color" in shader

Discussion in 'Shaders' started by unity_NpcxBF-EduiEdA, Nov 25, 2022.

  1. unity_NpcxBF-EduiEdA

    unity_NpcxBF-EduiEdA

    Joined:
    Apr 9, 2019
    Posts:
    10

    Attached Files:

  2. JuanGuzmanH

    JuanGuzmanH

    Joined:
    Feb 8, 2018
    Posts:
    70
  3. unity_NpcxBF-EduiEdA

    unity_NpcxBF-EduiEdA

    Joined:
    Apr 9, 2019
    Posts:
    10
  4. JuanGuzmanH

    JuanGuzmanH

    Joined:
    Feb 8, 2018
    Posts:
    70
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    That afore linked shader file explicitly says it’s a port of that ShaderToy.

    Photoshop’s Color blend node works by converting both inputs from RGB to HSV, then lerping the H(ue) of the base to the overlay, and then converting back to RGB.

    Annoyingly, Unity does not provide any Shader Graph nodes for conversion between RGB and HSV. (It does for the VFX Graph.) So you’d have to copy the HLSL code from the appropriate functions into one or several Custom Function nodes to do those conversions.
     
  6. blunarvratislav

    blunarvratislav

    Joined:
    Sep 9, 2020
    Posts:
    1
    I could't find the exact math behind the Photoshop Color blend mode, but I made my own shader that works in almost the same way, the result are just a tiny bit different.

    I don't know if you still need it, but for anyone who may need it later, here it is
    https://github.com/veebe/ColorShader/blob/main/ColorBlendShader.shader
     
    petermochnacky likes this.