protected void OtherSettingsGUI(bool showMotionVectors, bool showSkinnedMotionVectors = false, bool showSortingLayerFields = false) { m_ShowOtherSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowOtherSettings.value, Styles.otherSettings); if (m_ShowOtherSettings.value) { EditorGUI.indentLevel++; if (SupportedRenderingFeatures.active.motionVectors) { if (showMotionVectors) { EditorGUILayout.PropertyField(m_MotionVectors, Styles.motionVectors, true); } else if (showSkinnedMotionVectors) { EditorGUILayout.PropertyField(m_SkinnedMotionVectors, Styles.skinnedMotionVectors, true); } } EditorGUILayout.PropertyField(m_DynamicOccludee, Styles.dynamicOcclusion); if (showSortingLayerFields) { SortingLayerEditorUtility.RenderSortingLayerFields(m_SortingOrder, m_SortingLayerID); } DrawRenderingLayer(); DrawRendererPriority(m_RendererPriority); EditorGUI.indentLevel--; } EditorGUILayout.EndFoldoutHeaderGroup(); }
public void RenderTerrainSettings() { if (m_SerializedObject == null || m_GameObjectsSerializedObject == null || m_GameObjectsSerializedObject.targetObjectsCount == 0) { return; } m_GameObjectsSerializedObject.Update(); var settings = Lightmapping.GetLightingSettingsOrDefaultsFallback(); bool bakedGI = settings.bakedGI; bool realtimeGI = settings.realtimeGI; bool contributeGI = (m_StaticEditorFlags.intValue & (int)StaticEditorFlags.ContributeGI) != 0; m_ShowLightingSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowLightingSettings.value, Styles.lightingSettings); if (m_ShowLightingSettings.value) { EditorGUI.indentLevel += 1; contributeGI = ContributeGISettings(); if (!(bakedGI || realtimeGI) && !isPrefabAsset && contributeGI) { EditorGUILayout.HelpBox(Styles.giNotEnabledInfo.text, MessageType.Info); EditorGUI.indentLevel -= 1; return; } using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.IntPopup(Styles.receiveGITitle, 1, Styles.receiveGILightmapStrings, Styles.receiveGILightmapValues); } EditorGUI.indentLevel -= 1; } EditorGUILayout.EndFoldoutHeaderGroup(); EditorGUILayout.Space(); if (contributeGI) { m_ShowLightmapSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowLightmapSettings.value, Styles.lightmapSettings); if (m_ShowLightmapSettings.value) { EditorGUI.indentLevel += 1; if (GUI.enabled) { ShowTerrainChunks(m_Terrains); } LightmapScaleGUI(false, Styles.scaleInLightmap, false); LightmapParametersGUI(m_LightmapParameters, Styles.lightmapParameters); if ((m_Terrains != null) && (m_Terrains.Length > 0)) { if (GUI.enabled && m_Terrains.Length == 1 && m_Terrains[0].terrainData != null) { ShowBakePerformanceWarning(m_Terrains[0]); } ShowAtlasGUI(m_Terrains[0].GetInstanceID(), false); ShowRealtimeLMGUI(m_Terrains[0]); } EditorGUI.indentLevel -= 1; } EditorGUILayout.EndFoldoutHeaderGroup(); GUILayout.Space(10); } }
public void RenderSettings(bool showLightmapSettings) { if (m_SerializedObject == null || m_GameObjectsSerializedObject == null || m_GameObjectsSerializedObject.targetObjectsCount == 0) { return; } var settings = Lightmapping.GetLightingSettingsOrDefaultsFallback(); var lightmapper = settings.lightmapper; bool bakedGI = settings.bakedGI; bool realtimeGI = settings.realtimeGI; m_GameObjectsSerializedObject.Update(); ReceiveGI receiveGI = (ReceiveGI)m_ReceiveGI.intValue; bool contributeGI = (m_StaticEditorFlags.intValue & (int)StaticEditorFlags.ContributeGI) != 0; bool showEnlightenSettings = isPrefabAsset || realtimeGI || (bakedGI && lightmapper == LightingSettings.Lightmapper.Enlighten); // m_ReceiveGI might still be set to Lightmaps, but LightProbes is shown in the inspector since the contributeGI if off. // In this case we still have to mark it as "multiple values" even though both have "Lightmaps" as the value, but one is showing a grayed out "Light Probes" in the UI bool showMixedGIValue = m_ReceiveGI.hasMultipleDifferentValues || ((m_StaticEditorFlags.hasMultipleDifferentValuesBitwise & (int)StaticEditorFlags.ContributeGI) != 0); m_ShowLightingSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowLightingSettings.value, Styles.lightingSettings); if (m_ShowLightingSettings.value) { EditorGUI.indentLevel += 1; EditorGUILayout.PropertyField(m_CastShadows, Styles.castShadows, true); bool isDeferredRenderingPath = SceneView.IsUsingDeferredRenderingPath(); if (SupportedRenderingFeatures.active.receiveShadows) { using (new EditorGUI.DisabledScope(isDeferredRenderingPath)) EditorGUILayout.PropertyField(m_ReceiveShadows, Styles.receiveShadows, true); } if (!showLightmapSettings) { EditorGUI.indentLevel -= 1; EditorGUILayout.EndFoldoutHeaderGroup(); return; } contributeGI = ContributeGISettings(); if (!(bakedGI || realtimeGI) && !isPrefabAsset && contributeGI) { EditorGUILayout.HelpBox(Styles.giNotEnabledInfo.text, MessageType.Info); EditorGUI.indentLevel -= 1; EditorGUILayout.EndFoldoutHeaderGroup(); return; } if (contributeGI) { var rect = EditorGUILayout.GetControlRect(); EditorGUI.BeginProperty(rect, Styles.receiveGITitle, m_ReceiveGI); EditorGUI.BeginChangeCheck(); receiveGI = (ReceiveGI)EditorGUI.IntPopup(rect, Styles.receiveGITitle, (int)receiveGI, Styles.receiveGILightmapStrings, Styles.receiveGILightmapValues); if (EditorGUI.EndChangeCheck()) { m_ReceiveGI.intValue = (int)receiveGI; } EditorGUI.EndProperty(); if (showEnlightenSettings) { EditorGUILayout.PropertyField(m_ImportantGI, Styles.importantGI); } if (receiveGI == ReceiveGI.LightProbes && !showMixedGIValue) { LightmapScaleGUI(true, Styles.albedoScale, true); } } else { using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = showMixedGIValue; receiveGI = (ReceiveGI)EditorGUILayout.IntPopup(Styles.receiveGITitle, (int)ReceiveGI.LightProbes, Styles.receiveGILightmapStrings, Styles.receiveGILightmapValues); EditorGUI.showMixedValue = false; } } EditorGUI.indentLevel -= 1; } EditorGUILayout.EndFoldoutHeaderGroup(); if (showLightmapSettings && contributeGI && receiveGI == ReceiveGI.Lightmaps && !showMixedGIValue) { m_ShowLightmapSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowLightmapSettings.value, Styles.lightmapSettings); if (m_ShowLightmapSettings.value) { EditorGUI.indentLevel += 1; bool showProgressiveSettings = isPrefabAsset || (bakedGI && lightmapper != LightingSettings.Lightmapper.Enlighten); LightmapScaleGUI(true, Styles.scaleInLightmap, false); if (showProgressiveSettings) { EditorGUILayout.PropertyField(m_StitchLightmapSeams, Styles.stitchLightmapSeams); } LightmapParametersGUI(m_LightmapParameters, Styles.lightmapParameters); if (showEnlightenSettings) { RendererUVSettings(); } if ((m_Renderers != null) && (m_Renderers.Length > 0)) { ShowAtlasGUI(m_Renderers[0].GetInstanceID(), true); ShowRealtimeLMGUI(m_Renderers[0]); if (Lightmapping.HasZeroAreaMesh(m_Renderers[0])) { EditorGUILayout.HelpBox(Styles.zeroAreaPackingMesh.text, MessageType.Warning); } DisplayMeshWarning(); if (showEnlightenSettings) { if (Lightmapping.HasClampedResolution(m_Renderers[0])) { EditorGUILayout.HelpBox(Styles.clampedPackingResolution.text, MessageType.Warning); } } if (showProgressiveSettings) { if (Lightmapping.HasUVOverlaps(m_Renderers[0])) { EditorGUILayout.HelpBox(Styles.uvOverlap.text, MessageType.Warning); } } } EditorGUI.indentLevel -= 1; } EditorGUILayout.EndFoldoutHeaderGroup(); } }
public override void OnInspectorGUI() { serializedObject.Update(); if (targets.Length == 1) { DoToolbar(); } m_ShowProbeModeRealtimeOptions.target = reflectionProbeMode == ReflectionProbeMode.Realtime; m_ShowProbeModeCustomOptions.target = reflectionProbeMode == ReflectionProbeMode.Custom; // Bake/custom/realtime type EditorGUILayout.IntPopup(m_Mode, Styles.reflectionProbeMode, Styles.reflectionProbeModeValues, Styles.typeText); // We cannot show multiple different type controls if (!m_Mode.hasMultipleDifferentValues) { EditorGUI.indentLevel++; { // Custom cubemap UI (Bake button and manual cubemap assignment) if (EditorGUILayout.BeginFadeGroup(m_ShowProbeModeCustomOptions.faded)) { EditorGUILayout.PropertyField(m_RenderDynamicObjects, Styles.renderDynamicObjects); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = m_CustomBakedTexture.hasMultipleDifferentValues; var newCubemap = EditorGUILayout.ObjectField(Styles.customCubemapText, m_CustomBakedTexture.objectReferenceValue, typeof(Texture), false); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { m_CustomBakedTexture.objectReferenceValue = newCubemap; } } EditorGUILayout.EndFadeGroup(); // Realtime UI if (EditorGUILayout.BeginFadeGroup(m_ShowProbeModeRealtimeOptions.faded)) { EditorGUILayout.PropertyField(m_RefreshMode, Styles.refreshMode); EditorGUILayout.PropertyField(m_TimeSlicingMode, Styles.timeSlicing); EditorGUILayout.Space(); } EditorGUILayout.EndFadeGroup(); } EditorGUI.indentLevel--; } EditorGUILayout.Space(); m_ShowRuntimeSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowRuntimeSettings.value, Styles.runtimeSettingsHeader); if (m_ShowRuntimeSettings.value) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_Importance, Styles.importanceText); EditorGUILayout.PropertyField(m_IntensityMultiplier, Styles.intensityText); // Only take graphic Tier settings into account when built-in render pipeline is active. if (GraphicsSettings.currentRenderPipeline == null && Rendering.EditorGraphicsSettings.GetCurrentTierSettings().reflectionProbeBoxProjection == false) { using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.Toggle(Styles.boxProjectionText, false); } } else { EditorGUILayout.PropertyField(m_BoxProjection, Styles.boxProjectionText); } bool isDeferredRenderingPath = SceneView.IsUsingDeferredRenderingPath(); bool isDeferredReflections = isDeferredRenderingPath && (UnityEngine.Rendering.GraphicsSettings.GetShaderMode(BuiltinShaderType.DeferredReflections) != BuiltinShaderMode.Disabled); using (new EditorGUI.DisabledScope(!isDeferredReflections && !SupportedRenderingFeatures.active.reflectionProbesBlendDistance)) { EditorGUILayout.PropertyField(m_BlendDistance, Styles.blendDistanceText); } // Bounds editing (box projection bounds + the bounds that objects use to check if they should be affected by this reflection probe) if (EditorGUILayout.BeginFadeGroup(m_ShowBoxOptions.faded)) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_BoxSize, Styles.sizeText); EditorGUILayout.PropertyField(m_BoxOffset, Styles.centerText); if (EditorGUI.EndChangeCheck()) { Vector3 center = m_BoxOffset.vector3Value; Vector3 size = m_BoxSize.vector3Value; if (ValidateAABB(ref center, ref size)) { m_BoxOffset.vector3Value = center; m_BoxSize.vector3Value = size; } } } EditorGUILayout.EndFadeGroup(); EditorGUI.indentLevel--; } EditorGUILayout.EndFoldoutHeaderGroup(); m_ShowCubemapCaptureSettings.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_ShowCubemapCaptureSettings.value, Styles.captureCubemapHeader); if (m_ShowCubemapCaptureSettings.value) { EditorGUI.indentLevel++; int[] reflectionResolutionValuesArray = null; GUIContent[] reflectionResolutionTextArray = null; GetResolutionArray(ref reflectionResolutionValuesArray, ref reflectionResolutionTextArray); EditorGUILayout.IntPopup(m_Resolution, reflectionResolutionTextArray, reflectionResolutionValuesArray, Styles.resolutionText, GUILayout.MinWidth(40)); EditorGUILayout.PropertyField(m_HDR, Styles.hdrText); EditorGUILayout.PropertyField(m_ShadowDistance, Styles.shadowDistanceText); EditorGUILayout.IntPopup(m_ClearFlags, Styles.clearFlags, Styles.clearFlagsValues, Styles.clearFlagsText); EditorGUILayout.PropertyField(m_BackgroundColor, Styles.backgroundColorText); EditorGUILayout.PropertyField(m_CullingMask, Styles.cullingMaskText); EditorGUILayout.PropertyField(m_UseOcclusionCulling, Styles.useOcclusionCulling); EditorGUILayout.PropertiesField(EditorGUI.s_ClipingPlanesLabel, m_NearAndFarProperties, EditorGUI.s_NearAndFarLabels, EditorGUI.kNearFarLabelsWidth); EditorGUI.indentLevel--; } EditorGUILayout.EndFoldoutHeaderGroup(); EditorGUILayout.Space(); if (targets.Length == 1) { ReflectionProbe probe = (ReflectionProbe)target; if (probe.mode == ReflectionProbeMode.Custom && probe.customBakedTexture != null) { Cubemap cubemap = probe.customBakedTexture as Cubemap; if (cubemap && cubemap.mipmapCount == 1) { EditorGUILayout.HelpBox("No mipmaps in the cubemap, Smoothness value in Standard shader will be ignored.", MessageType.Warning); } } } DoBakeButton(); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
private void OnGUI() { if (settings == null) { settings = ConstantGenerator.GetSettingsFile(); } if (logo == null) { logo = ConstantGenerator.GetLogo(); } if (border == null) { border = ConstantGenerator.GetBorder(); } EditorGUI.BeginChangeCheck(); StartGUI("Layers"); if (DrawGenButton()) { LayersGen.Generate(); window.Close(); } if (DrawForceGenButton()) { LayersGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Tags"); if (DrawGenButton()) { TagsGen.Generate(); window.Close(); } if (DrawForceGenButton()) { TagsGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Sort Layers"); if (DrawGenButton()) { SortingLayersGen.Generate(); window.Close(); } if (DrawForceGenButton()) { SortingLayersGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Scenes"); if (DrawGenButton()) { ScenesGen.Generate(); window.Close(); } if (DrawForceGenButton()) { ScenesGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Shader Props"); if (DrawGenButton()) { ShaderPropsGen.Generate(false); window.Close(); } if (DrawForceGenButton()) { ShaderPropsGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Anim Params"); if (DrawGenButton()) { AnimParamsGen.Generate(); window.Close(); } if (DrawForceGenButton()) { AnimParamsGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Anim Layers"); if (DrawGenButton()) { AnimLayersGen.Generate(); window.Close(); } if (DrawForceGenButton()) { AnimLayersGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Anim States"); if (DrawGenButton()) { AnimStatesGen.Generate(); window.Close(); } if (DrawForceGenButton()) { AnimStatesGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Nav Areas"); if (DrawGenButton()) { NavAreasGen.Generate(); window.Close(); } if (DrawForceGenButton()) { NavAreasGen.ForceGenerate(); window.Close(); } EndGUI(); // ========================================================================================= DrawLine(Color.white, 2, 5); GUIStyle style = new GUIStyle(GUI.skin.button); style.alignment = TextAnchor.MiddleCenter; style.fontStyle = FontStyle.Bold; EGL.BeginHorizontal(); EGL.BeginVertical(); EGL.BeginHorizontal(); if (GL.Button("GENERATE ALL", style)) { LayersGen.Generate(); TagsGen.Generate(); SortingLayersGen.Generate(); ScenesGen.Generate(); ShaderPropsGen.Generate(false); AnimParamsGen.Generate(); AnimLayersGen.Generate(); AnimStatesGen.Generate(); window.Close(); } GL.FlexibleSpace(); EGL.EndHorizontal(); EGL.BeginHorizontal(); if (GL.Button("FORCE GENERATE ALL", style)) { LayersGen.ForceGenerate(); TagsGen.ForceGenerate(); SortingLayersGen.ForceGenerate(); ScenesGen.ForceGenerate(); ShaderPropsGen.ForceGenerate(); AnimParamsGen.ForceGenerate(); AnimLayersGen.ForceGenerate(); AnimStatesGen.ForceGenerate(); window.Close(); } GL.FlexibleSpace(); EGL.EndHorizontal(); EGL.EndVertical(); EGL.BeginVertical(); // --------------------------------------------------------------------------------------- Color genOnReloadColor; Color updateOnReloadColor; if (settings.regenerateOnMissing) { genOnReloadColor = Color.green * 2; } else { genOnReloadColor = Color.white * 1.5f; } if (settings.updateOnReload) { updateOnReloadColor = Color.green * 2; } else { updateOnReloadColor = Color.white * 1.5f; } EGL.BeginHorizontal(); GUI.backgroundColor = genOnReloadColor; if (GL.Button(new GUIContent("ReGen On Missing", "Automatically re-generates the constants file is none is present."), style)) { settings.regenerateOnMissing = !settings.regenerateOnMissing; EditorUtility.SetDirty(settings); } EGL.EndHorizontal(); EGL.BeginHorizontal(); GUI.backgroundColor = updateOnReloadColor; if (GL.Button(new GUIContent("Update On Reload", "Automatically re-generates the constants on editor recompile if any changes are detected."), style)) { settings.updateOnReload = !settings.updateOnReload; EditorUtility.SetDirty(settings); } EGL.EndHorizontal(); EGL.EndVertical(); EGL.EndHorizontal(); // ========================================================================================= DrawLine(Color.white, 2, 5); GUI.backgroundColor = Color.gray; GUI.contentColor = Color.white * 10; // check for unity versions using conditional directives // NOTE: there is no "BeginFoldoutHeaderGroup" in below 2019.1 #if UNITY_2019_OR_NEWER showFoldOut = EGL.BeginFoldoutHeaderGroup(showFoldOut, "Create Generator Script"); #else showFoldOut = EGL.Foldout(showFoldOut, "Create Generator Script"); #endif if (showFoldOut) { GL.Space(5); GUI.contentColor = Color.white * 10; generatorName = EGL.TextField("Generator Name", generatorName); outputFileName = EGL.TextField("Output File Name", outputFileName); GL.Space(5); EGL.BeginHorizontal(); if (!settings.regenerateOnMissing) { EGL.BeginVertical(); GL.FlexibleSpace(); EGL.HelpBox("NOTE: Force Generate will only delete the file but will NOT generate a new one if the [ReGen On Missing] is turned off", MessageType.Warning); EGL.EndVertical(); } else { // ============================================================================ // Draw Ma Awesome Logo EGL.BeginVertical(); GL.FlexibleSpace(); Rect horiRect = EGL.BeginHorizontal(); Rect boxRect = new Rect(horiRect.x + 3, horiRect.y - 54, 125, 52); Rect backgroundRect = boxRect; backgroundRect.width = border.width; backgroundRect.height = border.height; GUI.DrawTexture(backgroundRect, border); // GUI.Box( boxRect, iconBackground, ); GUI.Label(new Rect(boxRect.x + 3, boxRect.y + 16, 100, 20), "Created BY: "); Rect logoRect = new Rect(boxRect.x + 76, boxRect.y + 2, logo.width, logo.height); GUI.DrawTexture(logoRect, logo); EGL.EndHorizontal(); EGL.EndVertical(); // ============================================================================ } GL.FlexibleSpace(); GUI.contentColor = Color.white * 5; EGL.BeginVertical(); GL.FlexibleSpace(); GUI.backgroundColor = Color.white * 2.5f; GUI.contentColor = Color.black * 5; if (GL.Button("Create", new GUIStyle(GUI.skin.button) { fontStyle = FontStyle.Bold, fontSize = 12 }, GL.Width(75), GL.Height(30))) { if (generatorName == string.Empty || outputFileName == string.Empty || generatorName == null || outputFileName == null) { Debug.LogWarning("Fill out all the fields"); } else { TemplateGen.GenerateTemplate(generatorName, outputFileName); window.Close(); } } EGL.EndVertical(); GL.Space(1); EGL.EndHorizontal(); } #if UNITY_2019_OR_NEWER EGL.EndFoldoutHeaderGroup(); #endif if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(settings); } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { Material material = materialEditor.target as Material; FindProperties(properties); // Always needed vars bool surfaceModeChanged = false; var workflow = (WorkflowMode)workflowmodeProp.floatValue; var surface = (SurfaceType)surfaceTypeProp.floatValue; bool alphaclipChanged = false; var alphaclip = (alphaClipProp.floatValue == 1)? true : false; // ----------------------- // Help var txt = new GUIContent("Help"); var position = GUILayoutUtility.GetRect(txt, GUIStyle.none); var headerPos = new Rect(position.x + 1, position.y, position.width - 20, 20); var btnPos = new Rect(position.x + headerPos.width, position.y, 20, 20); GUI.Label(headerPos, new GUIContent("Help"), EditorStyles.boldLabel); if (GUI.Button(btnPos, helpbuttonGUIContent, EditorStyles.boldLabel)) { Help.BrowseURL(url); } GUILayout.Space(10); // ----------------------- // Surface Options openSurfaceOptions = (surfaceOptionsProps.floatValue == 1.0f) ? true : false; EditorGUI.BeginChangeCheck(); openSurfaceOptions = EditorGUILayout.BeginFoldoutHeaderGroup(openSurfaceOptions, "Surface Options"); if (EditorGUI.EndChangeCheck()) { surfaceOptionsProps.floatValue = openSurfaceOptions? 1.0f : 0.0f; } if (openSurfaceOptions) { // Workflow EditorGUI.BeginChangeCheck(); //var workflow = (WorkflowMode)workflowmodeProp.floatValue; workflow = (WorkflowMode)EditorGUILayout.EnumPopup("Workflow Mode", workflow); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo("Workflow Mode"); workflowmodeProp.floatValue = (float)workflow; if ((float)workflow == 0.0f) { material.EnableKeyword("_SPECULAR_SETUP"); } else { material.DisableKeyword("_SPECULAR_SETUP"); } } // Surface EditorGUI.BeginChangeCheck(); //var surface = (SurfaceType)surfaceTypeProp.floatValue; surface = (SurfaceType)EditorGUILayout.EnumPopup("Surface Type", surface); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo("Surface Type"); surfaceModeChanged = true; surfaceTypeProp.floatValue = (float)surface; if (surface == SurfaceType.Opaque) { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.SetOverrideTag("RenderType", "Opaque"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry + 50; material.SetShaderPassEnabled("ShadowCaster", true); } else { material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent + 50; // Make it match Standard Lit shader material.SetOverrideTag("RenderType", "Transparent"); material.SetShaderPassEnabled("ShadowCaster", false); } } // Culling EditorGUI.BeginChangeCheck(); var culling = (RenderFace)cullingProp.floatValue; culling = (RenderFace)EditorGUILayout.EnumPopup("Render Face", culling); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo("Cull"); cullingProp.floatValue = (float)culling; material.doubleSidedGI = (RenderFace)cullingProp.floatValue != RenderFace.Front; } // Alpha Clipping // Allow alpha clipping for transparents as well // if (surface == SurfaceType.Opaque) { EditorGUI.BeginChangeCheck(); alphaclip = EditorGUILayout.Toggle(new GUIContent("Alpha Clipping"), alphaClipProp.floatValue == 1); // Make sure we set alpha clip if surface type has changed only as well if (EditorGUI.EndChangeCheck() || surfaceModeChanged) { alphaclipChanged = true; if (alphaclip) { alphaClipProp.floatValue = 1; material.EnableKeyword("_ALPHATEST_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest + 50; material.SetOverrideTag("RenderType", "TransparentCutout"); // We may have to re eanble camera fading if (cameraFadingEnabledProp.floatValue == 1) { material.EnableKeyword("_FADING_ON"); if (cameraFadeShadowsProp.floatValue == 1) { material.EnableKeyword("_FADING_SHADOWS_ON"); } else { material.DisableKeyword("_FADING_SHADOWS_ON"); } } else { material.DisableKeyword("_FADING_ON"); material.DisableKeyword("_FADING_SHADOWS_ON"); } } else { alphaClipProp.floatValue = 0; material.DisableKeyword("_ALPHATEST_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry + 50; material.SetOverrideTag("RenderType", "Opaque"); material.DisableKeyword("_FADING_ON"); material.DisableKeyword("_FADING_SHADOWS_ON"); } } if (alphaclip) { materialEditor.ShaderProperty(alphaCutoffProp, "Threshold", 1); } // } // Camera Fading if (alphaclip) { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(cameraFadingEnabledProp, "Camera Fading", 1); materialEditor.ShaderProperty(cameraFadeDistProp, "Fade Distance", 2); materialEditor.ShaderProperty(cameraFadeShadowsProp, "Fade Shadows", 2); materialEditor.ShaderProperty(cameraShadowFadeDistProp, "Shadow Fade Dist", 2); if (EditorGUI.EndChangeCheck()) { if (cameraFadingEnabledProp.floatValue == 1) { material.EnableKeyword("_FADING_ON"); if (cameraFadeShadowsProp.floatValue == 1) { material.EnableKeyword("_FADING_SHADOWS_ON"); } else { material.DisableKeyword("_FADING_SHADOWS_ON"); } } else { material.DisableKeyword("_FADING_ON"); material.DisableKeyword("_FADING_SHADOWS_ON"); } } } else { material.DisableKeyword("_FADING_ON"); material.DisableKeyword("_FADING_SHADOWS_ON"); } // Shadows EditorGUI.BeginChangeCheck(); var receiveShadows = EditorGUILayout.Toggle(new GUIContent("Receive Shadows"), receiveShadowsProp.floatValue == 1.0f); if (EditorGUI.EndChangeCheck()) { receiveShadowsProp.floatValue = receiveShadows ? 1.0f : 0.0f; if (receiveShadows) { material.DisableKeyword("_RECEIVE_SHADOWS_OFF"); } else { material.EnableKeyword("_RECEIVE_SHADOWS_OFF"); } } // Transparency if (surface == SurfaceType.Transparent) { EditorGUI.BeginChangeCheck(); //DoPopup(Styles.blendingMode, blendModeProp, Enum.GetNames(typeof(BlendMode))); var blendMode = (BlendMode)blendModeProp.floatValue; blendMode = (BlendMode)EditorGUILayout.EnumPopup("Blend Mode", blendMode); // Make sure we set blend mode if surface type has changed only as well if (EditorGUI.EndChangeCheck() || surfaceModeChanged) { blendModeProp.floatValue = (float)blendMode; material.DisableKeyword("_ALPHATEST_ON"); switch (blendMode) { case BlendMode.Alpha: material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); break; case BlendMode.Premultiply: material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); break; case BlendMode.Additive: material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); break; case BlendMode.Multiply: material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_ALPHAMODULATE_ON"); break; } } } // ZTesting EditorGUI.BeginChangeCheck(); var ztest = (UnityEngine.Rendering.CompareFunction)ztestProp.floatValue; ztest = (UnityEngine.Rendering.CompareFunction)EditorGUILayout.EnumPopup("ZTest", ztest); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo("ZTest"); ztestProp.floatValue = (float)ztest; } // Spacing EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); // ----------------------- // Surface Inputs openSurfaceInputs = (surfaceInputsProps.floatValue == 1.0f) ? true : false; EditorGUI.BeginChangeCheck(); openSurfaceInputs = EditorGUILayout.BeginFoldoutHeaderGroup(openSurfaceInputs, "Surface Inputs"); if (EditorGUI.EndChangeCheck()) { surfaceInputsProps.floatValue = openSurfaceInputs? 1.0f : 0.0f; } if (openSurfaceInputs) { EditorGUILayout.Space(); // Basemap / Color materialEditor.TexturePropertySingleLine(new GUIContent("Base Map"), baseMapProp, baseColorProp); // Metallic string[] smoothnessChannelNames; bool hasGlossMap = false; if ((WorkflowMode)workflowmodeProp.floatValue == WorkflowMode.Metallic) { hasGlossMap = metallicGlossMapProp.textureValue != null; smoothnessChannelNames = Styles.metallicSmoothnessChannelNames; EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine(new GUIContent("Metallic Map"), metallicGlossMapProp, hasGlossMap ? null : metallicProp); if (EditorGUI.EndChangeCheck()) { if (metallicGlossMapProp.textureValue != null) { material.EnableKeyword("_METALLICSPECGLOSSMAP"); } else { material.DisableKeyword("_METALLICSPECGLOSSMAP"); } } } // Specular else { hasGlossMap = specGlossMapProp.textureValue != null; smoothnessChannelNames = Styles.specularSmoothnessChannelNames; EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine(new GUIContent("Specular Map"), specGlossMapProp, hasGlossMap ? null : specColorProp); if (EditorGUI.EndChangeCheck()) { if (specGlossMapProp.textureValue != null) { material.EnableKeyword("_METALLICSPECGLOSSMAP"); } else { material.DisableKeyword("_METALLICSPECGLOSSMAP"); } } } // Smoothness EditorGUI.indentLevel++; EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = smoothnessProp.hasMixedValue; var smoothness = EditorGUILayout.Slider("Smoothness", smoothnessProp.floatValue, 0f, 1f); if (EditorGUI.EndChangeCheck()) { smoothnessProp.floatValue = smoothness; } EditorGUI.showMixedValue = false; EditorGUI.indentLevel--; // Chose Smoothness Cannel in case we have any GlossMap //if (hasGlossMap) { EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(surface != SurfaceType.Opaque); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = smoothnessMapChannelProp.hasMixedValue; var smoothnessSource = (int)smoothnessMapChannelProp.floatValue; // This is correct, but it does not allow fading if (surface == SurfaceType.Opaque && !alphaclip) { smoothnessSource = EditorGUILayout.Popup(new GUIContent("Source"), smoothnessSource, smoothnessChannelNames); } else { GUI.enabled = false; EditorGUILayout.Popup(new GUIContent("Source"), 0, smoothnessChannelNames); material.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"); GUI.enabled = true; } // Make sure we set the proper keyword even if only alphaclip has changed as well if (EditorGUI.EndChangeCheck() || alphaclipChanged) { smoothnessMapChannelProp.floatValue = smoothnessSource; if (smoothnessSource == 1) { material.EnableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"); } else { material.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"); } } EditorGUI.showMixedValue = false; EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; //} // We may still sample from Albedo alpha /* else { * // We can not sample smoothness from albedo alpha of the shader is transparent * if (surface == SurfaceType.Opaque && !alphaclip) { * EditorGUI.indentLevel++; * EditorGUI.BeginChangeCheck(); * var smoothnessFromAlbedoAlpha = EditorGUILayout.Toggle(new GUIContent("Source Albedo Alpha"), smoothnessMapChannelProp.floatValue == 1); * if (EditorGUI.EndChangeCheck()) { * if (smoothnessFromAlbedoAlpha) { * smoothnessMapChannelProp.floatValue = 1; * material.EnableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"); * } * else { * smoothnessMapChannelProp.floatValue = 0; * material.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"); * } * } * EditorGUI.indentLevel--; * } * else { * smoothnessMapChannelProp.floatValue = 0; * material.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"); * } * } */ EditorGUI.indentLevel--; // Normal // NOTE: _NORMALMAP is needed by Bent normal as well: see sh lighting. EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine(new GUIContent("Normal Map"), bumpMapProp, bumpMapScaleProp); if (EditorGUI.EndChangeCheck() || bumpMapProp.textureValue == null) { if (bumpMapProp.textureValue != null && bumpMapScaleProp.floatValue != 0.0f) { material.EnableKeyword("_NORMALMAP"); material.EnableKeyword("_SAMPLENORMAL"); enableNormalProp.floatValue = 1.0f; } else { if (BentNormalMapProp.textureValue == null) { material.DisableKeyword("_NORMALMAP"); } material.DisableKeyword("_SAMPLENORMAL"); enableNormalProp.floatValue = 0.0f; } } // Occlusion EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine(new GUIContent("Occlusion Map"), occlusionMapProp, occlusionMapProp.textureValue != null ? occlusionStrengthProp : null); if (EditorGUI.EndChangeCheck()) { if (occlusionMapProp.textureValue != null && occlusionStrengthProp.floatValue > 0) { material.EnableKeyword("_OCCLUSIONMAP"); enableOcclusionProp.floatValue = 1; } else { material.DisableKeyword("_OCCLUSIONMAP"); enableOcclusionProp.floatValue = 0; } } // Emission EditorGUI.BeginChangeCheck(); var emission = EditorGUILayout.Toggle(new GUIContent("Emission"), (emissionProp.floatValue == 1)? true : false); if (EditorGUI.EndChangeCheck()) { if (emission) { material.EnableKeyword("_EMISSION"); emissionProp.floatValue = 1; } else { material.DisableKeyword("_EMISSION"); emissionProp.floatValue = 0; } } if (emission) { EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertyWithHDRColor(new GUIContent("Emission Map"), emissionMapProp, emissionColorProp, false); if (EditorGUI.EndChangeCheck()) { var brightness = emissionColorProp.colorValue.maxColorComponent; material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive; if (brightness <= 0f) { material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack; } } } // Tiling EditorGUILayout.Space(); materialEditor.TextureScaleOffsetProperty(baseMapProp); // Spacing EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); // ----------------------- // Advanced Surface Inputs GUIContent labeltooltip; openAdvancedSurfaceInputs = (advancedSurfaceInputsProps.floatValue == 1.0f) ? true : false; EditorGUI.BeginChangeCheck(); openAdvancedSurfaceInputs = EditorGUILayout.BeginFoldoutHeaderGroup(openAdvancedSurfaceInputs, "Advanced Surface Inputs"); if (EditorGUI.EndChangeCheck()) { advancedSurfaceInputsProps.floatValue = openAdvancedSurfaceInputs? 1.0f : 0.0f; } if (openAdvancedSurfaceInputs) { EditorGUILayout.Space(); // Parallax EditorGUI.BeginChangeCheck(); labeltooltip = new GUIContent("Height Map (G)", "RGB texture which stores height in the green color channel used by parallax extrusion."); materialEditor.TexturePropertySingleLine(new GUIContent("Height Map (G)"), heightMapProp, heightMapProp.textureValue != null ? parallaxProp : null); if (EditorGUI.EndChangeCheck()) { if ((heightMapProp.textureValue != null) && (parallaxProp.floatValue > 0)) { material.EnableKeyword("_PARALLAX"); enableParallaxProp.floatValue = 1; } else { material.DisableKeyword("_PARALLAX"); enableParallaxProp.floatValue = 0; } } if (alphaclip && (heightMapProp.textureValue != null) && (parallaxProp.floatValue > 0)) { EditorGUI.BeginChangeCheck(); labeltooltip = new GUIContent("Parallax Shadows", "If checked the shader will apply parallax mapping even in the shadow caster pass. This is somehow correct for directional shadows where we can derive the view direction from the (shadow) camera’s forward vector but not in case we render spot lights. Furthermore even parallax directional shadow casters are quite unstable if you rotate the camera. So check if you really need this..."); var pShadows = EditorGUILayout.Toggle(labeltooltip, enableParallaxShadowsProp.floatValue == 1); if (EditorGUI.EndChangeCheck() || surfaceModeChanged) { if (pShadows) { enableParallaxShadowsProp.floatValue = 1; material.EnableKeyword("_PARALLAXSHADOWS"); } else { enableParallaxShadowsProp.floatValue = 0; material.DisableKeyword("_PARALLAXSHADOWS"); } } EditorGUILayout.Space(); } else { enableParallaxShadowsProp.floatValue = 0; material.DisableKeyword("_PARALLAXSHADOWS"); } // Bent Normals EditorGUI.BeginChangeCheck(); labeltooltip = new GUIContent("Bent Normal Map", "Cosine weighted Bent Normal Map in tangent space. If assigned the shader will tweak ambient diffuse lighting and ambient specular reflections."); materialEditor.TexturePropertySingleLine(labeltooltip, BentNormalMapProp); if (EditorGUI.EndChangeCheck()) { if (BentNormalMapProp.textureValue != null) { EnableBentNormalProp.floatValue = 1; material.EnableKeyword("_BENTNORMAL"); material.EnableKeyword("_NORMALMAP"); } else { EnableBentNormalProp.floatValue = 0; material.DisableKeyword("_BENTNORMAL"); if (bumpMapProp.textureValue == null) { material.DisableKeyword("_NORMALMAP"); } } } // Horizon Occlusion labeltooltip = new GUIContent("Horizon Occlusion", "Terminates light leaking caused by normal mapped ambient specular reflections where the reflection vector might end up pointing behind the surface being rendered."); materialEditor.ShaderProperty(HorizonOcclusionProp, labeltooltip, 0); // Specular AA EditorGUI.BeginChangeCheck(); labeltooltip = new GUIContent("Geometric Specular AA", "When enabled the shader reduces specular aliasing on high density meshes by reducing smoothness at grazing angles."); var specAA = EditorGUILayout.Toggle(labeltooltip, GeometricSpecularAAProp.floatValue == 1); if (EditorGUI.EndChangeCheck()) { if (specAA) { GeometricSpecularAAProp.floatValue = 1; material.EnableKeyword("_ENABLE_GEOMETRIC_SPECULAR_AA"); } else { GeometricSpecularAAProp.floatValue = 0; material.DisableKeyword("_ENABLE_GEOMETRIC_SPECULAR_AA"); } } if (specAA) { labeltooltip = new GUIContent("Screen Space Variance", "Controls the amount of Specular AA. Higher values give a more blurry result."); materialEditor.ShaderProperty(ScreenSpaceVarianceProp, labeltooltip, 1); labeltooltip = new GUIContent("Threshold", "Controls the amount of Specular AA. Higher values allow higher reduction."); materialEditor.ShaderProperty(SAAThresholdProp, labeltooltip, 1); } // GI TO AO EditorGUI.BeginChangeCheck(); labeltooltip = new GUIContent("GI to Specular Occlusion", "In case you use lightmaps you may activate this feature to derive some kind of specular occlusion just from the lightmap and its baked ambient occlusion."); var GIAO = EditorGUILayout.Toggle(labeltooltip, AOfromGIProp.floatValue == 1); if (EditorGUI.EndChangeCheck()) { if (GIAO) { AOfromGIProp.floatValue = 1; material.EnableKeyword("_ENABLE_AO_FROM_GI"); } else { AOfromGIProp.floatValue = 0; material.DisableKeyword("_ENABLE_AO_FROM_GI"); } } if (GIAO) { labeltooltip = new GUIContent("GI to AO Factor", "Controls the amount of specular occlusion. It acts as a factor to brighten the value sampled from the lightmap."); materialEditor.ShaderProperty(GItoAOProp, labeltooltip, 1); labeltooltip = new GUIContent("Bias", "Adds a constant value to brighten the value sampled from the lightmap."); materialEditor.ShaderProperty(GItoAOBiasProp, labeltooltip, 1); } // Spacing EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); // ----------------------- // Rim Lighting openRimLighingInputs = (RimLighingInputsProps.floatValue == 1.0f) ? true : false; EditorGUI.BeginChangeCheck(); openRimLighingInputs = EditorGUILayout.BeginFoldoutHeaderGroup(openRimLighingInputs, "Rim Lighting"); if (EditorGUI.EndChangeCheck()) { RimLighingInputsProps.floatValue = openRimLighingInputs? 1.0f : 0.0f; } if (openRimLighingInputs) { // Rim EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(RimProp, "Enable Rim Lighting", 0); materialEditor.ShaderProperty(RimColorProp, "Rim Color", 0); materialEditor.ShaderProperty(RimPowerProp, "Rim Power", 0); materialEditor.ShaderProperty(RimFrequencyProp, "Rim Frequency", 0); materialEditor.ShaderProperty(RimMinPowerProp, "Rim Min Power", 1); materialEditor.ShaderProperty(RimPerPositionFrequencyProp, "Rim Per Position Frequency", 1); if (EditorGUI.EndChangeCheck()) { if (RimProp.floatValue == 1) { material.EnableKeyword("_RIMLIGHTING"); } else { material.DisableKeyword("_RIMLIGHTING"); } } EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); // ----------------------- // Stencil Inputs openStencilOptions = (stencilOptionsProps.floatValue == 1.0f) ? true : false; EditorGUI.BeginChangeCheck(); openStencilOptions = EditorGUILayout.BeginFoldoutHeaderGroup(openStencilOptions, "Stencil Options"); if (EditorGUI.EndChangeCheck()) { stencilOptionsProps.floatValue = openStencilOptions? 1.0f : 0.0f; } if (openStencilOptions) { // Stencil materialEditor.ShaderProperty(stencilProp, "Stencil Reference", 0); materialEditor.ShaderProperty(readMaskProp, "Read Mask", 0); materialEditor.ShaderProperty(writeMaskProp, "Write Mask", 0); materialEditor.ShaderProperty(stencilCompProp, "Stencil Comparison", 0); materialEditor.ShaderProperty(stencilOpProp, "Stencil Operation", 0); materialEditor.ShaderProperty(stencilFailProp, "Stencil Fail Op", 0); materialEditor.ShaderProperty(stenciZfailProp, "Stencil ZFail Op", 0); EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); // ----------------------- // Advanced Settings openAdvancedOptions = (advancedOptionsProps.floatValue == 1.0f) ? true : false; EditorGUI.BeginChangeCheck(); openAdvancedOptions = EditorGUILayout.BeginFoldoutHeaderGroup(openAdvancedOptions, "Advanced"); if (EditorGUI.EndChangeCheck()) { advancedOptionsProps.floatValue = openAdvancedOptions? 1.0f : 0.0f; } if (openAdvancedOptions) { EditorGUI.BeginChangeCheck(); materialEditor.ShaderProperty(SpecularHighlightsProps, "Specular Highlights", 0); materialEditor.ShaderProperty(EnvironmentReflectionsProps, "Environment Reflections", 0); materialEditor.EnableInstancingField(); materialEditor.RenderQueueField(); if (EditorGUI.EndChangeCheck()) { if (SpecularHighlightsProps.floatValue == 1) { material.DisableKeyword("_SPECULARHIGHLIGHTS_OFF"); } else { material.EnableKeyword("_SPECULARHIGHLIGHTS_OFF"); } if (EnvironmentReflectionsProps.floatValue == 1) { material.DisableKeyword("_ENVIRONMENTREFLECTIONS_OFF"); } else { material.EnableKeyword("_ENVIRONMENTREFLECTIONS_OFF"); } } EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); // Fix all the missing stuff // Needed to make the Selection Outline work // Lightmapper needs it for alpha testing?! if (material.HasProperty("_MainTex") && material.HasProperty("_BaseMap")) { if (material.GetTexture("_BaseMap") != null) { material.SetTexture("_MainTex", material.GetTexture("_BaseMap")); } } }