Basically, what I’m trying to do is apply a texture over a game model’s main texture. The texture being applied contains some colors that the player is painting on in order to make the object look like it’s being painted. However, some of the things I’ve tried to do don’t seem to work, and I’m not sure what the issue is. Here is what I’ve tried so far:
Shader "Gameplay/PaintingShader"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_PaintRenderTex ("Paint Render Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf StandardSpecular fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
sampler2D _PaintRenderTex;
struct Input
{
float2 uv_MainTex;
float2 uv_PaintRenderTex;
};
void surf (Input IN, inout SurfaceOutputStandardSpecular o)
{
fixed4 main = tex2D (_MainTex, IN.uv_MainTex);
fixed4 paint = tex2D (_PaintRenderTex, IN.uv_PaintRenderTex);
o.Albedo = main.rgb * paint.rgb;
o.Alpha = main.a;
}
ENDCG
}
FallBack "Diffuse"
}
This causes the textures to “mix” together. So if the main texture has brown and the applied texture is blue, a green color is painted on the game model instead of the blue because the colors are mixing. here is my other attempt:
Shader "Custom/Paint"
{
Properties
{
_MainTex ("Albedo (RGBA)", 2D) = "white" {}
_PaintTex ("Paint Texture (RGBA)", 2D) = "white" {}
_BlendAmount("Blend Amount", Range(0.0, 1.0)) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _PaintTex;
fixed _BlendAmount;
struct Input {
float2 uv_MainTex;
float2 uv_PaintTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 main = tex2D (_MainTex, IN.uv_MainTex);
fixed4 paint = tex2D (_PaintTex, IN.uv_PaintTex);
o.Albedo = lerp(main.rgb, paint, main.a * _BlendAmount);
}
ENDCG
}
FallBack "Diffuse"
}
This has been a problem because even though the applied texture is transparent over the areas with no color, the applied texture will completely take over the main texture with a single color. The blending between textures works, but Unity (or something) doesn’t seem to recognize that the applied texture has any transparency. Can anyone suggest what I should be doing to achieve the affect that I am looking for?