static void SetMaterialKeywords(Material material) { // Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation // (MaterialProperty value might come from renderer material property block) int workflow = material.GetInt("_Workflow"); int samplingMode = material.GetInt("_SamplingMode"); int blendModeEnum = material.GetInt("_BlendMode"); MGUI.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap") || material.GetTexture("_DetailNormalMap")); MGUI.SetKeyword(material, "_WORKFLOW_PACKED_ON", workflow == 1); MGUI.SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap")); MGUI.SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap")); MGUI.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap")); MGUI.SetKeyword(material, "_REFLECTION_FALLBACK_ON", material.GetTexture("_ReflCube")); MGUI.SetKeyword(material, "_REFLECTION_OVERRIDE_ON", material.GetTexture("_ReflCubeOverride")); MGUI.SetKeyword(material, "_SCREENSPACE_REFLECTIONS_ON", material.GetInt("_SSR") == 1); MGUI.SetKeyword(material, "_SPECULARHIGHLIGHTS_OFF", material.GetInt("_SpecularHighlights") == 0); MGUI.SetKeyword(material, "_GLOSSYREFLECTIONS_OFF", material.GetInt("_GlossyReflections") == 0); MGUI.SetKeyword(material, "_STOCHASTIC_ON", samplingMode == 1); MGUI.SetKeyword(material, "_TSS_ON", samplingMode == 2); MGUI.SetKeyword(material, "_TRIPLANAR_ON", samplingMode == 3); MGUI.SetKeyword(material, "_DECAL_ON", samplingMode == 4); MGUI.SetKeyword(material, "_DETAIL_ROUGH_ON", material.GetTexture("_DetailRoughnessMap")); MGUI.SetKeyword(material, "_DETAIL_AO_ON", material.GetTexture("_DetailAOMap")); MGUI.SetKeyword(material, "_SUBSURFACE_ON", material.GetInt("_Subsurface") == 1); MGUI.SetKeyword(material, "_AUDIOLINK_ON", material.GetInt("_AudioLinkEmission") > 0); MGUI.SetKeyword(material, "_DETAIL_SAMPLEMODE_ON", material.GetInt("_DetailSamplingMode") == 1); MGUI.SetKeyword(material, "_ALPHAMASK_ON", blendModeEnum > 0 && material.GetInt("_UseAlphaMask") == 1); MGUI.SetKeyword(material, "_BICUBIC_SAMPLING_ON", material.GetInt("_BicubicLightmap") == 1); MGUI.SetKeyword(material, "BAKERY_SH", material.GetInt("_BakeryMode") == 1); MGUI.SetKeyword(material, "BAKERY_RNM", material.GetInt("_BakeryMode") == 2); MGUI.SetKeyword(material, "_FILTERING_ON", material.GetInt("_Filtering") == 1); if (samplingMode < 3) { if (!material.GetTexture("_PackedMap")) { MGUI.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap")); } else { MGUI.SetKeyword(material, "_PARALLAXMAP", material.GetInt("_UseHeight") == 1); } } else { MGUI.SetKeyword(material, "_PARALLAXMAP", false); } // 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); bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0; MGUI.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled); material.SetShaderPassEnabled("Always", material.GetInt("_SSR") == 1); }
void ApplyMaterialSettings(Material mat) { bool ssrToggle = mat.GetInt("_SSR") == 1; int vertMode = mat.GetInt("_VertOffsetMode"); int reflMode = mat.GetInt("_Reflections"); int specMode = mat.GetInt("_Specular"); int foamToggle = mat.GetInt("_FoamToggle"); int foamNormalToggle = mat.GetInt("_FoamNormalToggle"); bool foamNormals = foamToggle == 1 && foamNormalToggle == 1; MGUI.SetKeyword(mat, "_REFLECTIONS_ON", reflMode > 0); MGUI.SetKeyword(mat, "_REFLECTIONS_MANUAL_ON", reflMode == 2); MGUI.SetKeyword(mat, "_SPECULAR_ON", specMode > 0); MGUI.SetKeyword(mat, "_SCREENSPACE_REFLECTIONS_ON", ssrToggle); MGUI.SetKeyword(mat, "_VERTEX_OFFSET_ON", vertMode == 1); MGUI.SetKeyword(mat, "_GERSTNER_WAVES_ON", vertMode == 2); MGUI.SetKeyword(mat, "_FOAM_NORMALS_ON", foamNormals); }
void ApplyMaterialSettings(Material mat) { bool softening = mat.GetInt("_Softening") == 1; bool distortion = mat.GetInt("_Distortion") == 1; bool distortUV = mat.GetInt("_DistortMainTex") == 1 && distortion; bool layering = mat.GetTexture("_SecondTex"); bool pulse = mat.GetInt("_Pulse") == 1; bool falloff = mat.GetInt("_Falloff") == 1; bool flipbook = mat.GetInt("_FlipbookBlending") == 1; bool cutout = mat.GetInt("_IsCutout") == 1; bool filtering = mat.GetInt("_Filtering") == 1; MGUI.SetKeyword(mat, "_ALPHATEST_ON", cutout); MGUI.SetKeyword(mat, "_FADING_ON", softening); MGUI.SetKeyword(mat, "_DISTORTION_ON", distortion); MGUI.SetKeyword(mat, "_DISTORTION_UV_ON", distortUV); MGUI.SetKeyword(mat, "_LAYERED_TEX_ON", layering); MGUI.SetKeyword(mat, "_PULSE_ON", pulse); MGUI.SetKeyword(mat, "_FALLOFF_ON", falloff); MGUI.SetKeyword(mat, "_FLIPBOOK_BLENDING_ON", flipbook); MGUI.SetKeyword(mat, "_FILTERING_ON", filtering); mat.SetShaderPassEnabled("Always", distortion); SetBlendMode(mat); }
public override void OnGUI(MaterialEditor me, MaterialProperty[] props) { Material material = (Material)me.target; isTransparent = material.shader.name.Contains("(Transparent)"); foreach (var property in GetType().GetFields(bindingFlags)) { if (property.FieldType == typeof(MaterialProperty)) { property.SetValue(this, FindProperty(property.Name, props)); } } EditorGUI.BeginChangeCheck(); { MGUI.BoldLabel("Image"); MGUI.Space2(); if (_FlipbookMode.floatValue == 0) { me.TexturePropertySingleLine(mainTex, _MainTex, _FlipbookMode); MGUI.TexPropLabel("Flipbook", 105); me.ShaderProperty(_Color, "Color"); if (_MainTex.textureValue) { MGUI.TextureSOScroll(me, _MainTex, _UVScroll); MGUI.Space6(); } } else { me.TexturePropertySingleLine(flipbookTex, _Flipbook, _FlipbookMode); MGUI.TexPropLabel("Flipbook", 105); if (_Flipbook.textureValue) { MGUI.TextureSO(me, _MainTex); MGUI.SpaceN2(); me.ShaderProperty(_FPS, "FPS"); MGUI.Space6(); } } MGUI.SetKeyword(material, "_FLIPBOOK_MODE", material.GetInt("_FlipbookMode") == 1); me.TexturePropertySingleLine(smoothTex, _SpecGlossMap, _Glossiness); MGUI.TextureSO(me, _SpecGlossMap, _SpecGlossMap.textureValue); MGUI.SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap")); MGUI.Space4(); MGUI.SetKeyword(material, "_EMISSION", true); me.ShaderProperty(_EmissionIntensity, "Emission Strength"); me.ShaderProperty(_LightmapEmissionScale, "Lightmap Emission Strength"); me.ShaderProperty(_BoostAmount, "Boost Multiplier"); me.ShaderProperty(_BoostThreshold, "Boost Threshold"); material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive; MGUI.Space4(); MGUI.BoldLabel("Panel"); MGUI.Space2(); me.TexturePropertySingleLine(RGBMatrixTex, _RGBSubPixelTex); MGUI.TextureSO(me, _RGBSubPixelTex, _RGBSubPixelTex.textureValue); me.ShaderProperty(_Backlight, "Backlit"); MGUI.Space4(); MGUI.BoldLabel("Render Settings"); if (isTransparent) { me.ShaderProperty(_ZWrite, "ZWrite"); } me.RenderQueueField(); MGUI.Space8(); } MGUI.Space20(); float buttonSize = 35f; Rect footerRect = EditorGUILayout.GetControlRect(); footerRect.x += (MGUI.GetInspectorWidth() / 2f) - buttonSize - 5f; footerRect.width = buttonSize; footerRect.height = buttonSize; if (GUI.Button(footerRect, MGUI.patIconTex)) { Application.OpenURL("https://www.patreon.com/mochieshaders"); } footerRect.x += buttonSize + 5f; footerRect.y += 17f; GUIStyle formatting = new GUIStyle(); formatting.fontSize = 15; formatting.fontStyle = FontStyle.Bold; if (EditorGUIUtility.isProSkin) { formatting.normal.textColor = new Color(0.8f, 0.8f, 0.8f, 1); formatting.hover.textColor = new Color(0.8f, 0.8f, 0.8f, 1); GUI.Label(footerRect, versionLabel, formatting); footerRect.y += 20f; footerRect.x -= 35f; footerRect.width = 70f; footerRect.height = 70f; GUI.Label(footerRect, MGUI.mochieLogoPro); GUILayout.Space(90); } else { GUI.Label(footerRect, versionLabel, formatting); footerRect.y += 20f; footerRect.x -= 35f; footerRect.width = 70f; footerRect.height = 70f; GUI.Label(footerRect, MGUI.mochieLogo); GUILayout.Space(90); } }