Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Ludus · Nov 01, 2011 at 01:02 PM · shadercolourpasstint

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. :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by syclamoth · Nov 01, 2011 at 03:14 PM

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)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ludus · Nov 01, 2011 at 06:40 PM 0
Share

Thanks for your help but I still can not seem to get it working. Played with both lines lots but nothing takes.

Would I need to add this in here? Or am I on the wrong track still.Have been messing with it regardless.

sampler2D _$$anonymous$$ainTex;

   sampler2D _SliceGuide;
   sampler2D _Bump$$anonymous$$ap;
   float _Color; //This bit here? Inside the sample section?
   float _SliceAmount;

Got anymore advice? I'm quite baffled.

avatar image syclamoth · Nov 02, 2011 at 03:10 AM 0
Share

No, it specifically has to be a float4. NOT a float. There's an important difference- a float only has one channel, where a float4 has 4 (since it represents a colour value).

You can use a half4 if you don't want to use as much memory (at the cost of accuracy, of course).

avatar image Ludus · Nov 02, 2011 at 10:11 AM 0
Share

Thanks for explaining the float issue. Only problem is just this one line which doesn't take.

o.Albedo = tex2D ($$anonymous$$ainTex, IN.uv$$anonymous$$ainTex).rgb * _Color;

And thanks for sticking with me throughout these questions :)

avatar image syclamoth · Nov 02, 2011 at 01:20 PM 0
Share

I don't really know how to make those go together properly- just try a few permutations. Now that you've got your _Color value in there, you can do whatever operations you need to on it- so long as they fit within the syntax of the CG shader language (which I'm honestly not that familiar with).

avatar image
0

Answer by jeffpk · Jun 26, 2012 at 04:58 PM

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.)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by BlackHunter · Oct 28, 2012 at 01:19 PM

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'
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kryptos · Oct 28, 2012 at 01:28 PM 0
Share

Don't post answer with your own question.

moderators with enough karma please delete this useless and non-relevant post.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Colour tinting layered textures with transparencies. 1 Answer

single-pass particle render shader 1 Answer

How do you send output from one shader pass to another? 0 Answers

Animation clip and color curves 0 Answers

Multi materials for one mesh 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges