- Home /
How to control Alpha Cutoff across the length of an object, is that even possible?
I'm starting to understand what's the deal with transparency depth sorting, ie. why it doesn't work right in Unity, or anywhere else, no matter what and that it's a royal pain in the butt and makes me want to throw my laptop through the window...
So now I am looking at the cutout shaders, which apparently don't have these problems. I know I can animate the alpha cutoff value from a script, which is a good start. My gloss map is basically the same as my bump map, so animating the alpha cutoff value makes it disappear from its creases outward, which actually looks cooler than a 'real' alpha fade.
But can I map gray values of an image file to alpha cutoff values in the shader- or more usefully, two separate images that I can blend between?
"/!\ No results found for 'alpha cutoff map'." —The Google
I want to make the object appear and disappear from one end to the other rather than all at once, so I want to map alpha cutoff value A to one end of the U or V axis, and alpha cutoff value B to the other end. Maybe blending ramp images is the way to do it, or maybe scripting within the shader- a prospect which still fills me with dread. Or, does the alpha cutoff value simply Not Work That Way?
The "DebugUV" shader copied and pasted straight from the manual gives three errors , which is not encouraging. And I am looking at the code of the AlphaTest-BumpSpec.shader from the builtin shaders packages and I'm not seeing anything in there that actually implements the alpha cutoff value. It's just declared as a #pragma after the CGPROGRA$$anonymous$$ line- so it's a 'canned' effect that is not open to editing...?
I'm pretty confident what you're trying to do is possible. It'll probably take a shader though.
Well, I've figured out that much, but how to expose the workings of the alpha cutoff in the shader so that I can map either UV coords or a texture file to it has me stumped. There's no place in the code for the builtin cutoff shaders for such a script to go as far as I can tell. Just #pragma surface surf BlinnPhong alphatest:_Cutoff and that's it.
Answer by Kiloblargh · May 25, 2011 at 10:16 AM
I think I figured out the answer, but I don't like it much...
• Open the compiled shader (all 5365 lines of it.)
• Find all instances of "_Cutoff"
• Add a _NewCutoff variable after it
• Change all the "x = (tmpvar_6 - _Cutoff);" lines to something cleverly incorporating '_NewCutoff' and 'texcoord'
• Realize that most of the dozens of SubPrograms don't have anything resembling that line because they are written in various equally illegible dialects of assembly language
• Hate life
Your answer
Follow this Question
Related Questions
Possible to pause a shader? 1 Answer
Cutout + Specularmask-shader error: "Material doesn't have a color property" 0 Answers
"Blend SrcFactor DstFactor, SrcFactorA DstFactorA" Does not work 2 Answers
Shader: Add one image's alpha to the other while keeping it unlit 1 Answer
Shader Depth Mask - Shadows with cutouts 2 Answers