- Home /
Avatar T-Shirt Color With Print
Hi i'm working in a T-shirt with a print, and I need that the main color don't affect the the print Like This without multiplying or change the color of the print. How do I can make change the color of the shirt without affect the print.
I'm using a png(Alpha) only with the print, but when i add to a shader it changes the color.
Answer by sirival · Dec 04, 2012 at 11:55 PM
You need to write a custom shader for this that would use a mask like the texture's alpha channel, to decide which parts of the model to tint. For example when the alpha is 1 you will use the texture color multiplied with the tint and when the alpha is 0 you will only use the texture color without multiplying it with a tint.
Let me know if you need more info on this.
hi, i read your answer and i didn´t understand very well so i did this shader, i noticed that the second texture it is not required because i'm only modifing the main color and when i do that the main texture also change its color. How can i do to print one texture which is going to be modify and then print the main texture whitout being affected by the color that i'm modifing?
Shader "ShaderAvatar/TShirt" {
Properties {
_Print ("Print", 2D) = "white" {}
_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
_BaseColor ("Base", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Transparent" }
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
CGPROGRA$$anonymous$$
#pragma surface surf Lambert
sampler2D _Print;
sampler2D _BaseColor;
fixed4 _Color;
struct Input {
float2 uv_Print;
float2 uv_BaseColor;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 d = tex2D (_Print, IN.uv_Print);
fixed4 c = tex2D(_BaseColor, IN.uv_BaseColor) * _Color;
o.Albedo = c.rgb;
o.Albedo *= d.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
Answer by ChristianLeyva · Dec 05, 2012 at 08:15 PM
I DID IT :D
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public float r=0,g=0,b=0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GameObject.Find("polySurface1").renderer.material.SetColor("_Color",new Color(r,g,b,1));
}
}
Shader "ShaderAvatar/TShirt" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_BlendTex ("Alpha Blended (RGBA) ", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Pass {
// Apply base texture
SetTexture [_MainTex] {
constantColor[_Color]
combine constant lerp(texture) previous
}
// Blend in the alpha texture using the lerp operator
SetTexture [_BlendTex] {
combine texture lerp (texture) previous
}
}
}
}
Hi, ¿How do I enable the scene light in the Shader?
Answer by sirival · Dec 05, 2012 at 09:39 PM
To make more clear what I was telling you in my first response, what I meant was that you can use only 1 texture for the whole thing.
The RGB of the texture will contain the print for your t-shirt. Now in the alpha channel of that texture you can set a pixel to 1 when you want it to be modified with a Color or set it to 0 when you do not want it to be modified ( so your print will be copied to the alpha channel of the texture as a black area ).
In your shader code you would do something like this:
half4 texColor = tex2D( _MainTex, IN.uv ); o.Albedo = lerp( 1, _Color, texColor.a ) * texColor.rgb;
That way you save memory and it will probably be more efficient as you do not have two texture accesses but only one.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084949im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Translate or Rotate a texture of a cube 2 Answers
Do alpha cut off with seperate texture? 1 Answer
Add transparency to this shader? 0 Answers
Toon and fun Shader or texture 1 Answer