123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using UnityEngine;
- using NativeBlendMode = UnityEngine.Rendering.BlendMode;
- namespace FairyGUI
- {
-
-
-
-
- public enum BlendMode
- {
- Normal,
- None,
- Add,
- Multiply,
- Screen,
- Erase,
- Mask,
- Below,
- Off,
- One_OneMinusSrcAlpha,
- Custom1,
- Custom2,
- Custom3
- }
-
-
-
- public class BlendModeUtils
- {
- public class BlendFactor
- {
- public NativeBlendMode srcFactor;
- public NativeBlendMode dstFactor;
- public bool pma;
- public BlendFactor(NativeBlendMode srcFactor, NativeBlendMode dstFactor, bool pma = false)
- {
- this.srcFactor = srcFactor;
- this.dstFactor = dstFactor;
- this.pma = pma;
- }
- }
-
-
- public static BlendFactor[] Factors = new BlendFactor[] {
-
- new BlendFactor(NativeBlendMode.SrcAlpha, NativeBlendMode.OneMinusSrcAlpha),
-
- new BlendFactor(NativeBlendMode.One, NativeBlendMode.One),
-
- new BlendFactor(NativeBlendMode.SrcAlpha, NativeBlendMode.One),
-
- new BlendFactor(NativeBlendMode.DstColor, NativeBlendMode.OneMinusSrcAlpha, true),
-
- new BlendFactor(NativeBlendMode.One, NativeBlendMode.OneMinusSrcColor, true),
-
- new BlendFactor(NativeBlendMode.Zero, NativeBlendMode.OneMinusSrcAlpha),
-
- new BlendFactor(NativeBlendMode.Zero, NativeBlendMode.SrcAlpha),
-
- new BlendFactor(NativeBlendMode.OneMinusDstAlpha, NativeBlendMode.DstAlpha),
-
- new BlendFactor(NativeBlendMode.One, NativeBlendMode.Zero),
-
- new BlendFactor(NativeBlendMode.One, NativeBlendMode.OneMinusSrcAlpha),
-
- new BlendFactor(NativeBlendMode.SrcAlpha, NativeBlendMode.OneMinusSrcAlpha),
-
- new BlendFactor(NativeBlendMode.SrcAlpha, NativeBlendMode.OneMinusSrcAlpha),
-
- new BlendFactor(NativeBlendMode.SrcAlpha, NativeBlendMode.OneMinusSrcAlpha)
- };
-
-
-
-
-
- public static void Apply(Material mat, BlendMode blendMode)
- {
- BlendFactor bf = Factors[(int)blendMode];
- mat.SetFloat(ShaderConfig.ID_BlendSrcFactor, (float)bf.srcFactor);
- mat.SetFloat(ShaderConfig.ID_BlendDstFactor, (float)bf.dstFactor);
- if (bf.pma)
- mat.SetFloat(ShaderConfig.ID_ColorOption, 1);
- else
- mat.SetFloat(ShaderConfig.ID_ColorOption, 0);
- }
-
-
-
-
-
-
- public static void Override(BlendMode blendMode, NativeBlendMode srcFactor, NativeBlendMode dstFactor)
- {
- BlendFactor bf = Factors[(int)blendMode];
- bf.srcFactor = srcFactor;
- bf.dstFactor = dstFactor;
- }
- }
- }
|