- Home /
Unity Custom CutOut Shader
Hey guys!
I've been searching Google, Unity forums and Unity Answers, all looking for a simple solution to my problem.
I downloaded the latest source files for built in shaders.
I then adapted the Cutout Diffuse/Spec/Normal/NormSpec shaders to use a custom texture for my alpha. This is primarily for carpet edges, fade out effects, etc.
The problem I've come across is that for lightmapping, it seems to always want to use the Alpha Channel of "_MainTex", regardless of how I have set up the surface shader.
In a previous thread I read that downloading the Extended Lightmapper plugin would help, but I didn't see any settings that would help with this case.
So is this to do with Unity's internal workings, or is it because of the fallback shader handling the shadow casting.
If it's the latter, how do I fix this?
Here's the Cutout Diffuse Shader. You can see how little of a change I made.
Shader "Fade/Diffuse"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_AlphaTex ("Alpha", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 300
CGPROGRAM
#pragma surface surf Lambert alphatest:_Cutoff
sampler2D _MainTex;
sampler2D _AlphaTex;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float2 uv_AlphaTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 MAIN = tex2D(_MainTex, IN.uv_MainTex) * _Color;
fixed4 ALPHA = tex2D(_AlphaTex, IN.uv_AlphaTex);
o.Albedo = MAIN.rgb;
o.Alpha = ALPHA;
}
ENDCG
}
FallBack "Transparent/Cutout/Diffuse"
}
Thanks!
$$anonymous$$ay help future googlers:
Answer by atolver · Nov 07, 2014 at 03:21 PM
If you just want the alpha from your alpha texture, you should use ALPHA.a.
Unless you are trying to calculate alpha from the RGB values as well. In such a case, you would need to tell the shader which calculation to use (like adding the RGB values together or using the dot product).
Hey atolver!
In terms of the actual display of the end material, it looks great.
I'm referring to the Beast Lightmapping issues.
No matter how the surface shader is set up, no matter where the end alpha comes from, etc, Beast still tries to use the non existent(blank) alpha channel of _$$anonymous$$ainTex.
Ah, gotcha. I don't know much about Beast.
This is just specualation, but it sounds like Beast is looking to use the alpha from something called "$$anonymous$$ainTex". Have you tried simply switching the names of the variables? That is, get your alpha value from $$anonymous$$ainTex and then get your color values from _AlphaTex. It's not uncommon for shaders to use predefined variable names.
Hey atolver!
I've already stated in my main question that Beast uses "_$$anonymous$$ainTex.a", but for some effects I was looking to be able to use an entirely different texture.
I can't swap out the variables names because _$$anonymous$$ainTex is being used for diffuse, which is also passed to the fall back shader.
I'm asking if anyone knows how to get beast to accept a different texture for alpha.
I want to know if it's possible, or if it's a limitation.
Your answer
Follow this Question
Related Questions
Particle Cutout that cast shadow ? 2 Answers
Is there any double sided shadow casting transparent cutout shader? 3 Answers
Toon Shader Working With Multiple Spotlight Shadows (Pro) 0 Answers
(SOLVED) How to bake lightmaps with transparent cutout shader ? 2 Answers
Shader: Cutout behavior mixed with masking behavior 0 Answers