public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { if (stencilID <= 0 && colorWriteMask == ColorWriteMask.All || (UnityEngine.Object) baseMat == (UnityEngine.Object) null) return baseMat; if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning((object) ("Material " + baseMat.name + " doesn't have _Stencil property"), (UnityEngine.Object) baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning((object) ("Material " + baseMat.name + " doesn't have _StencilOp property"), (UnityEngine.Object) baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning((object) ("Material " + baseMat.name + " doesn't have _StencilComp property"), (UnityEngine.Object) baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning((object) ("Material " + baseMat.name + " doesn't have _StencilReadMask property"), (UnityEngine.Object) baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning((object) ("Material " + baseMat.name + " doesn't have _StencilWriteMask property"), (UnityEngine.Object) baseMat); return baseMat; } if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning((object) ("Material " + baseMat.name + " doesn't have _ColorMask property"), (UnityEngine.Object) baseMat); return baseMat; } for (int index = 0; index < StencilMaterial.m_List.Count; ++index) { StencilMaterial.MatEntry matEntry = StencilMaterial.m_List[index]; if ((UnityEngine.Object) matEntry.baseMat == (UnityEngine.Object) baseMat && matEntry.stencilId == stencilID && (matEntry.operation == operation && matEntry.compareFunction == compareFunction) && (matEntry.readMask == readMask && matEntry.writeMask == writeMask && matEntry.colorMask == colorWriteMask)) { ++matEntry.count; return matEntry.customMat; } } StencilMaterial.MatEntry matEntry1 = new StencilMaterial.MatEntry(); matEntry1.count = 1; matEntry1.baseMat = baseMat; matEntry1.customMat = new Material(baseMat); matEntry1.customMat.hideFlags = HideFlags.HideAndDontSave; matEntry1.stencilId = stencilID; matEntry1.operation = operation; matEntry1.compareFunction = compareFunction; matEntry1.readMask = readMask; matEntry1.writeMask = writeMask; matEntry1.colorMask = colorWriteMask; matEntry1.useAlphaClip = operation != StencilOp.Keep && writeMask > 0; matEntry1.customMat.name = string.Format("Stencil Id:{0}, Op:{1}, Comp:{2}, WriteMask:{3}, ReadMask:{4}, ColorMask:{5} AlphaClip:{6} ({7})", (object) stencilID, (object) operation, (object) compareFunction, (object) writeMask, (object) readMask, (object) colorWriteMask, (object) (bool) (matEntry1.useAlphaClip ? 1 : 0), (object) baseMat.name); matEntry1.customMat.SetInt("_Stencil", stencilID); matEntry1.customMat.SetInt("_StencilOp", (int) operation); matEntry1.customMat.SetInt("_StencilComp", (int) compareFunction); matEntry1.customMat.SetInt("_StencilReadMask", readMask); matEntry1.customMat.SetInt("_StencilWriteMask", writeMask); matEntry1.customMat.SetInt("_ColorMask", (int) colorWriteMask); if (matEntry1.customMat.HasProperty("_UseAlphaClip")) matEntry1.customMat.SetInt("_UseAlphaClip", !matEntry1.useAlphaClip ? 0 : 1); if (matEntry1.useAlphaClip) matEntry1.customMat.EnableKeyword("UNITY_UI_ALPHACLIP"); else matEntry1.customMat.DisableKeyword("UNITY_UI_ALPHACLIP"); StencilMaterial.m_List.Add(matEntry1); return matEntry1.customMat; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { a = (StyledTexturePreview)attribute; var tex = (Texture)property.objectReferenceValue; if (a.displayName != "") { GUILayout.BeginHorizontal(); GUILayout.Space(-1); GUILayout.Label(a.displayName, GUILayout.Width(EditorGUIUtility.labelWidth - 1)); tex = (Texture)EditorGUILayout.ObjectField(tex, typeof(Texture), false); GUILayout.EndHorizontal(); GUILayout.Space(10); property.objectReferenceValue = tex; } if (tex == null) { return; } var styledText = new GUIStyle(EditorStyles.toolbarButton) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Normal, fontSize = 10, }; var styledPopup = new GUIStyle(EditorStyles.toolbarPopup) { alignment = TextAnchor.MiddleCenter, fontSize = 10, }; var rect = GUILayoutUtility.GetRect(0, 0, Screen.width, 0); EditorGUI.DrawPreviewTexture(rect, tex, null, ScaleMode.ScaleAndCrop, 1, 0, channelMask); GUILayout.Space(2); GUILayout.BeginHorizontal(); GUILayout.Label((UnityEngine.Profiling.Profiler.GetRuntimeMemorySizeLong(tex) / 1024f / 1024f).ToString("F2") + " mb", styledText); GUILayout.Space(-1); GUILayout.Label(tex.width.ToString(), styledText); GUILayout.Space(-1); GUILayout.Label(tex.graphicsFormat.ToString(), styledText); GUILayout.Space(-1); channel = EditorGUILayout.Popup(channel, new string[] { "RGB", "R", "G", "B", "A" }, styledPopup, GUILayout.MaxWidth(60)); GUILayout.EndHorizontal(); if (channel == 0) { channelMask = ColorWriteMask.All; } else if (channel == 1) { channelMask = ColorWriteMask.Red; } else if (channel == 2) { channelMask = ColorWriteMask.Green; } else if (channel == 3) { channelMask = ColorWriteMask.Blue; } else if (channel == 4) { channelMask = ColorWriteMask.Alpha; } }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask) { return StencilMaterial.Add(baseMat, stencilID, operation, compareFunction, colorWriteMask, (int) byte.MaxValue, (int) byte.MaxValue); }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask) { return(StencilMaterial.Add(baseMat, stencilID, operation, compareFunction, colorWriteMask, 255, 255)); }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { Material result; if ((stencilID <= 0 && colorWriteMask == ColorWriteMask.All) || baseMat == null) { result = baseMat; } else if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _Stencil property", baseMat); result = baseMat; } else if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilOp property", baseMat); result = baseMat; } else if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilComp property", baseMat); result = baseMat; } else if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilReadMask property", baseMat); result = baseMat; } else if (!baseMat.HasProperty("_StencilWriteMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilWriteMask property", baseMat); result = baseMat; } else if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _ColorMask property", baseMat); result = baseMat; } else { for (int i = 0; i < StencilMaterial.m_List.Count; i++) { StencilMaterial.MatEntry matEntry = StencilMaterial.m_List[i]; if (matEntry.baseMat == baseMat && matEntry.stencilId == stencilID && matEntry.operation == operation && matEntry.compareFunction == compareFunction && matEntry.readMask == readMask && matEntry.writeMask == writeMask && matEntry.colorMask == colorWriteMask) { matEntry.count++; result = matEntry.customMat; return(result); } } StencilMaterial.MatEntry matEntry2 = new StencilMaterial.MatEntry(); matEntry2.count = 1; matEntry2.baseMat = baseMat; matEntry2.customMat = new Material(baseMat); matEntry2.customMat.hideFlags = HideFlags.HideAndDontSave; matEntry2.stencilId = stencilID; matEntry2.operation = operation; matEntry2.compareFunction = compareFunction; matEntry2.readMask = readMask; matEntry2.writeMask = writeMask; matEntry2.colorMask = colorWriteMask; matEntry2.useAlphaClip = (operation != StencilOp.Keep && writeMask > 0); matEntry2.customMat.name = string.Format("Stencil Id:{0}, Op:{1}, Comp:{2}, WriteMask:{3}, ReadMask:{4}, ColorMask:{5} AlphaClip:{6} ({7})", new object[] { stencilID, operation, compareFunction, writeMask, readMask, colorWriteMask, matEntry2.useAlphaClip, baseMat.name }); matEntry2.customMat.SetInt("_Stencil", stencilID); matEntry2.customMat.SetInt("_StencilOp", (int)operation); matEntry2.customMat.SetInt("_StencilComp", (int)compareFunction); matEntry2.customMat.SetInt("_StencilReadMask", readMask); matEntry2.customMat.SetInt("_StencilWriteMask", writeMask); matEntry2.customMat.SetInt("_ColorMask", (int)colorWriteMask); if (matEntry2.customMat.HasProperty("_UseAlphaClip")) { matEntry2.customMat.SetInt("_UseAlphaClip", (!matEntry2.useAlphaClip) ? 0 : 1); } if (matEntry2.useAlphaClip) { matEntry2.customMat.EnableKeyword("UNITY_UI_ALPHACLIP"); } else { matEntry2.customMat.DisableKeyword("UNITY_UI_ALPHACLIP"); } StencilMaterial.m_List.Add(matEntry2); result = matEntry2.customMat; } return(result); }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask) { return Add(baseMat, stencilID, operation, compareFunction, colorWriteMask, 0xff, 0xff); }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { if (((stencilID <= 0) && (colorWriteMask == ColorWriteMask.All)) || (baseMat == null)) { return baseMat; } if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _Stencil property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilOp property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilComp property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilReadMask property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilWriteMask property", baseMat); return baseMat; } if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _ColorMask property", baseMat); return baseMat; } for (int i = 0; i < m_List.Count; i++) { MatEntry entry = m_List[i]; if ((((entry.baseMat == baseMat) && (entry.stencilId == stencilID)) && ((entry.operation == operation) && (entry.compareFunction == compareFunction))) && (((entry.readMask == readMask) && (entry.writeMask == writeMask)) && (entry.colorMask == colorWriteMask))) { entry.count++; return entry.customMat; } } MatEntry item = new MatEntry { count = 1, baseMat = baseMat, customMat = new Material(baseMat) }; item.customMat.hideFlags = HideFlags.HideAndDontSave; item.stencilId = stencilID; item.operation = operation; item.compareFunction = compareFunction; item.readMask = readMask; item.writeMask = writeMask; item.colorMask = colorWriteMask; item.useAlphaClip = (operation != StencilOp.Keep) && (writeMask > 0); item.customMat.name = string.Format("Stencil Id:{0}, Op:{1}, Comp:{2}, WriteMask:{3}, ReadMask:{4}, ColorMask:{5} AlphaClip:{6} ({7})", new object[] { stencilID, operation, compareFunction, writeMask, readMask, colorWriteMask, item.useAlphaClip, baseMat.name }); item.customMat.SetInt("_Stencil", stencilID); item.customMat.SetInt("_StencilOp", (int) operation); item.customMat.SetInt("_StencilComp", (int) compareFunction); item.customMat.SetInt("_StencilReadMask", readMask); item.customMat.SetInt("_StencilWriteMask", writeMask); item.customMat.SetInt("_ColorMask", (int) colorWriteMask); if (item.customMat.HasProperty("_UseAlphaClip")) { item.customMat.SetInt("_UseAlphaClip", !item.useAlphaClip ? 0 : 1); } if (item.useAlphaClip) { item.customMat.EnableKeyword("UNITY_UI_ALPHACLIP"); } else { item.customMat.DisableKeyword("UNITY_UI_ALPHACLIP"); } m_List.Add(item); return item.customMat; }
/// <summary> /// Add a new material using the specified base and stencil ID. /// </summary> public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { if ((stencilID <= 0 && colorWriteMask == ColorWriteMask.All) || baseMat == null) { return(baseMat); } if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _Stencil property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilOp property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilComp property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilReadMask property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilWriteMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilWriteMask property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _ColorMask property", baseMat); return(baseMat); } for (int i = 0; i < m_List.Count; ++i) { MatEntry ent = m_List[i]; if (ent.baseMat == baseMat && ent.stencilId == stencilID && ent.operation == operation && ent.compareFunction == compareFunction && ent.readMask == readMask && ent.writeMask == writeMask && ent.colorMask == colorWriteMask) { ++ent.count; return(ent.customMat); } } var newEnt = new MatEntry(); newEnt.count = 1; newEnt.baseMat = baseMat; newEnt.customMat = new Material(baseMat); newEnt.customMat.hideFlags = HideFlags.HideAndDontSave; newEnt.stencilId = stencilID; newEnt.operation = operation; newEnt.compareFunction = compareFunction; newEnt.readMask = readMask; newEnt.writeMask = writeMask; newEnt.colorMask = colorWriteMask; newEnt.useAlphaClip = operation != StencilOp.Keep && writeMask > 0; newEnt.customMat.name = string.Format("Stencil Id:{0}, Op:{1}, Comp:{2}, WriteMask:{3}, ReadMask:{4}, ColorMask:{5} AlphaClip:{6} ({7})", stencilID, operation, compareFunction, writeMask, readMask, colorWriteMask, newEnt.useAlphaClip, baseMat.name); newEnt.customMat.SetInt("_Stencil", stencilID); newEnt.customMat.SetInt("_StencilOp", (int)operation); newEnt.customMat.SetInt("_StencilComp", (int)compareFunction); newEnt.customMat.SetInt("_StencilReadMask", readMask); newEnt.customMat.SetInt("_StencilWriteMask", writeMask); newEnt.customMat.SetInt("_ColorMask", (int)colorWriteMask); // left for backwards compatability if (newEnt.customMat.HasProperty("_UseAlphaClip")) { newEnt.customMat.SetInt("_UseAlphaClip", newEnt.useAlphaClip ? 1 : 0); } if (newEnt.useAlphaClip) { newEnt.customMat.EnableKeyword("UNITY_UI_ALPHACLIP"); } else { newEnt.customMat.DisableKeyword("UNITY_UI_ALPHACLIP"); } m_List.Add(newEnt); return(newEnt.customMat); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } // show texture Texture t = target as Texture; if (t == null) // texture might be gone by now, in case this code is used for floating texture preview { return; } // Render target must be created before we can display it (case 491797) RenderTexture rt = t as RenderTexture; if (rt != null) { if (!SystemInfo.IsFormatSupported(rt.graphicsFormat, FormatUsage.Render)) { return; // can't do this RT format } rt.Create(); } if (IsCubemap()) { m_CubemapPreview.OnPreviewGUI(t, r, background); return; } // target can report zero sizes in some cases just after a parameter change; // guard against that. int texWidth = Mathf.Max(t.width, 1); int texHeight = Mathf.Max(t.height, 1); float mipLevel = GetMipLevelForRendering(); float zoomLevel = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1); Rect wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel); PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); FilterMode oldFilter = t.filterMode; TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point); Texture2D t2d = t as Texture2D; ColorWriteMask colorWriteMask = ColorWriteMask.All; switch (m_PreviewMode) { case PreviewMode.R: colorWriteMask = ColorWriteMask.Red | ColorWriteMask.Alpha; break; case PreviewMode.G: colorWriteMask = ColorWriteMask.Green | ColorWriteMask.Alpha; break; case PreviewMode.B: colorWriteMask = ColorWriteMask.Blue | ColorWriteMask.Alpha; break; } if (m_PreviewMode == PreviewMode.A) { EditorGUI.DrawTextureAlpha(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel); } else { if (t2d != null && t2d.alphaIsTransparency) { EditorGUI.DrawTextureTransparent(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask); } else { EditorGUI.DrawPreviewTexture(wantedRect, t, null, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask); } } // TODO: Less hacky way to prevent sprite rects to not appear in smaller previews like icons. if ((wantedRect.width > 32 && wantedRect.height > 32) && Event.current.type == EventType.Repaint) { string path = AssetDatabase.GetAssetPath(t); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; SpriteMetaData[] spritesheet = textureImporter != null ? textureImporter.spritesheet : null; if (spritesheet != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple) { Rect screenRect = new Rect(); Rect sourceRect = new Rect(); GUI.CalculateScaledTextureRects(wantedRect, ScaleMode.StretchToFill, (float)t.width / (float)t.height, ref screenRect, ref sourceRect); int origWidth = t.width; int origHeight = t.height; textureImporter.GetWidthAndHeight(ref origWidth, ref origHeight); float definitionScale = (float)t.width / (float)origWidth; HandleUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(Handles.matrix); GL.Begin(GL.LINES); GL.Color(new Color(1f, 1f, 1f, 0.5f)); foreach (SpriteMetaData sprite in spritesheet) { Rect spriteRect = sprite.rect; Rect spriteScreenRect = new Rect(); spriteScreenRect.xMin = screenRect.xMin + screenRect.width * (spriteRect.xMin / t.width * definitionScale); spriteScreenRect.xMax = screenRect.xMin + screenRect.width * (spriteRect.xMax / t.width * definitionScale); spriteScreenRect.yMin = screenRect.yMin + screenRect.height * (1f - spriteRect.yMin / t.height * definitionScale); spriteScreenRect.yMax = screenRect.yMin + screenRect.height * (1f - spriteRect.yMax / t.height * definitionScale); DrawRect(spriteScreenRect); } GL.End(); GL.PopMatrix(); } } TextureUtil.SetFilterModeNoDirty(t, oldFilter); m_Pos = PreviewGUI.EndScrollView(); if (mipLevel != 0) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20), "Mip " + mipLevel); } }
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change static public void SetupCommonDecalMaterialKeywordsAndPass(Material material) { bool affectsMaskmap = false; affectsMaskmap |= material.HasProperty(kAffectMetal) && material.GetFloat(kAffectMetal) == 1.0f; affectsMaskmap |= material.HasProperty(kAffectAO) && material.GetFloat(kAffectAO) == 1.0f; affectsMaskmap |= material.HasProperty(kAffectSmoothness) && material.GetFloat(kAffectSmoothness) == 1.0f; CoreUtils.SetKeyword(material, "_MATERIAL_AFFECTS_ALBEDO", material.HasProperty(kAffectAlbedo) && material.GetFloat(kAffectAlbedo) == 1.0f); CoreUtils.SetKeyword(material, "_MATERIAL_AFFECTS_NORMAL", material.HasProperty(kAffectNormal) && material.GetFloat(kAffectNormal) == 1.0f); CoreUtils.SetKeyword(material, "_MATERIAL_AFFECTS_MASKMAP", affectsMaskmap); // Albedo : RT0 RGB, A - sRGB // Normal : RT1 RGB, A // Smoothness: RT2 B, A // Metal: RT2 R, RT3 R // AO: RT2 G, RT3 G // Note RT3 is only RG ColorWriteMask mask0 = 0, mask1 = 0, mask2 = 0, mask3 = 0; if (material.HasProperty(kAffectAlbedo) && material.GetFloat(kAffectAlbedo) == 1.0f) { mask0 |= ColorWriteMask.All; } if (material.HasProperty(kAffectNormal) && material.GetFloat(kAffectNormal) == 1.0f) { mask1 |= ColorWriteMask.All; } if (material.HasProperty(kAffectMetal) && material.GetFloat(kAffectMetal) == 1.0f) { mask2 |= mask3 |= ColorWriteMask.Red; } if (material.HasProperty(kAffectAO) && material.GetFloat(kAffectAO) == 1.0f) { mask2 |= mask3 |= ColorWriteMask.Green; } if (material.HasProperty(kAffectSmoothness) && material.GetFloat(kAffectSmoothness) == 1.0f) { mask2 |= ColorWriteMask.Blue | ColorWriteMask.Alpha; } material.SetInt(HDShaderIDs._DecalColorMask0, (int)mask0); material.SetInt(HDShaderIDs._DecalColorMask1, (int)mask1); material.SetInt(HDShaderIDs._DecalColorMask2, (int)mask2); material.SetInt(HDShaderIDs._DecalColorMask3, (int)mask3); // First reset the pass (in case new shader graph add or remove a pass) material.SetShaderPassEnabled(HDShaderPassNames.s_DBufferProjectorStr, true); material.SetShaderPassEnabled(HDShaderPassNames.s_DecalProjectorForwardEmissiveStr, true); material.SetShaderPassEnabled(HDShaderPassNames.s_DBufferMeshStr, true); material.SetShaderPassEnabled(HDShaderPassNames.s_DecalMeshForwardEmissiveStr, true); // Then disable pass is they aren't needed if (material.FindPass(HDShaderPassNames.s_DBufferProjectorStr) != -1) { material.SetShaderPassEnabled(HDShaderPassNames.s_DBufferProjectorStr, ((int)mask0 + (int)mask1 + (int)mask2 + (int)mask3) != 0); } if (material.FindPass(HDShaderPassNames.s_DecalProjectorForwardEmissiveStr) != -1) { material.SetShaderPassEnabled(HDShaderPassNames.s_DecalProjectorForwardEmissiveStr, material.HasProperty(kAffectEmission) && material.GetFloat(kAffectEmission) == 1.0f); } if (material.FindPass(HDShaderPassNames.s_DBufferMeshStr) != -1) { material.SetShaderPassEnabled(HDShaderPassNames.s_DBufferMeshStr, ((int)mask0 + (int)mask1 + (int)mask2 + (int)mask3) != 0); } if (material.FindPass(HDShaderPassNames.s_DecalMeshForwardEmissiveStr) != -1) { material.SetShaderPassEnabled(HDShaderPassNames.s_DecalMeshForwardEmissiveStr, material.HasProperty(kAffectEmission) && material.GetFloat(kAffectEmission) == 1.0f); } // Set stencil state material.SetInt(kDecalStencilWriteMask, (int)StencilUsage.Decals); material.SetInt(kDecalStencilRef, (int)StencilUsage.Decals); }
/// <summary> /// Add a new material using the specified base and stencil ID. /// </summary> public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { if ((stencilID <= 0 && colorWriteMask == ColorWriteMask.All) || baseMat == null) return baseMat; if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _Stencil property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilOp property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilComp property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilReadMask property", baseMat); return baseMat; } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilWriteMask property", baseMat); return baseMat; } if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _ColorMask property", baseMat); return baseMat; } for (int i = 0; i < m_List.Count; ++i) { MatEntry ent = m_List[i]; if (ent.baseMat == baseMat && ent.stencilId == stencilID && ent.operation == operation && ent.compareFunction == compareFunction && ent.readMask == readMask && ent.writeMask == writeMask && ent.colorMask == colorWriteMask) { ++ent.count; return ent.customMat; } } var newEnt = new MatEntry(); newEnt.count = 1; newEnt.baseMat = baseMat; newEnt.customMat = new Material(baseMat); newEnt.customMat.hideFlags = HideFlags.HideAndDontSave; newEnt.stencilId = stencilID; newEnt.operation = operation; newEnt.compareFunction = compareFunction; newEnt.readMask = readMask; newEnt.writeMask = writeMask; newEnt.colorMask = colorWriteMask; newEnt.useAlphaClip = operation != StencilOp.Keep && writeMask > 0; newEnt.customMat.name = string.Format("Stencil Id:{0}, Op:{1}, Comp:{2}, WriteMask:{3}, ReadMask:{4}, ColorMask:{5} AlphaClip:{6} ({7})", stencilID, operation, compareFunction, writeMask, readMask, colorWriteMask, newEnt.useAlphaClip, baseMat.name); newEnt.customMat.SetInt("_Stencil", stencilID); newEnt.customMat.SetInt("_StencilOp", (int)operation); newEnt.customMat.SetInt("_StencilComp", (int)compareFunction); newEnt.customMat.SetInt("_StencilReadMask", readMask); newEnt.customMat.SetInt("_StencilWriteMask", writeMask); newEnt.customMat.SetInt("_ColorMask", (int)colorWriteMask); // left for backwards compatability if (newEnt.customMat.HasProperty("_UseAlphaClip")) newEnt.customMat.SetInt("_UseAlphaClip", newEnt.useAlphaClip ? 1 : 0); if (newEnt.useAlphaClip) newEnt.customMat.EnableKeyword("UNITY_UI_ALPHACLIP"); else newEnt.customMat.DisableKeyword("UNITY_UI_ALPHACLIP"); m_List.Add(newEnt); return newEnt.customMat; }
public static void SetColorWriteMask(ColorWriteMask value) { Context.SetColorWriteMask(value); }
public void SetColorWriteMask(ColorWriteMask mask) { colorWriteMask = mask; }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { if (((stencilID <= 0) && (colorWriteMask == ColorWriteMask.All)) || (baseMat == null)) { return(baseMat); } if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _Stencil property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilOp property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilComp property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilReadMask property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilWriteMask property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _ColorMask property", baseMat); return(baseMat); } for (int i = 0; i < m_List.Count; i++) { MatEntry entry = m_List[i]; if ((((entry.baseMat == baseMat) && (entry.stencilId == stencilID)) && ((entry.operation == operation) && (entry.compareFunction == compareFunction))) && (((entry.readMask == readMask) && (entry.writeMask == writeMask)) && (entry.colorMask == colorWriteMask))) { entry.count++; return(entry.customMat); } } MatEntry item = new MatEntry { count = 1, baseMat = baseMat, customMat = new Material(baseMat) }; item.customMat.hideFlags = HideFlags.HideAndDontSave; item.stencilId = stencilID; item.operation = operation; item.compareFunction = compareFunction; item.readMask = readMask; item.writeMask = writeMask; item.colorMask = colorWriteMask; item.useAlphaClip = (operation != StencilOp.Keep) && (writeMask > 0); item.customMat.name = $"Stencil Id:{stencilID}, Op:{operation}, Comp:{compareFunction}, WriteMask:{writeMask}, ReadMask:{readMask}, ColorMask:{colorWriteMask} AlphaClip:{item.useAlphaClip} ({baseMat.name})"; item.customMat.SetInt("_Stencil", stencilID); item.customMat.SetInt("_StencilOp", (int)operation); item.customMat.SetInt("_StencilComp", (int)compareFunction); item.customMat.SetInt("_StencilReadMask", readMask); item.customMat.SetInt("_StencilWriteMask", writeMask); item.customMat.SetInt("_ColorMask", (int)colorWriteMask); if (item.customMat.HasProperty("_UseAlphaClip")) { item.customMat.SetInt("_UseAlphaClip", !item.useAlphaClip ? 0 : 1); } if (item.useAlphaClip) { item.customMat.EnableKeyword("UNITY_UI_ALPHACLIP"); } else { item.customMat.DisableKeyword("UNITY_UI_ALPHACLIP"); } m_List.Add(item); return(item.customMat); }
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask) => Add(baseMat, stencilID, operation, compareFunction, colorWriteMask, 0xff, 0xff);
public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask) { if (((stencilID <= 0) && (colorWriteMask == ColorWriteMask.All)) || (baseMat == null)) { return(baseMat); } if (!baseMat.HasProperty("_Stencil")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _Stencil property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilOp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilOp property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilComp")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilComp property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilReadMask property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_StencilReadMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _StencilWriteMask property", baseMat); return(baseMat); } if (!baseMat.HasProperty("_ColorMask")) { Debug.LogWarning("Material " + baseMat.name + " doesn't have _ColorMask property", baseMat); return(baseMat); } for (int i = 0; i < m_List.Count; i++) { MatEntry entry = m_List[i]; if ((((entry.baseMat == baseMat) && (entry.stencilId == stencilID)) && ((entry.operation == operation) && (entry.compareFunction == compareFunction))) && (((entry.readMask == readMask) && (entry.writeMask == writeMask)) && (entry.colorMask == colorWriteMask))) { entry.count++; return(entry.customMat); } } MatEntry item = new MatEntry { count = 1, baseMat = baseMat, customMat = new Material(baseMat) }; item.customMat.hideFlags = HideFlags.HideAndDontSave; item.stencilId = stencilID; item.operation = operation; item.compareFunction = compareFunction; item.readMask = readMask; item.writeMask = writeMask; item.colorMask = colorWriteMask; item.useAlphaClip = (operation != StencilOp.Keep) && (writeMask > 0); object[] args = new object[] { stencilID, operation, compareFunction, writeMask, readMask, colorWriteMask, item.useAlphaClip, baseMat.name }; item.customMat.name = string.Format("Stencil Id:{0}, Op:{1}, Comp:{2}, WriteMask:{3}, ReadMask:{4}, ColorMask:{5} AlphaClip:{6} ({7})", args); item.customMat.SetInt("_Stencil", stencilID); item.customMat.SetInt("_StencilOp", (int)operation); item.customMat.SetInt("_StencilComp", (int)compareFunction); item.customMat.SetInt("_StencilReadMask", readMask); item.customMat.SetInt("_StencilWriteMask", writeMask); item.customMat.SetInt("_ColorMask", (int)colorWriteMask); item.customMat.SetInt("_UseAlphaClip", !item.useAlphaClip ? 0 : 1); m_List.Add(item); return(item.customMat); }