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.

Blending two colors with texture AND weighting

Discussion in 'Shaders' started by Zita, Dec 16, 2014.

  1. Zita

    Zita

    Joined:
    Oct 24, 2014
    Posts:
    17
    Hi

    Can somebody help me with this shader?

    I have two colors which I want to blend between using an alpha-texture. This works fine. Now I need to add support for a "blend-weight". This should work as to shift the blending between the two colors to be only Color1 when Weight is 0 and only Color2 when Weight is 1, no matter what the texture says. When Weight is 0.5 it should be an even blend according to the texture as normal.

    But what do I need to change?

    Shader "ColorBlender" {
    Properties {
    _Color1 ("Color1", Color) = (0,0,1,1)
    _Color2 ("Color2", Color) = (1,0,0,1)
    _Weight ("Weight", Range (0.0,1.0)) = 0.5
    _MainTex ("Texture", 2D) = "white" {}
    }

    SubShader {
    Tags { "Queue" = "Transparent" }
    Pass {

    Lighting Off
    Cull Off

    Color [_Color1]

    SetTexture [_MainTex]
    {
    ConstantColor [_Color2]
    Combine constant Lerp(texture) primary
    }
    }
    }
    }
     
  2. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    You should write vertex and pixel shaders for this case, because its impollible to make this with FF shader pipeline.
     
  3. Zita

    Zita

    Joined:
    Oct 24, 2014
    Posts:
    17
    If I limit the weighting to 0 -> only Color1 and 1 -> blended as normal. Still impossible?

    Can't the primary color be weighted somehow? Then it wouldn't matter what the texture-block does...

    I prefer to keep this simple so that it work on as many devices as possible, but that might not be a problem anyway? Im very new to this...
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,465
    This fixed pipeline code will actually be converted into normal shader code anyway. The fixed pipeline is not actually supported anymore.
    From this topic:
     
unityunity