/// <summary> /// Initializes a new instance of the <see cref="T:DesktopSprites.Interop.Win32.BLENDFUNCTION"/> structure. /// </summary> /// <param name="blendOp">The source blend operation.</param> /// <param name="sourceConstantAlpha">Specifies an alpha transparency value to be used on the entire source bitmap. The /// <see cref="P:DesktopSprites.Interop.Win32.BLENDFUNCTION.SourceConstantAlpha"/> value is combined with any per-pixel /// alpha values in the source bitmap. If you set <see cref="P:DesktopSprites.Win32.BLENDFUNCTION.SourceConstantAlpha"/> to 0, it /// is assumed that your image is transparent. Set the <see cref="P:DesktopSprites.Win32.BLENDFUNCTION.SourceConstantAlpha"/> /// value to 255 (opaque) when you only want to use per-pixel alpha values.</param> /// <param name="alphaFormat">This member controls the way the source and destination bitmaps are interpreted.</param> public BLENDFUNCTION(BlendOp blendOp, byte sourceConstantAlpha, AlphaFormat alphaFormat) { BlendOp = blendOp; BlendFlags = 0; SourceConstantAlpha = sourceConstantAlpha; AlphaFormat = alphaFormat; }
public static BlendEquationMode Convert(this BlendOp op) { switch (op) { case BlendOp.Add: case BlendOp.AddGl: return(BlendEquationMode.FuncAdd); case BlendOp.Minimum: case BlendOp.MinimumGl: return(BlendEquationMode.Min); case BlendOp.Maximum: case BlendOp.MaximumGl: return(BlendEquationMode.Max); case BlendOp.Subtract: case BlendOp.SubtractGl: return(BlendEquationMode.FuncSubtract); case BlendOp.ReverseSubtract: case BlendOp.ReverseSubtractGl: return(BlendEquationMode.FuncReverseSubtract); } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(BlendOp)} enum value: {op}."); return(BlendEquationMode.FuncAdd); }
public SemiTransParams(BlendOp blendOp, BlendMode srcFac, BlendMode dstFac, Byte alpha) { this.blendOp = blendOp; this.srcFac = srcFac; this.dstFac = dstFac; this.alpha = alpha; }
static int IntToEnum(IntPtr L) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); BlendOp o = (BlendOp)arg0; LuaScriptMgr.PushEnum(L, o); return(1); }
internal static BlendEquationMode Convert(BlendOp blendOp) { if (!blendOps.ContainsKey(blendOp)) { throw new NotSupportedException("indexFormat is not supported"); } return(blendOps[blendOp]); }
public static Color OpColor(Color left, Color right, BlendOp op) { switch (op) { case BlendOp.Add: return(left + right); case BlendOp.Sub: return(left - right); } return(Color.white); }
public void Read(AssetStream stream) { SrcBlend.Read(stream); DestBlend.Read(stream); SrcBlendAlpha.Read(stream); DestBlendAlpha.Read(stream); BlendOp.Read(stream); BlendOpAlpha.Read(stream); ColMask.Read(stream); }
public void Read(AssetReader reader) { SrcBlend.Read(reader); DestBlend.Read(reader); SrcBlendAlpha.Read(reader); DestBlendAlpha.Read(reader); BlendOp.Read(reader); BlendOpAlpha.Read(reader); ColMask.Read(reader); }
public void SetColorBlend( Material m, BlendMode Src, BlendMode Dst, BlendOp ColorOp ) { m.SetFloat("_BlendSrc", (float)Src); m.SetFloat("_BlendDst", (float)Dst); m.SetFloat("_BlendColorOp", (float)ColorOp); }
public void SetAlphaBlend( Material m, BlendMode AlphaSrc, BlendMode AlphaDst, BlendOp AlphaOp ) { m.SetFloat("_BlendAlphaSrc", (float)AlphaSrc); m.SetFloat("_BlendAlphaDst", (float)AlphaDst); m.SetFloat("_BlendAlphaOp", (float)AlphaOp); }
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)); }
public static void SetupMaterialBlendStates(Material mat, BlendOp blendop, BlendMode src, BlendMode dst, bool blend, bool dither) { mat.SetOverrideTag("RenderType", blend ? "Transparent" : "TransparentCutout"); mat.SetInt("_BlendOp", (int)blendop); mat.SetInt("_SrcBlend", (int)src); mat.SetInt("_DstBlend", (int)dst); mat.SetInt("_ZWrite", blend ? 0 : 1); SetKeyword(mat, "_ALPHATEST_ON", !blend && !dither); SetKeyword(mat, "_ALPHABLEND_ON", blend); SetKeyword(mat, "_ALPHATEST_DITHERED", !blend && dither); mat.renderQueue = (int)(blend? RenderQueue.Transparent: RenderQueue.AlphaTest); }
public virtual void SetupBlendMode() { blendPreset = (BlendPreset)this.blendPresetProperty.floatValue; blendModeSrc = (BlendMode)this.blendModeSrcProperty.floatValue; blendModeDst = (BlendMode)this.blendModeDstProperty.floatValue; blendOp = (BlendOp)this.blendOpProperty.floatValue; blendPreset = (BlendPreset)EditorGUILayout.EnumPopup("Blend Mode", blendPreset); bool disableCustomBlend = true; switch (blendPreset) { case BlendPreset.Alpha_Blend: blendModeSrc = BlendMode.SrcAlpha; blendModeDst = BlendMode.OneMinusSrcAlpha; blendOp = BlendOp.Add; break; case BlendPreset.Add: blendModeSrc = BlendMode.SrcAlpha; blendModeDst = BlendMode.One; blendOp = BlendOp.Add; break; case BlendPreset.AddRev: blendModeSrc = BlendMode.SrcAlpha; blendModeDst = BlendMode.One; blendOp = BlendOp.ReverseSubtract; break; case BlendPreset.Multiply: blendModeSrc = BlendMode.Zero; blendModeDst = BlendMode.SrcColor; blendOp = BlendOp.Add; break; case BlendPreset.PreMulBlend: blendModeSrc = BlendMode.One; blendModeDst = BlendMode.OneMinusSrcAlpha; blendOp = BlendOp.Add; break; case BlendPreset.Custom: disableCustomBlend = false; break; } EditorGUI.BeginDisabledGroup(disableCustomBlend); blendModeSrc = (BlendMode)EditorGUILayout.EnumPopup("Src", blendModeSrc); blendModeDst = (BlendMode)EditorGUILayout.EnumPopup("Dest", blendModeDst); blendOp = (BlendOp)EditorGUILayout.EnumPopup("Op", blendOp); EditorGUI.EndDisabledGroup(); }
private void GetMaterialProperties(Material material) { color = material.GetColor(shaderProperties.colorID); sourceColorBlendMode = (BlendMode)material.GetInt(shaderProperties.sourceColorBlendModeID); destinationColorBlendMode = (BlendMode)material.GetInt(shaderProperties.destinationColorBlendModeID); sourceAlphaBlendMode = (BlendMode)material.GetInt(shaderProperties.sourceAlphaBlendModeID); destinationAlphaBlendMode = (BlendMode)material.GetInt(shaderProperties.destinationAlphaBlendModeID); cullMode = (CullMode)material.GetInt(shaderProperties.cullModeID); zWriteMode = (ZWriteMode)material.GetInt(shaderProperties.zWriteModeID); zTestMode = (ZTestMode)material.GetInt(shaderProperties.zTestModeID); depthOffsetFactor = material.GetFloat(shaderProperties.depthOffsetFactorID); depthOffsetUnits = material.GetFloat(shaderProperties.depthOffsetUnitsID); blendOpColor = (BlendOp)material.GetInt(shaderProperties.blendOpColorID); blendOpAlpha = (BlendOp)material.GetInt(shaderProperties.blendOpAlphaID); }
public BlendDescriptor( bool enable, BlendOp colorOp, BlendFactor colorSrcFactor, BlendFactor colorDstFactor, BlendOp alphaOp, BlendFactor alphaSrcFactor, BlendFactor alphaDstFactor) { Enable = enable; ColorOp = colorOp; ColorSrcFactor = colorSrcFactor; ColorDstFactor = colorDstFactor; AlphaOp = alphaOp; AlphaSrcFactor = alphaSrcFactor; AlphaDstFactor = alphaDstFactor; }
public static BlendOperation Convert(BlendOp op) { switch (op) { case BlendOp.Add: return(BlendOperation.Add); case BlendOp.Max: return(BlendOperation.Maximum); case BlendOp.Min: return(BlendOperation.Minimum); case BlendOp.InvSub: return(BlendOperation.ReverseSubtract); case BlendOp.Sub: return(BlendOperation.Subtract); } throw new ArgumentException("Bad operation"); }
public RenderTargetBlendState( ColorWriteMask writeMask = ColorWriteMask.All, BlendMode sourceColorBlendMode = BlendMode.One, BlendMode destinationColorBlendMode = BlendMode.Zero, BlendMode sourceAlphaBlendMode = BlendMode.One, BlendMode destinationAlphaBlendMode = BlendMode.Zero, BlendOp colorBlendOperation = BlendOp.Add, BlendOp alphaBlendOperation = BlendOp.Add) { m_WriteMask = (byte)writeMask; m_SourceColorBlendMode = (byte)sourceColorBlendMode; m_DestinationColorBlendMode = (byte)destinationColorBlendMode; m_SourceAlphaBlendMode = (byte)sourceAlphaBlendMode; m_DestinationAlphaBlendMode = (byte)destinationAlphaBlendMode; m_ColorBlendOperation = (byte)colorBlendOperation; m_AlphaBlendOperation = (byte)alphaBlendOperation; m_Padding = 0; }
public BlendState( ColorWriteMask writeMask = ColorWriteMask.All, BlendMode sourceColorBlendMode = BlendMode.One, BlendMode destinationColorBlendMode = BlendMode.Zero, BlendMode sourceAlphaBlendMode = BlendMode.One, BlendMode destinationAlphaBlendMode = BlendMode.Zero, BlendOp colorBlendOperation = BlendOp.Add, BlendOp alphaBlendOperation = BlendOp.Add) { this.check0 = 0; this.check1 = 0; this.m_WriteMask = (byte)writeMask; this.m_SourceColorBlendMode = (byte)sourceColorBlendMode; this.m_DestinationColorBlendMode = (byte)destinationColorBlendMode; this.m_SourceAlphaBlendMode = (byte)sourceAlphaBlendMode; this.m_DestinationAlphaBlendMode = (byte)destinationAlphaBlendMode; this.m_ColorBlendOperation = (byte)colorBlendOperation; this.m_AlphaBlendOperation = (byte)alphaBlendOperation; this.m_Padding = 0; }
/// <summary> /// Creates a text to render with a BitmapFont. /// </summary> public static Entity CreateTextWithBitmapFont(EntityManager mgr, ref Entity fontEntity, string text, float size, Color color, BlendOp blending, float2 pivot) { Entity e = mgr.CreateEntity(typeof(Text2DStyle), typeof(Text2DRenderer), typeof(Text2DStyleBitmapFont)); mgr.SetComponentData(e, new Text2DRenderer() { blending = blending, pivot = pivot, style = e }); mgr.SetComponentData(e, new Text2DStyle() { color = color, size = size }); mgr.SetComponentData(e, new Text2DStyleBitmapFont() { font = fontEntity }); mgr.AddBufferFromString <TextString>(e, text); return(e); }
public PipelineColorBlendAttachmentState ( Bool32 blendEnable = default, BlendFactor srcColorBlendFactor = default, BlendFactor dstColorBlendFactor = default, BlendOp colorBlendOp = default, BlendFactor srcAlphaBlendFactor = default, BlendFactor dstAlphaBlendFactor = default, BlendOp alphaBlendOp = default, ColorComponentFlags colorWriteMask = default ) { BlendEnable = blendEnable; SrcColorBlendFactor = srcColorBlendFactor; DstColorBlendFactor = dstColorBlendFactor; ColorBlendOp = colorBlendOp; SrcAlphaBlendFactor = srcAlphaBlendFactor; DstAlphaBlendFactor = dstAlphaBlendFactor; AlphaBlendOp = alphaBlendOp; ColorWriteMask = colorWriteMask; }
private void ExposeMaterialProperties() { // Create a style for the titles GUIStyle guiStyle = new GUIStyle(); guiStyle.fontStyle = FontStyle.Bold; guiStyle.normal.textColor = Color.white; // Start the check if anything has changed... EditorGUI.BeginChangeCheck(); // Show the properties EditorGUILayout.LabelField("Main texture and color", guiStyle); //TexturePropertySingleLine(new GUIContent(ShaderProperties.MAIN_TEXTURE_DESCRIPTION), GetMaterialProperties(targets)[0]); TextureProperty(GetMaterialProperties(targets)[0], ShaderProperties.MAIN_TEXTURE_DESCRIPTION); color = EditorGUILayout.ColorField(ShaderProperties.COLOR_DESCRIPTION, color); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Color Blending", guiStyle); sourceColorBlendMode = (BlendMode)EditorGUILayout.EnumPopup(ShaderProperties.SOURCE_COLOR_BLEND_MODE_DESCRIPTION, sourceColorBlendMode); destinationColorBlendMode = (BlendMode)EditorGUILayout.EnumPopup(ShaderProperties.DESTINATION_COLOR_BLEND_MODE_DESCRIPTION, destinationColorBlendMode); blendOpColor = (BlendOp)EditorGUILayout.EnumPopup(ShaderProperties.BLEND_OP_COLOR_DESCRIPTION, blendOpColor); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Alpha Blending", guiStyle); sourceAlphaBlendMode = (BlendMode)EditorGUILayout.EnumPopup(ShaderProperties.SOURCE_ALPHA_BLEND_MODE_DESCRIPTION, sourceAlphaBlendMode); destinationAlphaBlendMode = (BlendMode)EditorGUILayout.EnumPopup(ShaderProperties.DESTINATION_ALPHA_BLEND_MODE_DESCRIPTION, destinationAlphaBlendMode); blendOpAlpha = (BlendOp)EditorGUILayout.EnumPopup(ShaderProperties.BLEND_OP_ALPHA_DESCRIPTION, blendOpAlpha); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Culling", guiStyle); cullMode = (CullMode)EditorGUILayout.EnumPopup(ShaderProperties.CULL_MODE_DESCRIPTION, cullMode); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Z Write/Test/Depth", guiStyle); zWriteMode = (ZWriteMode)EditorGUILayout.EnumPopup(ShaderProperties.Z_WRITE_MODE_DESCRIPTION, zWriteMode); zTestMode = (ZTestMode)EditorGUILayout.EnumPopup(ShaderProperties.Z_TEST_MODE_DESCRIPTION, zTestMode); depthOffsetFactor = EditorGUILayout.FloatField(ShaderProperties.DEPTH_OFFSET_FACTOR_DESCRIPTION, depthOffsetFactor); depthOffsetUnits = EditorGUILayout.FloatField(ShaderProperties.DEPTH_OFFSET_UNITS_DESCRIPTION, depthOffsetUnits); }
/// <summary> /// Renders a full watercolor brush into the given texture. /// </summary> /// <param name="outputTex"> /// The RenderTexture used to hold the result. /// Must have stencil bits in the depth buffer. /// Its depth/stencil buffer will be modified during rendering. /// </param> /// <param name="nVariants"> /// The number of individual shapes to blend together. /// </param> /// <param name="color"> /// The color of each variant. /// </param> public static void RenderFull(PolyShapeGPU shape, RenderTexture outputTex, Mesh meshBuffer, int nVariants, Vector2 offset, Vector2 scale, Color color, BlendMode blendSrc = BlendMode.SrcAlpha, BlendMode blendDest = BlendMode.OneMinusSrcAlpha, BlendOp blendOp = BlendOp.Add) { var shapeVariantTex = RenderTexture.GetTemporary(shape.VariationShapeSize, 1, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); shapeVariantTex.filterMode = FilterMode.Point; shapeVariantTex.wrapMode = TextureWrapMode.Repeat; for (int i = 0; i < nVariants; ++i) { shape.GenerateVariation(shapeVariantTex); Render(shapeVariantTex, outputTex, meshBuffer, offset, scale, color, blendSrc, blendDest, blendOp); } RenderTexture.ReleaseTemporary(shapeVariantTex); }
public Material SetBlendOp(BlendOp op) { this.blendOp = op; return(this); }
public static RenderStateDescriptor BlendOp(BlendOp op, BlendOp opAlpha) => new RenderStateDescriptor { type = RenderStateType.BlendOp, value = $"BlendOp {op}, {opAlpha}" };
/// <summary> /// Renders this shape into the given texture. /// </summary> /// <param name="outputTex"> /// The texture that will contain the result. /// Must have stencil bits in the depth buffer. /// Its depth/stencil buffer will be modified during rendering. /// </param> /// <param name="meshBuffer"> /// A mesh to use during rendering. /// If the mesh does not have the right number of vertices, it will be updated. /// </param> /// <param name="offset"> /// The offset of this shape in the output texture. /// </param> /// <param name="scale"> /// The scale of this shape in the output texture. /// </param> public static void Render(Texture shapeTex, RenderTexture outputTex, Mesh meshBuffer, Vector2 offset, Vector2 scale, Color color, BlendMode blendSrc = BlendMode.SrcAlpha, BlendMode blendDest = BlendMode.OneMinusSrcAlpha, BlendOp blendOp = BlendOp.Add) { //Make sure we have the Material/shaders for this. if (shapeRenderMat == null) { var shader = Shader.Find("PolyShape/Renderer"); if (shader == null) { throw new InvalidOperationException("No Renderer shader found!"); } shapeRenderMat = new Material(shader); } //Reset the mesh if it's not correct. int nVerts = shapeTex.width; if (meshBuffer.GetTopology(0) != MeshTopology.LineStrip || meshBuffer.vertexCount != nVerts) { var verts = new Vector3[nVerts]; var inds = new int[nVerts]; for (int i = 0; i < nVerts; ++i) { //Set the vertex's X position to be // the corresponding texel in the shape texture. verts[i] = new Vector3((i + 0.5f) / nVerts, 0.0f, 0.0f); inds[i] = i; } meshBuffer.vertices = verts; meshBuffer.SetIndices(inds, MeshTopology.LineStrip, 0); meshBuffer.UploadMeshData(true); } //Prepare the material/shape texture. shapeTex.filterMode = FilterMode.Point; shapeTex.wrapMode = TextureWrapMode.Repeat; shapeRenderMat.mainTexture = shapeTex; shapeRenderMat.SetVector("_ShapeOffsetAndScale", new Vector4(offset.x, offset.y, scale.x, scale.y)); shapeRenderMat.color = color; shapeRenderMat.SetInt("_BlendSrc", (int)blendSrc); shapeRenderMat.SetInt("_BlendDest", (int)blendDest); shapeRenderMat.SetInt("_BlendOp", (int)blendOp); //Render the passes. var oldRendTex = RenderTexture.active; RenderTexture.active = outputTex; GL.Clear(true, false, Color.clear); shapeRenderMat.SetPass(0); Graphics.DrawMeshNow(meshBuffer, Matrix4x4.identity); shapeRenderMat.SetPass(1); Graphics.DrawMeshNow(ScreenQuadRenderer.QuadMesh, Matrix4x4.identity); RenderTexture.active = oldRendTex; }
public BlendMode(EndianBinaryReader er) { BlendOperator = (BlendOp)er.ReadByte(); SourceFactor = (BlendSource)er.ReadByte(); DestinationFactor = (BlendDestination)er.ReadByte(); LogicOperator = (BlendLogicOp)er.ReadByte(); }
/// <summary> /// /// </summary> public PipelineColorBlendAttachmentState(Bool32 blendEnable, BlendFactor sourceColorBlendFactor, BlendFactor destinationColorBlendFactor, BlendOp colorBlendOp, BlendFactor sourceAlphaBlendFactor, BlendFactor destinationAlphaBlendFactor, BlendOp alphaBlendOp, ColorComponentFlags colorWriteMask) { this.BlendEnable = blendEnable; this.SourceColorBlendFactor = sourceColorBlendFactor; this.DestinationColorBlendFactor = destinationColorBlendFactor; this.ColorBlendOp = colorBlendOp; this.SourceAlphaBlendFactor = sourceAlphaBlendFactor; this.DestinationAlphaBlendFactor = destinationAlphaBlendFactor; this.AlphaBlendOp = alphaBlendOp; this.ColorWriteMask = colorWriteMask; }
public static BlendOperation Convert ( BlendOp op ) { switch ( op ) { case BlendOp.Add : return BlendOperation.Add; case BlendOp.Max : return BlendOperation.Maximum; case BlendOp.Min : return BlendOperation.Minimum; case BlendOp.InvSub : return BlendOperation.ReverseSubtract; case BlendOp.Sub : return BlendOperation.Subtract; } throw new ArgumentException("Bad operation"); }
// 混合 public static Vector4 BlendHandle( Vector4 src, Vector4 dst, BlendFactor srcColorFactor, BlendFactor dstColorFactor, BlendFactor srcAlphaFactor, BlendFactor dstAlphaFactor, BlendOp blendColorOp, BlendOp blendAlphaOp ) { var sr = src.r; var sg = src.g; var sb = src.b; var sa = src.a; var dr = dst.r; var dg = dst.g; var db = dst.b; var da = dst.a; var oneMSA = 1 - sa; var oneMDA = 1 - da; switch (srcColorFactor) { case BlendFactor.One: /* noops */ break; case BlendFactor.Zero: sr = 0; sg = 0; sb = 0; break; case BlendFactor.SrcAlpha: sr *= sa; sg *= sa; sb *= sa; break; case BlendFactor.OneMinusSrcAlpha: sr *= oneMSA; sg *= oneMSA; sb *= oneMSA; break; case BlendFactor.DstAlpha: sr *= da; sg *= da; sb *= da; break; case BlendFactor.OneMinusDstAlpha: sr *= oneMDA; sg *= oneMDA; sb *= oneMDA; break; default: throw new NotImplementedException($"Not implements"); } switch (dstColorFactor) { case BlendFactor.One: /* noops */ break; case BlendFactor.Zero: dr = 0; dg = 0; db = 0; break; case BlendFactor.SrcAlpha: dr *= sa; dg *= sa; db *= sa; break; case BlendFactor.OneMinusSrcAlpha: dr *= oneMSA; dg *= oneMSA; db *= oneMSA; break; case BlendFactor.DstAlpha: dr *= da; dg *= da; db *= da; break; case BlendFactor.OneMinusDstAlpha: dr *= oneMDA; dg *= oneMDA; db *= oneMDA; break; default: throw new NotImplementedException($"Not implements"); } switch (srcAlphaFactor) { case BlendFactor.One: /* noops */ break; case BlendFactor.Zero: sa = 0; break; case BlendFactor.SrcAlpha: sa *= sa; break; case BlendFactor.OneMinusSrcAlpha: sa *= oneMSA; break; case BlendFactor.DstAlpha: sa *= da; break; case BlendFactor.OneMinusDstAlpha: sa *= oneMDA; break; default: throw new NotImplementedException($"Not implements"); } switch (dstAlphaFactor) { case BlendFactor.One: /* noops */ break; case BlendFactor.Zero: da = 0; break; case BlendFactor.SrcAlpha: da *= sa; break; case BlendFactor.OneMinusSrcAlpha: da *= oneMSA; break; case BlendFactor.DstAlpha: da *= da; break; case BlendFactor.OneMinusDstAlpha: da *= oneMDA; break; default: throw new NotImplementedException($"Not implements"); } switch (blendColorOp) { case BlendOp.Add: sr += dr; sg += dg; sb += db; break; case BlendOp.Sub: sr -= dr; sg -= dg; sb -= db; break; case BlendOp.Multiply: sr *= dr; sg *= dg; sb *= db; break; case BlendOp.Divide: sr /= dr; sg /= dg; sb /= db; break; // 除法的性能好渣,尽量不用 default: throw new NotImplementedException($"Not implements"); } switch (blendAlphaOp) { case BlendOp.Add: sa += da; break; case BlendOp.Sub: sa -= da; break; case BlendOp.Multiply: sa *= da; break; case BlendOp.Divide: sa /= da; break; // 除法的性能好渣,尽量不用 default: throw new NotImplementedException($"Not implements"); } return(Vector4.Get(sr, sg, sb, sa)); }
public static bool IsAdd(this BlendOp _this) { return(_this == BlendOp.Add); }
void OnValidate() { BlendMode srcMode = BlendMode.SrcAlpha, dstMode = BlendMode.OneMinusSrcAlpha; BlendOp op = 0; if (material == null) { material = GetComponent <Renderer>().sharedMaterial; } switch (blendMode) { case BlendingMode.Darken: { srcMode = BlendMode.One; dstMode = BlendMode.One; op = BlendOp.Min; } break; case BlendingMode.Multiply: { srcMode = BlendMode.DstColor; dstMode = BlendMode.Zero; } break; case BlendingMode.Lighten: { srcMode = BlendMode.One; dstMode = BlendMode.One; op = BlendOp.Max; } break; case BlendingMode.Additive: { srcMode = BlendMode.One; dstMode = BlendMode.One; } break; case BlendingMode.Soft_Additive: { srcMode = BlendMode.OneMinusDstColor; dstMode = BlendMode.One; } break; case BlendingMode.Linear_Burn: { srcMode = BlendMode.One; dstMode = BlendMode.One; op = BlendOp.ReverseSubtract; } break; case BlendingMode.Overlay: { srcMode = BlendMode.One; dstMode = BlendMode.SrcColor; } break; default: break; } material.SetInt("_SrcMode", (int)srcMode); material.SetInt("_DstMode", (int)dstMode); material.SetInt("_BlendOp", (int)op); }