/// <summary> /// /// </summary> /// <param name="other"></param> /// <returns></returns> public virtual bool Equals(Material other) { if (other == null) { return(false); } return(AlphaTest.Equals(other.AlphaTest) && Blending.Equals(other.Blending) && ClipIntersections.Equals(other.ClipIntersections) && ClipShadows.Equals(other.ClipShadows) && ColorWrite.Equals(other.ColorWrite) && DepthTest.Equals(other.DepthTest) && DepthWrite.Equals(other.DepthWrite) && Dithering.Equals(other.Dithering) && FlatShading.Equals(other.FlatShading) && Fog.Equals(other.Fog) && Lights.Equals(other.Lights) && Opacity.Equals(other.Opacity) && Overdraw.Equals(other.Overdraw) && PremultipliedAlpha.Equals(other.PremultipliedAlpha) && Side.Equals(other.Side) && Transparent.Equals(other.Transparent) && VertexColors.Equals(other.VertexColors) && Visible.Equals(other.Visible) && UserData == other.UserData && ClippingPlanes == other.ClippingPlanes && string.Equals(Precision, other.Precision)); }
public override void OnInspectorGUI() { if (_dithering == null) { _dithering = (Dithering)target; } //_dithering.GrayScaleShader = (Shader)EditorGUILayout.ObjectField("GrayScaleShader", _dithering.GrayScaleShader, typeof(Shader)); //_dithering.ColoredShader = (Shader)EditorGUILayout.ObjectField("ColoredShader", _dithering.ColoredShader, typeof(Shader)); //_dithering.ColloredHsvShader = (Shader)EditorGUILayout.ObjectField("ColloredHsvShader", _dithering.ColloredHsvShader, typeof(Shader)); _dithering.DitheringTexture = (Texture)EditorGUILayout.ObjectField("dithering Tex", _dithering.DitheringTexture, typeof(Texture), true); _dithering.ShaderType = (Dithering.Type)EditorGUILayout.EnumPopup("Type", _dithering.ShaderType); switch (_dithering.ShaderType) { case Dithering.Type.Collored: ComponentField("Red Steps", ref _dithering.RedSteps); ComponentField("Green Steps", ref _dithering.GreenSteps); ComponentField("Blue Steps", ref _dithering.BlueSteps); DrawBitInfo('R', 'G', 'B', _dithering.RedSteps, _dithering.GreenSteps, _dithering.BlueSteps); break; case Dithering.Type.ColloredHsv: ComponentField("Hue Steps", ref _dithering.HueSteps); ComponentField("Saturation Steps", ref _dithering.SaturationSteps); ComponentField("Value Steps", ref _dithering.ValueSteps); DrawBitInfo('H', 'S', 'V', _dithering.HueSteps, _dithering.SaturationSteps, _dithering.ValueSteps); break; case Dithering.Type.Grayscale: ComponentField("Brightness Steps", ref _dithering.BrightnessSteps); break; } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Open Dithering Texture Creator")) { CreateDitheringTexWizard.CreateWizard(); } GUILayout.EndHorizontal(); if (GUI.changed) { _dithering.Repaint(); } }
// TODO: Disable dithering for animated textures again? It doesn't actually remove all flickering, because different frames can still have different palettes...! static byte[] CreateTextureData( Image <Rgba32> image, Rgba32[] palette, IDictionary <Rgba32, int> colorIndexMappingCache, TextureSettings textureSettings, Func <Rgba32, bool> isTransparent, bool disableDithering) { var getColorIndex = ColorQuantization.CreateColorIndexLookup(palette, colorIndexMappingCache, isTransparent); var ditheringAlgorithm = textureSettings.DitheringAlgorithm ?? (disableDithering ? DitheringAlgorithm.None : DitheringAlgorithm.FloydSteinberg); switch (ditheringAlgorithm) { default: case DitheringAlgorithm.None: return(ApplyPaletteWithoutDithering()); case DitheringAlgorithm.FloydSteinberg: return(Dithering.FloydSteinberg(image, palette, getColorIndex, textureSettings.DitherScale ?? 0.75f, isTransparent)); } byte[] ApplyPaletteWithoutDithering() { var textureData = new byte[image.Width * image.Height]; for (int y = 0; y < image.Height; y++) { var rowSpan = image.GetPixelRowSpan(y); for (int x = 0; x < image.Width; x++) { var color = rowSpan[x]; textureData[y * image.Width + x] = (byte)getColorIndex(color); } } return(textureData); } }
public override float DrawInner(ref Rect r) { float prevYpos = r.y; r.y = 0; r.y += 20; r.xMin += 20; // Indent BlendModePreset before = blendModePreset; GUI.enabled = ps.catLighting.renderPath == SFPSC_Lighting.RenderPath.Forward; blendModePreset = (BlendModePreset)UndoableLabeledEnumPopupNamed(r, "混合模式", blendModePreset, strBlendModePreset, "blend mode"); GUI.enabled = true; if (blendModePreset != before) { ConformBlendsToPreset(); } if (blendModePreset == BlendModePreset.Custom) { GUI.color = new Color(1f, 1f, 1f, 0.5f); GUI.Label(r.PadLeft(70).PadTop(-1), "自定义混合 点击选择预设", EditorStyles.miniLabel); GUI.color = Color.white; } r.y += 20; //if( blendModePreset != BlendModePreset.Opaque ) { //if( blendModePreset != BlendModePreset.Custom ) //GUI.enabled = false; //EditorGUILayout.BeginHorizontal( GUILayout.Width( maxWidth ) ); //{ //Indent(); string srcStr = "来源 * "; string dstStr = " + 目标 * "; int srcStrWidth = SF_GUI.WidthOf(srcStr, EditorStyles.miniLabel); int dstStrWidth = SF_GUI.WidthOf(dstStr, EditorStyles.miniLabel); int fieldWidth = Mathf.FloorToInt((r.width - srcStrWidth - dstStrWidth) / 2); Rect rSrcLb = new Rect(r); rSrcLb.width = srcStrWidth; Rect rSrcField = new Rect(r); rSrcField.x = rSrcLb.xMax; rSrcField.width = fieldWidth; Rect rDstLb = new Rect(r); rDstLb.x = rSrcField.xMax; rDstLb.width = dstStrWidth; Rect rDstField = new Rect(rSrcField); rDstField.x = rDstLb.xMax; EditorGUI.BeginChangeCheck(); GUI.Label(rSrcLb, srcStr, EditorStyles.miniLabel); blendSrc = (BlendMode)UndoableEnumPopup(rSrcField, blendSrc, "blend source"); GUI.Label(rDstLb, dstStr, EditorStyles.miniLabel); blendDst = (BlendMode)UndoableEnumPopup(rDstField, blendDst, "blend destination"); if (EditorGUI.EndChangeCheck()) { ConformPresetToBlend(); } //if( blendModePreset != BlendModePreset.Custom ) //GUI.enabled = true; r.y += 20; //} UndoableColorMask(r, "颜色遮罩", ref colorMask); r.y += 20; bool canEditDithering = editor.mainNode.alphaClip.IsConnectedAndEnabled(); EditorGUI.BeginDisabledGroup(!canEditDithering); if (canEditDithering) { dithering = (Dithering)UndoableLabeledEnumPopupNamed(r, "抖动的 alpha 剪辑", dithering, strDithering, "dithered alpha clip"); } else { UndoableLabeledEnumPopup(r, "抖动的 alpha 剪辑", Dithering.Off, "dithered alpha clip"); } EditorGUI.EndDisabledGroup(); r.y += 20; bool canEditAlphaToCoverage = editor.mainNode.alphaClip.IsConnectedAndEnabled() || editor.mainNode.alpha.IsConnectedAndEnabled(); EditorGUI.BeginDisabledGroup(!canEditAlphaToCoverage); if (canEditAlphaToCoverage) { alphaToCoverage = UndoableToggle(r, alphaToCoverage, "Alpha 叠加(MSAA 一起发送)", "alpha to coverage"); } else { GUI.Toggle(r, false, "Alpha 叠加(MSAA 一起发送)"); } EditorGUI.EndDisabledGroup(); r.y += 20; OffsetBlock(ref r); RefractionBlock(ref r); FogBlock(ref r); SortingBlock(ref r); StencilBlock(ref r); r.y += prevYpos; return((int)r.yMax); }
public override void Deserialize(string key, string value) { switch (key) { case "blpr": // This is no longer saved, but in old shaders, we have to read it with old enum indices // 0 "Opaque", // 1 "Alpha Blended", // - "Alpha Blended (Premultiplied)", // 2 "Additive", // 3 "Screen", // 4 "Multiplicative", int iVal = int.Parse(value); if (iVal > 1) // Offset due to adding premul { iVal++; } blendModePreset = (BlendModePreset)iVal; ConformBlendsToPreset(); lockSrcDstRead = true; break; case "bsrc": if (lockSrcDstRead) { break; } blendSrc = (BlendMode)int.Parse(value); break; case "bdst": if (lockSrcDstRead) { lockSrcDstRead = false; break; } blendDst = (BlendMode)int.Parse(value); ConformPresetToBlend(); break; case "dpts": depthTest = (DepthTest)int.Parse(value); break; case "wrdp": writeDepth = bool.Parse(value); break; case "dith": dithering = (Dithering)int.Parse(value); break; case "atcv": alphaToCoverage = bool.Parse(value); break; case "rfrpo": perObjectRefraction = bool.Parse(value); break; case "rfrpn": refractionPassName = value; break; case "coma": colorMask = int.Parse(value); break; case "ufog": useFog = bool.Parse(value); break; case "aust": autoSort = bool.Parse(value); break; case "igpj": ignoreProjector = bool.Parse(value); break; case "qofs": queueOffset = int.Parse(value); break; case "qpre": queuePreset = (Queue)int.Parse(value); break; case "rntp": renderType = (RenderType)int.Parse(value); break; // Fog booleans case "fgom": fogOverrideMode = bool.Parse(value); break; case "fgoc": fogOverrideColor = bool.Parse(value); break; case "fgod": fogOverrideDensity = bool.Parse(value); break; case "fgor": fogOverrideRange = bool.Parse(value); break; // Fog values case "fgmd": fogMode = (ShaderFogMode)int.Parse(value); break; case "fgcr": fogColor.r = float.Parse(value); break; case "fgcg": fogColor.g = float.Parse(value); break; case "fgcb": fogColor.b = float.Parse(value); break; case "fgca": fogColor.a = float.Parse(value); break; case "fgde": fogDensity = float.Parse(value); break; case "fgrn": fogRange.x = float.Parse(value); break; case "fgrf": fogRange.y = float.Parse(value); break; // Stencil buffer: case "stcl": useStencilBuffer = bool.Parse(value); break; case "atwp": allowStencilWriteThroughProperties = bool.Parse(value); break; case "stva": stencilValue = byte.Parse(value); break; case "stmr": stencilMaskRead = byte.Parse(value); break; case "stmw": stencilMaskWrite = byte.Parse(value); break; case "stcp": stencilComparison = (DepthTestStencil)int.Parse(value); break; case "stps": stencilPass = (StencilOp)int.Parse(value); break; case "stfa": stencilFail = (StencilOp)int.Parse(value); break; case "stfz": stencilFailZ = (StencilOp)int.Parse(value); break; // Offset case "ofsf": offsetFactor = int.Parse(value); break; case "ofsu": offsetUnits = int.Parse(value); break; } }
public void UpdateDominoes() { IColorSpaceComparison comp; switch (m_regression_mode) { case 0: comp = new CmcComparison(); break; case 1: comp = new Cie1976Comparison(); break; case 2: comp = new Cie94Comparison(); break; default: comp = new CieDe2000Comparison(); break; } float scaling_x = (SourceImage.Width - 1) / size_x; float scaling_y = (SourceImage.Height - 1) / size_y; if (!m_allow_stretch) { if (scaling_x > scaling_y) { scaling_x = scaling_y; } else { scaling_y = scaling_x; } } // fix transparency: if image is transparent, background appears black Bitmap notransparency = new Bitmap(SourceImage.Width, SourceImage.Height); Graphics temp = Graphics.FromImage(notransparency); temp.Clear(Color.White); System.Drawing.Imaging.ImageAttributes Att = new System.Drawing.Imaging.ImageAttributes(); Att.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY); temp.DrawImage(SourceImage, new Rectangle(0, 0, SourceImage.Width, SourceImage.Height), 0, 0, SourceImage.Width, SourceImage.Height, GraphicsUnit.Pixel, Att); // image to read from WriteableBitmap pixelsource = BitmapFactory.ConvertToPbgra32Format(ImageHelper.BitmapToBitmapSource(notransparency)); pixelsource.Lock(); System.Windows.Media.Color[] sourceColors = new System.Windows.Media.Color[shapes.Length]; dominoes = new int[shapes.Length]; if (!calculation_mode) { // if source pixel = top left pixel of each domino for (int i = 0; i < shapes.Length; i++) { RectangleF container = shapes[i].GetContainer(scaling_x, scaling_y); try { sourceColors[i] = pixelsource.GetPixel((int)container.X, (int)container.Y); } catch (Exception) { } dominoes[i] = Dithering.Compare(new Rgb() { R = sourceColors[i].R, G = sourceColors[i].G, B = sourceColors[i].B }.To <Lab>(), comp, lab_colors, 0); } } else { // if source pixel is average of region for (int i = 0; i < shapes.Length; i++) { RectangleF container = shapes[i].GetContainer(scaling_x, scaling_y); int r = 0, g = 0, b = 0; int counter = 0; // for loop: each container for (float x_iterator = container.X; x_iterator < container.X + container.Width; x_iterator++) { for (float y_iterator = container.Y; y_iterator < container.Y + container.Width; y_iterator++) { if (shapes[i].IsInside(new PointF(x_iterator, y_iterator), true, scaling_x, scaling_y)) { System.Windows.Media.Color c = pixelsource.GetPixel((int)x_iterator, (int)y_iterator); r += c.R; g += c.G; b += c.B; counter++; } } } sourceColors[i] = System.Windows.Media.Color.FromRgb((byte)(r / counter), (byte)(g / counter), (byte)(b / counter)); // calculates the color of the domino dominoes[i] = Dithering.Compare(new Rgb() { R = sourceColors[i].R, G = sourceColors[i].G, B = sourceColors[i].B }.To <Lab>(), comp, lab_colors, 0); } } }