- Home /
Multiply Mode uses strange Alpha
(Link to code: http://pastebin.com/P1WxYquh)
Hey Everyone -
I'm writing my own multi-pass shader for handling several effects at once. This is for a sprite-based game.
This shader has three textures: one for the base colors, one for highlights (using additive mode), and one for interior shadows (using multiply mode). It also has four other settings: an overall opacity (slider), main Tint color, highlight color, and shadow color (all RGBA). These colors have an alpha value to give direct control over the intensity of the highlights and shadows.
Here's how it appears in Unity's GUI: http://grab.by/aEGc
Everything works great, except for the multiply mode when I use "Blend Zero SrcColor."
Here's an image showing the results with various settings (yes, that's Saki from Arcana Heart, which I'm only using for test purposes): http://imm.io/7Mmh
1 - Opacity set to 0, Tint Highlight and Shadow set to Alpha 0.
2 - Same as #1, Opacity set to 1.0
3 - Same as #1, Highlight set to Alpha 1.0 (you can see the alpha in the actual texture map coming through)
4 - Same as #1, Shadow set to Alpha 1.0, using standard blending ("Blend SrcAlpha OneMinusSrcAlpha")
5 - Same as #1, Shadow set to Alpha 1.0, using multiply blending ("Blend Zero SrcColor")
As you can see, the alpha on the multiply texture becomes fragmented when I use Blend Zero SrcColor, oddly enough. Any ideas on how I can handle this issue?
Thanks for your time and insight!
Answer by shionyr · Aug 04, 2011 at 07:59 PM
Did it!
// Based on Particles/VertexLit Blended
Shader "Custom/VertexLit Blended w Add and Mult" {
Properties {
// _EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)
_Opacity ("Object Opacity", Range(0.0, 1.0) ) = 1.0
_MainTex ("Main Diffuse", 2D) = "white" {}
_AddTex ("Hilight Texture", 2D) = "white" {}
_MultTex ("Shadow Texture", 2D) = "white" {}
_TintColor ( "Main Tint Color", Color) = (.5, .5, .5, 0)
_AddColor ( "Hilight Tint Color", Color) = (0,0,0,0)
_MultColor ( "Shadow Color", Color) = (1, 1, 1, 0.0)
}
SubShader {
// Preps and Setup
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Tags { "LightMode" = "Vertex" }
Cull Off
Lighting On
Material { } //Emission [_EmisColor] }
ColorMaterial AmbientAndDiffuse
ZWrite Off
ColorMask RGB
AlphaTest Greater .001
Blend SrcAlpha OneMinusSrcAlpha
Pass {
// Set Tint Color and apply main texture's alpha to it.
SetTexture [_MainTex]{
constantColor [_TintColor]
combine constant lerp (constant) texture
}
// Apply main texture with the Opacity setting included
SetTexture [_MainTex]{
constantColor(0,0,0,[_Opacity])
combine previous, texture * constant
}
// Apply lighting
SetTexture [_MainTex]{
combine primary * previous
}
}
Blend SrcAlpha One
Pass {
// Apply the Highlights, using the opacity in AddTex.
SetTexture [_AddTex]{
ConstantColor [_AddColor]
combine constant, texture * constant
}
SetTexture [_AddTex] {
ConstantColor(0,0,0,[_Opacity])
combine previous, previous * constant
}
}
Blend DstColor Zero
Pass {
SetTexture[_MainTex] {
ConstantColor(1,1,1,[_Opacity])
combine texture, constant
}
SetTexture[_MultTex] {
combine previous, previous * texture
}
SetTexture[_MultTex] {
ConstantColor[_MultColor]
combine one-previous alpha + constant
}
}
}
}
Your answer
Follow this Question
Related Questions
Would learning some GLSL help with Unity Shading? 1 Answer
How to smoothen/sharpen edges while using alphatest 0 Answers
Implementing Custom Vertex Lighting Shader 1 Answer
Is there any way to set Shaderlab Pass Tags based on material properties? 1 Answer
How to achive the same look? Which shaders to use? 2 Answers