예제 #1
0
	// Constructor
	public UPALayer (UPAImage img) {
		name = "Layer " + (img.layers.Count + 1);
		opacity = 1;
		mode = BlendMode.NORMAL;
		
		map = new Color[img.width * img.height];
		tex = new Texture2D (img.width, img.height);
		
		for (int x = 0; x < img.width; x++) {
			for (int y = 0; y < img.height; y++) {
				map[x + y * img.width] = Color.clear;
				tex.SetPixel (x,y, Color.clear);
			}
		}
		
		tex.filterMode = FilterMode.Point;
		tex.Apply ();
		
		enabled = true;
		locked = false;
		parentImg = img;
		
		// Because Unity won't record map (Color[]) as an undo,
		// we instead register a callback to LoadMapFromTex since undoing textures works fine
		Undo.undoRedoPerformed += LoadMapFromTex; // subscribe to the undo event
	}
        public void Begin(GraphicsDevice gd)
        {
            Debug.Assert(batchMode == BatchMode.None, "Bad batch mode: " + batchMode);

            matrixStack.Clear();
            matrix = Matrix.Identity;

            drawColor = Color.White;
            blendMode = BlendMode.AlphaBlend;

            if (graphicsDevice != gd)
            {
                graphicsDevice = gd;
                spriteBatch = new SpriteBatch(graphicsDevice);
                basicEffect = new BasicEffect(graphicsDevice);

                int width = gd.Viewport.Width;
                int height = gd.Viewport.Height;

                Matrix worldMatrix = Matrix.Identity;
                Matrix viewMatrix = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up);
                Matrix projection = Matrix.CreateOrthographicOffCenter(0.0f, width, height, 0, 1.0f, 1000.0f);
                camera = new Camera(worldMatrix, viewMatrix, projection);

                basicEffect.World = worldMatrix;
                basicEffect.View = viewMatrix;
                basicEffect.Projection = projection;
                basicEffect.VertexColorEnabled = true;
            }
        }
예제 #3
0
		protected override Batch GetNewInstanceOfBatch(Material material, BlendMode blendMode,
			int numberOfQuadsToAdd)
		{
			if ((material.Shader as ShaderWithFormat).Format.Is3D)
				throw new BatchRenderer2DCannotBeUsedToRender3D(); //ncrunch: no coverage
			return new Batch2D(material, blendMode, numberOfQuadsToAdd);
		}
예제 #4
0
        public TerrainSpriteLayer(World world, WorldRenderer wr, Sheet sheet, BlendMode blendMode, PaletteReference palette, bool restrictToBounds)
        {
            worldRenderer = wr;
            this.restrictToBounds = restrictToBounds;
            Sheet = sheet;
            BlendMode = blendMode;
            paletteIndex = palette.TextureIndex;

            map = world.Map;
            rowStride = 4 * map.MapSize.X;

            vertices = new Vertex[rowStride * map.MapSize.Y];
            vertexBuffer = Game.Renderer.Device.CreateVertexBuffer(vertices.Length);
            emptySprite = new Sprite(sheet, Rectangle.Empty, TextureChannel.Alpha);

            wr.PaletteInvalidated += () =>
            {
                paletteIndex = palette.TextureIndex;

                // Everything in the layer uses the same palette,
                // so we can fix the indices in one pass
                for (var i = 0; i < vertices.Length; i++)
                {
                    var v = vertices[i];
                    vertices[i] = new Vertex(v.X, v.Y, v.Z, v.U, v.V, paletteIndex, v.C);
                }

                for (var row = 0; row < map.MapSize.Y; row++)
                    dirtyRows.Add(row);
            };
        }
예제 #5
0
 /// <summary>
 /// Creates a new DrawTechnique using the specified <see cref="BlendMode"/> and <see cref="Duality.Resources.ShaderProgram"/>.
 /// </summary>
 /// <param name="blendType"></param>
 /// <param name="shader"></param>
 /// <param name="formatPref"></param>
 public DrawTechnique(BlendMode blendType, ContentRef<ShaderProgram> shader, VertexDeclaration formatPref = null)
 {
     this.blendType = blendType;
     this.shader = shader;
     this.prefFormat = formatPref;
     this.prefType = formatPref != null ? formatPref.DataType : null;
 }
예제 #6
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct a set of render states with all its attributes
 /// </summary>
 /// <param name="blendMode">Blend mode to use</param>
 /// <param name="transform">Transform to use</param>
 /// <param name="texture">Texture to use</param>
 /// <param name="shader">Shader to use</param>
 ////////////////////////////////////////////////////////////
 public RenderStates(BlendMode blendMode, Transform transform, Texture texture, Shader shader)
 {
     BlendMode = blendMode;
     Transform = transform;
     Texture = texture;
     Shader = shader;
 }
예제 #7
0
 public void DrawVertexBuffer(IVertexBuffer<Vertex> buffer, int start, int length, PrimitiveType type, Sheet sheet, BlendMode blendMode)
 {
     shader.SetTexture("DiffuseTexture", sheet.GetTexture());
     renderer.Device.SetBlendMode(blendMode);
     shader.Render(() => renderer.DrawBatch(buffer, start, length, type));
     renderer.Device.SetBlendMode(BlendMode.None);
 }
예제 #8
0
		public LayerProperties (string name, bool hidden, double opacity, BlendMode blendmode)
		{
			this.Opacity = opacity;			
			this.Hidden = hidden;
			this.Name = name;
			this.BlendMode = blendmode;
		}
 public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
 {
     switch (blendMode)
     {
     case BlendMode.Opaque:
         material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
         material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
         material.SetInt("_ZWrite", 1);
         material.DisableKeyword("_ALPHATEST_ON");
         material.DisableKeyword("_ALPHABLEND_ON");
         material.renderQueue = -1;
         break;
     case BlendMode.Cutout:
         material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
         material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
         material.SetInt("_ZWrite", 1);
         material.EnableKeyword("_ALPHATEST_ON");
         material.DisableKeyword("_ALPHABLEND_ON");
         material.renderQueue = 2450;
         break;
     case BlendMode.Transparent:
         material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
         material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
         material.SetInt("_ZWrite", 0);
         material.DisableKeyword("_ALPHATEST_ON");
         material.EnableKeyword("_ALPHABLEND_ON");
         material.renderQueue = 3000;
         break;
     }
 }
예제 #10
0
        public void SetBlendMode(BlendMode blendMode)
        {
            Assert.IsNotNull(renderer, Errors.E_RENDER_TARGET_NULL);

            int result = SDL.SDL_SetTextureBlendMode(Handle, (SDL.SDL_BlendMode)blendMode);
            if (Utilities.IsError(result))
                throw new InvalidOperationException(Utilities.GetErrorMessage("SDL_SetTextureBlendMode"));
        }
예제 #11
0
 /// <summary>
 /// http://en.wikipedia.org/wiki/Alpha_compositing
 /// </summary>
 /// <param name="destination_rect"></param>
 /// <param name="source"></param>
 /// <param name="source_rect"></param>
 /// <param name="blendMode"></param>
 public void Blit(
     Rectangle destination_rect,
     IPixelCanvas source,
     Rectangle source_rect,
     BlendMode blendMode)
 {
     Blit(destination_rect, source, source_rect, 255, 255, 255, 255, blendMode);
 }
예제 #12
0
파일: Layer.cs 프로젝트: PintaProject/Pinta
        public Layer(ImageSurface surface, bool hidden, double opacity, string name)
        {
            Surface = surface;

            this.hidden = hidden;
            this.opacity = opacity;
            this.name = name;
            this.blend_mode = BlendMode.Normal;
        }
예제 #13
0
 public void OnInspectorGUI(Action onValueChanged)
 {
     // blend mode.
     var newBlendMode = (BlendMode)EditorGUILayout.Popup("Rendering Mode", (int)blendMode, Enum.GetNames(typeof(BlendMode)), new GUILayoutOption[0]);
     if (newBlendMode != blendMode) {
         this.blendMode = newBlendMode;
         onValueChanged();
     }
 }
예제 #14
0
 /// <summary>
 /// http://en.wikipedia.org/wiki/Alpha_compositing
 /// </summary>
 /// <param name="destination_rect"></param>
 /// <param name="source"></param>
 /// <param name="source_rect"></param>
 /// <param name="blendMode"></param>
 public void Blit(
     System.Drawing.Rectangle destination_rect,
     IPixelCanvas source,
     System.Drawing.Rectangle source_rect,
     BlendMode blendMode
     )
 {
     Blit(destination_rect, source, source_rect, 255, 255, 255, 255, blendMode);
 }
예제 #15
0
		void SetRenderStateForSprite(Sprite s)
		{
			renderer.CurrentBatchRenderer = this;

			if (s.BlendMode != currentBlend || s.Sheet != currentSheet || nv + 4 > renderer.TempBufferSize)
				Flush();

			currentBlend = s.BlendMode;
			currentSheet = s.Sheet;
		}
예제 #16
0
파일: Quad.cs 프로젝트: dreamsxin/engine-1
        public Quad(Quad from)
        {
            v = new VertexPositionTextureColour[4];

            for (int i = 0; i < 4; ++i)
            {
                v[i] = from.v[i];
            }
            tex = from.tex;
            blend = from.blend;
        }
        public void DrawLineDDA(Rectangle bounds, int x1, int y1, int x2, int y2, IPixelCanvas pen, BlendMode blendMode = BlendMode.Copy)
        {
            var x1_d = (double)x1;
            var y1_d = (double)y1;
            var x2_d = (double)x2;
            var y2_d = (double)y2;

            if (!TryCohenSutherlandClip(bounds, ref x1_d, ref y1_d, ref x2_d, ref y2_d))
                return;

            DrawLineDDA((int)x1_d, (int)y1_d, (int)x2_d, (int)y2_d, pen, blendMode);
        }
예제 #18
0
 public static void SetBlendState(BlendMode blendMode)
 {
     if (blendMode.Type == GXBlendMode.Blend)
     {
         GL.Enable(EnableCap.Blend);
         GL.BlendFunc(GetOpenGLBlendSrc(blendMode.SourceFact), GetOpenGLBlendDest(blendMode.DestinationFact));
     }
     else
     {
         GL.Disable(EnableCap.Blend);
     }
 }
예제 #19
0
        public static void SetBlendEquation(this Graphics graphics, BlendMode blendMode)
        {
            if (neverSet || lastSet != blendMode)
            {
                graphics.SetBlendEquation (
                    blendMode.RgbBlendFunction, blendMode.SourceRgb, blendMode.DestinationRgb,
                    blendMode.AlphaBlendFunction, blendMode.SourceAlpha, blendMode.DestinationAlpha
                    );

                neverSet = false;
                lastSet = blendMode;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenOverlayMaterial"/> class.
        /// </summary>
        public ScreenOverlayMaterial(string overlayTexturePath)
            : base(DefaultLayers.Opaque)
        {
            this.OverlayMode = BlendMode.Overlay;
            this.overlayTexturePath = overlayTexturePath;
            this.SamplerMode = AddressMode.LinearClamp;
            this.Intensity = 1.0f;

            this.shaderParameters = new ScreenOverlayEffectParameters();
            this.shaderParameters.Intensity = this.Intensity;
            this.Parameters = this.shaderParameters;

            this.InitializeTechniques(techniques);
        }
예제 #21
0
        public TilePropertiesCommand(Tile tile, string newId, BlendMode newBlendMode, PropertyCollection newProperties)
        {
            m_tile = tile;

            m_oldId = tile.Id;
            m_oldBlendMode = tile.BlendMode;
            m_oldProperties = new PropertyCollection(tile.Properties);

            m_newId = newId;
            m_newBlendMode = newBlendMode;
            m_newProperties = newProperties;

            m_description = "Change tile properties";
        }
예제 #22
0
파일: StaticTile.cs 프로젝트: dekk7/xEngine
        /// <summary>
        /// Constructs a static tile for the given layer, tile sheet, blend
        /// mode and tile index
        /// </summary>
        /// <param name="layer">Layer to assign the tile to</param>
        /// <param name="tileSheet">Tile sheet associated with the tile</param>
        /// <param name="blendMode">Tile blend mode</param>
        /// <param name="tileIndex">Index of the tile in the given tile sheet</param>
        public StaticTile(Layer layer, TileSheet tileSheet, BlendMode blendMode, int tileIndex)
            : base(layer)
        {
            if (!layer.Map.TileSheets.Contains(tileSheet))
                throw new Exception("The specified TileSheet is not in the parent map");

            m_blendMode = blendMode;

            m_tileSheet = tileSheet;

            if (tileIndex < 0 || tileIndex >= tileSheet.TileCount)
                throw new Exception("The specified Tile Index is out of range");

            m_tileIndex = tileIndex;
        }
		/// <summary>
		/// Creates a new effect that will render clouds onto an image.
		/// </summary>
		/// <param name="scale">The relative size of the clouds. Valid range is 2 - 1000.</param>
		/// <param name="power">The power of the clouds. Valid range is 0 - 100.</param>
		/// <param name="seed">Seed value for random generator.</param>
		/// <param name="fromColor">Initial cloud color.</param>
		/// <param name="toColor">Final cloud color.</param>
		/// <param name="blendMode">Blend mode to use when applying clouds.</param>
		public CloudsEffect (int scale = 250, int power = 50, int seed = 0, ColorBgra fromColor = new ColorBgra (), ColorBgra toColor = new ColorBgra (), BlendMode blendMode = BlendMode.Normal)
		{
			if (scale < 2 || scale > 1000)
				throw new ArgumentOutOfRangeException ("scale");
			if (power < 0 || power > 100)
				throw new ArgumentOutOfRangeException ("radius");

			this.scale = scale;
			this.power = power;
			this.seed = seed;
			this.from_color = fromColor;
			this.to_color = toColor;
			this.blend_mode = blendMode;

			blend_op = Utility.GetBlendModeOp (blend_mode);
		}
예제 #24
0
 /// Copies one render texture onto another.
 public static void Blit(RenderTexture source, Rect sourceRect, RenderTexture dest, Rect destRect, BlendMode blendMode)
 {
     // Make the destination texture the target for all rendering
     RenderTexture.active = dest;
     // Assign the source texture to a property from a shader
     source.SetGlobalShaderProperty ("__RenderTex");
     // Set up the simple Matrix
     GL.PushMatrix ();
     GL.LoadOrtho ();
     Material blitMaterial = GetBlitMaterial(blendMode);
     for (int i = 0; i < blitMaterial.passCount; i++) {
         blitMaterial.SetPass (i);
         DrawQuad();
     }
     GL.PopMatrix ();
 }
예제 #25
0
		public Batch2D(Material material, BlendMode blendMode, 
			int minimumNumberOfQuads = MinNumberOfQuads)
		{
			Material = material;
			BlendMode = blendMode;
			minimumNumberOfQuads = MathExtensions.Max(minimumNumberOfQuads, MinNumberOfQuads);
			hasUV = ((material.Shader.Flags & ShaderFlags.Textured) != 0);
			hasColor = ((material.Shader.Flags & ShaderFlags.Colored) != 0);
			indices = new short[minimumNumberOfQuads * IndicesPerQuad];
			if (!hasUV)
				verticesColor = new VertexPosition2DColor[minimumNumberOfQuads * VerticesPerQuad];
			else if (hasColor)
				verticesColorUV = new VertexPosition2DColorUV[minimumNumberOfQuads * VerticesPerQuad];
			else
				verticesUV = new VertexPosition2DUV[minimumNumberOfQuads * VerticesPerQuad];
		}
예제 #26
0
 public static string ToString(BlendMode blendMode)
 {
     switch (blendMode)
     {
         case BlendMode.Add:
             return "Add";
         case BlendMode.Blend:
             return "Blend";
         case BlendMode.Multiply:
             return "Multiply";
         case BlendMode.Subtract:
             return "Subtract";
         default:
             throw new ArgumentOutOfRangeException(nameof(blendMode), blendMode, null);
     }
 }
예제 #27
0
파일: Sprite.cs 프로젝트: CH4Code/OpenRA
        public Sprite(Sheet sheet, Rectangle bounds, float2 offset, TextureChannel channel, BlendMode blendMode = BlendMode.Alpha)
        {
            Sheet = sheet;
            Bounds = bounds;
            Offset = offset;
            Channel = channel;
            Size = new float2(bounds.Size);
            BlendMode = blendMode;

            FractionalOffset = offset / Size;

            Left = (float)Math.Min(bounds.Left, bounds.Right) / sheet.Size.Width;
            Top = (float)Math.Min(bounds.Top, bounds.Bottom) / sheet.Size.Height;
            Right = (float)Math.Max(bounds.Left, bounds.Right) / sheet.Size.Width;
            Bottom = (float)Math.Max(bounds.Top, bounds.Bottom) / sheet.Size.Height;
        }
예제 #28
0
        public static Material GetMaterial(ObjectType objectType, RenderMode renderMode, BlendMode blendMode)
        {
            if (blendMode == BlendMode.Normal)
            {
                if (objectType == ObjectType.MeshDefault)
                {
                    var mat = new Material(Shader.Find("Diffuse"));
                    mat.hideFlags = HideFlags.HideAndDontSave;
                    return mat;
                }
                else if (objectType == ObjectType.SpriteDefault)
                {
                    var mat = new Material(Shader.Find("Sprites/Default"));
                    mat.hideFlags = HideFlags.HideAndDontSave;
                    return mat;
                }
                else if (objectType == ObjectType.ParticleDefault)
                {
                    var mat = new Material(Shader.Find("Particles/Additive"));
                    mat.hideFlags = HideFlags.HideAndDontSave;
                    return mat;
                }
                else return null;
            }

            // Framebuffer won't work in the editor, so fallback to Grab mode.
            if (Application.isEditor && renderMode == RenderMode.Framebuffer) renderMode = RenderMode.Grab;

            // Disable caching for mesh and particle materials, as they are sharing them.
            if (objectType != ObjectType.MeshDefault && objectType != ObjectType.ParticleDefault &&
                cachedMaterials.ContainsKey(objectType) &&
                cachedMaterials[objectType].ContainsKey(renderMode) &&
                cachedMaterials[objectType][renderMode].ContainsKey(blendMode))
                return cachedMaterials[objectType][renderMode][blendMode];
            else
            {
                var mat = new Material(Resources.Load<Shader>(string.Format("BlendModes/{0}/{1}", objectType, renderMode)));
                mat.hideFlags = HideFlags.HideAndDontSave;
                mat.EnableKeyword("BM" + blendMode.ToString());

                if (!cachedMaterials.ContainsKey(objectType)) cachedMaterials.Add(objectType, new Dictionary<RenderMode, Dictionary<BlendMode, Material>>());
                if (!cachedMaterials[objectType].ContainsKey(renderMode)) cachedMaterials[objectType].Add(renderMode, new Dictionary<BlendMode, Material>());
                if (!cachedMaterials[objectType][renderMode].ContainsKey(blendMode)) cachedMaterials[objectType][renderMode].Add(blendMode, mat);

                return mat;
            }
        }
예제 #29
0
        public TerrainSpriteLayer(World world, WorldRenderer wr, Sheet sheet, BlendMode blendMode, PaletteReference palette, bool restrictToBounds)
        {
            worldRenderer = wr;
            this.restrictToBounds = restrictToBounds;
            Sheet = sheet;
            BlendMode = blendMode;
            this.palette = palette;

            map = world.Map;
            rowStride = 6 * map.MapSize.X;

            vertices = new Vertex[rowStride * map.MapSize.Y];
            vertexBuffer = Game.Renderer.Device.CreateVertexBuffer(vertices.Length);
            emptySprite = new Sprite(sheet, Rectangle.Empty, TextureChannel.Alpha);

            wr.PaletteInvalidated += UpdatePaletteIndices;
        }
    public override void OnEnable()
    {
        base.OnEnable();

        BlendMode currentBlendMode = BlendMode.Normal;

        foreach (var keyword in ((Material)target).shaderKeywords)
        {
            if (keyword.StartsWith("BM"))
            {
                currentBlendMode = (BlendMode)Enum.Parse(typeof(BlendMode), keyword.Replace("BM", string.Empty), true);
                break;
            }
        }

        selectedBlendMode = currentBlendMode;
    }
예제 #31
0
        /// StandardShader variables
        ///
        /// _Color
        /// _MainTex
        /// _Cutoff
        /// _Glossiness
        /// _Metallic
        /// _MetallicGlossMap
        /// _BumpScale
        /// _BumpMap
        /// _Parallax
        /// _ParallaxMap
        /// _OcclusionStrength
        /// _OcclusionMap
        /// _EmissionColor
        /// _EmissionMap
        /// _DetailMask
        /// _DetailAlbedoMap
        /// _DetailNormalMapScale
        /// _DetailNormalMap
        /// _UVSec
        /// _EmissionScaleUI
        /// _EmissionColorUI
        /// _Mode
        /// _SrcBlend
        /// _DstBlend
        /// _ZWrite
        public virtual Material CreateMaterial(int i, glTFMaterial x, bool hasVertexColor)
        {
            var shader = m_shaderStore.GetShader(x);
            //Debug.LogFormat("[{0}]{1}", i, shader.name);
            var material = new Material(shader);

#if UNITY_EDITOR
            // textureImporter.SaveAndReimport(); may destroy this material
            material.hideFlags = HideFlags.DontUnloadUnusedAsset;
#endif

            material.name = (x == null || string.IsNullOrEmpty(x.name))
                ? string.Format("material_{0:00}", i)
                : x.name
            ;

            if (x == null)
            {
                Debug.LogWarning("glTFMaterial is empty");
                return(material);
            }

            // unlit material
            if (x.extensions != null && x.extensions.KHR_materials_unlit != null)
            {
                // texture
                if (x.pbrMetallicRoughness.baseColorTexture != null)
                {
                    var texture = GetTextureFunc(x.pbrMetallicRoughness.baseColorTexture.index);
                    if (texture != null)
                    {
                        material.mainTexture = texture.Texture;
                    }

                    // Texture Offset and Scale
                    SetTextureOffsetAndScale(material, x.pbrMetallicRoughness.baseColorTexture, "_MainTex");
                }

                // color
                if (x.pbrMetallicRoughness.baseColorFactor != null && x.pbrMetallicRoughness.baseColorFactor.Length == 4)
                {
                    var color = x.pbrMetallicRoughness.baseColorFactor;
                    material.color = (new Color(color[0], color[1], color[2], color[3])).gamma;
                }

                //renderMode
                if (x.alphaMode == "OPAQUE")
                {
                    UniUnlit.Utils.SetRenderMode(material, UniUnlit.UniUnlitRenderMode.Opaque);
                }
                else if (x.alphaMode == "BLEND")
                {
                    UniUnlit.Utils.SetRenderMode(material, UniUnlit.UniUnlitRenderMode.Transparent);
                }
                else if (x.alphaMode == "MASK")
                {
                    UniUnlit.Utils.SetRenderMode(material, UniUnlit.UniUnlitRenderMode.Cutout);
                }
                else
                {
                    // default OPAQUE
                    UniUnlit.Utils.SetRenderMode(material, UniUnlit.UniUnlitRenderMode.Opaque);
                }

                // culling
                if (x.doubleSided)
                {
                    UniUnlit.Utils.SetCullMode(material, UniUnlit.UniUnlitCullMode.Off);
                }
                else
                {
                    UniUnlit.Utils.SetCullMode(material, UniUnlit.UniUnlitCullMode.Back);
                }

                // VColor
                if (hasVertexColor)
                {
                    UniUnlit.Utils.SetVColBlendMode(material, UniUnlit.UniUnlitVertexColorBlendOp.Multiply);
                }

                UniUnlit.Utils.ValidateProperties(material, true);

                return(material);
            }

            // PBR material
            if (x.pbrMetallicRoughness != null)
            {
                if (x.pbrMetallicRoughness.baseColorFactor != null && x.pbrMetallicRoughness.baseColorFactor.Length == 4)
                {
                    var color = x.pbrMetallicRoughness.baseColorFactor;
                    material.color = (new Color(color[0], color[1], color[2], color[3])).gamma;
                }

                if (x.pbrMetallicRoughness.baseColorTexture != null && x.pbrMetallicRoughness.baseColorTexture.index != -1)
                {
                    var texture = GetTextureFunc(x.pbrMetallicRoughness.baseColorTexture.index);
                    if (texture != null)
                    {
                        material.mainTexture = texture.Texture;
                    }

                    // Texture Offset and Scale
                    SetTextureOffsetAndScale(material, x.pbrMetallicRoughness.baseColorTexture, "_MainTex");
                }

                if (x.pbrMetallicRoughness.metallicRoughnessTexture != null && x.pbrMetallicRoughness.metallicRoughnessTexture.index != -1)
                {
                    material.EnableKeyword("_METALLICGLOSSMAP");
                    var texture = GetTextureFunc(x.pbrMetallicRoughness.metallicRoughnessTexture.index);
                    if (texture != null)
                    {
                        var prop = "_MetallicGlossMap";
                        // Bake roughnessFactor values into a texture.
                        material.SetTexture(prop, texture.ConvertTexture(prop, x.pbrMetallicRoughness.roughnessFactor));
                    }

                    material.SetFloat("_Metallic", 1.0f);
                    // Set 1.0f as hard-coded. See: https://github.com/dwango/UniVRM/issues/212.
                    material.SetFloat("_GlossMapScale", 1.0f);

                    // Texture Offset and Scale
                    SetTextureOffsetAndScale(material, x.pbrMetallicRoughness.metallicRoughnessTexture, "_MetallicGlossMap");
                }
                else
                {
                    material.SetFloat("_Metallic", x.pbrMetallicRoughness.metallicFactor);
                    material.SetFloat("_Glossiness", 1.0f - x.pbrMetallicRoughness.roughnessFactor);
                }
            }

            if (x.normalTexture != null && x.normalTexture.index != -1)
            {
                material.EnableKeyword("_NORMALMAP");
                var texture = GetTextureFunc(x.normalTexture.index);
                if (texture != null)
                {
                    var prop = "_BumpMap";
                    material.SetTexture(prop, texture.ConvertTexture(prop));
                    material.SetFloat("_BumpScale", x.normalTexture.scale);
                }

                // Texture Offset and Scale
                SetTextureOffsetAndScale(material, x.normalTexture, "_BumpMap");
            }

            if (x.occlusionTexture != null && x.occlusionTexture.index != -1)
            {
                var texture = GetTextureFunc(x.occlusionTexture.index);
                if (texture != null)
                {
                    var prop = "_OcclusionMap";
                    material.SetTexture(prop, texture.ConvertTexture(prop));
                    material.SetFloat("_OcclusionStrength", x.occlusionTexture.strength);
                }

                // Texture Offset and Scale
                SetTextureOffsetAndScale(material, x.occlusionTexture, "_OcclusionMap");
            }

            if (x.emissiveFactor != null ||
                (x.emissiveTexture != null && x.emissiveTexture.index != -1))
            {
                material.EnableKeyword("_EMISSION");
                material.globalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;

                if (x.emissiveFactor != null && x.emissiveFactor.Length == 3)
                {
                    material.SetColor("_EmissionColor", new Color(x.emissiveFactor[0], x.emissiveFactor[1], x.emissiveFactor[2]));
                }

                if (x.emissiveTexture != null && x.emissiveTexture.index != -1)
                {
                    var texture = GetTextureFunc(x.emissiveTexture.index);
                    if (texture != null)
                    {
                        material.SetTexture("_EmissionMap", texture.Texture);
                    }

                    // Texture Offset and Scale
                    SetTextureOffsetAndScale(material, x.emissiveTexture, "_EmissionMap");
                }
            }

            BlendMode blendMode = BlendMode.Opaque;
            // https://forum.unity.com/threads/standard-material-shader-ignoring-setfloat-property-_mode.344557/#post-2229980
            switch (x.alphaMode)
            {
            case "BLEND":
                blendMode = BlendMode.Fade;
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.DisableKeyword("_ALPHATEST_ON");
                material.EnableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = 3000;
                break;

            case "MASK":
                blendMode = BlendMode.Cutout;
                material.SetOverrideTag("RenderType", "TransparentCutout");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.SetFloat("_Cutoff", x.alphaCutoff);
                material.EnableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = 2450;

                break;

            default:     // OPAQUE
                blendMode = BlendMode.Opaque;
                material.SetOverrideTag("RenderType", "");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = -1;
                break;
            }

            material.SetFloat("_Mode", (float)blendMode);
            return(material);
        }
예제 #32
0
 static void Add(uint src, uint dest, BlendMode mode)
 {
     _map.Add(new Tuple <uint, uint>(src, dest), mode);
 }
예제 #33
0
        public static Color Calculate(Color srcColor, Color destColor,
                                      BlendOp op, BlendMode srcFactor, BlendMode destFactor, BlendMode srcFactorA, BlendMode destFactorA)
        {
            Color left  = FactorColor(srcColor, destColor, srcFactor) * srcColor;
            Color right = FactorColor(srcColor, destColor, destFactor) * destColor;

            left.a  = FactorAlpha(srcColor.a, destColor.a, srcFactorA) * srcColor.a;
            right.a = FactorAlpha(srcColor.a, destColor.a, destFactorA) * destColor.a;

            return(OpColor(left, right, op));
        }
예제 #34
0
 public void Draw(Texture2D tex, Rectangle source, Rectangle dest, Color4 color, BlendMode mode = BlendMode.Normal, bool flip = false, QuadRotation orient = QuadRotation.None)
 {
     DrawQuad(tex, source, dest, color, mode, flip, orient);
 }
예제 #35
0
 public static Material getFillUnlitMaterial(BlendMode blendMode)
 {
     return(fillUnlitMaterials[(int)blendMode]);
 }
예제 #36
0
 public void DrawVertexBuffer(IVertexBuffer <Vertex> buffer, int start, int length, PrimitiveType type, Sheet sheet, BlendMode blendMode)
 {
     shader.SetTexture("DiffuseTexture", sheet.GetTexture());
     renderer.Device.SetBlendMode(blendMode);
     shader.Render(() => renderer.DrawBatch(buffer, start, length, type));
     renderer.Device.SetBlendMode(BlendMode.None);
 }
예제 #37
0
        public static void SetupBaseUnlitKeywords(this Material material)
        {
            // First thing, be sure to have an up to date RenderQueue
            material.ResetMaterialCustomRenderQueue();

            bool alphaTestEnable = material.HasProperty(kAlphaCutoffEnabled) && material.GetFloat(kAlphaCutoffEnabled) > 0.0f;

            CoreUtils.SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable);

            // Setup alpha to mask using the _AlphaToMaskInspectorValue that we configure in the material UI
            float alphaToMaskEnabled = material.HasProperty("_AlphaToMaskInspectorValue") && material.GetFloat("_AlphaToMaskInspectorValue") > 0.0 ? 1 : 0;

            material.SetFloat(kAlphaToMask, alphaTestEnable ? alphaToMaskEnabled : 0);

            bool alphaToMaskEnable = alphaTestEnable && material.HasProperty(kAlphaToMask) && material.GetFloat(kAlphaToMask) > 0.0f;

            CoreUtils.SetKeyword(material, "_ALPHATOMASK_ON", alphaToMaskEnable);

            SurfaceType surfaceType = material.GetSurfaceType();

            CoreUtils.SetKeyword(material, "_SURFACE_TYPE_TRANSPARENT", surfaceType == SurfaceType.Transparent);

            bool transparentWritesMotionVec = (surfaceType == SurfaceType.Transparent) && material.HasProperty(kTransparentWritingMotionVec) && material.GetInt(kTransparentWritingMotionVec) > 0;

            CoreUtils.SetKeyword(material, "_TRANSPARENT_WRITES_MOTION_VEC", transparentWritesMotionVec);

            if (material.HasProperty(kAddPrecomputedVelocity))
            {
                CoreUtils.SetKeyword(material, "_ADD_PRECOMPUTED_VELOCITY", material.GetInt(kAddPrecomputedVelocity) != 0);
            }

            HDRenderQueue.RenderQueueType renderQueueType = HDRenderQueue.GetTypeByRenderQueueValue(material.renderQueue);
            bool needOffScreenBlendFactor = renderQueueType == HDRenderQueue.RenderQueueType.AfterPostprocessTransparent || renderQueueType == HDRenderQueue.RenderQueueType.LowTransparent;

            // Alpha tested materials always have a prepass where we perform the clip.
            // Then during Gbuffer pass we don't perform the clip test, so we need to use depth equal in this case.
            if (alphaTestEnable)
            {
                material.SetInt(kZTestGBuffer, (int)UnityEngine.Rendering.CompareFunction.Equal);
            }
            else
            {
                material.SetInt(kZTestGBuffer, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
            }

            // If the material use the kZTestDepthEqualForOpaque it mean it require depth equal test for opaque but transparent are not affected
            if (material.HasProperty(kZTestDepthEqualForOpaque))
            {
                if (surfaceType == SurfaceType.Opaque)
                {
                    // When the material is after post process, we need to use LEssEqual because there is no depth prepass for unlit opaque
                    if (HDRenderQueue.k_RenderQueue_AfterPostProcessOpaque.Contains(material.renderQueue))
                    {
                        material.SetInt(kZTestDepthEqualForOpaque, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
                    }
                    else
                    {
                        material.SetInt(kZTestDepthEqualForOpaque, (int)UnityEngine.Rendering.CompareFunction.Equal);
                    }
                }
                else
                {
                    material.SetInt(kZTestDepthEqualForOpaque, (int)material.GetTransparentZTest());
                }
            }

            if (surfaceType == SurfaceType.Opaque)
            {
                material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                // Caution:  we need to setup One for src and Zero for Dst for all element as users could switch from transparent to Opaque and keep remaining value.
                // Unity will disable Blending based on these default value.
                // Note that for after postprocess we setup 0 in opacity inside the shaders, so we correctly end with 0 in opacity for the compositing pass
                material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt(kZWrite, 1);
            }
            else
            {
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt(kZWrite, material.GetTransparentZWrite() ? 1 : 0);

                if (material.HasProperty(kBlendMode))
                {
                    BlendMode blendMode = material.GetBlendMode();

                    // When doing off-screen transparency accumulation, we change blend factors as described here: https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch23.html
                    switch (blendMode)
                    {
                    // Alpha
                    // color: src * src_a + dst * (1 - src_a)
                    // src * src_a is done in the shader as it allow to reduce precision issue when using _BLENDMODE_PRESERVE_SPECULAR_LIGHTING (See Material.hlsl)
                    case BlendMode.Alpha:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        if (needOffScreenBlendFactor)
                        {
                            material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                            material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        }
                        else
                        {
                            material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                            material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        }
                        break;

                    // Additive
                    // color: src * src_a + dst
                    // src * src_a is done in the shader
                    case BlendMode.Additive:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        if (needOffScreenBlendFactor)
                        {
                            material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                            material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        }
                        else
                        {
                            material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                            material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        }
                        break;

                    // PremultipliedAlpha
                    // color: src * src_a + dst * (1 - src_a)
                    // src is supposed to have been multiplied by alpha in the texture on artists side.
                    case BlendMode.Premultiply:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        if (needOffScreenBlendFactor)
                        {
                            material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                            material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        }
                        else
                        {
                            material.SetInt("_AlphaSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                            material.SetInt("_AlphaDstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        }
                        break;
                    }
                }
            }

            bool fogEnabled = material.HasProperty(kEnableFogOnTransparent) && material.GetFloat(kEnableFogOnTransparent) > 0.0f && surfaceType == SurfaceType.Transparent;

            CoreUtils.SetKeyword(material, "_ENABLE_FOG_ON_TRANSPARENT", fogEnabled);

            if (material.HasProperty(kDistortionEnable) && material.HasProperty(kDistortionBlendMode))
            {
                bool distortionDepthTest = material.GetFloat(kDistortionDepthTest) > 0.0f;
                if (material.HasProperty(kZTestModeDistortion))
                {
                    if (distortionDepthTest)
                    {
                        material.SetInt(kZTestModeDistortion, (int)UnityEngine.Rendering.CompareFunction.LessEqual);
                    }
                    else
                    {
                        material.SetInt(kZTestModeDistortion, (int)UnityEngine.Rendering.CompareFunction.Always);
                    }
                }

                var distortionBlendMode = material.GetInt(kDistortionBlendMode);
                switch (distortionBlendMode)
                {
                default:
                case 0:     // Add
                    material.SetInt("_DistortionSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionDstBlend", (int)UnityEngine.Rendering.BlendMode.One);

                    material.SetInt("_DistortionBlurSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionBlurDstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionBlurBlendOp", (int)UnityEngine.Rendering.BlendOp.Add);
                    break;

                case 1:     // Multiply
                    material.SetInt("_DistortionSrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
                    material.SetInt("_DistortionDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);

                    material.SetInt("_DistortionBlurSrcBlend", (int)UnityEngine.Rendering.BlendMode.DstAlpha);
                    material.SetInt("_DistortionBlurDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                    material.SetInt("_DistortionBlurBlendOp", (int)UnityEngine.Rendering.BlendOp.Add);
                    break;

                case 2:     // Replace
                    material.SetInt("_DistortionSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);

                    material.SetInt("_DistortionBlurSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionBlurDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                    material.SetInt("_DistortionBlurBlendOp", (int)UnityEngine.Rendering.BlendOp.Add);
                    break;
                }
            }

            CullMode doubleSidedOffMode = (surfaceType == SurfaceType.Transparent) ? material.GetTransparentCullMode() : material.GetOpaqueCullMode();

            bool isBackFaceEnable  = material.HasProperty(kTransparentBackfaceEnable) && material.GetFloat(kTransparentBackfaceEnable) > 0.0f && surfaceType == SurfaceType.Transparent;
            bool doubleSidedEnable = material.HasProperty(kDoubleSidedEnable) && material.GetFloat(kDoubleSidedEnable) > 0.0f;

            DoubleSidedGIMode doubleSidedGIMode = DoubleSidedGIMode.Auto;

            if (material.HasProperty(kDoubleSidedGIMode))
            {
                doubleSidedGIMode = (DoubleSidedGIMode)material.GetFloat(kDoubleSidedGIMode);
            }

            // Disable culling if double sided
            material.SetInt("_CullMode", doubleSidedEnable ? (int)UnityEngine.Rendering.CullMode.Off : (int)doubleSidedOffMode);

            // We have a separate cullmode (_CullModeForward) for Forward in case we use backface then frontface rendering, need to configure it
            if (isBackFaceEnable)
            {
                material.SetInt("_CullModeForward", (int)UnityEngine.Rendering.CullMode.Back);
            }
            else
            {
                material.SetInt("_CullModeForward", (int)(doubleSidedEnable ? UnityEngine.Rendering.CullMode.Off : doubleSidedOffMode));
            }

            CoreUtils.SetKeyword(material, "_DOUBLESIDED_ON", doubleSidedEnable);

            // A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
            // or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.
            // The fixup routine makes sure that the material is in the correct state if/when changes are made to the mode or color.
            if (material.HasProperty(kEmissionColor))
            {
                material.SetColor(kEmissionColor, Color.white); // kEmissionColor must always be white to allow our own material to control the GI (this allow to fallback from builtin unity to our system).
                                                                // as it happen with old material that it isn't the case, we force it.
                MaterialEditor.FixupEmissiveFlag(material);
            }

            material.SetupMainTexForAlphaTestGI("_UnlitColorMap", "_UnlitColor");

            // depth offset for ShaderGraphs (they don't have the displacement mode property)
            if (!material.HasProperty(kDisplacementMode) && material.HasProperty(kDepthOffsetEnable))
            {
                // Depth offset is only enabled if per pixel displacement is
                bool depthOffsetEnable = (material.GetFloat(kDepthOffsetEnable) > 0.0f);
                CoreUtils.SetKeyword(material, "_DEPTHOFFSET_ON", depthOffsetEnable);
            }

            // DoubleSidedGI has to be synced with our double sided toggle
            var  serializedObject = new SerializedObject(material);
            bool doubleSidedGI    = false;

            if (doubleSidedGIMode == DoubleSidedGIMode.Auto)
            {
                doubleSidedGI = doubleSidedEnable;
            }
            else if (doubleSidedGIMode == DoubleSidedGIMode.On)
            {
                doubleSidedGI = true;
            }
            else if (doubleSidedGIMode == DoubleSidedGIMode.Off)
            {
                doubleSidedGI = false;
            }
            // material always call setdirty, so set only if new value is different
            if (doubleSidedGI != material.doubleSidedGI)
            {
                material.doubleSidedGI = doubleSidedGI;
            }
            serializedObject.ApplyModifiedProperties();
        }
예제 #38
0
    void SetupMaterialBlendMode(Material material)
    {
        if (material == null)
        {
            throw new System.ArgumentNullException("material");
        }
        bool alphaClip = material.HasProperty("_AlphaClip") ? material.GetFloat("_AlphaClip") == 1 : false;

        if (alphaClip)
        {
            material.EnableKeyword("_ALPHATEST_ON");
        }
        else
        {
            material.DisableKeyword("_ALPHATEST_ON");
        }
        SurfaceType surfaceType = (SurfaceType)material.GetFloat("_Surface");

        if (surfaceType == SurfaceType.Opaque)
        {
            material.SetOverrideTag("RenderType", "");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetInt("_ZWrite", 1);
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = -1;
            material.SetShaderPassEnabled("ShadowCaster", true);
        }
        else
        {
            material.SetOverrideTag("RenderType", "Transparent");
            material.SetInt("_ZWrite", 0);
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
            material.SetShaderPassEnabled("ShadowCaster", false);

            BlendMode blendMode = (BlendMode)material.GetFloat("_Blend");
            switch (blendMode)
            {
            case BlendMode.Alpha:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                break;

            case BlendMode.Premultiply:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                break;

            case BlendMode.Additive:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                break;

            case BlendMode.Multiply:
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                break;
            }
        }
    }
예제 #39
0
        public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
        {
            if (material == null)
            {
                throw new ArgumentNullException("material");
            }

            // _Emission property is lost after assigning Standard shader to the material
            // thus transfer it before assigning the new shader
            if (material.HasProperty("_Emission"))
            {
                material.SetColor("_EmissionColor", material.GetColor("_Emission"));
            }

            base.AssignNewShaderToMaterial(material, oldShader, newShader);

            if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
            {
                SetupMaterialBlendMode(material);
                return;
            }

            SurfaceType surfaceType = SurfaceType.Opaque;
            BlendMode   blendMode   = BlendMode.Alpha;

            if (oldShader.name.Contains("/Transparent/Cutout/"))
            {
                surfaceType = SurfaceType.Opaque;
                material.SetFloat("_AlphaClip", 1);
            }
            else if (oldShader.name.Contains("/Transparent/"))
            {
                // NOTE: legacy shaders did not provide physically based transparency
                // therefore Fade mode
                surfaceType = SurfaceType.Transparent;
                blendMode   = BlendMode.Alpha;
            }
            material.SetFloat("_Surface", (float)surfaceType);
            material.SetFloat("_Blend", (float)blendMode);

            if (oldShader.name.Equals("Standard (Specular setup)"))
            {
                material.SetFloat("_WorkflowMode", (float)WorkflowMode.Specular);
                Texture texture = material.GetTexture("_SpecGlossMap");
                if (texture != null)
                {
                    material.SetTexture("_MetallicSpecGlossMap", texture);
                }
            }
            else
            {
                material.SetFloat("_WorkflowMode", (float)WorkflowMode.Metallic);
                Texture texture = material.GetTexture("_MetallicGlossMap");
                if (texture != null)
                {
                    material.SetTexture("_MetallicSpecGlossMap", texture);
                }
            }

            MaterialChanged(material);
        }
예제 #40
0
        private void SetupBlendState(BlendMode mode)
        {
            bool depthWrite      = this.renderOptions.DepthWrite;
            bool useAlphaTesting = false;

            switch (mode)
            {
            default:
            case BlendMode.Solid:
                GL.DepthMask(depthWrite);
                GL.Disable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                break;

            case BlendMode.Mask:
                GL.DepthMask(depthWrite);
                GL.Disable(EnableCap.Blend);
                if (this.useAlphaToCoverageBlend)
                {
                    GL.Enable(EnableCap.SampleAlphaToCoverage);
                }
                else
                {
                    useAlphaTesting = true;
                }
                break;

            case BlendMode.Alpha:
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                GL.BlendFuncSeparate(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha, BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
                break;

            case BlendMode.AlphaPre:
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                GL.BlendFuncSeparate(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha, BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
                break;

            case BlendMode.Add:
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                GL.BlendFuncSeparate(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One, BlendingFactorSrc.One, BlendingFactorDest.One);
                break;

            case BlendMode.Light:
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                GL.BlendFuncSeparate(BlendingFactorSrc.DstColor, BlendingFactorDest.One, BlendingFactorSrc.Zero, BlendingFactorDest.One);
                break;

            case BlendMode.Multiply:
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                GL.BlendFunc(BlendingFactorSrc.DstColor, BlendingFactorDest.Zero);
                break;

            case BlendMode.Invert:
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.SampleAlphaToCoverage);
                GL.BlendFunc(BlendingFactorSrc.OneMinusDstColor, BlendingFactorDest.OneMinusSrcColor);
                break;
            }

            this.internalShaderState.Set(
                BuiltinShaderFields.AlphaTestThreshold,
                useAlphaTesting  ? 0.5f : -1.0f);
        }
예제 #41
0
 public virtual void BlendMode(int layer, BlendMode mode, bool deffered = false)
 {
     BlendMode(layer, mode.ToString(), deffered);
 }
예제 #42
0
 static void SetBlendModes(Material material, BlendMode src, BlendMode dst)
 {
     material.SetFloat("_SrcBlend", (float)src);
     material.SetFloat("_DstBlend", (float)dst);
 }
예제 #43
0
 private void OnBlendModeChanged(object sender, EventArgs e)
 {
     blendmode = UserBlendOps.GetBlendModeByName(blendComboBox.ActiveText);
     PintaCore.Layers.CurrentLayer.BlendMode = blendmode;
 }
예제 #44
0
        public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
        {
            switch (blendMode)
            {
            case BlendMode.Back:
                material.SetOverrideTag("RenderType", "TransparentCutout");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.EnableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Back);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                break;

            case BlendMode.Front:
                material.SetOverrideTag("RenderType", "TransparentCutout");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.EnableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Front);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                break;

            case BlendMode.Doubleside:
                material.SetOverrideTag("RenderType", "TransparentCutout");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.EnableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                break;

            case BlendMode.Fade:
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.DisableKeyword("_ALPHATEST_ON");
                material.EnableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Back);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                break;

            case BlendMode.FadeDouble:
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.DisableKeyword("_ALPHATEST_ON");
                material.EnableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                break;
            }
        }
        /// <summary>
        /// Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).
        /// </summary>
        /// <param name="bmp">The destination WriteableBitmap.</param>
        /// <param name="destPosition">The destination position in the destination bitmap.</param>
        /// <param name="source">The source WriteableBitmap.</param>
        /// <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>
        /// <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>
        /// <param name="blendMode">The blending mode <see cref="BlendMode"/>.</param>
        public static void Blit(this WriteableBitmap bmp, Point destPosition, WriteableBitmap source, Rect sourceRect, Color color, BlendMode blendMode)
        {
            var destRect = new Rect(destPosition, new Size(sourceRect.Width, sourceRect.Height));

            Blit(bmp, destRect, source, sourceRect, color, blendMode);
        }
예제 #46
0
        public static void SetupMaterialBlendMode(Material material)
        {
            if (material == null)
            {
                throw new ArgumentNullException("material");
            }

            bool alphaClip = material.GetFloat("_AlphaClip") == 1;

            if (alphaClip)
            {
                material.EnableKeyword("_ALPHATEST_ON");
            }
            else
            {
                material.DisableKeyword("_ALPHATEST_ON");
            }

            var queueOffset = 0; // queueOffsetRange;

            if (material.HasProperty("_QueueOffset"))
            {
                queueOffset = queueOffsetRange - (int)material.GetFloat("_QueueOffset");
            }

            SurfaceType surfaceType = (SurfaceType)material.GetFloat("_Surface");

            if (surfaceType == SurfaceType.Opaque)
            {
                if (alphaClip)
                {
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                    material.SetOverrideTag("RenderType", "TransparentCutout");
                }
                else
                {
                    material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry;
                    material.SetOverrideTag("RenderType", "Opaque");
                }
                material.renderQueue += queueOffset;
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.SetShaderPassEnabled("ShadowCaster", true);
            }
            else
            {
                BlendMode blendMode = (BlendMode)material.GetFloat("_Blend");
                var       queue     = (int)UnityEngine.Rendering.RenderQueue.Transparent;

                // Specific Transparent Mode Settings
                switch (blendMode)
                {
                case BlendMode.Alpha:
                    material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                    material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                    break;

                case BlendMode.Premultiply:
                    material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                    break;

                case BlendMode.Additive:
                    material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                    break;

                case BlendMode.Multiply:
                    material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
                    material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                    material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                    material.EnableKeyword("_ALPHAMODULATE_ON");
                    break;
                }
                // General Transparent Material Settings
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_ZWrite", 0);
                material.renderQueue = queue + queueOffset;
                material.SetShaderPassEnabled("ShadowCaster", false);
            }
        }
예제 #47
0
        internal unsafe MojoVertex *AddDrawOp(int primType, int primCount, Image img, Effect effect, BlendMode blendMode)
        {
            if (_drawBuffer.Size + primCount * (int)primType > Global.MAX_VERTS)
            {
                Flush();
            }

            if (blendMode == BlendMode.None)
            {
                BlendMode = _blendMode;
            }

            if (img != _drawOp.Image || effect != _drawOp.Effect || primType != _drawOp.PrimType || blendMode != _drawOp.BlendMode)
            {
                _drawOp            = _drawBuffer.AddDrawOp();
                _drawOp.Image      = img;
                _drawOp.Effect     = effect;
                _drawOp.PrimType   = primType;
                _drawOp.BlendMode  = blendMode;
                _drawOp.PrimCount  = primCount;
                _drawOp.PrimOffset = _drawBuffer.Size;
            }
            else
            {
                _drawOp.PrimCount += primCount;
            }

            return(_drawBuffer.AddVertices(primType * primCount));
        }
예제 #48
0
 Material BuildMaterialBlended(BlendMode sourceBlendMode, BlendMode destinationBlendMode) => _material.BuildMaterialBlended(sourceBlendMode, destinationBlendMode);
예제 #49
0
 public static Material getStrokeMaterial(BlendMode blendMode)
 {
     return(strokeMaterials[(int)blendMode]);
 }
예제 #50
0
 private void AddFlare(Texture texture, float size = -1, float distance = 0, BlendMode blending = BlendMode.Normal, float opacity = 1)
 {
     AddFlare(Color.White, texture, size, distance, blending, opacity);
 }
        /// <summary>
        /// Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).
        /// </summary>
        /// <param name="bmp">The destination WriteableBitmap.</param>
        /// <param name="destRect">The rectangle that defines the destination region.</param>
        /// <param name="source">The source WriteableBitmap.</param>
        /// <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>
        /// <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent. If the BlendMode is ColorKeying, this color will be used as color key to mask all pixels with this value out.</param>
        /// <param name="blendMode">The blending mode <see cref="BlendMode"/>.</param>
        internal static void Blit(this WriteableBitmap bmp, Rect destRect, WriteableBitmap source, Rect sourceRect, Color color, BlendMode blendMode)
        {
            if (color.A == 0)
            {
                return;
            }
#if WPF
            var isPrgba = source.Format == PixelFormats.Pbgra32 || source.Format == PixelFormats.Prgba64 || source.Format == PixelFormats.Prgba128Float;
#endif
            var dw = (int)destRect.Width;
            var dh = (int)destRect.Height;

            using (var srcContext = source.GetBitmapContext(ReadWriteMode.ReadOnly))
            {
                using (var destContext = bmp.GetBitmapContext())
                {
                    var sourceWidth = srcContext.Width;
                    var dpw         = destContext.Width;
                    var dph         = destContext.Height;

                    var intersect = new Rect(0, 0, dpw, dph);
                    intersect.Intersect(destRect);
                    if (intersect.IsEmpty)
                    {
                        return;
                    }

                    var sourcePixels = srcContext.Pixels;
                    var destPixels   = destContext.Pixels;
                    var sourceLength = srcContext.Length;

                    int sourceIdx = -1;
                    int px        = (int)destRect.X;
                    int py        = (int)destRect.Y;

                    int    x;
                    int    y;
                    int    idx;
                    double ii;
                    double jj;
                    int    sr = 0;
                    int    sg = 0;
                    int    sb = 0;
                    int    dr, dg, db;
                    int    sourcePixel;
                    int    sa = 0;
                    int    da;
                    int    ca = color.A;
                    int    cr = color.R;
                    int    cg = color.G;
                    int    cb = color.B;
                    bool   tinted = color != Colors.White;
                    var    sw = (int)sourceRect.Width;
                    var    sdx = sourceRect.Width / destRect.Width;
                    var    sdy = sourceRect.Height / destRect.Height;
                    int    sourceStartX = (int)sourceRect.X;
                    int    sourceStartY = (int)sourceRect.Y;
                    int    lastii, lastjj;
                    lastii = -1;
                    lastjj = -1;
                    jj     = sourceStartY;
                    y      = py;
                    for (int j = 0; j < dh; j++)
                    {
                        if (y >= 0 && y < dph)
                        {
                            ii          = sourceStartX;
                            idx         = px + y * dpw;
                            x           = px;
                            sourcePixel = sourcePixels[0];

                            // Scanline BlockCopy is much faster (3.5x) if no tinting and blending is needed,
                            // even for smaller sprites like the 32x32 particles.
                            if (blendMode == BlendMode.None && !tinted)
                            {
                                sourceIdx = (int)ii + (int)jj * sourceWidth;
                                var offset = x < 0 ? -x : 0;
                                var xx     = x + offset;
                                var wx     = sourceWidth - offset;
                                var len    = xx + wx < dpw ? wx : dpw - xx;
                                if (len > sw)
                                {
                                    len = sw;
                                }
                                if (len > dw)
                                {
                                    len = dw;
                                }
                                BitmapContext.BlockCopy(srcContext, (sourceIdx + offset) * 4, destContext, (idx + offset) * 4, len * 4);
                            }

                            // Pixel by pixel copying
                            else
                            {
                                for (int i = 0; i < dw; i++)
                                {
                                    if (x >= 0 && x < dpw)
                                    {
                                        if ((int)ii != lastii || (int)jj != lastjj)
                                        {
                                            sourceIdx = (int)ii + (int)jj * sourceWidth;
                                            if (sourceIdx >= 0 && sourceIdx < sourceLength)
                                            {
                                                sourcePixel = sourcePixels[sourceIdx];
                                                sa          = ((sourcePixel >> 24) & 0xff);
                                                sr          = ((sourcePixel >> 16) & 0xff);
                                                sg          = ((sourcePixel >> 8) & 0xff);
                                                sb          = ((sourcePixel) & 0xff);
                                                if (tinted && sa != 0)
                                                {
                                                    sa          = (((sa * ca) * 0x8081) >> 23);
                                                    sr          = ((((((sr * cr) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
                                                    sg          = ((((((sg * cg) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
                                                    sb          = ((((((sb * cb) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
                                                    sourcePixel = (sa << 24) | (sr << 16) | (sg << 8) | sb;
                                                }
                                            }
                                            else
                                            {
                                                sa = 0;
                                            }
                                        }
                                        if (blendMode == BlendMode.None)
                                        {
                                            destPixels[idx] = sourcePixel;
                                        }
                                        else if (blendMode == BlendMode.ColorKeying)
                                        {
                                            sr = ((sourcePixel >> 16) & 0xff);
                                            sg = ((sourcePixel >> 8) & 0xff);
                                            sb = ((sourcePixel) & 0xff);

                                            if (sr != color.R || sg != color.G || sb != color.B)
                                            {
                                                destPixels[idx] = sourcePixel;
                                            }
                                        }
                                        else if (blendMode == BlendMode.Mask)
                                        {
                                            int destPixel = destPixels[idx];
                                            da        = ((destPixel >> 24) & 0xff);
                                            dr        = ((destPixel >> 16) & 0xff);
                                            dg        = ((destPixel >> 8) & 0xff);
                                            db        = ((destPixel) & 0xff);
                                            destPixel = ((((da * sa) * 0x8081) >> 23) << 24) |
                                                        ((((dr * sa) * 0x8081) >> 23) << 16) |
                                                        ((((dg * sa) * 0x8081) >> 23) << 8) |
                                                        ((((db * sa) * 0x8081) >> 23));
                                            destPixels[idx] = destPixel;
                                        }
                                        else if (sa > 0)
                                        {
                                            int destPixel = destPixels[idx];
                                            da = ((destPixel >> 24) & 0xff);
                                            if ((sa == 255 || da == 0) &&
                                                blendMode != BlendMode.Additive &&
                                                blendMode != BlendMode.Subtractive &&
                                                blendMode != BlendMode.Multiply
                                                )
                                            {
                                                destPixels[idx] = sourcePixel;
                                            }
                                            else
                                            {
                                                dr = ((destPixel >> 16) & 0xff);
                                                dg = ((destPixel >> 8) & 0xff);
                                                db = ((destPixel) & 0xff);
                                                if (blendMode == BlendMode.Alpha)
                                                {
                                                    var isa = 255 - sa;
#if NETFX_CORE
                                                    // Special case for WinRT since it does not use pARGB (pre-multiplied alpha)
                                                    destPixel = ((da & 0xff) << 24) |
                                                                ((((sr * sa + isa * dr) >> 8) & 0xff) << 16) |
                                                                ((((sg * sa + isa * dg) >> 8) & 0xff) << 8) |
                                                                (((sb * sa + isa * db) >> 8) & 0xff);
#elif WPF
                                                    if (isPrgba)
                                                    {
                                                        destPixel = ((da & 0xff) << 24) |
                                                                    (((((sr << 8) + isa * dr) >> 8) & 0xff) << 16) |
                                                                    (((((sg << 8) + isa * dg) >> 8) & 0xff) << 8) |
                                                                    ((((sb << 8) + isa * db) >> 8) & 0xff);
                                                    }
                                                    else
                                                    {
                                                        destPixel = ((da & 0xff) << 24) |
                                                                    (((((sr * sa) + isa * dr) >> 8) & 0xff) << 16) |
                                                                    (((((sg * sa) + isa * dg) >> 8) & 0xff) << 8) |
                                                                    ((((sb * sa) + isa * db) >> 8) & 0xff);
                                                    }
#else
                                                    destPixel = ((da & 0xff) << 24) |
                                                                (((((sr << 8) + isa * dr) >> 8) & 0xff) << 16) |
                                                                (((((sg << 8) + isa * dg) >> 8) & 0xff) << 8) |
                                                                ((((sb << 8) + isa * db) >> 8) & 0xff);
#endif
                                                }
                                                else if (blendMode == BlendMode.Additive)
                                                {
                                                    int a = (255 <= sa + da) ? 255 : (sa + da);
                                                    destPixel = (a << 24) |
                                                                (((a <= sr + dr) ? a : (sr + dr)) << 16) |
                                                                (((a <= sg + dg) ? a : (sg + dg)) << 8) |
                                                                (((a <= sb + db) ? a : (sb + db)));
                                                }
                                                else if (blendMode == BlendMode.Subtractive)
                                                {
                                                    int a = da;
                                                    destPixel = (a << 24) |
                                                                (((sr >= dr) ? 0 : (sr - dr)) << 16) |
                                                                (((sg >= dg) ? 0 : (sg - dg)) << 8) |
                                                                (((sb >= db) ? 0 : (sb - db)));
                                                }
                                                else if (blendMode == BlendMode.Multiply)
                                                {
                                                    // Faster than a division like (s * d) / 255 are 2 shifts and 2 adds
                                                    int ta = (sa * da) + 128;
                                                    int tr = (sr * dr) + 128;
                                                    int tg = (sg * dg) + 128;
                                                    int tb = (sb * db) + 128;

                                                    int ba = ((ta >> 8) + ta) >> 8;
                                                    int br = ((tr >> 8) + tr) >> 8;
                                                    int bg = ((tg >> 8) + tg) >> 8;
                                                    int bb = ((tb >> 8) + tb) >> 8;

                                                    destPixel = (ba << 24) |
                                                                ((ba <= br ? ba : br) << 16) |
                                                                ((ba <= bg ? ba : bg) << 8) |
                                                                ((ba <= bb ? ba : bb));
                                                }

                                                destPixels[idx] = destPixel;
                                            }
                                        }
                                    }
                                    x++;
                                    idx++;
                                    ii += sdx;
                                }
                            }
                        }
                        jj += sdy;
                        y++;
                    }
                }
            }
        }
예제 #52
0
        public void SetBlendMode(BlendMode mode)
        {
            VerifyThreadAffinity();
            OpenGL.glBlendEquation(OpenGL.GL_FUNC_ADD);
            OpenGL.CheckGLError();

            switch (mode)
            {
            case BlendMode.None:
                OpenGL.glDisable(OpenGL.GL_BLEND);
                break;

            case BlendMode.Alpha:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_ONE, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
                break;

            case BlendMode.Additive:
            case BlendMode.Subtractive:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_ONE, OpenGL.GL_ONE);
                if (mode == BlendMode.Subtractive)
                {
                    OpenGL.CheckGLError();
                    OpenGL.glBlendEquationSeparate(OpenGL.GL_FUNC_REVERSE_SUBTRACT, OpenGL.GL_FUNC_ADD);
                }

                break;

            case BlendMode.Multiply:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_DST_COLOR, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
                OpenGL.CheckGLError();
                break;

            case BlendMode.Multiplicative:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_ZERO, OpenGL.GL_SRC_COLOR);
                break;

            case BlendMode.DoubleMultiplicative:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_DST_COLOR, OpenGL.GL_SRC_COLOR);
                break;

            case BlendMode.LowAdditive:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_DST_COLOR, OpenGL.GL_ONE);
                break;

            case BlendMode.Screen:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_SRC_COLOR, OpenGL.GL_ONE_MINUS_SRC_COLOR);
                break;

            case BlendMode.Translucent:
                OpenGL.glEnable(OpenGL.GL_BLEND);
                OpenGL.CheckGLError();
                OpenGL.glBlendFunc(OpenGL.GL_DST_COLOR, OpenGL.GL_ONE_MINUS_DST_COLOR);
                break;
            }

            OpenGL.CheckGLError();
        }
예제 #53
0
        public DrawSpritesDescription(Matrix transformation, BlendMode blendMode, IReadOnlyCollection <Vector3> positions, IReadOnlyCollection <Vector2> sizes, IReadOnlyCollection <Color4> colors, string texturePath = "")
        {
            GeometryDescriptor = new SpritesDescriptor();

            Update(transformation, blendMode, positions, sizes, colors, texturePath);
        }
        public static void Blit(BitmapContext destContext, int dpw, int dph, Rect destRect, BitmapContext srcContext, Rect sourceRect, int sourceWidth)
        {
            const BlendMode blendMode = BlendMode.Alpha;

            int dw = (int)destRect.Width;
            int dh = (int)destRect.Height;

            Rect intersect = new Rect(0, 0, dpw, dph);

            intersect.Intersect(destRect);
            if (intersect.IsEmpty)
            {
                return;
            }
#if WPF
            var isPrgba = srcContext.Format == PixelFormats.Pbgra32 || srcContext.Format == PixelFormats.Prgba64 || srcContext.Format == PixelFormats.Prgba128Float;
#endif

            var    sourcePixels = srcContext.Pixels;
            var    destPixels   = destContext.Pixels;
            int    sourceLength = srcContext.Length;
            int    sourceIdx    = -1;
            int    px           = (int)destRect.X;
            int    py           = (int)destRect.Y;
            int    x;
            int    y;
            int    idx;
            double ii;
            double jj;
            int    sr = 0;
            int    sg = 0;
            int    sb = 0;
            int    dr, dg, db;
            int    sourcePixel;
            int    sa = 0;
            int    da;

            var sw = (int)sourceRect.Width;
            var sdx = sourceRect.Width / destRect.Width;
            var sdy = sourceRect.Height / destRect.Height;
            int sourceStartX = (int)sourceRect.X;
            int sourceStartY = (int)sourceRect.Y;
            int lastii, lastjj;
            lastii = -1;
            lastjj = -1;
            jj     = sourceStartY;
            y      = py;
            for (var j = 0; j < dh; j++)
            {
                if (y >= 0 && y < dph)
                {
                    ii          = sourceStartX;
                    idx         = px + y * dpw;
                    x           = px;
                    sourcePixel = sourcePixels[0];

                    // Pixel by pixel copying
                    for (var i = 0; i < dw; i++)
                    {
                        if (x >= 0 && x < dpw)
                        {
                            if ((int)ii != lastii || (int)jj != lastjj)
                            {
                                sourceIdx = (int)ii + (int)jj * sourceWidth;
                                if (sourceIdx >= 0 && sourceIdx < sourceLength)
                                {
                                    sourcePixel = sourcePixels[sourceIdx];
                                    sa          = ((sourcePixel >> 24) & 0xff);
                                    sr          = ((sourcePixel >> 16) & 0xff);
                                    sg          = ((sourcePixel >> 8) & 0xff);
                                    sb          = ((sourcePixel) & 0xff);
                                }
                                else
                                {
                                    sa = 0;
                                }
                            }

                            if (sa > 0)
                            {
                                int destPixel = destPixels[idx];
                                da = ((destPixel >> 24) & 0xff);
                                if ((sa == 255 || da == 0))
                                {
                                    destPixels[idx] = sourcePixel;
                                }
                                else
                                {
                                    dr = ((destPixel >> 16) & 0xff);
                                    dg = ((destPixel >> 8) & 0xff);
                                    db = ((destPixel) & 0xff);
                                    var isa = 255 - sa;
#if NETFX_CORE
                                    // Special case for WinRT since it does not use pARGB (pre-multiplied alpha)
                                    destPixel = ((da & 0xff) << 24) |
                                                ((((sr * sa + isa * dr) >> 8) & 0xff) << 16) |
                                                ((((sg * sa + isa * dg) >> 8) & 0xff) << 8) |
                                                (((sb * sa + isa * db) >> 8) & 0xff);
#elif WPF
                                    if (isPrgba)
                                    {
                                        destPixel = ((da & 0xff) << 24) |
                                                    (((((sr << 8) + isa * dr) >> 8) & 0xff) << 16) |
                                                    (((((sg << 8) + isa * dg) >> 8) & 0xff) << 8) |
                                                    ((((sb << 8) + isa * db) >> 8) & 0xff);
                                    }
                                    else
                                    {
                                        destPixel = ((da & 0xff) << 24) |
                                                    (((((sr * sa) + isa * dr) >> 8) & 0xff) << 16) |
                                                    (((((sg * sa) + isa * dg) >> 8) & 0xff) << 8) |
                                                    ((((sb * sa) + isa * db) >> 8) & 0xff);
                                    }
#else
                                    destPixel = ((da & 0xff) << 24) |
                                                (((((sr << 8) + isa * dr) >> 8) & 0xff) << 16) |
                                                (((((sg << 8) + isa * dg) >> 8) & 0xff) << 8) |
                                                ((((sb << 8) + isa * db) >> 8) & 0xff);
#endif
                                    destPixels[idx] = destPixel;
                                }
                            }
                        }
                        x++;
                        idx++;
                        ii += sdx;
                    }
                }
                jj += sdy;
                y++;
            }
        }
예제 #55
0
    private void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
    {
        switch (blendMode)
        {
        case BlendMode.Opaque:
            material.SetOverrideTag("RenderType", "");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetInt("_ZWrite", 1);
            material.DisableKeyword("_ALPHATEST_ON");
            material.DisableKeyword("_ALPHABLEND_ON");
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = -1;
            break;

        case BlendMode.AlphaTest:
            material.SetOverrideTag("RenderType", "TransparentCutout");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetInt("_ZWrite", 1);
            material.EnableKeyword("_ALPHATEST_ON");
            material.DisableKeyword("_ALPHABLEND_ON");
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = 2450;
            break;

        case BlendMode.AlphaBlend:
            material.SetOverrideTag("RenderType", "Transparent");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            material.SetInt("_ZWrite", 0);
            material.DisableKeyword("_ALPHATEST_ON");
            material.EnableKeyword("_ALPHABLEND_ON");
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = 3000;
            break;

        case BlendMode.Premultiply:
            material.SetOverrideTag("RenderType", "Transparent");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            material.SetInt("_ZWrite", 0);
            material.DisableKeyword("_ALPHATEST_ON");
            material.EnableKeyword("_ALPHABLEND_ON");
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = 3000;
            break;

        case BlendMode.Additive:
            material.SetOverrideTag("RenderType", "Transparent");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_ZWrite", 0);
            material.DisableKeyword("_ALPHATEST_ON");
            material.DisableKeyword("_ALPHABLEND_ON");
            material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = 3000;
            break;

        case BlendMode.Multiply:
            material.SetOverrideTag("RenderType", "Transparent");
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            material.SetInt("_ZWrite", 0);
            material.DisableKeyword("_ALPHATEST_ON");
            material.EnableKeyword("_ALPHABLEND_ON");
            material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
            material.renderQueue = 3000;
            break;
        }
    }
예제 #56
0
        public void DrawRotated(Texture2D tex, Rectangle source, Rectangle dest, Vector2 origin, Color4 color, BlendMode mode, float angle, bool flip = false)
        {
            if (rs.ScissorEnabled && !scissorUsed)
            {
                Flush();
                scissorUsed = true;
            }
            Prepare(mode, tex, false);
            float x  = dest.X;
            float y  = dest.Y;
            float w  = dest.Width;
            float h  = dest.Height;
            float dx = -origin.X;
            float dy = -origin.Y;

            float srcX = (float)source.X;
            float srcY = (float)source.Y;
            float srcW = (float)source.Width;
            float srcH = (float)source.Height;


            var cos = MathF.Cos(angle);
            var sin = MathF.Sin(angle);
            var tl  = new Vector2(
                x + dx * cos - dy * sin,
                y + dx * sin + dy * cos
                );
            var tr = new Vector2(
                x + (dx + w) * cos - dy * sin,
                y + (dx + w) * sin + dy * cos
                );
            var bl = new Vector2(
                x + dx * cos - (dy + h) * sin,
                y + dx * sin + (dy + h) * cos
                );
            var br = new Vector2(
                x + (dx + w) * cos - (dy + h) * sin,
                y + (dx + w) * sin + (dy + h) * cos
                );

            Vector2 ta = new Vector2(srcX / (float)tex.Width,
                                     srcY / (float)tex.Height);
            Vector2 tb = new Vector2((srcX + srcW) / (float)tex.Width,
                                     srcY / (float)tex.Height);
            Vector2 tc = new Vector2(srcX / (float)tex.Width,
                                     (srcY + srcH) / (float)tex.Height);
            Vector2 td = new Vector2((srcX + srcW) / (float)tex.Width,
                                     (srcY + srcH) / (float)tex.Height);

            vertices [vertexCount++] = new Vertex2D(
                tl, ta,
                0,
                color
                );
            vertices [vertexCount++] = new Vertex2D(
                tr, tb,
                0,
                color
                );
            vertices [vertexCount++] = new Vertex2D(
                bl, tc,
                0,
                color
                );
            vertices [vertexCount++] = new Vertex2D(
                br, td,
                0,
                color
                );

            primitiveCount += 2;
        }
예제 #57
0
        private void AddFlare(Color color, Texture texture, float size = -1, float distance = 0, BlendMode blending = BlendMode.Normal, float opacity = 1)
        {
            distance = Mathf.Min(distance, Mathf.Max(0, distance));
            var lensFlareInfo = new LensFlareInfo()
            {
                Texture  = texture,             // THREE.Texture
                Size     = size,                // size in pixels (-1 = use texture.width)
                Distance = distance,            // distance (0-1) from light source (0=at light source)
                x        = 0,
                y        = 0,
                Z        = 0,       // screen position (-1 => 1) z = 0 is ontop z = 1 is back
                Scale    = 1,       // scale
                Rotation = 1,       // rotation
                Opacity  = opacity, // opacity
                Color    = color,   // color
                Blending = blending // blending
            };

            lenFlareInfos.Add(lensFlareInfo);
        }
예제 #58
0
 public void SetBlendMode(BlendMode mode)
 {
 }
예제 #59
0
        public FxBasicAppearance(AlchemyNode ale) : base(ale)
        {
            AleParameter temp;

            if (ale.TryGetParameter("BasicApp_QuadTexture", out temp))
            {
                QuadTexture = (bool)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_TriTexture", out temp))
            {
                if ((bool)temp.Value)
                {
                    FLLog.Warning("ALE", "BasicApp_TriTexture not implemented");
                }
            }
            if (ale.TryGetParameter("BasicApp_MotionBlur", out temp))
            {
                MotionBlur = (bool)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_Color", out temp))
            {
                Color = (AlchemyColorAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_Alpha", out temp))
            {
                Alpha = (AlchemyFloatAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_HtoVAspect", out temp))
            {
                HToVAspect = (AlchemyFloatAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_Rotate", out temp))
            {
                Rotate = (AlchemyFloatAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_TexName", out temp))
            {
                Texture = (string)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_UseCommonTexFrame", out temp))
            {
                UseCommonAnimation = (bool)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_TexFrame", out temp))
            {
                Animation = (AlchemyFloatAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_CommonTexFrame", out temp))
            {
                CommonAnimation = (AlchemyCurveAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_FlipTexU", out temp))
            {
                FlipHorizontal = (bool)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_FlipTexV", out temp))
            {
                FlipVertical = (bool)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_Size", out temp))
            {
                Size = (AlchemyFloatAnimation)temp.Value;
            }
            if (ale.TryGetParameter("BasicApp_BlendInfo", out temp))
            {
                BlendInfo = BlendMap.Map((Tuple <uint, uint>)temp.Value);
            }
        }
예제 #60
0
        // All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if ocde change
        static public void SetupBaseUnlitKeywords(Material material)
        {
            bool alphaTestEnable = material.HasProperty(kAlphaCutoffEnabled) && material.GetFloat(kAlphaCutoffEnabled) > 0.0f;

            SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable);

            SurfaceType surfaceType = (SurfaceType)material.GetFloat(kSurfaceType);

            SetKeyword(material, "_SURFACE_TYPE_TRANSPARENT", surfaceType == SurfaceType.Transparent);

            bool enableBlendModePreserveSpecularLighting = material.HasProperty(kEnableBlendModePreserveSpecularLighting) && material.GetFloat(kEnableBlendModePreserveSpecularLighting) > 0.0f;

            SetKeyword(material, "_BLENDMODE_PRESERVE_SPECULAR_LIGHTING", enableBlendModePreserveSpecularLighting);

            // These need to always been set either with opaque or transparent! So a users can switch to opaque and remove the keyword correctly
            SetKeyword(material, "_BLENDMODE_ALPHA", false);
            SetKeyword(material, "_BLENDMODE_ADD", false);
            SetKeyword(material, "_BLENDMODE_MULTIPLY", false);
            SetKeyword(material, "_BLENDMODE_PRE_MULTIPLY", false);

            if (surfaceType == SurfaceType.Opaque)
            {
                material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt("_ZWrite", 1);
                material.renderQueue = alphaTestEnable ? (int)HDRenderQueue.AlphaTest : -1;
            }
            else
            {
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_ZWrite", 0);
                var isPrePass = material.HasProperty(kPreRefractionPass) && material.GetFloat(kPreRefractionPass) > 0.0f;
                material.renderQueue = (int)(isPrePass ? HDRenderQueue.PreRefraction : HDRenderQueue.Transparent);

                if (material.HasProperty(kBlendMode))
                {
                    BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode);

                    SetKeyword(material, "_BLENDMODE_ALPHA", BlendMode.Alpha == blendMode);
                    SetKeyword(material, "_BLENDMODE_ADD", BlendMode.Additive == blendMode);
                    SetKeyword(material, "_BLENDMODE_MULTIPLY", BlendMode.Multiplicative == blendMode);
                    SetKeyword(material, "_BLENDMODE_PRE_MULTIPLY", BlendMode.PremultipliedAlpha == blendMode);

                    switch (blendMode)
                    {
                    // Alpha
                    // color: src * src_a + dst * (1 - src_a)
                    // src * src_a is done in the shader as it allow to reduce precision issue when using _BLENDMODE_PRESERVE_SPECULAR_LIGHTING (See Material.hlsl)
                    case BlendMode.Alpha:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        break;

                    // Additive
                    // color: src * src_a + dst
                    // src * src_a is done in the shader
                    case BlendMode.Additive:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        break;

                    // Multiplicative
                    // color: src * dst
                    case BlendMode.Multiplicative:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                        break;

                    // PremultipliedAlpha
                    // color: src * src_a + dst * (1 - src_a)
                    // src is supposed to have been multiplied by alpha in the texture on artists side.
                    case BlendMode.PremultipliedAlpha:
                        material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                        break;
                    }
                }
            }

            bool doubleSidedEnable = material.HasProperty(kDoubleSidedEnable) && material.GetFloat(kDoubleSidedEnable) > 0.0f;

            if (doubleSidedEnable)
            {
                material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
            }
            else
            {
                material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back);
            }
            SetKeyword(material, "_DOUBLESIDED_ON", doubleSidedEnable);


            bool fogEnabled = material.HasProperty(kEnableFogOnTransparent) && material.GetFloat(kEnableFogOnTransparent) > 0.0f && surfaceType == SurfaceType.Transparent;

            SetKeyword(material, "_ENABLE_FOG_ON_TRANSPARENT", fogEnabled);

            if (material.HasProperty(kDistortionEnable))
            {
                bool distortionDepthTest = material.GetFloat(kDistortionDepthTest) > 0.0f;
                if (distortionDepthTest)
                {
                    material.SetInt("_ZTestMode", (int)UnityEngine.Rendering.CompareFunction.LessEqual);
                }
                else
                {
                    material.SetInt("_ZTestMode", (int)UnityEngine.Rendering.CompareFunction.Always);
                }

                var distortionBlendMode = material.GetInt(kDistortionBlendMode);
                switch (distortionBlendMode)
                {
                default:
                case 0:     // Add
                    material.SetInt("_DistortionSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionDstBlend", (int)UnityEngine.Rendering.BlendMode.One);

                    material.SetInt("_DistortionBlurSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionBlurDstBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    material.SetInt("_DistortionBlurBlendOp", (int)UnityEngine.Rendering.BlendOp.Max);
                    break;

                case 1:     // Multiply
                    material.SetInt("_DistortionSrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
                    material.SetInt("_DistortionDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);

                    material.SetInt("_DistortionBlurSrcBlend", (int)UnityEngine.Rendering.BlendMode.DstAlpha);
                    material.SetInt("_DistortionBlurDstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                    material.SetInt("_DistortionBlurBlendOp", (int)UnityEngine.Rendering.BlendOp.Add);
                    break;
                }
            }

            // A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
            // or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.
            // The fixup routine makes sure that the material is in the correct state if/when changes are made to the mode or color.
            MaterialEditor.FixupEmissiveFlag(material);

            // Commented out for now because unfortunately we used the hard coded property names used by the GI system for our own parameters
            // So we need a way to work around that before we activate this.
            SetupMainTexForAlphaTestGI("_EmissiveColorMap", "_EmissiveColor", material);

            // DoubleSidedGI has to be synced with our double sided toggle
            var serializedObject = new SerializedObject(material);
            var doubleSidedGIppt = serializedObject.FindProperty("m_DoubleSidedGI");

            doubleSidedGIppt.boolValue = doubleSidedEnable;
            serializedObject.ApplyModifiedProperties();
        }