- Home /
[Solved] Shader: cutout shader over a texture
Hello community,
Currently i'm trying to make a shader that has a main texture + a transparent(cutout) texture/layer on top of it. Imagine this as a 'skin & eyebrow' situation the main texture is the skin. The eyebrow texture is suppose to be the transparent overlaying part of the shader.
The current code only seem to show the material color as it's base, the code as below does need an extra texture my question is, how to swap the material color as the background layer and use a texture instead in order to get a (png eyebrow) over a skin texture. It is a really basic concept but i've just started looking into the whole shader department so if anyone can help me on my way, please do ;) Here is what the shader code currently looks like:
Shader "custom/headshader" {
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGBA)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 250
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float2 uv_DecalTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = lerp(_Color, c.rgb, c.a);
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
}
Isn't Decal what you are describing? Note that I am not familiar with shaders but decal is simply having one main texture and a tetxure to apply on top of it.
Hi fafase, yes it was decal which i was looking for but with a alpha channel for the second texture, the code by electricsause in the answers below solved it.
Answer by electricsauce · Jun 01, 2013 at 03:44 PM
I think you're trying to display a one texture on top of a background texture but what you're doing is using the cloud alpha to cutout the background.
Try this instead: http://answers.unity3d.com/questions/273680/transparent-cutout-shader.html
Thank you for your reply, i tried that thread one before somehow it doesn't work on the specific model (it does on others) It is the same idea what i want to achieve i've noticed that the previous code above didn't seem to work for me anymore the new code above[edited post] is the one i'm currently using which is almost doing what i want except it uses the material color as 'base texture' for the transparant texture.
Do you have any pics of the effect you're looking for and what you have so far?
I don't do surface shaders much, but try this:
Shader "Custom/z_BlendTex_Test" { Properties
{
//we're not using color in this shader
//_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
_$$anonymous$$ainTex ("Base (RGBA)", 2D) = "white" {}
_DecalTex("Decal Texture (RGB)", 2D) = "white" {}
_BlendAmount("Blend Amount", Range(0.0, 1.0)) = 1.0
}
SubShader
{
//rendertype opaque means we're not using a transparent shader
Tags { "RenderType"="Opaque" }
LOD 250
CGPROGRA$$anonymous$$
#pragma surface surf Lambert
sampler2D _$$anonymous$$ainTex;
sampler2D _DecalTex;
fixed _BlendAmount;
//fixed4 _Color;
struct Input
{
float2 uv_$$anonymous$$ainTex;
float2 uv_DecalTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex);
fixed4 cd = tex2D(_DecalTex, IN.uv_DecalTex);
//switch the order of c and cd in the lerp function to change the cutout effect
o.Albedo = lerp(cd, c.rgb, c.a * _BlendAmount);
//we don't need to pass the alpha since we're not using transparency
//o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
}
Hi thanks a lot for looking into it, and putting up some side notes. it worked exactly how i wanted it after switching the order of c and cd around (line 35). It was kind of weird as without switching the order around it didn't filter out the transparent part of the png file out. - Anyway it works thanks again!!
Your answer
Follow this Question
Related Questions
apply transparent png, material color shine through 3 Answers
Models becoming transparent 1 Answer
Remove white edges on texture help 2 Answers
PNG or TGA32 for semitransparent material 2 Answers
About shader! 0 Answers