Add Colour tint onto another shader?

Been messing with shaders recently combining a few things and thought I was getting the hang of this (simple things, like allowing bump maps to other shaders). What I want to do is colour materials at runtime. Looking at the unity documentation this is supposed to be the simplest of the simple.


Shader "Tutorial/Basic" {
Properties {
    _Color ("Main Color", Color) = (1,0.5,0.5,1)
}
SubShader {
    Pass {
        Material {
            Diffuse [_Color]
        }
        Lighting On
    }
}

}


That is how colour is added. I have tried and tested over and over and I can’t seem to get it to work in my shader. Looking at it the one I’m editing doesn’t even have a pass that I can see. So my question is quite Simply how do I add this onto this script here?


Shader “Custom Shaders/PlanetBlend” {

Properties {
 _Color ("Main Color", Color) = (1,1,1,1)
  _MainTex ("Texture (RGB)", 2D) = "white" {}
  _SliceGuide ("_SliceGuide (RGB)", 2D) = "white" {}
  _SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.5
  //New
  _BumpMap ("Bumpmap", 2D) = "bump" {}
}
SubShader {
  Tags { "RenderType" = "Opaque" }
  Cull Off
   //Lighting Off
  CGPROGRAM
  #pragma surface surf Lambert addshadow
  struct Input {
      float2 uv_MainTex;
      float2 uv_SliceGuide;
      float2 uv_BumpMap;
      float _SliceAmount;
  };
  sampler2D _MainTex;
  sampler2D _SliceGuide;
  sampler2D _BumpMap;
  float _SliceAmount;

  void surf (Input IN, inout SurfaceOutput o) {
      clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount);
      o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
      o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;  

  }
  ENDCG
}
Fallback "Diffuse"

}


Many thanks. I don’t need a direct answer, but a educational nod to where I’m going about this wrong would be nice. :slight_smile:

In this bit-

sampler2D _MainTex;
sampler2D _SliceGuide;
sampler2D _BumpMap;
float _SliceAmount;

You need to add the line

float4 _Color;

and from then on, you can use the Color value you input in the top of the shader inside your CG bit! In this case, it’d go something like this-

o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;

Which would multiply the main texture with the tint colour.

(Small disclaimer- I am hardly an expert on CG scripting, but I know how to hack a few things together)

To multiply the rgb, use .rgb in both cases

o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color.rgb;

This is called "swizzling’ and the two operands must be swizzled compatibly (in this case three elements in each)

BUT I’m not sure multiplying is the right way to tint something. He’e a gedanken experiment to show why…

(r,g,b) * (0,1,0) = (0,g,0)

See? Rather then tinting its totally removes (sets to black) any color that isnt green.

What I think you are reaching for is something like an averaging of the hues, which would require color space conversion. (Im working on the same problem right now.)

eror in colorcorrection

Assets/Standard Assets/Image Effects (Pro Only)/ColorCorrectionEffect.cs(6,14): error CS0101: The namespace `global::' already contains a definition for `ColorCorrectionEffect'