示例#1
0
        /// <summary>
        /// Get an array of names from the context to display in a popup. These are in the same
        /// order as the list.
        /// </summary>
        /// <param name="useOverride"> Should the variant come from the override context? </param>
        /// <returns> string array of variant names. </returns>
        private string[] GetVariantsArray()
        {
            DS_HazeView view = target as DS_HazeView;

            return(view.ContextAsset != null?view.ContextAsset.Context.GetItemNames() : new string[]
            {
                string.Empty
            });
        }
示例#2
0
        /// <summary>
        /// Create the Controller, Zone and View needed to see DeepSky effects, fitting
        /// the zone around the passed terrain or object (if supplied) and applying the
        /// selected preset.
        /// </summary>
        /// <param name="boundsObject"> The Zone will be scaled to surround this object/terrain. </param>
        /// <param name="presetPath"> Asset path to preset Context to load settings from. </param>
        private void AddQuickSetupToScene(GameObject boundsObject, string presetPath)
        {
            DS_HazeCore core = DS_HazeCore.Instance;
            GameObject  cont;

            if (core == null)
            {
                cont = new GameObject("DS_HazeController", typeof(DS_HazeCore));
                cont.transform.position = new Vector3(0, 0, 0);
            }
            else
            {
                cont = core.gameObject;
                Debug.Log("DeepSky::AddQuickSetupToScene - There is already a Haze Controller in this scene! Skipping adding a new one.");
            }

            GameObject          zone     = new GameObject("DS_HazeZone", typeof(DS_HazeZone));
            DS_HazeContextAsset ctxAsset = AssetDatabase.LoadAssetAtPath <DS_HazeContextAsset>(presetPath);

            if (ctxAsset == null)
            {
                Debug.LogWarning("DeepSky::AddQuickSetupToScene - Unable to load preset " + presetPath);
            }
            else
            {
                DS_HazeZone zoneComp = zone.GetComponent <DS_HazeZone>();
                DS_HazeZoneEditor.SetZoneFromContextPreset(zoneComp, ctxAsset);
            }

            Vector3 zoneSize     = new Vector3(250, 100, 250);
            Vector3 zoneLocation = Vector3.zero;

            if (boundsObject)
            {
                zoneLocation = boundsObject.transform.position;

                bool    useDefault = false;
                Vector3 objSize    = zoneSize;

                Terrain ter = boundsObject.GetComponent <Terrain>();
                if (ter)
                {
                    // This is a terrain, get the size from the terrain data and scale zone to default inner blend zone.
                    objSize       = ter.terrainData.size;
                    zoneLocation += ter.terrainData.size * 0.5f;
                }
                else
                {
                    // Normal object, fit to mesh renderer bounds (if there is a mesh renderer).
                    MeshRenderer mr = boundsObject.GetComponent <MeshRenderer>();
                    if (mr)
                    {
                        objSize      = mr.bounds.size;
                        zoneLocation = mr.bounds.center;
                    }
                    else
                    {
                        Debug.Log("DeepSky::AddQuickSetupToScene - Supplied object has no Mesh Renderer to get bounds from! Using default size.");
                        useDefault = true;
                    }
                }

                if (!useDefault)
                {
                    // Make sure there is at least some size.
                    if (objSize.x < 10)
                    {
                        objSize.x = 10;
                    }
                    if (objSize.y < 10)
                    {
                        objSize.y = 10;
                    }
                    if (objSize.z < 10)
                    {
                        objSize.z = 10;
                    }

                    zoneSize = objSize;
                    float   dT    = Mathf.Min(zoneSize.x, zoneSize.y, zoneSize.z) * 0.1f;
                    Vector3 scale = new Vector3(zoneSize.x / (zoneSize.x - dT), zoneSize.y / (zoneSize.y - dT), zoneSize.z / (zoneSize.z - dT));
                    zoneSize.Scale(scale);
                    zoneSize.y += objSize.y * 0.1f; // Scale up by 10% in Y to give a little extra room at the top/bottom of the terrain/mesh.
                }
            }
            zone.transform.localScale = zoneSize;
            zone.transform.position   = zoneLocation;
            zone.transform.SetParent(cont.transform);

            DS_HazeView view = m_Camera.GetComponent <DS_HazeView>();

            if (view)
            {
                Debug.Log("DeepSky::AddQuickSetupToScene - The camera already has a Haze View! Skipping adding a new one.");
                return;
            }
            else
            {
                view             = m_Camera.gameObject.AddComponent <DS_HazeView>();
                view.DirectLight = m_DirectionalLight;
            }
        }
示例#3
0
        /// <summary>
        /// Draw the custom Inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            // Styling and icons.
            GUIStyle helpBoxStyle = new GUIStyle(EditorStyles.helpBox);

            helpBoxStyle.richText = true;
            Texture2D helpIconImage = EditorGUIUtility.FindTexture("console.infoicon.sml");
            GUIStyle  helpIconStyle = new GUIStyle();

            helpIconStyle.normal.background    = helpIconImage;
            helpIconStyle.onNormal.background  = helpIconImage;
            helpIconStyle.active.background    = helpIconImage;
            helpIconStyle.onActive.background  = helpIconImage;
            helpIconStyle.focused.background   = helpIconImage;
            helpIconStyle.onFocused.background = helpIconImage;

            // Get the serialized properties upfront.
            serializedObject.Update();
            DS_HazeView        view                         = target as DS_HazeView;
            SerializedProperty renderLocal                  = serializedObject.FindProperty("m_RenderLocalVolumetrics");
            SerializedProperty useTemporal                  = serializedObject.FindProperty("m_TemporalReprojection");
            SerializedProperty lightProp                    = serializedObject.FindProperty("m_DirectLight");
            SerializedProperty ctxOverProp                  = serializedObject.FindProperty("m_OverrideContextAsset");
            SerializedProperty ctxProp                      = serializedObject.FindProperty("m_Context");
            SerializedProperty ctxTimeProp                  = serializedObject.FindProperty("m_OverrideTime");
            SerializedProperty ctxVariantOverProp           = serializedObject.FindProperty("m_OverrideContextVariant");
            SerializedProperty ctxVariantProp               = serializedObject.FindProperty("m_ContextItemIndex");
            SerializedProperty ctxGaussDepthProp            = serializedObject.FindProperty("m_GaussianDepthFalloff");
            SerializedProperty ctxUpDepthProp               = serializedObject.FindProperty("m_UpsampleDepthThreshold");
            SerializedProperty ctxTemporalProp              = serializedObject.FindProperty("m_TemporalRejectionScale");
            SerializedProperty ctxTemporalBlendProp         = serializedObject.FindProperty("m_TemporalBlendFactor");
            SerializedProperty applyAirProp                 = serializedObject.FindProperty("m_ApplyAirToSkybox");
            SerializedProperty applyHazeProp                = serializedObject.FindProperty("m_ApplyHazeToSkybox");
            SerializedProperty applyFogEProp                = serializedObject.FindProperty("m_ApplyFogExtinctionToSkybox");
            SerializedProperty applyFogRProp                = serializedObject.FindProperty("m_ApplyFogLightingToSkybox");
            SerializedProperty ctxShowTemporalProp          = serializedObject.FindProperty("m_ShowTemporalRejection");
            SerializedProperty ctxShowUpsampleThresholdProp = serializedObject.FindProperty("m_ShowUpsampleThreshold");

            // Populate the array of context variant names for the popup from the override.
            string[] variants = { string.Empty };
            variants = GetVariantsArray();

            bool updateTemporalKeywords = false;
            bool updateSkyboxKeywords   = false;
            bool updateDebugKeywords    = false;

            // Main GUI layout and drawing.
            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("General:", EditorStyles.boldLabel);

                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(useTemporal);
                if (EditorGUI.EndChangeCheck())
                {
                    updateTemporalKeywords = true;
                }

                EditorGUILayout.PropertyField(renderLocal);
                EditorGUI.BeginChangeCheck();
                Object tmp = lightProp.objectReferenceValue;
                EditorGUILayout.PropertyField(lightProp);
                if (EditorGUI.EndChangeCheck())
                {
                    // Remove the command buffer if no longer referencing the directional light.
                    if (tmp != null && tmp != lightProp.objectReferenceValue)
                    {
                        view.RemoveCommandBufferFromLight((Light)tmp);
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Overrides:", EditorStyles.boldLabel);
                m_HelpTxtOverridesExpanded = EditorGUILayout.Toggle(m_HelpTxtOverridesExpanded, helpIconStyle, GUILayout.Width(helpIconImage.width));
                EditorGUILayout.EndHorizontal();
                if (m_HelpTxtOverridesExpanded)
                {
                    EditorGUILayout.TextArea(m_HelpTxtOverrides, helpBoxStyle);
                }
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginChangeCheck();
                    ctxOverProp.boolValue = EditorGUILayout.Toggle(ctxOverProp.boolValue, GUILayout.Width(16));
                    if (EditorGUI.EndChangeCheck())
                    {
                        variants = GetVariantsArray();
                    }
                    if (!ctxOverProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUILayout.LabelField("Context:", GUILayout.Width(100));
                    EditorGUILayout.PropertyField(ctxProp, GUIContent.none);
                    GUI.enabled = true;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                {
                    if (!ctxOverProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUI.BeginChangeCheck();
                    ctxTimeProp.boolValue = EditorGUILayout.Toggle(ctxTimeProp.boolValue, EditorStyles.radioButton, GUILayout.Width(16));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (ctxTimeProp.boolValue)
                        {
                            ctxVariantOverProp.boolValue = false;
                        }
                    }
                    if (!ctxTimeProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUILayout.LabelField("Time:", GUILayout.Width(100));
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Time"), GUIContent.none);
                    GUI.enabled = true;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                {
                    if (!ctxOverProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUI.BeginChangeCheck();
                    ctxVariantOverProp.boolValue = EditorGUILayout.Toggle(ctxVariantOverProp.boolValue, EditorStyles.radioButton, GUILayout.Width(16));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (ctxVariantOverProp.boolValue)
                        {
                            ctxTimeProp.boolValue = false;
                        }
                    }
                    if (!ctxVariantOverProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUILayout.LabelField("Variant:", GUILayout.Width(100));
                    ctxVariantProp.intValue = EditorGUILayout.Popup(ctxVariantProp.intValue, variants);
                    GUI.enabled             = true;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Shader Parameters:", EditorStyles.boldLabel);
                m_HelpTxtShaderFeaturesExpanded = EditorGUILayout.Toggle(m_HelpTxtShaderFeaturesExpanded, helpIconStyle, GUILayout.Width(helpIconImage.width));
                EditorGUILayout.EndHorizontal();
                if (m_HelpTxtShaderFeaturesExpanded)
                {
                    EditorGUILayout.TextArea(m_HelpTxtShader, helpBoxStyle);
                }
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.LabelField("Apply To Skybox:");
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(applyAirProp, new GUIContent("Air"));
                EditorGUILayout.PropertyField(applyHazeProp, new GUIContent("Haze"));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(applyFogEProp, new GUIContent("Fog"));
                EditorGUILayout.PropertyField(applyFogRProp, new GUIContent("Fog Lighting"));
                EditorGUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                if (EditorGUI.EndChangeCheck())
                {
                    updateSkyboxKeywords = true;
                }
                EditorGUILayout.PropertyField(ctxGaussDepthProp);
                EditorGUILayout.PropertyField(ctxUpDepthProp);
                if (useTemporal.boolValue == false)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PropertyField(ctxTemporalProp);
                EditorGUILayout.PropertyField(ctxTemporalBlendProp);
                GUI.enabled = true;

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Debug Options:", EditorStyles.boldLabel);

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginChangeCheck();
                    if (useTemporal.boolValue == false)
                    {
                        GUI.enabled = false;
                    }
                    ctxShowTemporalProp.boolValue = EditorGUILayout.Toggle(ctxShowTemporalProp.boolValue, EditorStyles.radioButton, GUILayout.Width(16));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (ctxShowTemporalProp.boolValue)
                        {
                            ctxShowUpsampleThresholdProp.boolValue = false;
                        }
                        updateDebugKeywords = true;
                    }
                    if (!ctxShowTemporalProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUILayout.LabelField("Show Temporal Rejection");
                    GUI.enabled = true;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginChangeCheck();
                    ctxShowUpsampleThresholdProp.boolValue = EditorGUILayout.Toggle(ctxShowUpsampleThresholdProp.boolValue, EditorStyles.radioButton, GUILayout.Width(16));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (ctxShowUpsampleThresholdProp.boolValue)
                        {
                            ctxShowTemporalProp.boolValue = false;
                        }
                        updateDebugKeywords = true;
                    }
                    if (!ctxShowUpsampleThresholdProp.boolValue)
                    {
                        GUI.enabled = false;
                    }
                    EditorGUILayout.LabelField("Show Upsample Threshold");
                    GUI.enabled = true;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();

            if (updateTemporalKeywords)
            {
                view.SetTemporalKeywords();
            }
            if (updateSkyboxKeywords)
            {
                view.SetSkyboxKeywords();
            }
            if (updateDebugKeywords)
            {
                view.SetDebugKeywords();
            }
        }