override public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("GetHeight: " + label + " RTP_EndAreaDecorator"); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.helperFlag) { customEditor.helperFlag = false; return 0; } customEditor.helperFlag = true; if (customEditor.showFlag) { EditorGUILayout.EndVertical(); if (indent) { // EditorGUI.indentLevel--; EditorGUILayout.EndHorizontal(); } } } return 0; }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { if (GUILayout.Button("Edit")) { EditorWindow.GetWindow<MaterialNodeEditor>(); } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly // Use default labelWidth EditorGUIUtility.labelWidth = 0f; // Detect any changes to the material EditorGUI.BeginChangeCheck(); { GUILayout.Label (Styles.material0Header, EditorStyles.boldLabel); // Texture materialEditor.TexturePropertySingleLine (Styles.albedo, albedoMap); materialEditor.TexturePropertySingleLine (Styles.specular, specularMap); materialEditor.TexturePropertySingleLine (Styles.normal, bumpMap); materialEditor.TextureScaleOffsetProperty (albedoMap); GUILayout.Label (Styles.maskHeader, EditorStyles.boldLabel); materialEditor.TexturePropertySingleLine (Styles.blendMask, blendMask); materialEditor.TextureScaleOffsetProperty (blendMask); GUILayout.Label (Styles.material1Header, EditorStyles.boldLabel); materialEditor.TexturePropertySingleLine (Styles.albedo, albedoMap2); materialEditor.TexturePropertySingleLine (Styles.specular, specularMap2); materialEditor.TexturePropertySingleLine (Styles.normal, bumpMap2); materialEditor.TextureScaleOffsetProperty (albedoMap2); } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " RTP_MaterialProp"); if (!parsed) { parsed = true; parsedLabel = RTP_MatPropStringParser.Parse(label); } label = parsedLabel; if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { EditorGUI.BeginDisabledGroup(customEditor.inactiveFlag); EditorGUIUtility.labelWidth = 300; EditorGUI.BeginChangeCheck(); float pval = prop.floatValue; float nval = EditorGUI.Popup(position, label, (int)pval, props); if (EditorGUI.EndChangeCheck()) { prop.floatValue = nval; } EditorGUI.EndDisabledGroup(); } } }
void DrawLayer(MaterialEditor editor, int i, MaterialProperty[] props, string[] keyWords, Workflow workflow, bool hasGloss, bool hasSpec, bool isParallax, bool hasEmis, bool hasDistBlend) { EditorGUIUtility.labelWidth = 0f; var albedoMap = FindProperty ("_Tex" + i, props); var tint = FindProperty("_Tint" + i, props); var normalMap = FindProperty ("_Normal" + i, props); var smoothness = FindProperty("_Glossiness" + i, props); var glossinessMap = FindProperty("_GlossinessTex" + i, props, false); var metallic = FindProperty("_Metallic" + i, props, false); var emissionTex = FindProperty("_Emissive" + i, props); var emissionMult = FindProperty("_EmissiveMult" + i, props); var parallax = FindProperty("_Parallax" + i, props); var texScale = FindProperty("_TexScale" + i, props); var specMap = FindProperty("_SpecGlossMap" + i, props, false); var specColor = FindProperty("_SpecColor" + i, props, false); var distUVScale = FindProperty("_DistUVScale" + i, props, false); editor.TexturePropertySingleLine(new GUIContent("Albedo/Height"), albedoMap); editor.ShaderProperty(tint, "Tint"); editor.TexturePropertySingleLine(new GUIContent("Normal"), normalMap); if (workflow == Workflow.Metallic) { editor.TexturePropertySingleLine(new GUIContent("Metal(R)/Smoothness(A)"), glossinessMap); } else { editor.TexturePropertySingleLine(new GUIContent("Specular(RGB)/Gloss(A)"), specMap); } if (workflow == Workflow.Metallic && !hasGloss) { editor.ShaderProperty(smoothness, "Smoothness"); editor.ShaderProperty(metallic, "Metallic"); } else if (workflow == Workflow.Specular && !hasSpec) { editor.ShaderProperty(smoothness, "Smoothness"); editor.ShaderProperty(specColor, "Specular Color"); } editor.TexturePropertySingleLine(new GUIContent("Emission"), emissionTex); editor.ShaderProperty(emissionMult, "Emissive Multiplier"); editor.ShaderProperty(texScale, "Texture Scale"); if (hasDistBlend) { editor.ShaderProperty(distUVScale, "Distance UV Scale"); } if (isParallax) { editor.ShaderProperty(parallax, "Parallax Height"); } if (i != 1) { editor.ShaderProperty(FindProperty("_Contrast"+i, props), "Interpolation Contrast"); } }
bool checkVisible(MaterialEditor editor) { if (visibilityProp != "") { Material mat=editor.target as Material; if (mat.HasProperty(visibilityProp)) { return mat.GetFloat(visibilityProp)==1 ? true:false; } } return true; }
bool checkVisible(MaterialEditor editor) { bool visible = true; if (visibilityProp != "") { Material mat=editor.target as Material; if (mat.HasProperty(visibilityProp)) { return (mat.GetFloat(visibilityProp)==1); } } return visible; }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { FindProperties(properties); if (ShaderPropertiesGUI(materialEditor) || _initial) foreach (Material m in materialEditor.targets) SetMaterialKeywords(m); _initial = false; }
//TODO: see if there is a better callback function public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { string content = File.ReadAllText(TEMPLATE_PATH); content = content.Replace(ORIGINAL_SHADER_NAME, string.Format(SHADER_NAME_SYNTAX, materialEditor.target.name.Split(' ')[0])); content = content.Replace(PRE_EDITOR, EDITOR); File.WriteAllText(string.Format(OUTPUT_PATH, materialEditor.target.name.Split(' ')[0] + ".shader"), content); AssetDatabase.ImportAsset (string.Format(RELATIVE_OUTPUT_PATH, materialEditor.target.name.Split(' ')[0] + ".shader")); Shader shader = Shader.Find(string.Format(SHADER_NAME_SYNTAX, materialEditor.target.name)); materialEditor.SetShader(shader); }
override public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { bool inactiveFlag=false; if (checkVisible(editor, ref inactiveFlag)) { if (prop.floatValue==1) { return MaterialEditor.GetDefaultPropertyHeight(prop); } else { return MaterialEditor.GetDefaultPropertyHeight(prop)-5; } } return -2; }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { bool inactiveFlag = false; //if (!checkNormalmapsUsage(editor.target as Material, label)) return; //if (!checkIBLUsage(editor.target as Material, label)) return; if (checkVisible (editor, ref inactiveFlag)) { EditorGUI.BeginDisabledGroup(inactiveFlag); position.x+=12; position.width-=12; EditorGUI.HelpBox(position, label, MessageType.Warning); EditorGUI.EndDisabledGroup(); } }
override public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { return 20; } return -2; } return 0; }
override public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("GetHeight: " + label+ " RTP_MaterialProp" ); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { return 20; } return -2; } return MaterialEditor.GetDefaultPropertyHeight(prop); }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " RTP_HeaderDecorator"); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { customEditor.nextLabelWidth = nextLabelWidth; } } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { Rect rect = GUILayoutUtility.GetLastRect(); rect.width = Mathf.Min(rect.width, EditorGUIUtility.labelWidth); EditorGUI.LabelField(rect, new GUIContent("", toolTip)); } } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { bool inactiveFlag = false; if (checkVisible (editor, ref inactiveFlag)) { EditorGUI.BeginDisabledGroup(inactiveFlag); Color col = GUI.color; GUI.color = new Color(0.3f,0.9f,1,1f); position.x+=12; bool state = EditorGUI.Foldout(position, prop.floatValue==1, label, true); GUI.color = col; prop.floatValue = state ? 1 : 0; EditorGUI.EndDisabledGroup(); } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { base.OnGUI(materialEditor, properties); Material mat = materialEditor.target as Material; string[] keywords = mat.shaderKeywords; // mat.renderQueue int order = mat.renderQueue - GeometryQueueNum; EditorGUI.BeginChangeCheck(); order = EditorGUILayout.IntPopup("Render Order (Relative to Geometry)", order, optionNames, options); mat.renderQueue = GeometryQueueNum + order; if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(mat); } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " RTP_HeaderDecorator"); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { EditorGUI.BeginDisabledGroup(customEditor.inactiveFlag); position.y += 2; EditorGUI.LabelField(position, headerLabel + (active_layer_flag ? " " +(customEditor.active_layer+1) : ""), EditorStyles.boldLabel); EditorGUI.EndDisabledGroup(); } } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (!customEditor.showFlag) return; if (!parsed) { parsed = true; parsedLabel = RTP_MatPropStringParser.Parse(label); } label = parsedLabel; Color col = GUI.contentColor; Color bcol = GUI.backgroundColor; GUI.contentColor = new Color(1f, 1f, 0.8f, 1f); GUI.backgroundColor = backgroundColor; Rect pos = new Rect(position); pos.y += 3; pos.height -= 3; //if (visibilityProp1 != null) //{ // pos.x += 12; // pos.width -= 12; //} EditorGUI.HelpBox(pos, (foldoutFlag ? " " : "") + label, MessageType.None); if (foldoutFlag) { Rect fpos = new Rect(pos); fpos.x += 15; fpos.y += 1; bool state = EditorGUI.Foldout(fpos, prop.floatValue == 1, "", true); prop.floatValue = state ? 1 : 0; } GUI.contentColor = col; GUI.backgroundColor = bcol; } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " RTP_MaterialProp"); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { bool featureActive = customEditor.CheckDefine(prop.name, false); EditorGUI.BeginDisabledGroup(customEditor.inactiveFlag); EditorGUI.BeginChangeCheck(); bool feature_doesntFit = (featureActive != prop.floatValue > 0); Color col = GUI.color; if (feature_doesntFit) { GUI.color = new Color(1,0.6f,0.6f,1); } float nval=EditorGUILayout.ToggleLeft(new GUIContent(label, toolTip), prop.floatValue>0 ? true:false, feature_doesntFit ? EditorStyles.boldLabel : EditorStyles.label) ? 1:0; GUI.color = col; if (EditorGUI.EndChangeCheck()) { prop.floatValue = nval; if (nval==0 && dependentFeatures!=null) { for(int i=0; i<dependentFeatures.Length; i++) { if ((editor.target as Material).HasProperty(dependentFeatures[i])) { foreach(Material mat in editor.targets) { mat.SetFloat(dependentFeatures[i], 0); } } } } } EditorGUI.EndDisabledGroup(); } } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { // render the default gui base.OnGUI(materialEditor, properties); Material targetMat = materialEditor.target as Material; // see if redify is set, and show a checkbox bool redify = Array.IndexOf(targetMat.shaderKeywords, "REDIFY_ON") != -1; EditorGUI.BeginChangeCheck(); redify = EditorGUILayout.Toggle("Redify material", redify); if (EditorGUI.EndChangeCheck()) { // enable or disable the keyword based on checkbox if (redify) targetMat.EnableKeyword("REDIFY_ON"); else targetMat.DisableKeyword("REDIFY_ON"); } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (!checkVisible(editor)) return; myEditor = editor; float nval; //label += "#" + myKeyword + "#"; if (myMode=="RIGHT") { nval = EditorGUI.Toggle(position, label, prop.floatValue==1) ? 1:0; } else { if (label.Substring(0,1)==" ") { position.x+=12; position.width-=12; nval = EditorGUI.ToggleLeft(position, label.Substring(3), prop.floatValue==1, EditorStyles.boldLabel) ? 1:0; } else { nval = EditorGUI.ToggleLeft(position, label, prop.floatValue==1, EditorStyles.boldLabel) ? 1:0; } } if (nval!=prop.floatValue) { prop.floatValue = nval; if (myKeyword!="") Apply(prop); } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " Button"); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag) { EditorGUI.BeginDisabledGroup(customEditor.inactiveFlag); Rect rect = position; if (GUI.Button(rect, buttonLabel)) { Type thisType = customEditor.GetType(); MethodInfo theMethod = thisType.GetMethod(functionName); theMethod.Invoke(customEditor, new System.Object[] { });//, userParameters); } EditorGUI.EndDisabledGroup(); } } }
bool ShaderPropertiesGUI(MaterialEditor materialEditor) { EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine(_albedoText, _albedoMap, _albedoColor); materialEditor.ShaderProperty(_metallic, "Metallic"); materialEditor.ShaderProperty(_smoothness, "Smoothness"); EditorGUILayout.Space(); materialEditor.TexturePropertySingleLine(_normalMapText, _bumpMap, null); EditorGUILayout.Space(); materialEditor.TexturePropertySingleLine(_occlusionText, _occlusionMap, _occlusionMap.textureValue ? _occlusionStrength : null); EditorGUILayout.Space(); materialEditor.ShaderProperty(_mapScale, "Mapping Scale"); return EditorGUI.EndChangeCheck(); }
void DrawLayer(MaterialEditor editor, int i, MaterialProperty[] props, string[] keyWords, bool hasGloss, bool isParallax, bool hasEmis) { EditorGUIUtility.labelWidth = 0f; var albedoMap = FindProperty ("_Tex" + i, props); var normalMap = FindProperty ("_Normal" + i, props); var smoothness = FindProperty("_Glossiness" + i, props); var glossinessMap = FindProperty("_GlossinessTex" + i, props); var metallic = FindProperty("_Metallic" + i, props); var emissionTex = FindProperty("_Emissive" + i, props); var emissionMult = FindProperty("_EmissiveMult" + i, props); var parallax = FindProperty("_Parallax" + i, props); var texScale = FindProperty("_TexScale" + i, props); //editor.TexturePropertySingleLine("Albedo (RGB) Height (A)", albedoMap); editor.TexturePropertySingleLine(new GUIContent("Albedo/Height"), albedoMap); editor.TexturePropertySingleLine(new GUIContent("Normal"), normalMap); editor.TexturePropertySingleLine(new GUIContent("Metal(R)/Smoothness(A)"), glossinessMap); if (!hasGloss) { editor.ShaderProperty(smoothness, "Smoothness"); editor.ShaderProperty(metallic, "Metallic"); } editor.TexturePropertySingleLine(new GUIContent("Emission"), emissionTex); editor.ShaderProperty(emissionMult, "Emissive Multiplier"); editor.ShaderProperty(texScale, "Texture Scale"); if (isParallax) { editor.ShaderProperty(parallax, "Parallax Height"); } if (i != 1) { editor.ShaderProperty(FindProperty("_Contrast"+i, props), "Interpolation Contrast"); } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " RTP_BeginAreaDecorator"); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; //if (label == "Triplanar tile size") //{ // Debug.Log("E"+ customEditor.test); // customEditor.test++; //} //if (!customEditor.helperFlag) //{ // customEditor.helperFlag = true; // return 0; //} //customEditor.helperFlag = false; if (customEditor.showFlag) { if (indent) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(indentVal); } if (type == "none") { EditorGUILayout.BeginVertical(); } else { EditorGUILayout.BeginVertical(type); } } } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { targetMat = materialEditor.target as Material; string[] oldKeyWords = targetMat.shaderKeywords; GUIStyle style = EditorStyles.helpBox; style.margin = new RectOffset(0, 0, 0, 0); materialEditor.ShaderProperty(properties[0], properties[0].displayName); materialEditor.ShaderProperty(properties[1], properties[1].displayName); materialEditor.ShaderProperty(properties[2], properties[2].displayName); //Not needed since Unity batches sprites on its own //EditorGUILayout.Separator(); //materialEditor.EnableInstancingField(); //Debug.Log(materialEditor.IsInstancingEnabled() + " " + Application.isBatchMode); EditorGUILayout.Separator(); SpriteAtlas(materialEditor, style, oldKeyWords.Contains("ATLAS_ON"), "Sprite inside an atlas?", "ATLAS_ON"); EditorGUILayout.Separator(); GUILayout.Label("___Color Effects___", EditorStyles.boldLabel); Glow(materialEditor, properties, style, oldKeyWords.Contains("GLOW_ON")); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("FADE_ON"), "2.Fade", "FADE_ON", 7, 13); Outline(materialEditor, properties, style, oldKeyWords.Contains("OUTBASE_ON")); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("GRADIENT_ON"), "4.Gradient", "GRADIENT_ON", 31, 35); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("COLORSWAP_ON"), "5.Color Swap", "COLORSWAP_ON", 36, 42); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("HSV_ON"), "6.Hue Shift", "HSV_ON", 43, 45); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("CHANGECOLOR_ON"), "7.Change 1 Color", "CHANGECOLOR_ON", 123, 126); ColorRamp(materialEditor, properties, style, oldKeyWords.Contains("COLORRAMP_ON")); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("HITEFFECT_ON"), "9.Hit Effect", "HITEFFECT_ON", 46, 48); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("NEGATIVE_ON"), "10.Negative", "NEGATIVE_ON", 49, 49); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("PIXELATE_ON"), "11.Pixelate", "PIXELATE_ON", 50, 50); GreyScale(materialEditor, properties, style, oldKeyWords.Contains("GREYSCALE_ON")); Posterize(materialEditor, properties, style, oldKeyWords.Contains("POSTERIZE_ON")); Blur(materialEditor, properties, style, oldKeyWords.Contains("BLUR_ON")); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("MOTIONBLUR_ON"), "15.Motion Blur", "MOTIONBLUR_ON", 62, 63); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("GHOST_ON"), "16.Ghost", "GHOST_ON", 64, 65); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("INNEROUTLINE_ON"), "17.Inner Outline", "INNEROUTLINE_ON", 66, 69); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("HOLOGRAM_ON"), "18.Hologram", "HOLOGRAM_ON", 73, 77); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("CHROMABERR_ON"), "19.Chromatic Aberration", "CHROMABERR_ON", 78, 79); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("GLITCH_ON"), "20.Glitch", "GLITCH_ON", 80, 80); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("FLICKER_ON"), "21.Flicker", "FLICKER_ON", 81, 83); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("SHADOW_ON"), "22.Shadow", "SHADOW_ON", 84, 87); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ALPHACUTOFF_ON"), "23.Alpha Cutoff", "ALPHACUTOFF_ON", 70, 70); EditorGUILayout.Separator(); GUILayout.Label("___UV Effects___", EditorStyles.boldLabel); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("DOODLE_ON"), "24.Hand Drawn", "DOODLE_ON", 88, 89); Grass(materialEditor, properties, style, oldKeyWords.Contains("WIND_ON")); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("WAVEUV_ON"), "26.Wave", "WAVEUV_ON", 94, 98); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ROUNDWAVEUV_ON"), "27.Round Wave", "ROUNDWAVEUV_ON", 127, 128); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("RECTSIZE_ON"), "28.Rect Size (Enable wireframe to see result)", "RECTSIZE_ON", 99, 99); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("OFFSETUV_ON"), "29.Offset", "OFFSETUV_ON", 100, 101); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("CLIPPING_ON"), "30.Clipping / Fill Amount", "CLIPPING_ON", 102, 105); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("TEXTURESCROLL_ON"), "31.Texture Scroll", "TEXTURESCROLL_ON", 106, 107); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ZOOMUV_ON"), "32.Zoom", "ZOOMUV_ON", 108, 108); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("DISTORT_ON"), "33.Distortion", "DISTORT_ON", 109, 112); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("TWISTUV_ON"), "34.Twist", "TWISTUV_ON", 113, 116); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("ROTATEUV_ON"), "35.Rotate", "ROTATEUV_ON", 117, 117); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("POLARUV_ON"), "36.Polar Coordinates (Tile texture for good results)", "POLARUV_ON", -1, -1); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("FISHEYE_ON"), "37.Fish Eye", "FISHEYE_ON", 118, 118); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("PINCH_ON"), "38.Pinch", "PINCH_ON", 119, 119); GenericEffect(materialEditor, properties, style, oldKeyWords.Contains("SHAKEUV_ON"), "39.Shake", "SHAKEUV_ON", 120, 122); }
private void Gradient(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag) { bool ini = toggle; toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle); if (ini != toggle && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle) { targetMat.EnableKeyword(flag); EditorGUILayout.BeginVertical(style); { materialEditor.ShaderProperty(properties[140], properties[140].displayName); MaterialProperty gradIsRadial = ShaderGUI.FindProperty("_GradIsRadial", properties); if (gradIsRadial.floatValue == 1) { targetMat.EnableKeyword("RADIALGRADIENT_ON"); materialEditor.ShaderProperty(properties[31], properties[31].displayName); materialEditor.ShaderProperty(properties[32], properties[32].displayName); materialEditor.ShaderProperty(properties[34], properties[34].displayName); materialEditor.ShaderProperty(properties[138], properties[138].displayName); } else { targetMat.DisableKeyword("RADIALGRADIENT_ON"); bool simpleGradient = oldKeyWords.Contains("GRADIENT2COL_ON"); bool simpleGradToggle = EditorGUILayout.Toggle("2 Color Gradient?", simpleGradient); if (simpleGradient && !simpleGradToggle) { targetMat.DisableKeyword("GRADIENT2COL_ON"); } else if (!simpleGradient && simpleGradToggle) { targetMat.EnableKeyword("GRADIENT2COL_ON"); } materialEditor.ShaderProperty(properties[31], properties[31].displayName); materialEditor.ShaderProperty(properties[32], properties[32].displayName); if (!simpleGradToggle) { materialEditor.ShaderProperty(properties[33], properties[33].displayName); } materialEditor.ShaderProperty(properties[34], properties[34].displayName); if (!simpleGradToggle) { materialEditor.ShaderProperty(properties[35], properties[35].displayName); } if (!simpleGradToggle) { materialEditor.ShaderProperty(properties[138], properties[138].displayName); } materialEditor.ShaderProperty(properties[139], properties[139].displayName); } } EditorGUILayout.EndVertical(); } else { targetMat.DisableKeyword(flag); } EditorGUILayout.EndToggleGroup(); }
private void ColorChange(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle) { bool ini = toggle; toggle = EditorGUILayout.BeginToggleGroup("7.Change 1 Color", toggle); if (ini != toggle && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle) { targetMat.EnableKeyword("CHANGECOLOR_ON"); EditorGUILayout.BeginVertical(style); { for (int i = 123; i < 127; i++) { materialEditor.ShaderProperty(properties[i], properties[i].displayName); } EditorGUILayout.Separator(); ini = oldKeyWords.Contains("CHANGECOLOR2_ON"); bool toggle2 = ini; toggle2 = EditorGUILayout.Toggle("Use Color 2", ini); if (ini != toggle2 && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle2) { targetMat.EnableKeyword("CHANGECOLOR2_ON"); for (int i = 143; i < 146; i++) { materialEditor.ShaderProperty(properties[i], properties[i].displayName); } } else { targetMat.DisableKeyword("CHANGECOLOR2_ON"); } EditorGUILayout.Separator(); ini = oldKeyWords.Contains("CHANGECOLOR3_ON"); toggle2 = ini; toggle2 = EditorGUILayout.Toggle("Use Color 3", toggle2); if (ini != toggle2 && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle2) { targetMat.EnableKeyword("CHANGECOLOR3_ON"); for (int i = 146; i < 149; i++) { materialEditor.ShaderProperty(properties[i], properties[i].displayName); } } else { targetMat.DisableKeyword("CHANGECOLOR3_ON"); } } EditorGUILayout.EndVertical(); } else { targetMat.DisableKeyword("CHANGECOLOR_ON"); } EditorGUILayout.EndToggleGroup(); }
public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor) { EditorGUI.LabelField(position, label, EditorStyles.boldLabel); position.y += 17.0f; Vector4 value = prop.vectorValue; EditorGUI.BeginChangeCheck(); float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0f; DrawSlider(ref position, label0, min0, max0, ref value, 0); DrawSlider(ref position, label1, min1, max1, ref value, 1); DrawSlider(ref position, label2, min2, max2, ref value, 2); DrawSlider(ref position, label3, min3, max3, ref value, 3); EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.vectorValue = value; } GUILayout.Space(64); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { FindProperties(properties); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly _materialEditor = materialEditor; ShaderPropertiesGUI(); }
/// <summary> /// Displays the content of the section, must be ovewritten by a child class /// </summary> /// <param name="materialEditor">Material editor provided by the custom inspector window</param> /// <param name="properties">Material properties provided by the custom inspector window</param> public abstract void SectionContent(MaterialEditor materialEditor, MaterialProperty[] properties);
private void SecondaryMapGUI( MaterialEditor materialEditor, Material[] materials) { EditorGUILayout.LabelField("Secondary Maps", EditorStyles.boldLabel); var oldDetail = this.detailTex.textureValue; EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine( new GUIContent("Detail Texture"), this.detailTex); if (EditorGUI.EndChangeCheck()) { if (this.detailTex.textureValue == null) { foreach (var m in materials) { m.DisableKeyword("_DETAIL_MULX2"); m.DisableKeyword("_DETAIL_MUL"); m.DisableKeyword("_DETAIL_ADD"); m.DisableKeyword("_DETAIL_LERP"); } } else if (oldDetail == null) { foreach (var m in materials) { m.EnableKeyword("_DETAIL_MULX2"); } } } if (this.detailTex.textureValue != null) { var contents = new GUIContent[] { new GUIContent("Mul X2"), new GUIContent("Mul"), new GUIContent("Add"), new GUIContent("Lerp"), }; var keywords = new string[] { "_DETAIL_MULX2", "_DETAIL_MUL", "_DETAIL_ADD", "_DETAIL_LERP", }; this.ListOptions(materials, contents, keywords, true); EditorGUILayout.BeginHorizontal(); if (this.CheckOption(materials, "Detail Color", "_DETAIL_COLOR")) { materialEditor.ColorProperty(this.detailColor, string.Empty); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.EndHorizontal(); } if (this.CheckOption( materials, "UV Animation", "_DETAIL_ANIMATION")) { materialEditor.VectorProperty(this.detailUVSpeed, "UV Speed"); } materialEditor.TextureScaleOffsetProperty(this.detailTex); var uvContents = new GUIContent[] { new GUIContent("UV 0"), new GUIContent("UV 1"), }; var uvKeywords = new string[] { "_", "_DETAIL_UV1", }; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("UV Set"); this.ListOptions(materials, uvContents, uvKeywords); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { TCP2_GUI.HeaderAndHelp(position, this.header, null, this.help); }
public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor materialEditor) { //Material material = materialEditor.target as Material; EditorGUI.indentLevel = (int)indent; }
protected override void OnGUISafe(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { using (new FixedFieldsScope()) { EditorGUIUtility.labelWidth = 0; var vectorValue = prop.vectorValue; EditorGUI.BeginChangeCheck(); vectorValue = EditorGUI.Vector3Field(position, label, vectorValue); if (EditorGUI.EndChangeCheck()) { prop.vectorValue = vectorValue; } } }
protected override float GetPropertyHeightSafe(MaterialProperty prop, string label, MaterialEditor editor) { return(EditorGUIUtility.singleLineHeight); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { showCustomInspector = EditorGUILayout.Toggle("Use Custom Inspector", showCustomInspector); if (!showCustomInspector) { base.OnGUI(materialEditor, properties); } else { EditorGUI.BeginChangeCheck(); //Start Checking if something Changed Material targetMat = materialEditor.target as Material; //Take material Undo.RecordObject(targetMat, null); #region setCustomAssets //FONT Font customFont = AssetDatabase.LoadAssetAtPath(GetAssetPath() + "Simple.ttf", typeof(Font)) as Font; //Textures Texture texturesTex = AssetDatabase.LoadAssetAtPath(GetAssetPath() + "Textures.png", typeof(Texture2D)) as Texture2D; #endregion #region GUIStyles generals //STYLE FOR FOLDOUTS GUIStyle foldoutTitleStyle = new GUIStyle("Foldout"); //New GUIStyle taking Foldout as reference foldoutTitleStyle.font = customFont; //Change font foldoutTitleStyle.fontSize = 20; //Change font size foldoutTitleStyle.fixedHeight = 20; foldoutTitleStyle.margin.left = 15; //OPTION GUILayoutOption[] colorsLayout = new GUILayoutOption[4]; colorsLayout[0] = GUILayout.MaxHeight(40); colorsLayout[1] = GUILayout.MinHeight(20); colorsLayout[2] = GUILayout.MinWidth(20); colorsLayout[3] = GUILayout.MaxWidth(500); #endregion #region TitleImage //GetImage //Texture titleTex = AssetDatabase.LoadAssetAtPath(), typeof(Texture2D)) as Texture2D; Texture titleTex = AssetDatabase.LoadAssetAtPath(GetAssetPath() + "ToonBump.png", typeof(Texture2D)) as Texture2D; //Get Title image GUIContent title = new GUIContent(titleTex); //Set it to a content to be able to use the image //Options GUILayoutOption[] titleOptions = new GUILayoutOption[4]; //Change some options titleOptions[0] = GUILayout.MaxWidth(300); titleOptions[1] = GUILayout.MaxHeight(150); titleOptions[2] = GUILayout.MinWidth(200); titleOptions[3] = GUILayout.MinHeight(150); //Draw GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(title, titleOptions); //Image encapsulated to be centered GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); #endregion #region Colors Group mainColor = EditorGUILayout.ColorField(new GUIContent("Main Color"), targetMat.GetColor("_MainColor"), false, false, false, colorsLayout); highlights = EditorGUILayout.ColorField(new GUIContent("Highlights Color"), targetMat.GetColor("_Highlights"), false, false, false, colorsLayout); shadows = EditorGUILayout.ColorField(new GUIContent("Shadows Color"), targetMat.GetColor("_Shadows"), false, false, false, colorsLayout); outlineWidth = EditorGUILayout.Slider("Outline Width", targetMat.GetFloat("_OutlineWidth"), 0, 1); outlineColor = EditorGUILayout.ColorField(new GUIContent("Outline Color"), targetMat.GetColor("_OutlineColor"), false, false, false, colorsLayout); GUILayout.Space(10); #endregion #region Emision Group GUILayout.BeginHorizontal("box"); GUILayout.BeginVertical(); GUIContent emisiveOptionsFoldoutTitle = new GUIContent("Emisive Options"); //The content of the foldout: the label + an image emisiveOptionsBool = EditorGUILayout.Foldout(emisiveOptionsBool, emisiveOptionsFoldoutTitle, true, foldoutTitleStyle); GUILayout.Space(10); if (emisiveOptionsBool) { if (targetMat.GetFloat("_EmisiveMapOn") == 0) { emisiveMapOn = false; } else if (targetMat.GetFloat("_EmisiveMapOn") == 1) { emisiveMapOn = true; } emisiveMapOn = EditorGUILayout.Toggle("Emisive Map", emisiveMapOn); emisiveMapColor = EditorGUILayout.ColorField(new GUIContent("EmisiveMapColor"), targetMat.GetColor("_EmisiveMapColor"), false, false, false, colorsLayout); emisiveMapIntensity = EditorGUILayout.FloatField(new GUIContent("EmisiveMapIntensity"), targetMat.GetFloat("_EmisiveMapIntensity")); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(15); #endregion #region Fresnel Group GUILayout.BeginHorizontal("box"); GUILayout.BeginVertical(); GUIContent fresnelFoldoutTitle = new GUIContent("Fresnel Options"); //The content of the foldout: the label + an image fresnelOptionsBool = EditorGUILayout.Foldout(fresnelOptionsBool, fresnelFoldoutTitle, true, foldoutTitleStyle); GUILayout.Space(10); if (fresnelOptionsBool) { if (targetMat.GetFloat("_FresnelOn") == 0) { fresnelOn = false; } else if (targetMat.GetFloat("_FresnelOn") == 1) { fresnelOn = true; } fresnelOn = EditorGUILayout.Toggle("Fresnel", fresnelOn); fresnelColor = EditorGUILayout.ColorField(new GUIContent("Fresnel Color"), targetMat.GetColor("_FresnelColor"), false, false, false, colorsLayout); fresnelIntensity = EditorGUILayout.FloatField(new GUIContent("Fresnel Intensity"), targetMat.GetFloat("_FresnelIntensity")); fresnelExponent = EditorGUILayout.FloatField(new GUIContent("Fresnel Exponent"), targetMat.GetFloat("_FresnelExponent")); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(15); #endregion #region Textures Group GUILayout.BeginHorizontal("box"); GUILayout.BeginVertical(); GUIContent texturesFoldoutTitle = new GUIContent("Textures", texturesTex); //The content of the foldout: the label + an image texturesBool = EditorGUILayout.Foldout(texturesBool, texturesFoldoutTitle, true, foldoutTitleStyle); GUILayout.Space(10); if (texturesBool) { diffuseTiling = EditorGUILayout.Vector2Field("Diffuse Tiling", targetMat.GetTextureScale("_Diffuse")); diffuse = EditorGUILayout.ObjectField("Diffuse", targetMat.GetTexture("_Diffuse"), typeof(Texture2D), false) as Texture2D; normalMapTiling = EditorGUILayout.Vector2Field("Guide NormalMap Tiling", targetMat.GetTextureScale("_NormalMap")); normalMap = EditorGUILayout.ObjectField("Guide NormalMap", targetMat.GetTexture("_NormalMap"), typeof(Texture2D), false) as Texture2D; toonRampTiling = EditorGUILayout.Vector2Field("ToonRamp Tiling", targetMat.GetTextureScale("_ToonRamp")); toonRamp = EditorGUILayout.ObjectField("ToonRamp", targetMat.GetTexture("_ToonRamp"), typeof(Texture2D), false) as Texture2D; emisiveMapTiling = EditorGUILayout.Vector2Field("EmisiveMap Tiling", targetMat.GetTextureScale("_EmisiveMap")); emisiveMap = EditorGUILayout.ObjectField("EmisiveMap", targetMat.GetTexture("_EmisiveMap"), typeof(Texture2D), false) as Texture2D; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(15); #endregion //When something changed if (EditorGUI.EndChangeCheck() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")) { targetMat.SetColor("_MainColor", mainColor); targetMat.SetColor("_Highlights", highlights); targetMat.SetColor("_Shadows", shadows); targetMat.SetFloat("_OutlineWidth", outlineWidth); targetMat.SetColor("_OutlineColor", outlineColor); //EmisiveMap float emisiveMapOnTemp = 0; if (emisiveMapOn) { emisiveMapOnTemp = 1; } else { emisiveMapOnTemp = 0; } targetMat.SetFloat("_EmisiveMapOn", emisiveMapOnTemp); targetMat.SetColor("_EmisiveMapColor", emisiveMapColor); targetMat.SetFloat("_EmisiveMapIntensity", emisiveMapIntensity); //Fresnel float fresnelOnTemp = 0; if (fresnelOn) { fresnelOnTemp = 1; } else { fresnelOnTemp = 0; } targetMat.SetFloat("_FresnelOn", fresnelOnTemp); targetMat.SetColor("_FresnelColor", fresnelColor); targetMat.SetFloat("_FresnelIntensity", fresnelIntensity); targetMat.SetFloat("_FresnelExponent", fresnelExponent); targetMat.SetTextureScale("_Diffuse", diffuseTiling); targetMat.SetTexture("_Diffuse", diffuse); targetMat.SetTextureScale("_NormalMap", normalMapTiling); targetMat.SetTexture("_NormalMap", normalMap); targetMat.SetTextureScale("_ToonRamp", toonRampTiling); targetMat.SetTexture("_ToonRamp", toonRamp); targetMat.SetTextureScale("_EmisiveMap", emisiveMapTiling); targetMat.SetTexture("_EmisiveMap", emisiveMap); } } }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("OnGUI: " + label + " RTP_MaterialProp"); if (!parsed) { parsed = true; parsedLabel = RTP_MatPropStringParser.Parse(label); } label = parsedLabel; if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if (customEditor.showFlag && (show_for_active_layer == -1 || customEditor.active_layer == show_for_active_layer) && prop.name!= "dummy_end") { EditorGUI.BeginDisabledGroup(customEditor.inactiveFlag); switch (prop.type) { //case MaterialProperty.PropType.Range: // float ranges // { // editor.RangeProperty(position, prop, label); // break; // } //case MaterialProperty.PropType.Float: // floats // { // editor.FloatProperty(position, prop, label); // break; // } case MaterialProperty.PropType.Color: // colors { EditorGUIUtility.labelWidth -= 30; if (noAlphaFlag) { EditorGUI.ColorField(position, new GUIContent(label, ""), prop.colorValue, true, false, false, null); } else { editor.ColorProperty(position, prop, label); } break; } case MaterialProperty.PropType.Texture: // textures { EditorGUI.BeginChangeCheck(); if (miniThumbFlag) { editor.TexturePropertyMiniThumbnail(position, prop, label,""); } else { editor.TextureProperty(position, prop, label, !noTileOffsetFlag); } if (EditorGUI.EndChangeCheck() && prop.textureValue!=null && sharedTextures!=null) { for(int j=0; j<sharedTextures.Length; j++) { foreach(Material mat in editor.targets) { if (mat.HasProperty(sharedTextures[j])) { mat.SetTexture(sharedTextures[j], prop.textureValue); } } } } break; } case MaterialProperty.PropType.Vector: // vectors { if (byLayerFlag) { // // affect single vector component depending on active layer // int layerNum = customEditor.active_layer; float pval = prop.vectorValue[layerNum]; float nval; if (minVal == maxVal) { // float EditorGUIUtility.labelWidth -= 23; nval = EditorGUI.FloatField(position, label, pval); } else { // slider EditorGUIUtility.labelWidth = 160; nval = EditorGUI.Slider(position, label, pval, minVal, maxVal); } if (pval!=nval) { for(int i=0; i< prop.targets.Length; i++) { Material mat = (prop.targets[i] as Material); Vector4 vec = mat.GetVector(prop.name); vec[layerNum] = nval; mat.SetVector(prop.name, vec); } } } else { position.x += 12; position.width -= 12; editor.VectorProperty(position, prop, label); } break; } default: { if (customEditor.nextLabelWidth>0) { EditorGUIUtility.labelWidth = customEditor.nextLabelWidth; customEditor.nextLabelWidth = 0; } else { EditorGUIUtility.labelWidth -= 30; } editor.DefaultShaderProperty(position, prop, label); break; } } EditorGUI.EndDisabledGroup(); } } }
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] properties) { FindProperties(properties); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly _materialEditor = materialEditor; Material material = materialEditor.target as Material; ShaderPropertiesGUI(material); // Make sure that needed keywords are set up if we're switching some existing // material to a standard shader. if (_firstTimeApply) { SetMaterialKeywords(material); SetLightModeFromShader(material); _firstTimeApply = false; } }
private void Blending(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle, string inspector, string flag) { MaterialProperty srcM = ShaderGUI.FindProperty("_MySrcMode", properties); MaterialProperty dstM = ShaderGUI.FindProperty("_MyDstMode", properties); if (srcM.floatValue == 0 && dstM.floatValue == 0) { srcM.floatValue = 5; dstM.floatValue = 10; } bool ini = toggle; toggle = EditorGUILayout.BeginToggleGroup(inspector, toggle); if (ini != toggle && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle) { targetMat.EnableKeyword(flag); EditorGUILayout.BeginVertical(style); { GUILayout.Label("Look for 'ShaderLab: Blending' if you don't know what this is", style); if (GUILayout.Button("Back To Default Blending")) { srcM.floatValue = 5; dstM.floatValue = 10; targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); } srcMode = (UnityEngine.Rendering.BlendMode)srcM.floatValue; dstMode = (UnityEngine.Rendering.BlendMode)dstM.floatValue; srcMode = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("SrcMode", srcMode); dstMode = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("DstMode", dstMode); srcM.floatValue = (float)(srcMode); dstM.floatValue = (float)(dstMode); ini = oldKeyWords.Contains("PREMULTIPLYALPHA_ON"); toggle = EditorGUILayout.Toggle("Premultiply Alpha?", ini); if (ini != toggle && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle) { targetMat.EnableKeyword("PREMULTIPLYALPHA_ON"); } else { targetMat.DisableKeyword("PREMULTIPLYALPHA_ON"); } } EditorGUILayout.EndVertical(); } else { srcM.floatValue = 5; dstM.floatValue = 10; targetMat.DisableKeyword(flag); } EditorGUILayout.EndToggleGroup(); }
public static void drawBigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool scaleOffset) { Rect rect = GUILayoutUtility.GetRect(label, Styles.bigTextureStyle); float defaultLabelWidth = EditorGUIUtility.labelWidth; float defaultFieldWidth = EditorGUIUtility.fieldWidth; editor.SetDefaultGUIWidths(); editor.TextureProperty(position, prop, label.text, label.tooltip, scaleOffset); EditorGUIUtility.labelWidth = defaultLabelWidth; EditorGUIUtility.fieldWidth = defaultFieldWidth; DrawingData.lastGuiObjectHeaderRect = position; Rect object_rect = new Rect(position); object_rect.height += rect.height; DrawingData.lastGuiObjectRect = object_rect; }
public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties) { Rect thumbnailPos = position; thumbnailPos.x += hasFoldoutProperties ? 20 : 0; editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, (hasFoldoutProperties ? "Click here for extra properties" : "") + (label.tooltip != "" ? " | " : "") + label.tooltip); if (DrawingData.currentTexProperty.reference_property_exists) { ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[DrawingData.currentTexProperty.options.reference_property]; Rect r = position; r.x += EditorGUIUtility.labelWidth - CurrentIndentWidth(); r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth(); property.Draw(new CRect(r), new GUIContent()); } if (hasFoldoutProperties && DrawingData.currentTexProperty != null) { //draw dropdown triangle thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15; //This is an invisible button with zero functionality. But it needs to be here so that the triangle click reacts fast if (GUI.Button(thumbnailPos, "", Styles.none)) { ; } if (Event.current.type == EventType.Repaint) { EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false); } if (DrawingData.is_enabled) { //test click and draw scale/offset if (DrawingData.currentTexProperty.showFoldoutProperties) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { ShaderEditor.currentlyDrawing.editor.TextureScaleOffsetProperty(prop); DrawingData.currentTexProperty.HandleKajAnimatable(); } PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } EditorGUI.indentLevel -= 2; } if (ShaderEditor.input.MouseLeftClick && position.Contains(Event.current.mousePosition)) { ShaderEditor.input.Use(); DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties; } } } DrawingData.lastGuiObjectHeaderRect = position; Rect object_rect = new Rect(position); object_rect.height = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height; DrawingData.lastGuiObjectRect = object_rect; }
public static void drawStylizedBigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, bool skip_drag_and_drop_handling = false) { position.x += (EditorGUI.indentLevel) * 15; position.width -= (EditorGUI.indentLevel) * 15; Rect rect = GUILayoutUtility.GetRect(label, Styles.bigTextureStyle); rect.x += (EditorGUI.indentLevel) * 15; rect.width -= (EditorGUI.indentLevel) * 15; Rect border = new Rect(rect); border.position = new Vector2(border.x, border.y - position.height); border.height += position.height; if (DrawingData.currentTexProperty.reference_properties_exist) { border.height += 8; foreach (string r_property in DrawingData.currentTexProperty.options.reference_properties) { border.height += editor.GetPropertyHeight(ShaderEditor.currentlyDrawing.propertyDictionary[r_property].materialProperty); } } if (DrawingData.currentTexProperty.reference_property_exists) { border.height += editor.GetPropertyHeight(ShaderEditor.currentlyDrawing.propertyDictionary[DrawingData.currentTexProperty.options.reference_property].materialProperty); } //background GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true); Rect quad = new Rect(border); quad.width = quad.height / 2; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0, 0, 0.5f, 1), true); quad.x += border.width - quad.width; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0.5f, 0, 0.5f, 1), true); quad.width = border.height - 4; quad.height = quad.width; quad.x = border.x + border.width - quad.width - 1; quad.y += 2; Rect preview_rect_border = new Rect(position); preview_rect_border.height = rect.height + position.height - 6; preview_rect_border.width = preview_rect_border.height; preview_rect_border.y += 3; preview_rect_border.x += position.width - preview_rect_border.width - 3; Rect preview_rect = new Rect(preview_rect_border); preview_rect.height -= 6; preview_rect.width -= 6; preview_rect.x += 3; preview_rect.y += 3; if (prop.hasMixedValue) { Rect mixedRect = new Rect(preview_rect); mixedRect.y -= 5; mixedRect.x += mixedRect.width / 2 - 4; GUI.Label(mixedRect, "_"); } else if (prop.textureValue != null) { GUI.DrawTexture(preview_rect, prop.textureValue); } GUI.DrawTexture(preview_rect_border, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 0, Color.grey, 3, 5); //selection button and pinging Rect select_rect = new Rect(preview_rect); select_rect.height = 12; select_rect.y += preview_rect.height - 12; if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow && texturePickerWindowProperty.name == prop.name) { prop.textureValue = (Texture)EditorGUIUtility.GetObjectPickerObject(); ShaderEditor.repaint(); } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow) { texturePickerWindow = -1; texturePickerWindowProperty = null; } if (GUI.Button(select_rect, "Select", EditorStyles.miniButton)) { EditorGUIUtility.ShowObjectPicker <Texture>(prop.textureValue, false, "", 0); texturePickerWindow = EditorGUIUtility.GetObjectPickerControlID(); texturePickerWindowProperty = prop; } else if (Event.current.type == EventType.MouseDown && preview_rect.Contains(Event.current.mousePosition)) { EditorGUIUtility.PingObject(prop.textureValue); } if (!skip_drag_and_drop_handling) { if ((ShaderEditor.input.is_drag_drop_event) && preview_rect.Contains(ShaderEditor.input.mouse_position) && DragAndDrop.objectReferences[0] is Texture) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (ShaderEditor.input.is_drop_event) { DragAndDrop.AcceptDrag(); prop.textureValue = (Texture)DragAndDrop.objectReferences[0]; } } } //scale offset rect if (hasFoldoutProperties) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { Rect scale_offset_rect = new Rect(position); scale_offset_rect.y += 37; scale_offset_rect.width -= 2 + preview_rect.width + 10 + 30; scale_offset_rect.x += 30; editor.TextureScaleOffsetProperty(scale_offset_rect, prop); DrawingData.currentTexProperty.HandleKajAnimatable(); } float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 128; PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_property != null) { ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[options.reference_property]; ShaderEditor.currentlyDrawing.editor.ShaderProperty(property.materialProperty, property.content); } if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.currentlyDrawing.propertyDictionary[r_property]; ShaderEditor.currentlyDrawing.editor.ShaderProperty(property.materialProperty, property.content); property.HandleKajAnimatable(); } } EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUI.indentLevel -= 2; } Rect label_rect = new Rect(position); label_rect.x += 2; label_rect.y += 2; GUI.Label(label_rect, label); GUILayoutUtility.GetRect(0, 5); DrawingData.lastGuiObjectHeaderRect = position; DrawingData.lastGuiObjectRect = border; }
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { return(18f); }
private void MainMapGUI( MaterialEditor materialEditor, Material[] materials) { EditorGUILayout.LabelField("Main Maps", EditorStyles.boldLabel); bool albedoEnable = this.TextureGUIWithKeyword( materialEditor, materials, this.albedoTex, "Albedo Texture", "_ALBEDOMAP"); if (albedoEnable) { var contents = new GUIContent[] { new GUIContent("Normal"), new GUIContent("Emission"), new GUIContent("Smoothess"), new GUIContent("Metallic"), new GUIContent("Detail"), }; var keys = new string[] { "_", "_EMISSION_ALPHA", "_SMOOTHNESS_ALPHA", "_METALLIC_ALPHA", "_DETAIL_ALPHA", }; EditorGUI.indentLevel = 1; EditorGUILayout.PrefixLabel("Alpha Usage:"); this.ListOptions(materials, contents, keys, true); EditorGUI.indentLevel = 0; } bool normalEnable = this.TextureGUIWithKeyword( materialEditor, materials, this.normalTex, "Normal Texture", "_NORMALMAP"); if (normalEnable) { EditorGUI.indentLevel = 1; materialEditor.FloatProperty(this.normalScale, "Scale"); EditorGUI.indentLevel = 0; } this.TextureGUIWithKeyword( materialEditor, materials, this.maskTex, new GUIContent("Mask Texture", "smoothness(R), metallic(G), emission(B)"), "_MASKMAP"); if (this.albedoTex.textureValue != null || this.normalTex.textureValue != null || this.maskTex.textureValue != null) { materialEditor.TextureScaleOffsetProperty(this.albedoTex); } EditorGUILayout.Space(); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { if (materialEditor.target is Material material) { string current = material.GetTag(TAG_RENDER_TYPE, false); BlendModeOption currentBlendMode = BlendModeOption.Opaque; switch (current) { case "": case TAG_RENDER_TYPE_OPAQUE: currentBlendMode = BlendModeOption.Opaque; break; case TAG_RENDER_TYPE_CUTOUT: currentBlendMode = BlendModeOption.Cutout; break; case TAG_RENDER_TYPE_FADE: currentBlendMode = BlendModeOption.Fade; break; case TAG_RENDER_TYPE_TRANSPARENT: currentBlendMode = BlendModeOption.Transparent; break; } GUILayout.BeginHorizontal(); GUILayout.Label("Blend Mode"); BlendModeOption blend = (BlendModeOption)EditorGUILayout.EnumPopup(currentBlendMode); GUILayout.EndHorizontal(); if (blend != currentBlendMode) { ConfigureBlendMode(material, blend); } uvTransform = TextureRotationSlider(material, uvTransform, mainTexScaleTransform, mainTexRotation, true); if (uvTransform.HasValue) { if (uvTransform.Value.rotation != 0) { material.EnableKeyword(KW_UV_ROTATION); } else { material.DisableKeyword(KW_UV_ROTATION); } } if (GUI.changed) { EditorUtility.SetDirty(material); } void EnsureKeywordForMap(string textureProperty, string keyword) { if (material.HasProperty(textureProperty)) { if (material.GetTexture(textureProperty) && !material.IsKeywordEnabled(keyword)) { material.EnableKeyword(keyword); } if (!material.GetTexture(textureProperty) && material.IsKeywordEnabled(keyword)) { material.DisableKeyword(keyword); } } } EnsureKeywordForMap("_MetallicGlossMap", "_METALLICGLOSSMAP"); EnsureKeywordForMap("_OcclusionMap", "_OCCLUSION"); } base.OnGUI(materialEditor, properties); }
void DrawDynamicInspector(Material material, MaterialEditor materialEditor, MaterialProperty[] props) { var customPropsList = new List <MaterialProperty>(); if (multiSelection) { for (int i = 0; i < props.Length; i++) { var prop = props[i]; if (prop.flags == MaterialProperty.PropFlags.HideInInspector) { continue; } customPropsList.Add(prop); } } else { for (int i = 0; i < props.Length; i++) { var prop = props[i]; if (prop.flags == MaterialProperty.PropFlags.HideInInspector) { continue; } if (material.HasProperty("_BackgroundMode")) { if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundCubemapSpace") { continue; } if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundCubemap") { continue; } if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundExposure") { continue; } if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_SkyColor") { continue; } if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorColor") { continue; } if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_GroundColor") { continue; } if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorHeight") { continue; } if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorSmoothness") { continue; } } customPropsList.Add(prop); } } //Draw Custom GUI for (int i = 0; i < customPropsList.Count; i++) { var prop = customPropsList[i]; materialEditor.ShaderProperty(prop, prop.displayName); } GUILayout.Space(10); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { FindBaseMaterialProperties(props); FindMaterialProperties(props); m_MaterialEditor = materialEditor; // We should always register the key used to keep collapsable state InitExpandableState(materialEditor); // We should always do this call at the beginning m_MaterialEditor.serializedObject.Update(); Material material = m_MaterialEditor.target as Material; AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID())); InitializeMaterialLayers(materialImporter, ref m_MaterialLayers); bool optionsChanged = false; EditorGUI.BeginChangeCheck(); { using (var header = new HeaderScope(StylesBaseUnlit.optionText, (uint)Expandable.Base, this)) { if (header.expanded) { BaseMaterialPropertiesGUI(); } } MaterialTesselationPropertiesGUI(); VertexAnimationPropertiesGUI(); } if (EditorGUI.EndChangeCheck()) { optionsChanged = true; } // In case of pixel displacement and layered shader, all layers must used the same texture mapping for layer that have a heightmap // (Else the algorithm will not work correctly) if ((DisplacementMode)displacementMode.floatValue == DisplacementMode.Pixel) { float compareValue = -1.0f; bool match = true; if (material.GetTexture(kHeightMap + 0)) { compareValue = UVBase[0].floatValue; } if (material.GetTexture(kHeightMap + 1)) { if (compareValue == -1.0f) { compareValue = UVBase[1].floatValue; } else if (compareValue != UVBase[1].floatValue) { match = false; } } if (material.GetTexture(kHeightMap + 2)) { if (compareValue == -1.0f) { compareValue = UVBase[2].floatValue; } else if (compareValue != UVBase[2].floatValue) { match = false; } } if (material.GetTexture(kHeightMap + 3)) { if (compareValue == -1.0f) { compareValue = UVBase[3].floatValue; } else if (compareValue != UVBase[3].floatValue) { match = false; } } if (!match) { EditorGUILayout.HelpBox(styles.perPixelDisplacementLayersWarning.text, MessageType.Warning); } } bool layerChanged = DoLayersGUI(materialImporter); EditorGUI.BeginChangeCheck(); { DoEmissiveGUI(material); } if (EditorGUI.EndChangeCheck()) { optionsChanged = true; } using (var header = new HeaderScope(StylesBaseUnlit.advancedText, (uint)Expandable.Advance, this)) { if (header.expanded) { // NB RenderQueue editor is not shown on purpose: we want to override it based on blend mode m_MaterialEditor.EnableInstancingField(); m_MaterialEditor.ShaderProperty(enableSpecularOcclusion, Styles.enableSpecularOcclusionText); } } if (layerChanged || optionsChanged) { foreach (var obj in m_MaterialEditor.targets) { SetupMaterialKeywordsAndPassInternal((Material)obj); } // SaveAssetsProcessor the referenced material in the users data SaveMaterialLayers(materialImporter); } // We should always do this call at the end m_MaterialEditor.serializedObject.ApplyModifiedProperties(); }
public static void drawConfigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, bool skip_drag_and_drop_handling = false) { switch (Config.Get().default_texture_type) { case TextureDisplayType.small: drawSmallTextureProperty(position, prop, label, editor, hasFoldoutProperties); break; case TextureDisplayType.big: if (DrawingData.currentTexProperty.reference_properties_exist || DrawingData.currentTexProperty.reference_property_exists) { drawStylizedBigTextureProperty(position, prop, label, editor, hasFoldoutProperties); } else { drawBigTextureProperty(position, prop, label, editor, DrawingData.currentTexProperty.hasScaleOffset); } break; case TextureDisplayType.stylized_big: drawStylizedBigTextureProperty(position, prop, label, editor, hasFoldoutProperties, skip_drag_and_drop_handling); break; } }
// 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; CoreUtils.SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable); SurfaceType surfaceType = (SurfaceType)material.GetFloat(kSurfaceType); CoreUtils.SetKeyword(material, "_SURFACE_TYPE_TRANSPARENT", surfaceType == SurfaceType.Transparent); bool enableBlendModePreserveSpecularLighting = (surfaceType == SurfaceType.Transparent) && material.HasProperty(kEnableBlendModePreserveSpecularLighting) && material.GetFloat(kEnableBlendModePreserveSpecularLighting) > 0.0f; CoreUtils.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 CoreUtils.SetKeyword(material, "_BLENDMODE_ALPHA", false); CoreUtils.SetKeyword(material, "_BLENDMODE_ADD", false); CoreUtils.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.Priority.OpaqueAlphaTest : (int)HDRenderQueue.Priority.Opaque; } else { material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_ZWrite", 0); var isPrepass = material.HasProperty(kPreRefractionPass) && material.GetFloat(kPreRefractionPass) > 0.0f; material.renderQueue = (int)(isPrepass ? HDRenderQueue.Priority.PreRefraction : HDRenderQueue.Priority.Transparent) + (int)material.GetFloat(kTransparentSortPriority); if (material.HasProperty(kBlendMode)) { BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode); CoreUtils.SetKeyword(material, "_BLENDMODE_ALPHA", BlendMode.Alpha == blendMode); CoreUtils.SetKeyword(material, "_BLENDMODE_ADD", BlendMode.Additive == blendMode); CoreUtils.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; // 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 fogEnabled = material.HasProperty(kEnableFogOnTransparent) && material.GetFloat(kEnableFogOnTransparent) > 0.0f && surfaceType == SurfaceType.Transparent; CoreUtils.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; } } bool isBackFaceEnable = material.HasProperty(kTransparentBackfaceEnable) && material.GetFloat(kTransparentBackfaceEnable) > 0.0f && surfaceType == SurfaceType.Transparent; bool doubleSidedEnable = material.HasProperty(kDoubleSidedEnable) && material.GetFloat(kDoubleSidedEnable) > 0.0f; // Disable culling if double sided material.SetInt("_CullMode", doubleSidedEnable ? (int)UnityEngine.Rendering.CullMode.Off : (int)UnityEngine.Rendering.CullMode.Back); // 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", doubleSidedEnable ? (int)UnityEngine.Rendering.CullMode.Off : (int)UnityEngine.Rendering.CullMode.Back); } 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. 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(); }
MaterialProperty FindProperty(string path, Material material) { UnityObject[] mats = new[] { material }; return(MaterialEditor.GetMaterialProperty(mats, path)); }
public void DrawSection(MaterialEditor materialEditor) { EditorGUI.BeginChangeCheck(); TSFunctions.DrawSelector(Enum.GetNames(typeof(ToonyStandardGUI.BlendMode)), _blendMode, Styles.blendMode, materialEditor); if (EditorGUI.EndChangeCheck()) { foreach (Material mat in _blendMode.targets) { ToonyStandardGUI.SetupMaterialWithBlendMode(mat, (ToonyStandardGUI.BlendMode)_blendMode.floatValue, mat.GetFloat("_OutlineOn") > 0); } } //draw cull mode materialEditor.ShaderProperty(_Cull, Styles.cullMode); EditorGUILayout.Space(); //draw main properties materialEditor.TexturePropertySingleLine(Styles.mainTex, _MainTex, _Color); if ((ToonyStandardGUI.BlendMode)_blendMode.floatValue == ToonyStandardGUI.BlendMode.Cutout) { EditorGUI.indentLevel += MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1; materialEditor.ShaderProperty(_Cutoff, Styles.cutOff); EditorGUI.indentLevel -= MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1; } materialEditor.TexturePropertySingleLine(Styles.normal, _BumpMap, _BumpScale); if (level == InspectorLevel.Normal) { Rect r = TSFunctions.GetControlRectForSingleLine(); EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertyMiniThumbnail(r, _OcclusionMap, Styles.occlusion.text, Styles.occlusion.tooltip); if (EditorGUI.EndChangeCheck()) { gui.RegenerateMSOT(false); } TSFunctions.ProperSlider(MaterialEditor.GetRectAfterLabelWidth(r), ref _Occlusion); } else { materialEditor.ShaderProperty(_Occlusion, Styles.occlusion); } //emission EditorGUI.BeginChangeCheck(); if (materialEditor.EmissionEnabledProperty()) { materialEditor.TexturePropertySingleLine(Styles.emission, _Emission, _EmissionColor); materialEditor.LightmapEmissionProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel); } if (EditorGUI.EndChangeCheck()) { foreach (Material mat in _Emission.targets) { MaterialEditor.FixupEmissiveFlag(mat); bool shouldEmissionBeEnabled = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0; TSFunctions.SetKeyword(mat, "_EMISSION", shouldEmissionBeEnabled); if (shouldEmissionBeEnabled) { mat.SetOverrideTag("IsEmissive", "true"); } else { mat.SetOverrideTag("IsEmissive", "false"); } } } //if in expert mode show the MSOT map and a button for the texture packer if (level == InspectorLevel.Expert) { EditorGUILayout.BeginHorizontal(); materialEditor.TexturePropertySingleLine(Styles.MSOT, _MSOT); if (GUILayout.Button(Styles.TexturePackerButton)) { EditorGUILayout.EndHorizontal(); isTexturePackerOpen = !isTexturePackerOpen; Styles.ToggleTexturePackerContent(isTexturePackerOpen); } else { EditorGUILayout.EndHorizontal(); } if (isTexturePackerOpen) { EditorGUILayout.BeginVertical("box"); packer.DrawGUI(); EditorGUILayout.EndVertical(); if (_MSOT.textureValue != (Texture)packer.resultTex && packer.resultTex != null) { _MSOT.textureValue = packer.resultTex; packer.resultTex = null; } } } EditorGUILayout.Space(); materialEditor.TextureScaleOffsetProperty(_MainTex); //EditorGUILayout.Space(); //materialEditor.RenderQueueField(); EditorGUILayout.Space(); }
private void Outline(MaterialEditor materialEditor, MaterialProperty[] properties, GUIStyle style, bool toggle) { bool ini = toggle; toggle = EditorGUILayout.BeginToggleGroup("3.Outline", toggle); if (ini != toggle && !Application.isPlaying) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } if (toggle) { targetMat.EnableKeyword("OUTBASE_ON"); EditorGUILayout.BeginVertical(style); { materialEditor.ShaderProperty(properties[14], properties[14].displayName); materialEditor.ShaderProperty(properties[15], properties[15].displayName); materialEditor.ShaderProperty(properties[16], properties[16].displayName); materialEditor.ShaderProperty(properties[17], properties[17].displayName); MaterialProperty outline8dir = ShaderGUI.FindProperty("_Outline8Directions", properties); if (outline8dir.floatValue == 1) { targetMat.EnableKeyword("OUTBASE8DIR_ON"); } else { targetMat.DisableKeyword("OUTBASE8DIR_ON"); } materialEditor.ShaderProperty(properties[19], properties[19].displayName); MaterialProperty outlinePixel = ShaderGUI.FindProperty("_OutlineIsPixel", properties); if (outlinePixel.floatValue == 1) { targetMat.EnableKeyword("OUTBASEPIXELPERF_ON"); materialEditor.ShaderProperty(properties[20], properties[20].displayName); } else { targetMat.DisableKeyword("OUTBASEPIXELPERF_ON"); materialEditor.ShaderProperty(properties[18], properties[18].displayName); } materialEditor.ShaderProperty(properties[21], properties[21].displayName); MaterialProperty outlineTex = ShaderGUI.FindProperty("_OutlineTexToggle", properties); if (outlineTex.floatValue == 1) { targetMat.EnableKeyword("OUTTEX_ON"); materialEditor.ShaderProperty(properties[22], properties[22].displayName); materialEditor.ShaderProperty(properties[23], properties[23].displayName); materialEditor.ShaderProperty(properties[24], properties[24].displayName); materialEditor.ShaderProperty(properties[25], properties[25].displayName); MaterialProperty outlineTexGrey = ShaderGUI.FindProperty("_OutlineTexGrey", properties); if (outlineTexGrey.floatValue == 1) { targetMat.EnableKeyword("OUTGREYTEXTURE_ON"); } else { targetMat.DisableKeyword("OUTGREYTEXTURE_ON"); } } else { targetMat.DisableKeyword("OUTTEX_ON"); } materialEditor.ShaderProperty(properties[26], properties[26].displayName); MaterialProperty outlineDistort = ShaderGUI.FindProperty("_OutlineDistortToggle", properties); if (outlineDistort.floatValue == 1) { targetMat.EnableKeyword("OUTDIST_ON"); materialEditor.ShaderProperty(properties[27], properties[27].displayName); materialEditor.ShaderProperty(properties[28], properties[28].displayName); materialEditor.ShaderProperty(properties[29], properties[29].displayName); materialEditor.ShaderProperty(properties[30], properties[30].displayName); } else { targetMat.DisableKeyword("OUTDIST_ON"); } } EditorGUILayout.EndVertical(); } else { targetMat.DisableKeyword("OUTBASE_ON"); } EditorGUILayout.EndToggleGroup(); }
public static void SetupBaseUnlitKeywords(this Material material) { bool alphaTestEnable = material.HasProperty(kAlphaCutoffEnabled) && material.GetFloat(kAlphaCutoffEnabled) > 0.0f; CoreUtils.SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable); SurfaceType surfaceType = material.GetSurfaceType(); CoreUtils.SetKeyword(material, "_SURFACE_TYPE_TRANSPARENT", surfaceType == SurfaceType.Transparent); bool enableBlendModePreserveSpecularLighting = (surfaceType == SurfaceType.Transparent) && material.HasProperty(kEnableBlendModePreserveSpecularLighting) && material.GetFloat(kEnableBlendModePreserveSpecularLighting) > 0.0f; CoreUtils.SetKeyword(material, "_BLENDMODE_PRESERVE_SPECULAR_LIGHTING", enableBlendModePreserveSpecularLighting); bool transparentWritesMotionVec = (surfaceType == SurfaceType.Transparent) && material.HasProperty(kTransparentWritingMotionVec) && material.GetInt(kTransparentWritingMotionVec) > 0; CoreUtils.SetKeyword(material, "_TRANSPARENT_WRITES_MOTION_VEC", transparentWritesMotionVec); // These need to always been set either with opaque or transparent! So a users can switch to opaque and remove the keyword correctly CoreUtils.SetKeyword(material, "_BLENDMODE_ALPHA", false); CoreUtils.SetKeyword(material, "_BLENDMODE_ADD", false); CoreUtils.SetKeyword(material, "_BLENDMODE_PRE_MULTIPLY", false); 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.GetZWrite() ? 1 : 0); if (material.HasProperty(kBlendMode)) { BlendMode blendMode = material.GetBlendMode(); CoreUtils.SetKeyword(material, "_BLENDMODE_ALPHA", BlendMode.Alpha == blendMode); CoreUtils.SetKeyword(material, "_BLENDMODE_ADD", BlendMode.Additive == blendMode); CoreUtils.SetKeyword(material, "_BLENDMODE_PRE_MULTIPLY", BlendMode.Premultiply == blendMode); // 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() : CullMode.Back; bool isBackFaceEnable = material.HasProperty(kTransparentBackfaceEnable) && material.GetFloat(kTransparentBackfaceEnable) > 0.0f && surfaceType == SurfaceType.Transparent; bool doubleSidedEnable = material.HasProperty(kDoubleSidedEnable) && material.GetFloat(kDoubleSidedEnable) > 0.0f; // 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); } // 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. material.SetupMainTexForAlphaTestGI("_EmissiveColorMap", "_EmissiveColor"); // 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(); }
void InitEditorData(MaterialEditor materialEditor) { Editor = materialEditor; TextureArrayProperties = new List <ShaderProperty>(); IsFirstCall = true; }
override public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { //Debug.Log("GetHeight: " + label+ " RTP_MaterialProp" ); if (editor is RTP_CustomShaderGUI) { RTP_CustomShaderGUI customEditor = editor as RTP_CustomShaderGUI; if ( customEditor.showFlag && (show_for_active_layer==-1 || customEditor.active_layer==show_for_active_layer) && prop.name!="dummy_end") { if (miniThumbFlag) { return 20; } else { if ( (prop.type == MaterialProperty.PropType.Vector) && byLayerFlag) { return 17; } else { return MaterialEditor.GetDefaultPropertyHeight(prop); } } } return -2; } return MaterialEditor.GetDefaultPropertyHeight(prop); }
///////////////////////////////////////////////////////////////////////////////////////////// // Properties // ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////// // Particles // ///////////////// ///////////////////////////////////////////////////////////////////////////////////////////// // Draw // ///////////////////////////////////////////////////////////////////////////////////////////// ///////////////// // Options // ///////////////// protected override void DrawEmissionFlags(MaterialEditor materialEditor) { }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { mMaterialEditor = materialEditor; #if SHOW_DEFAULT_INSPECTOR base.OnGUI(); return; #else //Wait one frame to avoid GUI errors if(mJustChangedShader && Event.current.type != EventType.Layout) { mJustChangedShader = false; mVariantError = null; Event.current.Use(); //Avoid layout mismatch error } UpdateFeaturesFromShader(); //Get material keywords List<string> keywordsList = new List<string>(targetMaterial.shaderKeywords); bool updateKeywords = false; bool updateVariant = false; //Header EditorGUILayout.BeginHorizontal(); TCP2_GUI.HeaderBig("TOONY COLORS PRO 2 - INSPECTOR"); if(isGeneratedShader && TCP2_GUI.Button(TCP2_GUI.CogIcon, "O", "Open in Shader Generator")) { if(targetMaterial.shader != null) { TCP2_ShaderGenerator.OpenWithShader(targetMaterial.shader); } } TCP2_GUI.HelpButton("Unified Shader"); EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); if(!string.IsNullOrEmpty(mVariantError)) { EditorGUILayout.HelpBox(mVariantError, MessageType.Error); EditorGUILayout.HelpBox("Some of the shaders are packed to avoid super long loading times when you import Toony Colors Pro 2 into Unity.\n\n"+ "You can unpack them by category in the menu:\n\"Tools > Toony Colors Pro 2 > Unpack Shaders > ...\"", MessageType.Info); } //Iterate Shader properties materialEditor.serializedObject.Update(); SerializedProperty mShader = materialEditor.serializedObject.FindProperty("m_Shader"); if(materialEditor.isVisible && !mShader.hasMultipleDifferentValues && mShader.objectReferenceValue != null) { EditorGUIUtility.labelWidth = Screen.width - 120f; EditorGUIUtility.fieldWidth = 64f; EditorGUI.BeginChangeCheck(); MaterialProperty[] props = properties; //UNFILTERED PARAMETERS ============================================================== TCP2_GUI.HeaderAndHelp("BASE", "Base Properties"); if(ShowFilteredProperties(null, props)) { TCP2_GUI.Separator(); } //FILTERED PARAMETERS ================================================================ //RAMP TYPE -------------------------------------------------------------------------- if(CategoryFilter("TEXTURE_RAMP")) { if(isGeneratedShader) { ShowFilteredProperties("#RAMPT#", props); } else { if( TCP2_Utils.ShaderKeywordToggle("TCP2_RAMPTEXT", "Texture Toon Ramp", "Make the toon ramp based on a texture", keywordsList, ref updateKeywords, "Ramp Style") ) { ShowFilteredProperties("#RAMPT#", props); } else { ShowFilteredProperties("#RAMPF#", props); } } } else { ShowFilteredProperties("#RAMPF#", props); } TCP2_GUI.Separator(); //BUMP/NORMAL MAPPING ---------------------------------------------------------------- if(CategoryFilter("BUMP")) { if(isGeneratedShader) { TCP2_GUI.HeaderAndHelp("BUMP/NORMAL MAPPING", "Normal/Bump map"); ShowFilteredProperties("#NORM#", props); ShowFilteredProperties("#PLLX#", props); } else { if( TCP2_Utils.ShaderKeywordToggle("TCP2_BUMP", "BUMP/NORMAL MAPPING", "Enable bump mapping using normal maps", keywordsList, ref updateKeywords, "Normal/Bump map") ) { ShowFilteredProperties("#NORM#", props); } } TCP2_GUI.Separator(); } //SPECULAR --------------------------------------------------------------------------- if(CategoryFilter("SPECULAR", "SPECULAR_ANISOTROPIC")) { if(isGeneratedShader) { TCP2_GUI.HeaderAndHelp("SPECULAR", "Specular"); ShowFilteredProperties("#SPEC#", props); if(HasFlags("SPECULAR_ANISOTROPIC")) ShowFilteredProperties("#SPECA#", props); if(HasFlags("SPECULAR_TOON")) ShowFilteredProperties("#SPECT#", props); } else { bool specular = TCP2_Utils.HasKeywords(keywordsList, "TCP2_SPEC", "TCP2_SPEC_TOON"); TCP2_Utils.ShaderVariantUpdate("Specular", ShaderVariants, ShaderVariantsEnabled, specular, ref updateVariant); specular |= TCP2_Utils.ShaderKeywordRadio("SPECULAR", new string[]{"TCP2_SPEC_OFF","TCP2_SPEC","TCP2_SPEC_TOON"}, new GUIContent[] { new GUIContent("Off", "No Specular"), new GUIContent("Regular", "Default Blinn-Phong Specular"), new GUIContent("Cartoon", "Specular with smoothness control") }, keywordsList, ref updateKeywords); if( specular ) { ShowFilteredProperties("#SPEC#", props); bool specr = TCP2_Utils.HasKeywords(keywordsList, "TCP2_SPEC_TOON"); if(specr) { ShowFilteredProperties("#SPECT#", props); } } } TCP2_GUI.Separator(); } //REFLECTION ------------------------------------------------------------------------- if(CategoryFilter("REFLECTION") && !isMobileShader) { if(isGeneratedShader) { TCP2_GUI.HeaderAndHelp("REFLECTION", "Reflection"); ShowFilteredProperties("#REFL#", props); #if UNITY_5 if(HasFlags("U5_REFLPROBE")) ShowFilteredProperties("#REFL_U5#", props); #endif if(HasFlags("REFL_COLOR")) ShowFilteredProperties("#REFLC#", props); if(HasFlags("REFL_ROUGH")) { ShowFilteredProperties("#REFLR#", props); EditorGUILayout.HelpBox("Cubemap Texture needs to have MipMaps enabled for Roughness to work!", MessageType.Info); } } else { bool reflection = TCP2_Utils.HasKeywords(keywordsList, "TCP2_REFLECTION", "TCP2_REFLECTION_MASKED"); TCP2_Utils.ShaderVariantUpdate("Reflection", ShaderVariants, ShaderVariantsEnabled, reflection, ref updateVariant); reflection |= TCP2_Utils.ShaderKeywordRadio("REFLECTION", new string[]{"TCP2_REFLECTION_OFF","TCP2_REFLECTION","TCP2_REFLECTION_MASKED"}, new GUIContent[] { new GUIContent("Off", "No Cubemap Reflection"), new GUIContent("Global", "Global Cubemap Reflection"), new GUIContent("Masked", "Masked Cubemap Reflection (using the main texture's alpha channel)") }, keywordsList, ref updateKeywords); if( reflection ) { #if UNITY_5 //Reflection Probes toggle if( TCP2_Utils.ShaderKeywordToggle("TCP2_U5_REFLPROBE", "Use Reflection Probes", "Use Unity 5's Reflection Probes", keywordsList, ref updateKeywords) ) { ShowFilteredProperties("#REFL_U5#", props); } #endif ShowFilteredProperties("#REFL#", props); } } TCP2_GUI.Separator(); } //MATCAP ----------------------------------------------------------------------------- if(CategoryFilter("MATCAP")) { if(isGeneratedShader) { TCP2_GUI.Header("MATCAP"); ShowFilteredProperties("#MC#", props); TCP2_GUI.Separator(); } else if(isMobileShader) { bool matcap = TCP2_Utils.HasKeywords(keywordsList, "TCP2_MC", "TCP2_MCMASK"); TCP2_Utils.ShaderVariantUpdate("Matcap", ShaderVariants, ShaderVariantsEnabled, matcap, ref updateVariant); matcap |= TCP2_Utils.ShaderKeywordRadio("MATCAP", new string[]{"TCP2_MC_OFF","TCP2_MC","TCP2_MCMASK"}, new GUIContent[] { new GUIContent("Off", "No MatCap reflection"), new GUIContent("Global", "Global additive MatCap"), new GUIContent("Masked", "Masked additive MatCap (using the main texture's alpha channel)") }, keywordsList, ref updateKeywords); if( matcap ) { ShowFilteredProperties("#MC#", props); } TCP2_GUI.Separator(); } } //RIM -------------------------------------------------------------------------------- if(CategoryFilter("RIM", "RIM_OUTLINE")) { if(isGeneratedShader) { TCP2_GUI.HeaderAndHelp("RIM", "Rim"); ShowFilteredProperties("#RIM#", props); if(HasFlags("RIMDIR")) { ShowFilteredProperties("#RIMDIR#", props); if(HasFlags("PARALLAX")) { EditorGUILayout.HelpBox("Because it affects the view direction vector, Rim Direction may distort Parallax effect.", MessageType.Warning); } } } else { bool rim = TCP2_Utils.HasKeywords(keywordsList, "TCP2_RIM"); bool rimOutline = TCP2_Utils.HasKeywords(keywordsList, "TCP2_RIMO"); TCP2_Utils.ShaderVariantUpdate("Rim", ShaderVariants, ShaderVariantsEnabled, rim, ref updateVariant); TCP2_Utils.ShaderVariantUpdate("RimOutline", ShaderVariants, ShaderVariantsEnabled, rimOutline, ref updateVariant); rim |= rimOutline |= TCP2_Utils.ShaderKeywordRadio("RIM", new string[]{"TCP2_RIM_OFF","TCP2_RIM","TCP2_RIMO"}, new GUIContent[] { new GUIContent("Off", "No Rim effect"), new GUIContent("Lighting", "Rim lighting (additive)"), new GUIContent("Outline", "Rim outline (blended)") }, keywordsList, ref updateKeywords); if( rim || rimOutline ) { ShowFilteredProperties("#RIM#", props); if(CategoryFilter("RIMDIR")) { if( TCP2_Utils.ShaderKeywordToggle("TCP2_RIMDIR", "Directional Rim", "Enable directional rim control (rim calculation is approximated if enabled)", keywordsList, ref updateKeywords) ) { ShowFilteredProperties("#RIMDIR#", props); } } } } TCP2_GUI.Separator(); } //CUBEMAP AMBIENT -------------------------------------------------------------------- if(CategoryFilter("CUBE_AMBIENT") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("CUBEMAP AMBIENT", "Cubemap Ambient"); ShowFilteredProperties("#CUBEAMB#", props); TCP2_GUI.Separator(); } //DIRECTIONAL AMBIENT -------------------------------------------------------------------- if(CategoryFilter("DIRAMBIENT") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("DIRECTIONAL AMBIENT", "Directional Ambient"); //TODO Special Inspector for DirAmb DirectionalAmbientGUI("#DAMB#", props); // ShowFilteredProperties("#DAMB#", props); TCP2_GUI.Separator(); } //SKETCH -------------------------------------------------------------------------------- if(CategoryFilter("SKETCH", "SKETCH_GRADIENT") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("SKETCH", "Sketch"); bool sketch = HasFlags("SKETCH"); bool sketchG = HasFlags("SKETCH_GRADIENT"); if(sketch || sketchG) ShowFilteredProperties("#SKETCH#", props); if(sketchG) ShowFilteredProperties("#SKETCHG#", props); TCP2_GUI.Separator(); } //OUTLINE -------------------------------------------------------------------------------- if(CategoryFilter("OUTLINE", "OUTLINE_BLENDING")) { bool hasOutlineOpaque = false; bool hasOutlineBlending = false; bool hasOutline = false; if(isGeneratedShader) { TCP2_GUI.HeaderAndHelp("OUTLINE", "Outline"); hasOutlineOpaque = HasFlags("OUTLINE"); hasOutlineBlending = HasFlags("OUTLINE_BLENDING"); hasOutline = hasOutlineOpaque || hasOutlineBlending; } else { hasOutlineOpaque = TCP2_Utils.HasKeywords(keywordsList, "OUTLINES"); hasOutlineBlending = TCP2_Utils.HasKeywords(keywordsList, "OUTLINE_BLENDING"); hasOutline = hasOutlineOpaque || hasOutlineBlending; TCP2_Utils.ShaderVariantUpdate("Outline", ShaderVariants, ShaderVariantsEnabled, hasOutlineOpaque, ref updateVariant); TCP2_Utils.ShaderVariantUpdate("OutlineBlending", ShaderVariants, ShaderVariantsEnabled, hasOutlineBlending, ref updateVariant); hasOutline |= TCP2_Utils.ShaderKeywordRadio("OUTLINE", new string[]{"OUTLINE_OFF","OUTLINES","OUTLINE_BLENDING"}, new GUIContent[] { new GUIContent("Off", "No Outline"), new GUIContent("Opaque", "Opaque Outline"), new GUIContent("Blended", "Allows transparent Outline and other effects") }, keywordsList, ref updateKeywords); } if( hasOutline ) { EditorGUI.indentLevel++; //Outline Type --------------------------------------------------------------------------- ShowFilteredProperties("#OUTLINE#", props, false); if(!isMobileShader) { bool outlineTextured = TCP2_Utils.ShaderKeywordToggle("TCP2_OUTLINE_TEXTURED", "Outline Color from Texture", "If enabled, outline will take an averaged color from the main texture multiplied by Outline Color", keywordsList, ref updateKeywords); if(outlineTextured) { ShowFilteredProperties("#OUTLINETEX#", props); } } TCP2_Utils.ShaderKeywordToggle("TCP2_OUTLINE_CONST_SIZE", "Constant Size Outline", "If enabled, outline will have a constant size independently from camera distance", keywordsList, ref updateKeywords); if( TCP2_Utils.ShaderKeywordToggle("TCP2_ZSMOOTH_ON", "Correct Z Artefacts", "Enable the outline z-correction to try to hide artefacts from complex models", keywordsList, ref updateKeywords) ) { ShowFilteredProperties("#OUTLINEZ#", props); } //Smoothed Normals ----------------------------------------------------------------------- EditorGUI.indentLevel--; TCP2_GUI.Header("OUTLINE NORMALS", "Defines where to take the vertex normals from to draw the outline.\nChange this when using a smoothed mesh to fill the gaps shown in hard-edged meshes."); EditorGUI.indentLevel++; TCP2_Utils.ShaderKeywordRadio(null, new string[]{"TCP2_NONE", "TCP2_COLORS_AS_NORMALS", "TCP2_TANGENT_AS_NORMALS", "TCP2_UV2_AS_NORMALS"}, new GUIContent[] { new GUIContent("Regular", "Use regular vertex normals"), new GUIContent("Vertex Colors", "Use vertex colors as normals (with smoothed mesh)"), new GUIContent("Tangents", "Use tangents as normals (with smoothed mesh)"), new GUIContent("UV2", "Use second texture coordinates as normals (with smoothed mesh)"), }, keywordsList, ref updateKeywords); EditorGUI.indentLevel--; //Outline Blending ----------------------------------------------------------------------- if(hasOutlineBlending) { MaterialProperty[] blendProps = GetFilteredProperties("#BLEND#", props); if(blendProps.Length != 2) { EditorGUILayout.HelpBox("Couldn't find Blending properties!", MessageType.Error); } else { TCP2_GUI.Header("OUTLINE BLENDING", "BLENDING EXAMPLES:\nAlpha Transparency: SrcAlpha / OneMinusSrcAlpha\nMultiply: DstColor / Zero\nAdd: One / One\nSoft Add: OneMinusDstColor / One"); UnityEngine.Rendering.BlendMode blendSrc = (UnityEngine.Rendering.BlendMode)blendProps[0].floatValue; UnityEngine.Rendering.BlendMode blendDst = (UnityEngine.Rendering.BlendMode)blendProps[1].floatValue; EditorGUI.BeginChangeCheck(); float f = EditorGUIUtility.fieldWidth; float l = EditorGUIUtility.labelWidth; EditorGUIUtility.fieldWidth = 110f; EditorGUIUtility.labelWidth -= Mathf.Abs(f - EditorGUIUtility.fieldWidth); blendSrc = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Source Factor", blendSrc); blendDst = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Destination Factor", blendDst); EditorGUIUtility.fieldWidth = f; EditorGUIUtility.labelWidth = l; if(EditorGUI.EndChangeCheck()) { blendProps[0].floatValue = (float)blendSrc; blendProps[1].floatValue = (float)blendDst; } } } } TCP2_GUI.Separator(); } //LIGHTMAP -------------------------------------------------------------------------------- if(CategoryFilter("LIGHTMAP") && !isGeneratedShader) { TCP2_Utils.ShaderKeywordRadio("LIGHTMAP", new string[]{"TCP2_LIGHTMAP_OFF","TCP2_LIGHTMAP"}, new GUIContent[]{ new GUIContent("Unity", "Use Unity's built-in lightmap decoding"), new GUIContent("Toony Colors Pro 2", "Use TCP2's lightmap decoding (lightmaps will be affected by ramp and color settings)") }, keywordsList, ref updateKeywords); } //TRANSPARENCY -------------------------------------------------------------------------------- if(CategoryFilter("ALPHA", "CUTOUT") && isGeneratedShader) { bool alpha = false; bool cutout = false; if(isGeneratedShader) { TCP2_GUI.Header("TRANSPARENCY"); alpha = HasFlags("ALPHA"); cutout = HasFlags("CUTOUT"); } if( alpha ) { MaterialProperty[] blendProps = GetFilteredProperties("#ALPHA#", props); if(blendProps.Length != 2) { EditorGUILayout.HelpBox("Couldn't find Blending properties!", MessageType.Error); } else { TCP2_GUI.Header("BLENDING", "BLENDING EXAMPLES:\nAlpha Transparency: SrcAlpha / OneMinusSrcAlpha\nMultiply: DstColor / Zero\nAdd: One / One\nSoft Add: OneMinusDstColor / One"); UnityEngine.Rendering.BlendMode blendSrc = (UnityEngine.Rendering.BlendMode)blendProps[0].floatValue; UnityEngine.Rendering.BlendMode blendDst = (UnityEngine.Rendering.BlendMode)blendProps[1].floatValue; EditorGUI.BeginChangeCheck(); float f = EditorGUIUtility.fieldWidth; float l = EditorGUIUtility.labelWidth; EditorGUIUtility.fieldWidth = 110f; EditorGUIUtility.labelWidth -= Mathf.Abs(f - EditorGUIUtility.fieldWidth); blendSrc = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Source Factor", blendSrc); blendDst = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Destination Factor", blendDst); EditorGUIUtility.fieldWidth = f; EditorGUIUtility.labelWidth = l; if(EditorGUI.EndChangeCheck()) { blendProps[0].floatValue = (float)blendSrc; blendProps[1].floatValue = (float)blendDst; } } } if( cutout ) { ShowFilteredProperties("#CUTOUT#", props); } } #if DEBUG_INFO //-------------------------------------------------------------------------------------- //DEBUG -------------------------------------------------------------------------------- TCP2_GUI.SeparatorBig(); TCP2_GUI.Header("DEBUG"); //Clear Keywords if(GUILayout.Button("Clear Keywords", EditorStyles.miniButton)) { keywordsList.Clear(); updateKeywords = true; } //Shader Flags GUILayout.Label("Features", EditorStyles.boldLabel); string features = ""; if(mShaderFeatures != null) { foreach(string flag in mShaderFeatures) { features += flag + ", "; } } if(features.Length > 0) features = features.Substring(0, features.Length-2); GUILayout.Label(features, EditorStyles.wordWrappedMiniLabel); //Shader Keywords GUILayout.Label("Keywords", EditorStyles.boldLabel); string keywords = ""; foreach(string keyword in keywordsList) { keywords += keyword + ", "; } if(keywords.Length > 0) keywords = keywords.Substring(0, keywords.Length-2); GUILayout.Label(keywords, EditorStyles.wordWrappedMiniLabel); #endif //-------------------------------------------------------------------------------------- if(EditorGUI.EndChangeCheck()) { materialEditor.PropertiesChanged(); } } //Update Keywords if(updateKeywords) { if(materialEditor.targets != null && materialEditor.targets.Length > 0) { foreach(Object t in materialEditor.targets) { (t as Material).shaderKeywords = keywordsList.ToArray(); EditorUtility.SetDirty(t); } } else { targetMaterial.shaderKeywords = keywordsList.ToArray(); EditorUtility.SetDirty(targetMaterial); } } //Update Variant if(updateVariant && !isGeneratedShader) { string baseName = isMobileShader ? BASE_SHADER_NAME_MOB : BASE_SHADER_NAME; string newShader = baseName; for(int i = 0; i < ShaderVariants.Count; i++) { if(ShaderVariantsEnabled[i]) { newShader += " " + ShaderVariants[i]; } } newShader = newShader.TrimEnd(); //If variant shader string basePath = BASE_SHADER_PATH; if(newShader != baseName) { basePath = VARIANT_SHADER_PATH; } Shader shader = Shader.Find(basePath + newShader); if(shader != null) { SerializedProperty serializedKeywords = materialEditor.serializedObject.FindProperty("m_Shader"); serializedKeywords.objectReferenceValue = shader; materialEditor.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(targetMaterial); mJustChangedShader = true; } else { if(Event.current.type != EventType.Layout) { mVariantError = "Can't find shader variant:\n" + basePath + newShader; } materialEditor.Repaint(); } } else if(!string.IsNullOrEmpty(mVariantError) && Event.current.type != EventType.Layout) { mVariantError = null; materialEditor.Repaint(); } #endif }
void DrawReflectionControls(MaterialEditor materialEditor, Object[] materials, MaterialProperty _CubeTex) { int numReflective = 0; foreach (Material m in materials) { bool cr = m.GetShaderPassEnabled(Passes.MIXED_REFLECTIVE) || m.GetShaderPassEnabled(Passes.DYNAMIC_REFLECTIVE); if (cr) { numReflective++; } } bool cubeReflections = numReflective > 0; bool hasMixed = cubeReflections && numReflective < materials.Length; EditorGUI.showMixedValue = hasMixed; EditorGUI.BeginChangeCheck(); { cubeReflections = EditorGUILayout.Toggle("Cube Reflections", cubeReflections); } if (EditorGUI.EndChangeCheck()) { // The reason why we disable both Reflective Passes here is that // we can't be sure whether or not a given object will be baked or not. // That is actually handled by the Renderer itself, as it will receive the // renderingLayerMask used to enabled mixed vs. dynamic lighting. // Considering a Material could be shared across static/non-static geometry // this should prove to be more efficient than a variant. if (cubeReflections) { // enable reflective passes EnablePass(materials, Passes.MIXED_REFLECTIVE); EnablePass(materials, Passes.DYNAMIC_REFLECTIVE); } else { // disable reflective passes DisablePass(materials, Passes.MIXED_REFLECTIVE); DisablePass(materials, Passes.DYNAMIC_REFLECTIVE); } } // If we have cube reflections enabled, draw control for override if (cubeReflections || hasMixed) { EditorGUI.showMixedValue = _CubeTex.hasMixedValue; EditorGUI.BeginChangeCheck(); { materialEditor.ShaderProperty(_CubeTex, "Local Cubemap"); } if (EditorGUI.EndChangeCheck()) { if (_CubeTex.textureValue != null) { EnableKeyword(materials, Keywords.OVERRIDE_LOCAL_CUBEMAP); } else { DisableKeyword(materials, Keywords.OVERRIDE_LOCAL_CUBEMAP); } } } EditorGUI.showMixedValue = false; }