Exemplo n.º 1
0
        VisualElement CreateGUI(SampleVirtualTextureNode node, InspectableAttribute attribute,
                                out VisualElement propertyVisualElement)
        {
            PropertySheet propertySheet = new PropertySheet();

            var enumPropertyDrawer = new EnumPropertyDrawer();

            propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.addressMode == (SampleVirtualTextureNode.AddressMode)newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Address Mode Change");
                node.addressMode = (SampleVirtualTextureNode.AddressMode)newValue;
            },
                                                           node.addressMode,
                                                           "Address Mode",
                                                           SampleVirtualTextureNode.AddressMode.VtAddressMode_Wrap,
                                                           out var addressModeVisualElement));

            propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.lodCalculation == (SampleVirtualTextureNode.LodCalculation)newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Lod Mode Change");
                node.lodCalculation = (SampleVirtualTextureNode.LodCalculation)newValue;
            },
                                                           node.lodCalculation,
                                                           "Lod Mode",
                                                           SampleVirtualTextureNode.LodCalculation.VtLevel_Automatic,
                                                           out var lodCalculationVisualElement));

            propertySheet.Add(enumPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.sampleQuality == (SampleVirtualTextureNode.QualityMode)newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Quality Change");
                node.sampleQuality = (SampleVirtualTextureNode.QualityMode)newValue;
            },
                                                           node.sampleQuality,
                                                           "Quality",
                                                           SampleVirtualTextureNode.QualityMode.VtSampleQuality_High,
                                                           out var qualityVisualElement));

            var boolPropertyDrawer = new BoolPropertyDrawer();

            propertySheet.Add(boolPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.noFeedback == !newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Feedback Settings Change");
                node.noFeedback = !newValue;
            },
                                                           !node.noFeedback,
                                                           "Automatic Streaming",
                                                           out var propertyToggle));

            propertySheet.Add(boolPropertyDrawer.CreateGUI((newValue) =>
            {
                if (node.enableGlobalMipBias == newValue)
                {
                    return;
                }

                node.owner.owner.RegisterCompleteObjectUndo("Enable Global Mip Bias VT Change");
                node.enableGlobalMipBias = newValue;
            },
                                                           node.enableGlobalMipBias,
                                                           "Use Global Mip Bias",
                                                           out var enableGlobalMipBias));


            // display warning if the current master node doesn't support virtual texturing
            // TODO: Add warning when no active subTarget supports VT
            // if (!node.owner.isSubGraph)
            // {
            //     bool supportedByMasterNode =
            //         node.owner.GetNodes<IMasterNode>().FirstOrDefault()?.supportsVirtualTexturing ?? false;
            //     if (!supportedByMasterNode)
            //         propertySheet.Add(new HelpBoxRow(MessageType.Warning),
            //             (row) => row.Add(new Label(
            //                 "The current master node does not support Virtual Texturing, this node will do regular 2D sampling.")));
            // }

            // display warning if the current render pipeline doesn't support virtual texturing
            IVirtualTexturingEnabledRenderPipeline vtRp =
                GraphicsSettings.currentRenderPipeline as IVirtualTexturingEnabledRenderPipeline;

            if (vtRp == null)
            {
                propertySheet.Add(new HelpBoxRow(MessageType.Warning),
                                  (row) => row.Add(new Label(
                                                       "The current render pipeline does not support Virtual Texturing, this node will do regular 2D sampling.")));
            }
            else if (vtRp.virtualTexturingEnabled == false)
            {
                propertySheet.Add(new HelpBoxRow(MessageType.Warning),
                                  (row) => row.Add(new Label(
                                                       "The current render pipeline has disabled Virtual Texturing, this node will do regular 2D sampling.")));
            }
            else
            {
#if !ENABLE_VIRTUALTEXTURES
                propertySheet.Add(new HelpBoxRow(MessageType.Warning),
                                  (row) => row.Add(new Label(
                                                       "Virtual Texturing is disabled globally (possibly by the render pipeline settings), this node will do regular 2D sampling.")));
#endif
            }

            propertyVisualElement = propertySheet;
            return(propertySheet);
        }
Exemplo n.º 2
0
        private VisualElement CreateGUI(
            ChangeValueCallback valueChangedCallback,
            ShaderGUIOverrideInfo actualObject,
            out VisualElement shaderGUIOverrideField)
        {
            m_ShaderGUIOverrideInfo = actualObject;
            var propertySheet = new PropertySheet();

            shaderGUIOverrideField = null;

            string storedValue  = actualObject.ShaderGUIOverride;
            string preferredGUI = GraphUtil.CurrentPipelinePreferredShaderGUI(m_MasterNode as IMasterNode);

            var boolPropertyDrawer = new BoolPropertyDrawer();

            propertySheet.Add(boolPropertyDrawer.CreateGUI(
                                  newValue =>
            {
                m_ShaderGUIOverrideInfo.OverrideEnabled = newValue;
                if (m_ShaderGUIOverrideInfo.OverrideEnabled)
                {
                    // Display the pipeline's default upon activation, if it has one. Otherwise set up field to display user setting.
                    if (string.IsNullOrEmpty(storedValue) && !string.IsNullOrEmpty(preferredGUI))
                    {
                        ProcessShaderGUIField(preferredGUI);
                    }
                    else
                    {
                        ProcessShaderGUIField(storedValue);
                    }
                }

                valueChangedCallback(m_ShaderGUIOverrideInfo);
                AddWarningIfNeeded(m_ShaderGUIOverrideInfo);
                // Update the inspector after this value is changed as it needs to trigger a re-draw to expose the ShaderGUI text field
                this.inspectorUpdateDelegate();
            },
                                  m_ShaderGUIOverrideInfo.OverrideEnabled,
                                  "Override ShaderGUI",
                                  out var boolKeywordField));


            if (actualObject.OverrideEnabled)
            {
                var textPropertyDrawer = new TextPropertyDrawer();
                propertySheet.Add(textPropertyDrawer.CreateGUI(
                                      newValue =>
                {
                    if (m_ShaderGUIOverrideInfo.ShaderGUIOverride == newValue)
                    {
                        return;
                    }

                    ProcessShaderGUIField(newValue);
                    valueChangedCallback(m_ShaderGUIOverrideInfo);
                    AddWarningIfNeeded(m_ShaderGUIOverrideInfo);
                },
                                      m_ShaderGUIOverrideInfo.ShaderGUIOverride,
                                      "ShaderGUI",
                                      out var propertyTextField
                                      ));

                // Reset to default if the value is ever set to null and override is enabled
                if (string.IsNullOrEmpty(storedValue))
                {
                    m_ShaderGUIOverrideInfo.ShaderGUIOverride = preferredGUI;
                }

                var textField = (TextField)propertyTextField;
                textField.value        = m_ShaderGUIOverrideInfo.ShaderGUIOverride;
                shaderGUIOverrideField = textField;
                textField.isDelayed    = true;
            }
            else
            {
                // Upon disable, set the value back to null (for pipeline switching reasons, among other reasons)
                if (storedValue == preferredGUI)
                {
                    m_ShaderGUIOverrideInfo.ShaderGUIOverride = null;
                    valueChangedCallback(m_ShaderGUIOverrideInfo);
                    AddWarningIfNeeded(m_ShaderGUIOverrideInfo);
                }
            }

            propertySheet.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow"));
            return(propertySheet);
        }