Пример #1
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (PlatformVersion.Supports(PlatformApis.BlendModeColorFilter))
            {
                BlendMode?filterMode29 = GetFilterMode(mode);

                if (filterMode29 != null)
                {
                    drawable.SetColorFilter(new BlendModeColorFilter(color, filterMode29));
                }
            }
            else
            {
#pragma warning disable CS0612 // Type or member is obsolete
                PorterDuff.Mode?filterModePre29 = GetFilterModePre29(mode);
#pragma warning restore CS0612 // Type or member is obsolete

                if (filterModePre29 != null)
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    drawable.SetColorFilter(color, filterModePre29);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Пример #2
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (OperatingSystem.IsAndroidVersionAtLeast(29))
            {
                BlendMode?filterMode29 = GetFilterMode(mode);

                if (filterMode29 != null)
                {
                    drawable.SetColorFilter(new BlendModeColorFilter(color, filterMode29));
                }
            }
            else
            {
#pragma warning disable CS0612 // Type or member is obsolete
                PorterDuff.Mode?filterModePre29 = GetFilterModePre29(mode);
#pragma warning restore CS0612 // Type or member is obsolete

                if (filterModePre29 != null)
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    drawable.SetColorFilter(color, filterModePre29);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Пример #3
0
 public MixerBlendSetCommand(int?channel = null, int?layer = null, BlendMode?blendMode = null, Transform transform = null)
 {
     Channel   = channel;
     Layer     = layer;
     BlendMode = blendMode;
     Transform = transform;
 }
        public BoxDecoration(
            Color color                   = null,
            DecorationImage image         = null,
            Border border                 = null,
            BorderRadius borderRadius     = null,
            List <BoxShadow> boxShadow    = null,
            Gradient gradient             = null,
            BlendMode?backgroundBlendMode = null,
            BoxShape shape                = BoxShape.rectangle
            )
        {
            D.assert(
                backgroundBlendMode == null || color != null || gradient != null,
                () => "backgroundBlendMode applies to BoxDecoration\'s background color or " +
                "gradient, but no color or gradient was provided."
                );

            this.color               = color;
            this.image               = image;
            this.border              = border;
            this.borderRadius        = borderRadius;
            this.boxShadow           = boxShadow;
            this.gradient            = gradient;
            this.backgroundBlendMode = backgroundBlendMode;
            this.shape               = shape;
        }
Пример #5
0
        public void PutSprite(uint x, uint y, Sprite sprite, BlendMode?blendMode)
        {
            SetLayer();

            if (blendMode == null)
            {
                TpsGraphWrapper.PutSprite(x, y, TransparentColor, sprite._dataPtr);
            }
            else
            {
                TpsGraphWrapper.PutSpriteBlend(x, y, sprite._dataPtr, (byte)blendMode);
            }
        }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        BlendMode?currentblendMode = GetCurrentBlendMode();  // uneditable at runtime for now ...

        if (currentblendMode == null)
        {
            SetBlendMode(BlendMode.Add);
            currentblendMode = BlendMode.Add;
        }

        var newBlendMode = BlendMode.Add;

        if (newBlendMode != currentblendMode)
        {
            SetBlendMode(newBlendMode);
        }
    }
Пример #7
0
 public BoxDecoration copyWith(
     Color color                   = null,
     DecorationImage image         = null,
     Border border                 = null,
     BorderRadius borderRadius     = null,
     List <BoxShadow> boxShadow    = null,
     Gradient gradient             = null,
     BlendMode?backgroundBlendMode = null,
     BoxShape?shape                = null
     )
 {
     return(new BoxDecoration(
                color: color ?? this.color,
                image: image ?? this.image,
                border: border ?? this.border,
                borderRadius: borderRadius ?? this.borderRadius,
                boxShadow: boxShadow ?? this.boxShadow,
                gradient: gradient ?? this.gradient,
                backgroundBlendMode: backgroundBlendMode ?? this.backgroundBlendMode,
                shape: shape ?? this.shape
                ));
 }
Пример #8
0
        /// <summary>
        /// Sets the surface type.
        /// </summary>
        /// <param name="material"></param>
        /// <param name="surfaceType"></param>
        /// <param name="blendMode"></param>
        public static void SetSurfaceType(Material material, SurfaceType surfaceType, BlendMode?blendMode = null)
        {
            material.SetInt(Property.SurfaceType, (int)surfaceType);

            if (blendMode.HasValue)
            {
                material.SetInt(Property.BlendMode, (int)blendMode);
            }

            switch (surfaceType)
            {
            case SurfaceType.Opaque:
                material.SetInt(Property.SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt(Property.DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt(Property.AlphaSrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt(Property.AlphaDstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt(Property.ZWrite, 1);
                material.SetInt(Property.TransparentZWrite, 0);
                //SetKeyword(material, Keyword.AlphaTestOn, false);
                //SetKeyword(material, Keyword.AlphaBlendOn, false);
                material.renderQueue = 2225;      // @notice
                break;

            case SurfaceType.Transparent:
                switch (blendMode)
                {
                case BlendMode.Alpha:
                    material.SetInt(Property.SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt(Property.DstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    material.SetInt(Property.AlphaSrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt(Property.AlphaDstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    material.SetInt(Property.ZWrite, 0);
                    material.SetInt(Property.TransparentZWrite, 0);
                    //SetKeyword(material, Keyword.AlphaTestOn, true);
                    //SetKeyword(material, Keyword.AlphaBlendOn, false);
                    //SetKeyword(material, Keyword.AlphaPremultiplyOn, false);
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                    break;

                case BlendMode.Additive:
                    material.SetInt(Property.SrcBlend, (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                    material.SetInt(Property.DstBlend, (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt(Property.AlphaSrcBlend, (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                    material.SetInt(Property.AlphaDstBlend, (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt(Property.ZWrite, 0);
                    material.SetInt(Property.TransparentZWrite, 0);
                    //SetKeyword(material, Keyword.AlphaTestOn, false);
                    //SetKeyword(material, Keyword.AlphaBlendOn, true);
                    //SetKeyword(material, Keyword.AlphaPremultiplyOn, false);
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                    break;

                case BlendMode.Premultiply:
                    material.SetInt(Property.SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt(Property.DstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    material.SetInt(Property.AlphaSrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt(Property.AlphaDstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    material.SetInt(Property.ZWrite, 0);
                    material.SetInt(Property.TransparentZWrite, 0);
                    //SetKeyword(material, Keyword.AlphaTestOn, false);  // @notice true?
                    //SetKeyword(material, Keyword.AlphaBlendOn, false);
                    //SetKeyword(material, Keyword.AlphaPremultiplyOn, true);
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                    break;
                }
                break;
            }
        }
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor, object converterObject)
        {
            ILocalization lc = IOC.Resolve <ILocalization>();

            PropertyEditorCallback valueChangedCallback = () => editor.BuildEditor();

            StandardMaterialValueConverter[] converters = ((object[])converterObject).Cast <StandardMaterialValueConverter>().ToArray();

            PropertyInfo modeInfo          = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.Mode, "Mode");
            PropertyInfo cutoffInfo        = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.Cutoff, "Cutoff");
            PropertyInfo metallicMapInfo   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.MetallicGlossMap, "MetallicGlossMap");
            PropertyInfo bumpMapInfo       = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.BumpMap, "BumpMap");
            PropertyInfo parallaxMapInfo   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.ParallaxMap, "ParallaxMap");
            PropertyInfo occlusionMapInfo  = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.OcclusionMap, "OcclusionMap");
            PropertyInfo emissionMapInfo   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.EmissionMap, "EmissionMap");
            PropertyInfo emissionColorInfo = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.EmissionColor, "EmissionColor");
            PropertyInfo detailMaskInfo    = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.DetailMask, "DetailMask");
            PropertyInfo detailAlbedoMap   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.DetailAlbedoMap, "DetailAlbedoMap");
            PropertyInfo detailNormalMap   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.DetailNormalMap, "DetailNormalMap");

            PropertyInfo texInfo   = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture, "Texture");
            PropertyInfo colorInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color, "Color");
            PropertyInfo floatInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");

            BlendMode?mode = (BlendMode?)GetValue(editor.Materials, GetBlendMode);
            List <MaterialPropertyDescriptor> properties = new List <MaterialPropertyDescriptor>();

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_RenderingMode", "Rendering Mode"), RTShaderPropertyType.Float, modeInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, valueChangedCallback, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _MainTex), lc.GetString("ID_RTEditor_CD_StandardMaterial_Albedo", "Albedo"), RTShaderPropertyType.TexEnv, texInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _Color), lc.GetString("ID_RTEditor_CD_StandardMaterial_AlbedoColor", "Albedo Color"), RTShaderPropertyType.Color, colorInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, null, EraseAccessorTarget));
            if (mode == BlendMode.Cutout)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_AlphaCutoff", "Alpha Cutoff"), RTShaderPropertyType.Range, cutoffInfo, new RuntimeShaderInfo.RangeLimits(0.5f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_Metallic", "Metallic"), RTShaderPropertyType.TexEnv, metallicMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            bool?hasGlossMap = (bool?)GetValue(editor.Materials, IsMetallicGlossMapSet);

            if (hasGlossMap != null)
            {
                if (!hasGlossMap.Value)
                {
                    properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _Metallic), lc.GetString("ID_RTEditor_CD_StandardMaterial_Metallic", "Metallic"), RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                    var smoothness = (StandardMaterialUtils.SmoothnessMapChannel?)GetValue(editor.Materials, material => StandardMaterialUtils.GetSmoothnessMapChannel(material));
                    if (smoothness != null)
                    {
                        if (smoothness.Value == StandardMaterialUtils.SmoothnessMapChannel.SpecularMetallicAlpha)
                        {
                            properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _Glossiness), lc.GetString("ID_RTEditor_CD_StandardMaterial_Smoothness", "Smoothness"), RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.5f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                        }
                        else
                        {
                            properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _GlossMapScale), lc.GetString("ID_RTEditor_CD_StandardMaterial_Smoothness", "Smoothness"), RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                        }
                    }
                }
                else
                {
                    properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _GlossMapScale), lc.GetString("ID_RTEditor_CD_StandardMaterial_Smoothness", "Smoothness"), RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                }
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_NormalMap", "Normal Map"), RTShaderPropertyType.TexEnv, bumpMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));

            bool?hasBumpMap = (bool?)GetValue(converters, conv => conv.BumpMap != null);

            if (hasBumpMap != null && hasBumpMap.Value)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _BumpScale), lc.GetString("ID_RTEditor_CD_StandardMaterial_NormalMapScale", "Normal Map Scale"), RTShaderPropertyType.Float, floatInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_HeightMap", "Height Map"), RTShaderPropertyType.TexEnv, parallaxMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            bool?hasParallaxMap = (bool?)GetValue(converters, conv => conv.ParallaxMap != null);

            if (hasParallaxMap != null && hasParallaxMap.Value)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _Parallax), lc.GetString("ID_RTEditor_CD_StandardMaterial_HeightMapScale", "Height Map Scale"), RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.02f, 0.005f, 0.08f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_OcclusionMap", "Occlusion Map"), RTShaderPropertyType.TexEnv, occlusionMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            bool?occlusionMap = (bool?)GetValue(converters, conv => conv.OcclusionMap != null);

            if (occlusionMap != null && occlusionMap.Value)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _OcclusionStrength), lc.GetString("ID_RTEditor_CD_StandardMaterial_OcclusionStrength", "Occlusion Strength"), RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_EmissionMap", "Emission Map"), RTShaderPropertyType.TexEnv, emissionMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_EmissionMap", "Emission Color"), RTShaderPropertyType.Color, emissionColorInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.None, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_DetailMask", "Detail Mask"), RTShaderPropertyType.TexEnv, detailMaskInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_DetailAlbedoMap", "Detail Albedo Map"), RTShaderPropertyType.TexEnv, detailAlbedoMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_DetailNormalMap", "Detail Normal Map"), RTShaderPropertyType.TexEnv, detailNormalMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, CreateAccessors(editor, _DetailNormalMapScale), lc.GetString("ID_RTEditor_CD_StandardMaterial_DetailScale", "Detail Scale"), RTShaderPropertyType.Float, floatInfo, new RuntimeShaderInfo.RangeLimits(0, 0, 0), TextureDimension.None, null, EraseAccessorTarget));

            PropertyInfo tilingInfo = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.Tiling, "Tiling");
            PropertyInfo offsetInfo = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.Offset, "Offset");

            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_Tiling", "Tiling"), RTShaderPropertyType.Vector, tilingInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Materials, converters, lc.GetString("ID_RTEditor_CD_StandardMaterial_Offset", "Offset"), RTShaderPropertyType.Vector, offsetInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, null, EraseAccessorTarget));

            return(properties.ToArray());
        }