- Home /
Possible for a shader to have two decal slots?
Is it possible to have a shader like shown below? A shader that has two slots for transparent textures. I want one texture to be lower than the other - like the decals are applied in layers. I've tried probably 10 different decal shaders and none of them can do what I'm asking for here. Some accept multiple textures but then will not allow both textures to have transparency. Also I need offset/tiling access to both layers (independently - my meshes have two UVs if that will help)
Anyone have any ideas on how I can accomplish this? The technique I'm using below is functional but isn't as optimized as I believe a dedicated shader would be.
You could have a custom shader with, say, 3 textures. One as the main albedo and 2 as the decals. In the application of the albedo texture, add the 2 other textures to the main albedo. If they have black in the transparent (should work with transparent though) they should blend.
Here's what I have so far. This is taking two textures, both which can be transparent, but they are controlled by the slider. What I need is to have the two textures to just have their alpha transparent, and to be able to tell one to stay on top of the other. Does that require adding an albedo texture?
Shader "Custom/z_BlendTex_Test"
{
Properties{
_Blend("Blend", Range(0,1)) = 0.5
_$$anonymous$$ainTex("Tex1", 2D) = ""
_$$anonymous$$ainTex2("Tex2", 2D) = ""
}
SubShader
{
Lighting On
Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
Pass{
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
SetTexture[_$$anonymous$$ainTex]{
Combine texture
}
SetTexture[_$$anonymous$$ainTex2]{
ConstantColor(0,0,0,[_Blend])
Combine texture Lerp(constant) previous
}
}
}
Fallback "Diffuse"
}
Didn't realise you're working in shaderlab, can't really help you there, sorry. I also thought you were doing everything (including base texture work) in one shader.
Answer by Autonoma · Apr 22, 2016 at 01:58 PM
Figured it out - this requires two passes, but I'm fine with that. I was mainly trying to avoid having to have multiple meshes.
Shader "Custom/Priority Transparent" {
Properties{
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
_SecondTex("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha:fade
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
CGPROGRAM
#pragma surface surf Lambert alpha:fade
sampler2D _SecondTex;
fixed4 _Color;
struct Input {
float2 uv_SecondTex;
};
void surf(Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_SecondTex, IN.uv_SecondTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Legacy Shaders/Transparent/VertexLit"
}
Answer by neufoctobre · Oct 17, 2017 at 02:15 PM
Hi,
This Shader is perfect for what I need, is this shader is good for mobile performance ?!
Thanks !
Your answer
Follow this Question
Related Questions
Adding a clip() to the default shader? 0 Answers
Shader - What is float3.xy? 1 Answer
How to add Emission to my custom shader? 2 Answers
Drawing silhouette shader 0 Answers
Shader: Modify XY Position of Texture 0 Answers