Hello everyone.
I’ve got a request for a custom shader, if any of you are willing.
I’m proficient with C#, but shader language is complete greek to me. I’ve done some searching to find the particular functionality that I’m looking for, but I haven’t been able to figure out how to combine what I’ve found into a single shader.
I suppose I COULD go and learn all about shaders and how to write them, but I thought I’d ask here first!
I would like a single material, with two textures. I would like the material to use texture coordinates from two different sets of uvs. In this case, uv and uv2, in the filters mesh instance. Here is a shader I’ve found that can do that:
Shader "Custom/twotex" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AoTex ("AO (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
sampler2D _AoTex;
struct Input {
float2 uv_MainTex : TEXCOORD0;
float2 uv2_AoTex : TEXCOORD1;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex.xy);
half4 ao = tex2D (_AoTex, IN.uv2_AoTex.xy);
o.Albedo = c.rgb * ao.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
I realize that uv2 is intended to be used for light maps. This particular game takes place in space, there are no static meshes, and nothing that’s going to be baked into lightmaps, so I’m happy to use their uv coordinates for this reason.
Secondly, I would like the SECOND texture (uv2) to mask the first. Anything transparent in texture 2 should be transparent in texture 1.
Here is a shader I’ve found that allows me to do that:
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent" }
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous * texture}
}
}
}
What would the combined shader look like? Thanks in advance!
EDIT:
Thanks again to @jvo3dc , who helped solve this problem. Working shader:
Shader "Transparent/UV2Mask" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_MaskTex ("Mask (RGB)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex;
sampler2D _MaskTex;
struct Input {
float2 uv_MainTex : TEXCOORD0;
float2 uv2_MaskTex : TEXCOORD1;
};
void surf (Input IN, inout SurfaceOutput surface) {
half4 col = tex2D (_MainTex, IN.uv_MainTex.xy);
half4 mask = tex2D (_MaskTex, IN.uv2_MaskTex.xy);
surface.Albedo = col.rgb;
surface.Alpha = mask.a;
}
ENDCG
}
FallBack "Diffuse"
}