I'm trying to figure out how to add a transparency control to a CgFX shader. Ultimately it's for use with the ColladaMax exporter.
What I'd like to do is wire up the alpha of a bitmap to control the transparency of my mesh surface. But I can't figure out how to do it.
I'm using mental mill... maybe that's the problem? There don't seem to be any transparency nodes, except for compositors, but I don't want to make the surface blend with another input, I want it to blend with the rest of the scene.
Help!
Replies
http://forum.mentalimages.com/showthread.php?t=160
Nutshell... you can set it up in mental mill but you can't see it, have to edit the file after export.
Small world.
So I guess you're using Maya then? Still having some trouble with getting mental mill CgFX files to load up in the ColladaEffect material in Max, getting only errors so far.
Still poring through the help files. Is there a way to set the transparency blending mode? The cellphone hardware we're using for this project supports Lerp, Multiply, or Additive for transparency. Would I create a radio-button list (or dropdown) of the three methods, so one could be chosen? Or should I instead make three different shaders?
The shaders we need for this project are for fixed-function hardware, pretty simple. So the FX files are really just WYSIWYG for the artists, ultimately they'll be converted to hardware-specific code for runtime.
An example...
Color = DiffuseBitmap.rgb * Light.rgb * Tint.rgb,
Opacity = DiffuseBitmap.alpha * Light.alpha * Tint.alpha,
Then [lerp/mult/add] with behind.
I have the first two lines figured out, just not the latter.
<font class="small">Code:</font><hr /><pre>
// lerp
AlphaBlendEnable = TRUE;
DestBlend = InvSrcAlpha;
SrcBlend = SrcAlpha;
// add
AlphaBlendEnable = TRUE;
DestBlend = One;
SrcBlend = One;
// mul
AlphaBlendEnable = TRUE;
DestBlend = Zero;
SrcBlend = DestColor;
</pre><hr />
with DestBlend and SrcBlend you define factors for the "blending" equation, which normally is:
Output = (DestBlend * DestColor) + (SrcBlend * SrcColor)
SrcXXX = Source pixel = pixel processing output
DestXXX = Destination pixel = pixel that is "overwritten"
DestBlend/SrcBlend can be:
InvAlpha = (1-Alpha)
Alpha
InvColor = 1-Color
Color
One
Zero
---
Sometimes hardware supports other "blending" equations, like subtractive and "min/max" blends, but mostly only this simple additive base formula exists. Be aware that blending is after pixel processing, ie you cannot access pixels you overwrite in pixelshader or whatever. Workaround for this limitation involves rendering to texture. But yeah not wanting to take this too much off-topic hehe.
You can set the blend mode by selecting the standard material node and then choosing the blend mode you want from the drop-down box on the right that's labeled "Blend Mode."
If you're making a custom FX shader for your artists to use, I'd recommend using three separate techniques - one for each blend mode you want to support. That will give you a drop-down box in the max material editor (it's at that bottom of the panel) that will allow them to choose.
You can create a shader with three or more techniques by using the Techniques node. Here's a demo movie on how that works:
http://www.lumonix.net/ShaderFX_technique.wmv
In FX files, the transparency blending is specified in the render states toward the bottom of the shader - not in the pixel shader code. Try creating a simple ShaderFX shader with different blend modes set and take a look at the changes it makes to the render state code to see what I mean.
If you're doing blending within the shader itself - blending one texture with another, etc, you can use the color blend node. This node allows you to combine two inputs using any of the blend modes available in Photoshop.
For example we have one that optionally inverts the dest, multiplies it by an RGB value, multiplies the src with another RGB, then blends the dest and src using one of a list of modes (add, lerp, overlay, etc.).
// add
AlphaBlendEnable = TRUE;
DestBlend = SrcColor;
SrcBlend = DestColor;
which is the same as
SrcColor * DestColor *2