// Override the volume blending function.
        public override void Override(VolumeComponent state, float interpFactor)
        {
            VolumetricFog other = state as VolumetricFog;

            float   thisExtinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
            Vector3 thisScattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(thisExtinction, (Vector3)(Vector4)albedo.value);

            float   otherExtinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(other.meanFreePath);
            Vector3 otherScattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(otherExtinction, (Vector3)(Vector4)other.albedo.value);

            float   blendExtinction = Mathf.Lerp(otherExtinction, thisExtinction, interpFactor);
            Vector3 blendScattering = Vector3.Lerp(otherScattering, thisScattering, interpFactor);
            float   blendAsymmetry  = Mathf.Lerp(other.asymmetry, asymmetry, interpFactor);

            float blendMeanFreePath = VolumeRenderingUtils.MeanFreePathFromExtinction(blendExtinction);
            Color blendAlbedo       = (Color)(Vector4)VolumeRenderingUtils.AlbedoFromMeanFreePathAndScattering(blendMeanFreePath, blendScattering);

            blendAlbedo.a = 1.0f;

            if (meanFreePath.overrideState)
            {
                other.meanFreePath.value = blendMeanFreePath;
            }

            if (albedo.overrideState)
            {
                other.albedo.value = blendAlbedo;
            }

            if (asymmetry.overrideState)
            {
                other.asymmetry.value = blendAsymmetry;
            }
        }
예제 #2
0
        // index is only used when we need to re-create a component in a specific spot (e.g. reset)
        void CreateEditor(VolumeComponent component, SerializedProperty property, int index = -1, bool forceOpen = false)
        {
            var componentType = component.GetType();

            if (RenderPipelineManager.currentPipeline != null)
            {
                if (componentType.GetCustomAttributes(typeof(VolumeComponentMenuForRenderPipeline), true)
                    .FirstOrDefault() is VolumeComponentMenuForRenderPipeline volumeComponentMenuForRenderPipeline &&
                    !volumeComponentMenuForRenderPipeline.pipelineTypes.Contains(RenderPipelineManager.currentPipeline.GetType()))
                {
                    return;
                }
            }

            var editor = (VolumeComponentEditor)Editor.CreateEditor(component);

            editor.inspector    = m_BaseEditor;
            editor.baseProperty = property.Copy();
            editor.Init();

            if (forceOpen)
            {
                editor.baseProperty.isExpanded = true;
            }

            if (index < 0)
            {
                m_Editors.Add(editor);
            }
            else
            {
                m_Editors[index] = editor;
            }
        }
예제 #3
0
        static void CopySettings(VolumeComponent targetComponent)
        {
            string typeName = targetComponent.GetType().AssemblyQualifiedName;
            string typeData = JsonUtility.ToJson(targetComponent);

            EditorGUIUtility.systemCopyBuffer = $"{typeName}|{typeData}";
        }
        // index is only used when we need to re-create a component in a specific spot (e.g. reset)
        void CreateEditor(VolumeComponent settings, SerializedProperty property, int index = -1, bool forceOpen = false)
        {
            var  settingsType = settings.GetType();
            Type editorType;

            if (!m_EditorTypes.TryGetValue(settingsType, out editorType))
            {
                editorType = typeof(VolumeComponentEditor);
            }

            var editor = (VolumeComponentEditor)Activator.CreateInstance(editorType);

            editor.Init(settings, this);
            editor.baseProperty = property.Copy();

            if (forceOpen)
            {
                editor.baseProperty.isExpanded = true;
            }

            if (index < 0)
            {
                m_Editors.Add(editor);
            }
            else
            {
                m_Editors[index] = editor;
            }
        }
예제 #5
0
        // index is only used when we need to re-create a component in a specific spot (e.g. reset)
        void CreateEditor(VolumeComponent component, SerializedProperty property, int index = -1, bool forceOpen = false)
        {
            var  componentType = component.GetType();
            Type editorType;

            if (!m_EditorTypes.TryGetValue(componentType, out editorType))
            {
                editorType = typeof(VolumeComponentEditor);
            }

            var editor = (VolumeComponentEditor)Activator.CreateInstance(editorType);

//custom-begin: malte: context reference for exposed property resolver
            editor.Init(component, m_SerializedObject.context, m_BaseEditor);
//custom-end
            editor.baseProperty = property.Copy();

            if (forceOpen)
            {
                editor.baseProperty.isExpanded = true;
            }

            if (index < 0)
            {
                m_Editors.Add(editor);
            }
            else
            {
                m_Editors[index] = editor;
            }
        }
예제 #6
0
		private static void VolumeShelf_Closed(object sender, ClosedEventArgs e)
		{
			// note that the component is thrown away when the shelf is closed by the user
			_volumeShelf.Closed -= VolumeShelf_Closed;
			_volumeShelf = null;
			_volumeComponent = null;
		}
예제 #7
0
 void ToggleVolumeComp(VolumeComponent v)
 {
     if (pause.paused == true)
     {
         v.active = !v.active;
     }
 }
예제 #8
0
        static void PasteSettings(VolumeComponent targetComponent)
        {
            string clipboard = EditorGUIUtility.systemCopyBuffer;
            string typeData  = clipboard.Substring(clipboard.IndexOf('|') + 1);

            Undo.RecordObject(targetComponent, "Paste Settings");
            JsonUtility.FromJsonOverwrite(typeData, targetComponent);
        }
        void PasteSettings(VolumeComponent targetComponent)
        {
            Assert.IsNotNull(s_ClipboardContent);
            Assert.AreEqual(s_ClipboardContent.GetType(), targetComponent.GetType());

            Undo.RecordObject(targetComponent, "Paste Settings");
            EditorUtility.CopySerializedIfDifferent(s_ClipboardContent, targetComponent);
        }
예제 #10
0
 internal void Init(VolumeComponent target, Editor inspector)
 {
     this.target      = target;
     m_Inspector      = inspector;
     serializedObject = new SerializedObject(target);
     activeProperty   = serializedObject.FindProperty("active");
     OnEnable();
 }
예제 #11
0
        /// <summary>
        /// Проброс луча через объект
        /// </summary>
        /// <param name="pos">Расположение луча</param>
        /// <param name="dir">Направление луча</param>
        /// <param name="hitPos">Место пересечения</param>
        /// <param name="hitNormal">Нормаль пересечения</param>
        /// <param name="hitVolume">Пересеченный объект</param>
        /// <returns>True если есть пересечение</returns>
        internal bool RayCast(Vec3 pos, Vec3 dir, float rayLength, out Vec3 hitPos, out Vec3 hitNormal, out VolumeComponent hitVolume)
        {
            // Перестроение основной сферы
            if (needCullRebuild)
            {
                RebuildCullSphere();
            }

            // Пересечение с основной сферой
            if (Intersections.RaySphere(pos, dir, cullSphere.Position, cullSphere.Radius))
            {
                float           range = float.MaxValue;
                Vec3            norm  = Vec3.Zero;
                Vec3            hitp  = Vec3.Zero;
                VolumeComponent hvol  = null;

                // Пересечение с волюмами
                Vec3 tfpos = PointToLocal(pos);
                Vec3 tfnrm = VectorToLocal(dir);
                VolumeComponent[] volumes = GetComponents <VolumeComponent>();
                if (volumes != null && volumes.Length > 0)
                {
                    foreach (VolumeComponent v in volumes)
                    {
                        if (v.Enabled)
                        {
                            Vec3 hp, hn;
                            if (v.RayHit(tfpos, tfnrm, rayLength, out hp, out hn))
                            {
                                float dst = (hp - tfpos).Length;
                                if (dst < range)
                                {
                                    range = dst;
                                    hitp  = hp;
                                    norm  = hn;
                                    hvol  = v;
                                }
                            }
                        }
                    }
                }

                // Возврат
                if (hvol != null && range <= rayLength)
                {
                    hitPos    = PointToWorld(hitp);
                    hitNormal = VectorToWorld(norm);
                    hitVolume = hvol;
                    return(true);
                }
            }

            // Нет пересечения
            hitPos    = Vec3.Zero;
            hitNormal = Vec3.Zero;
            hitVolume = null;
            return(false);
        }
        void CopySettings(VolumeComponent targetComponent)
        {
            if (s_ClipboardContent != null)
            {
                CoreUtils.Destroy(s_ClipboardContent);
                s_ClipboardContent = null;
            }

            s_ClipboardContent = (VolumeComponent)CreateInstance(targetComponent.GetType());
            EditorUtility.CopySerializedIfDifferent(targetComponent, s_ClipboardContent);
        }
//custom-begin: malte: context reference for exposed property resolver
        internal void Init(VolumeComponent target, UnityEngine.Object context, Editor inspector)
//custom-end
        {
            this.target = target;
            m_Inspector = inspector;
//custom-begin: malte: context reference for exposed property resolver
            serializedObject = new SerializedObject(target, context);
//custom-end
            activeProperty = serializedObject.FindProperty("active");
            OnEnable();
        }
예제 #14
0
 /// <summary>
 /// Disable agent rotation on player
 /// </summary>
 private void Start()
 {
     health = _maxHealth;
     _agent.updateRotation = false;
     _bloom    = _pp.sharedProfile.components[1];
     _vignette = _pp.sharedProfile.components[2];
     _dof      = _pp.sharedProfile.components[3];
     _noise    = _cam.GetCinemachineComponent <CinemachineBasicMultiChannelPerlin>();
     _keyImagePos.Add(KeyCode.Q, _leftTrackImage.rectTransform.anchoredPosition);
     _keyImagePos.Add(KeyCode.W, _reverseImage.rectTransform.anchoredPosition);
     _keyImagePos.Add(KeyCode.O, _shootImage.rectTransform.anchoredPosition);
     _keyImagePos.Add(KeyCode.P, _rightTrackImage.rectTransform.anchoredPosition);
 }
        void OnContextClick(Vector2 position, VolumeComponent targetComponent, int id)
        {
            var menu = new GenericMenu();

            if (id == 0)
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Move Up"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Move to Top"));
            }
            else
            {
                menu.AddItem(EditorGUIUtility.TrTextContent("Move to Top"), false, () => MoveComponent(id, -id));
                menu.AddItem(EditorGUIUtility.TrTextContent("Move Up"), false, () => MoveComponent(id, -1));
            }

            if (id == m_Editors.Count - 1)
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Move to Bottom"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Move Down"));
            }
            else
            {
                menu.AddItem(EditorGUIUtility.TrTextContent("Move to Bottom"), false, () => MoveComponent(id, (m_Editors.Count - 1) - id));
                menu.AddItem(EditorGUIUtility.TrTextContent("Move Down"), false, () => MoveComponent(id, 1));
            }

            menu.AddSeparator(string.Empty);
            menu.AddItem(EditorGUIUtility.TrTextContent("Collapse All"), false, () => CollapseComponents());
            menu.AddItem(EditorGUIUtility.TrTextContent("Expand All"), false, () => ExpandComponents());
            menu.AddSeparator(string.Empty);
            menu.AddItem(EditorGUIUtility.TrTextContent("Reset"), false, () => ResetComponent(targetComponent.GetType(), id));
            menu.AddItem(EditorGUIUtility.TrTextContent("Remove"), false, () => RemoveComponent(id));
            menu.AddSeparator(string.Empty);
            menu.AddItem(EditorGUIUtility.TrTextContent("Copy Settings"), false, () => CopySettings(targetComponent));

            if (CanPaste(targetComponent))
            {
                menu.AddItem(EditorGUIUtility.TrTextContent("Paste Settings"), false, () => PasteSettings(targetComponent));
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Paste Settings"));
            }

            menu.AddSeparator(string.Empty);
            menu.AddItem(EditorGUIUtility.TrTextContent("Toggle All"), false, () => m_Editors[id].SetAllOverridesTo(true));
            menu.AddItem(EditorGUIUtility.TrTextContent("Toggle None"), false, () => m_Editors[id].SetAllOverridesTo(false));

            menu.DropDown(new Rect(position, Vector2.zero));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public VolumeComponentControl(VolumeComponent component)
        {
            _component = component;

            InitializeComponent();

            AddDefaultTabs();

            this._createVolumeButton.Click += new EventHandler(OnCreateVolumeButtonClick);

            _bindingSource            = new BindingSource();
            _bindingSource.DataSource = _component;

            _component.AllPropertiesChanged += new EventHandler(Refresh);
            _createVolumeButton.DataBindings.Add("Enabled", _bindingSource, "CreateVolumeEnabled", true, DataSourceUpdateMode.OnPropertyChanged);
            _tabControl.DataBindings.Add("Enabled", _bindingSource, "VolumeSettingsEnabled", true, DataSourceUpdateMode.OnPropertyChanged);
        }
예제 #17
0
        static bool CanPaste(VolumeComponent targetComponent)
        {
            if (string.IsNullOrWhiteSpace(EditorGUIUtility.systemCopyBuffer))
            {
                return(false);
            }

            string clipboard = EditorGUIUtility.systemCopyBuffer;
            int    separator = clipboard.IndexOf('|');

            if (separator < 0)
            {
                return(false);
            }

            return(targetComponent.GetType().AssemblyQualifiedName == clipboard.Substring(0, separator));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public VolumeComponentControl(VolumeComponent component)
        {
			_component = component;

			InitializeComponent();

			AddDefaultTabs();

			this._createVolumeButton.Click += new EventHandler(OnCreateVolumeButtonClick);

			_bindingSource = new BindingSource();
			_bindingSource.DataSource = _component;

			_component.AllPropertiesChanged += new EventHandler(Refresh);
			_createVolumeButton.DataBindings.Add("Enabled", _bindingSource, "CreateVolumeEnabled", true, DataSourceUpdateMode.OnPropertyChanged);
			_tabControl.DataBindings.Add("Enabled", _bindingSource, "VolumeSettingsEnabled", true, DataSourceUpdateMode.OnPropertyChanged);
		}
예제 #19
0
		public void Show()
		{
			if (_volumeComponent == null)
			{
				// create and initialize the layout component
				_volumeComponent = new VolumeComponent(this.Context.DesktopWindow);

				// launch the layout component in a shelf
				_volumeShelf = ApplicationComponent.LaunchAsShelf(
					this.Context.DesktopWindow,
					_volumeComponent,
					SR.TitleVolumeController,
					ShelfDisplayHint.DockLeft);

				_volumeShelf.Closed += VolumeShelf_Closed;
			}
		}
예제 #20
0
        public string[] AdditionalProperties(Type volumeComponentType)
        {
            VolumeComponent       component = null;
            VolumeComponentEditor editor    = null;

            CreateEditorAndComponent(volumeComponentType, ref component, ref editor);

            var fields = component
                         .GetFields()
                         .Where(f => f.GetCustomAttribute <AdditionalPropertyAttribute>() != null)
                         .Select(f => f.Name)
                         .ToArray();

            var notAdditionalParameters = editor.GetField("m_VolumeNotAdditionalParameters") as List <VolumeParameter>;

            Assert.True(fields.Count() + notAdditionalParameters.Count == component.parameters.Count);

            ScriptableObject.DestroyImmediate(component);

            return(fields);
        }
예제 #21
0
        public void TestOverridesChanges()
        {
            VolumeComponent       component = null;
            VolumeComponentEditor editor    = null;

            CreateEditorAndComponent(typeof(VolumeComponentMixedAdditionalAttributes), ref component, ref editor);

            component.SetAllOverridesTo(false);
            bool allOverridesState = (bool)editor.Invoke("AreAllOverridesTo", false);

            Assert.True(allOverridesState);

            component.SetAllOverridesTo(true);

            // Was the change correct?
            allOverridesState = (bool)editor.Invoke("AreAllOverridesTo", true);
            Assert.True(allOverridesState);

            // Enable the advance mode on the editor
            editor.showAdditionalProperties = true;

            // Everything is false
            component.SetAllOverridesTo(false);

            // Disable the advance mode on the editor
            editor.showAdditionalProperties = false;

            // Now just set to true the overrides of non additional properties
            editor.Invoke("SetOverridesTo", true);

            // Check that the non additional properties must be false
            allOverridesState = (bool)editor.Invoke("AreAllOverridesTo", true);
            Assert.False(allOverridesState);

            ScriptableObject.DestroyImmediate(component);
        }
예제 #22
0
    //UTD2018
    public static GameObject MakeVolume(string path, Texture2D noise = null, Material loading = null)
    {
        GameObject g = GameObject.CreatePrimitive(PrimitiveType.Cube);

        g.transform.position = Vector3.up;
        g.GetComponent <MeshRenderer>().material = loading;
        VolumeComponent vc = g.AddComponent <VolumeComponent>();

        vc.rayOffset = noise;
        VolumeRenderer vr = Camera.main.GetComponent <VolumeRenderer>();

        if (!vr)
        {
            Debug.Log("Volume Renderer not detected, adding one to the main camera...");
            vr = Camera.main.gameObject.AddComponent <VolumeRenderer>();
            vr.volumeObjects = new List <VolumeComponent>();
        }
        vr.volumeObjects.Add(vc);
        VolumeFileLoader vfl = g.AddComponent <VolumeFileLoader>();

        vfl.forceDataFormat = VolumeTextureFormat.Alpha8;
        vfl.dataPath        = path;
        return(g);
    }
예제 #23
0
 void DisableVolumeComp(VolumeComponent v)
 {
     v.active = false;
 }
예제 #24
0
 void EnableVolumeComp(VolumeComponent v)
 {
     v.active = true;
 }
    /// <summary>
    /// Turns off effect after given duration.
    /// </summary>
    /// <param name="component">Volume Component to turn off.</param>
    /// <param name="effectDurration">Time for effect to last.</param>
    /// <returns>IEnumerator</returns>
    private IEnumerator AfterTimeTurnOffEffect(VolumeComponent component, float effectDurration)
    {
        yield return(new WaitForSeconds(effectDurration));

        component.active = false;
    }
 // Copy/pasting is simply done by creating an in memory copy of the selected component and
 // copying over the serialized data to another; it doesn't use nor affect the OS clipboard
 bool CanPaste(VolumeComponent targetComponent)
 {
     return(s_ClipboardContent != null &&
            s_ClipboardContent.GetType() == targetComponent.GetType());
 }
예제 #27
0
 public void SetComponent(IApplicationComponent component)
 {
     _component = (VolumeComponent)component;
 }
예제 #28
0
 private void CreateEditorAndComponent(Type volumeComponentType, ref VolumeComponent component, ref VolumeComponentEditor editor)
 {
     component = (VolumeComponent)ScriptableObject.CreateInstance(volumeComponentType);
     editor    = (VolumeComponentEditor)Editor.CreateEditor(component);
     editor.Invoke("Init");
 }
예제 #29
0
        private static bool TryFindVolumeComponentWithName(Volume volume, string name, out VolumeComponent component)
        {
            foreach (var c in volume.profile.components)
            {
                if (c.GetType().Name == name)
                {
                    component = c;
                    return(true);
                }
            }

            component = null;
            return(false);
        }
예제 #30
0
 /// <summary>Get a VolumeParameter from a VolumeComponent</summary>
 /// <param name="component">The component to get the parameter from.</param>
 /// <param name="field">The field info of the parameter.</param>
 /// <returns>The volume parameter.</returns>
 public VolumeParameter GetParameter(VolumeComponent component, FieldInfo field)
 {
     return((VolumeParameter)field.GetValue(component));
 }
예제 #31
0
        void Awake()
        {
            var volume = GetComponent <Volume>();

            component_ = volume.profile.components[0];
        }
예제 #32
0
 public void SetComponent(IApplicationComponent component)
 {
     _component = (VolumeComponent)component;
 }