예제 #1
0
        public Renderer2D(Renderer2DData data) : base(data)
        {
            m_BlitMaterial     = CoreUtils.CreateEngineMaterial(data.blitShader);
            m_SamplingMaterial = CoreUtils.CreateEngineMaterial(data.samplingShader);

            m_Render2DLightingPass = new Render2DLightingPass(data, m_BlitMaterial, m_SamplingMaterial);
            m_FinalBlitPass        = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial);

            UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;

#pragma warning disable 618 // Obsolete warning
            PostProcessData postProcessData = data.postProcessData ? data.postProcessData : urpAsset.postProcessData;
#pragma warning restore 618 // Obsolete warning
            if (postProcessData != null)
            {
                m_ColorGradingLutPass  = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, postProcessData);
                m_PostProcessPass      = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, postProcessData, m_BlitMaterial);
                m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, postProcessData, m_BlitMaterial);
                k_AfterPostProcessColorHandle.Init("_AfterPostProcessTexture");
                k_ColorGradingLutHandle.Init("_InternalGradingLut");
            }

            m_UseDepthStencilBuffer = data.useDepthStencilBuffer;

            // We probably should declare these names in the base class,
            // as they must be the same across all ScriptableRenderer types for camera stacking to work.
            k_ColorTextureHandle.Init("_CameraColorTexture");
            k_DepthTextureHandle.Init("_CameraDepthAttachment");

            m_Renderer2DData = data;

            supportedRenderingFeatures = new RenderingFeatures()
            {
                cameraStacking = true,
            };

            m_LightCullResult = new Light2DCullResult();
            m_Renderer2DData.lightCullResult = m_LightCullResult;
        }
예제 #2
0
        static bool CreateLightValidation()
        {
            UniversalRenderPipeline pipeline = UnityEngine.Rendering.RenderPipelineManager.currentPipeline as UniversalRenderPipeline;

            if (pipeline != null)
            {
                UniversalRenderPipelineAsset asset = UniversalRenderPipeline.asset;
                if (asset != null)
                {
                    Renderer2DData assetData = asset.scriptableRendererData as Renderer2DData;
                    //if (assetData == null)
                    //    assetData = Renderer2DData.s_Renderer2DDataInstance;

                    if (assetData != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private void SetupReferences()
        {
            urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
            Assert.IsNotNull(urpAsset, "urpAsset is null!");

            lwrpaShadowField = urpAsset.GetType().GetField("m_MainLightShadowsSupported", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(lwrpaShadowField, "lwrpaShadowField is null!");

            lwrpaShadowResolutionField = urpAsset.GetType().GetField("m_MainLightShadowmapResolution", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(lwrpaShadowResolutionField, "lwrpaShadowResolutionField is null!");

            lwrpaSoftShadowField = urpAsset.GetType().GetField("m_SoftShadowsSupported", BindingFlags.NonPublic | BindingFlags.Instance);
            Assert.IsNotNull(lwrpaSoftShadowField, "lwrpaSoftShadowField is null!");

            GeneralSettingsReferences generalSettingsReferences = GameObject.FindObjectOfType <GeneralSettingsReferences>();
            QualitySettingsReferences qualitySettingsReferences = GameObject.FindObjectOfType <QualitySettingsReferences>();

            Assert.IsNotNull(generalSettingsReferences, "GeneralSettingsReferences not found in scene");
            Assert.IsNotNull(qualitySettingsReferences, "QualitySettingsReferences not found in scene");

            freeLookCamera = generalSettingsReferences.thirdPersonCamera;
            Assert.IsNotNull(freeLookCamera, "GeneralSettingsController: thirdPersonCamera reference missing");

            CinemachineVirtualCamera virtualCamera = generalSettingsReferences.firstPersonCamera;

            Assert.IsNotNull(virtualCamera, "GeneralSettingsController: firstPersonCamera reference missing");
            povCamera = virtualCamera.GetCinemachineComponent <CinemachinePOV>();
            Assert.IsNotNull(povCamera, "GeneralSettingsController: firstPersonCamera doesn't have CinemachinePOV component");

            environmentLight = qualitySettingsReferences.environmentLight;
            Assert.IsNotNull(environmentLight, "QualitySettingsController: environmentLight reference missing");

            postProcessVolume = qualitySettingsReferences.postProcessVolume;
            Assert.IsNotNull(postProcessVolume, "QualitySettingsController: postProcessVolume reference missing");

            firstPersonCamera = qualitySettingsReferences.firstPersonCamera;
            Assert.IsNotNull(firstPersonCamera, "QualitySettingsController: firstPersonCamera reference missing");
            Assert.IsNotNull(qualitySettingsReferences.thirdPersonCamera, "QualitySettingsController: thirdPersonCamera reference missing");
        }
예제 #4
0
    public void ValidateNewAssetResources()
    {
        UniversalRendererData        data  = ScriptableObject.CreateInstance <UniversalRendererData>();
        UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);

        Assert.AreNotEqual(null, asset.defaultMaterial);
        Assert.AreNotEqual(null, asset.defaultParticleMaterial);
        Assert.AreNotEqual(null, asset.defaultLineMaterial);
        Assert.AreNotEqual(null, asset.defaultTerrainMaterial);
        Assert.AreNotEqual(null, asset.defaultShader);

        // URP doesn't override the following materials
        Assert.AreEqual(null, asset.defaultUIMaterial);
        Assert.AreEqual(null, asset.defaultUIOverdrawMaterial);
        Assert.AreEqual(null, asset.defaultUIETC1SupportedMaterial);
        Assert.AreEqual(null, asset.default2DMaterial);

        Assert.AreNotEqual(null, asset.m_EditorResourcesAsset, "Editor Resources should be initialized when creating a new pipeline.");
        Assert.AreNotEqual(null, asset.m_RendererDataList, "A default renderer data should be created when creating a new pipeline.");
        ScriptableObject.DestroyImmediate(asset);
        ScriptableObject.DestroyImmediate(data);
    }
예제 #5
0
        void DrawGeneralSettings()
        {
            m_GeneralSettingsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_GeneralSettingsFoldout.value, Styles.generalSettingsText);
            if (m_GeneralSettingsFoldout.value)
            {
                EditorGUI.indentLevel++;

                EditorGUILayout.Space();
                EditorGUI.indentLevel--;
                m_RendererDataList.DoLayoutList();
                EditorGUI.indentLevel++;

                UniversalRenderPipelineAsset asset = target as UniversalRenderPipelineAsset;

                if (!asset.ValidateRendererData(-1))
                {
                    EditorGUILayout.HelpBox(Styles.rendererMissingDefaultMessage.text, MessageType.Error, true);
                }
                else if (!asset.ValidateRendererDataList(true))
                {
                    EditorGUILayout.HelpBox(Styles.rendererMissingMessage.text, MessageType.Warning, true);
                }

                EditorGUILayout.PropertyField(m_RequireDepthTextureProp, Styles.requireDepthTextureText);
                EditorGUILayout.PropertyField(m_RequireOpaqueTextureProp, Styles.requireOpaqueTextureText);
                EditorGUI.indentLevel++;
                EditorGUI.BeginDisabledGroup(!m_RequireOpaqueTextureProp.boolValue);
                EditorGUILayout.PropertyField(m_OpaqueDownsamplingProp, Styles.opaqueDownsamplingText);
                EditorGUI.EndDisabledGroup();
                EditorGUI.indentLevel--;
                EditorGUILayout.PropertyField(m_SupportsTerrainHolesProp, Styles.supportsTerrainHolesText);
                EditorGUI.indentLevel--;
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }

            EditorGUILayout.EndFoldoutHeaderGroup();
        }
예제 #6
0
    public void ValidateAssetSettings()
    {
        // Create a new asset and validate invalid settings
        UniversalRendererData        data  = ScriptableObject.CreateInstance <UniversalRendererData>();
        UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);

        if (asset != null)
        {
            asset.shadowDistance = -1.0f;
            Assert.GreaterOrEqual(asset.shadowDistance, 0.0f);

            asset.renderScale = -1.0f;
            Assert.GreaterOrEqual(asset.renderScale, UniversalRenderPipeline.minRenderScale);

            asset.renderScale = 32.0f;
            Assert.LessOrEqual(asset.renderScale, UniversalRenderPipeline.maxRenderScale);

            asset.shadowNormalBias = -1.0f;
            Assert.GreaterOrEqual(asset.shadowNormalBias, 0.0f);

            asset.shadowNormalBias = 32.0f;
            Assert.LessOrEqual(asset.shadowNormalBias, UniversalRenderPipeline.maxShadowBias);

            asset.shadowDepthBias = -1.0f;
            Assert.GreaterOrEqual(asset.shadowDepthBias, 0.0f);

            asset.shadowDepthBias = 32.0f;
            Assert.LessOrEqual(asset.shadowDepthBias, UniversalRenderPipeline.maxShadowBias);

            asset.maxAdditionalLightsCount = -1;
            Assert.GreaterOrEqual(asset.maxAdditionalLightsCount, 0);

            asset.maxAdditionalLightsCount = 32;
            Assert.LessOrEqual(asset.maxAdditionalLightsCount, UniversalRenderPipeline.maxPerObjectLights);
        }
        ScriptableObject.DestroyImmediate(asset);
        ScriptableObject.DestroyImmediate(data);
    }
예제 #7
0
        public static RenderPipelineAsset CreateAsset(ForwardRendererData data)
        {
#if UNITY_2019_3_OR_NEWER
            return(UniversalRenderPipelineAsset.Create(data));
#else
            var asset = LightweightRenderPipelineAsset.Create();

            using (var so = new SerializedObject(asset))
            {
                so.Update();

                var rendererProperty     = so.FindProperty("m_RendererData");
                var rendererTypeProperty = so.FindProperty("m_RendererType");
                rendererTypeProperty.enumValueIndex = (int)RendererType.Custom;

                rendererProperty.objectReferenceValue = data;

                so.ApplyModifiedProperties();
            }

            return(asset);
#endif
        }
예제 #8
0
        /// <summary>
        /// Sets all relevant RP settings in order they appear in URP
        /// </summary>
        /// <param name="asset">Pipeline asset to set</param>
        /// <param name="settings">The ProjectSettingItem with stored settings</param>
        private void SetPipelineSettings(UniversalRenderPipelineAsset asset, RenderSettingItem settings)
        {
            // General
            asset.supportsCameraDepthTexture = settings.SoftParticles;

            // Quality
            asset.supportsHDR     = m_GraphicsTierSettings.HDR;
            asset.msaaSampleCount = settings.MSAA == 0 ? 1 : settings.MSAA;

            // Main Light
            asset.mainLightRenderingMode = settings.PixelLightCount == 0
                ? LightRenderingMode.Disabled
                : LightRenderingMode.PerPixel;
            asset.supportsMainLightShadows     = settings.Shadows != ShadowQuality.Disable;
            asset.mainLightShadowmapResolution =
                GetEquivalentMainlightShadowResolution((int)settings.ShadowResolution);

            // Additional Lights
            asset.additionalLightsRenderingMode = settings.PixelLightCount == 0
                ? LightRenderingMode.PerVertex
                : LightRenderingMode.PerPixel;
            asset.maxAdditionalLightsCount            = settings.PixelLightCount != 0 ? Mathf.Max(0, settings.PixelLightCount) : 4;
            asset.supportsAdditionalLightShadows      = settings.Shadows != ShadowQuality.Disable;
            asset.additionalLightsShadowmapResolution =
                GetEquivalentAdditionalLightAtlasShadowResolution((int)settings.ShadowResolution);

            // Reflection Probes
            asset.reflectionProbeBlending      = m_GraphicsTierSettings.ReflectionProbeBlending;
            asset.reflectionProbeBoxProjection = m_GraphicsTierSettings.ReflectionProbeBoxProjection;

            // Shadows
            asset.shadowDistance      = settings.ShadowDistance;
            asset.shadowCascadeCount  = m_GraphicsTierSettings.CascadeShadows ? settings.ShadowCascadeCount : 0;
            asset.cascade2Split       = settings.CascadeSplit2;
            asset.cascade4Split       = settings.CascadeSplit4;
            asset.supportsSoftShadows = settings.Shadows == ShadowQuality.All;
        }
예제 #9
0
        private bool CheckRendererFeatureConfig()
        {
            UniversalRenderPipelineAsset uAsset   = UniversalRenderPipeline.asset;
            ScriptableRenderer           renderer = uAsset.scriptableRenderer;
            PropertyInfo rendererFeaturesProperty = renderer.GetType().GetProperty("rendererFeatures", BindingFlags.Instance | BindingFlags.NonPublic);

            if (rendererFeaturesProperty != null)
            {
                List <ScriptableRendererFeature> rendererFeatures = rendererFeaturesProperty.GetValue(renderer) as List <ScriptableRendererFeature>;
                if (rendererFeatures != null)
                {
                    bool waterFxFeatureAdded = false;
                    for (int i = 0; i < rendererFeatures.Count; ++i)
                    {
                        if (rendererFeatures[i] is PWaterEffectRendererFeature)
                        {
                            waterFxFeatureAdded = true;
                        }
                    }
                    return(waterFxFeatureAdded);
                }
            }
            return(true);
        }
 public UniveralRPMaterialGenerator(UniversalRenderPipelineAsset renderPipelineAsset)
 {
     supportsCameraOpaqueTexture = renderPipelineAsset.supportsCameraOpaqueTexture;
 }
    void OnDestroy()
    {
        UniversalRenderPipelineAsset asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;

        asset.shadowCascadeCount = prevShadowCascadeCount;
    }
예제 #12
0
        public static void FadingOptions(Material material, MaterialEditor materialEditor, ParticleProperties properties)
        {
            // Z write doesn't work with fading
            bool hasZWrite = (material.GetFloat("_ZWrite") > 0.0f);

            if (!hasZWrite)
            {
                // Soft Particles
                {
                    materialEditor.ShaderProperty(properties.softParticlesEnabled, Styles.softParticlesEnabled);
                    if (properties.softParticlesEnabled.floatValue >= 0.5f)
                    {
                        UniversalRenderPipelineAsset urpAsset = UniversalRenderPipeline.asset;
                        if (urpAsset != null && !urpAsset.supportsCameraDepthTexture)
                        {
                            GUIStyle warnStyle = new GUIStyle(GUI.skin.label);
                            warnStyle.fontStyle = FontStyle.BoldAndItalic;
                            warnStyle.wordWrap  = true;
                            EditorGUILayout.HelpBox("Soft Particles require depth texture. Please enable \"Depth Texture\" in the Universal Render Pipeline settings.", MessageType.Warning);
                        }

                        EditorGUI.indentLevel++;
                        BaseShaderGUI.TwoFloatSingleLine(Styles.softParticlesFadeText,
                                                         properties.softParticlesNearFadeDistance,
                                                         Styles.softParticlesNearFadeDistanceText,
                                                         properties.softParticlesFarFadeDistance,
                                                         Styles.softParticlesFarFadeDistanceText,
                                                         materialEditor);
                        EditorGUI.indentLevel--;
                    }
                }

                // Camera Fading
                {
                    materialEditor.ShaderProperty(properties.cameraFadingEnabled, Styles.cameraFadingEnabled);
                    if (properties.cameraFadingEnabled.floatValue >= 0.5f)
                    {
                        EditorGUI.indentLevel++;
                        BaseShaderGUI.TwoFloatSingleLine(Styles.cameraFadingDistanceText,
                                                         properties.cameraNearFadeDistance,
                                                         Styles.cameraNearFadeDistanceText,
                                                         properties.cameraFarFadeDistance,
                                                         Styles.cameraFarFadeDistanceText,
                                                         materialEditor);
                        EditorGUI.indentLevel--;
                    }
                }

                // Distortion
                if (properties.distortionEnabled != null)
                {
                    materialEditor.ShaderProperty(properties.distortionEnabled, Styles.distortionEnabled);
                    if (properties.distortionEnabled.floatValue >= 0.5f)
                    {
                        EditorGUI.indentLevel++;
                        materialEditor.ShaderProperty(properties.distortionStrength, Styles.distortionStrength);
                        materialEditor.ShaderProperty(properties.distortionBlend, Styles.distortionBlend);
                        EditorGUI.indentLevel--;
                    }
                }

                EditorGUI.showMixedValue = false;
            }
        }
예제 #13
0
 static void CreateUniversalPipeline()
 {
     ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, UniversalRenderPipelineAsset.CreateInstance <CreateUniversalPipelineAsset>(),
                                                             "UniversalRenderPipelineAsset.asset", null, null);
 }
예제 #14
0
 public override void Action(int instanceId, string pathName, string resourceFile)
 {
     //Create asset
     AssetDatabase.CreateAsset(UniversalRenderPipelineAsset.Create(UniversalRenderPipelineAsset.CreateRendererAsset(pathName, RendererType._2DRenderer)), pathName);
 }
예제 #15
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.Separator();

            // URP setup helpers
            pipe = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
            if (pipe == null)
            {
                EditorGUILayout.HelpBox("You must assign the Universal Rendering Pipeline asset in Project Settings / Graphics. Then, add the Highlight Plus Scriptable Render Feature to the list of Renderer Features of the Forward Renderer.", MessageType.Error);
                if (GUILayout.Button("Watch Setup Video Tutorial"))
                {
                    Application.OpenURL("https://youtu.be/OlCnEAcHJm0");
                }
                return;
            }

            if (!HighlightPlusRenderPassFeature.installed)
            {
                EditorGUILayout.HelpBox("Highlight Plus Render Feature must be added to the list of features of the Forward Renderer in the Universal Rendering Pipeline asset.", MessageType.Warning);
                if (GUILayout.Button("Watch Setup Video Tutorial"))
                {
                    Application.OpenURL("https://youtu.be/OlCnEAcHJm0");
                }
                if (GUILayout.Button("Go to Universal Rendering Pipeline Asset"))
                {
                    Selection.activeObject = pipe;
                }
                EditorGUILayout.Separator();
            }

            bool isManager = thisEffect.GetComponent <HighlightManager>() != null;

            serializedObject.Update();

            EditorGUILayout.BeginHorizontal();
            HighlightProfile prevProfile = (HighlightProfile)profile.objectReferenceValue;

            EditorGUILayout.PropertyField(profile, new GUIContent("Profile", "Create or load stored presets."));
            if (profile.objectReferenceValue != null)
            {
                if (prevProfile != profile.objectReferenceValue)
                {
                    profileChanged = true;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(EditorGUIUtility.labelWidth));
                if (GUILayout.Button(new GUIContent("Create", "Creates a new profile which is a copy of the current settings."), GUILayout.Width(60)))
                {
                    CreateProfile();
                    profileChanged     = false;
                    enableProfileApply = false;
                    GUIUtility.ExitGUI();
                    return;
                }
                if (GUILayout.Button(new GUIContent("Load", "Updates settings with the profile configuration."), GUILayout.Width(60)))
                {
                    profileChanged = true;
                }
                GUI.enabled = enableProfileApply;
                if (GUILayout.Button(new GUIContent("Save", "Updates profile configuration with changes in this inspector."), GUILayout.Width(60)))
                {
                    enableProfileApply = false;
                    profileChanged     = false;
                    thisEffect.profile.Save(thisEffect);
                    EditorUtility.SetDirty(thisEffect.profile);
                    GUIUtility.ExitGUI();
                    return;
                }
                GUI.enabled = true;
                if (GUILayout.Button(new GUIContent("Locate", "Finds the profile in the project"), GUILayout.Width(60)))
                {
                    if (thisEffect.profile != null)
                    {
                        Selection.activeObject = thisEffect.profile;
                        EditorGUIUtility.PingObject(thisEffect.profile);
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.PropertyField(profileSync, new GUIContent("Sync With Profile", "If disabled, profile settings will only be loaded when clicking 'Load' which allows you to customize settings after loading a profile and keep those changes."));
                EditorGUILayout.BeginHorizontal();
            }
            else
            {
                if (GUILayout.Button(new GUIContent("Create", "Creates a new profile which is a copy of the current settings."), GUILayout.Width(60)))
                {
                    CreateProfile();
                    GUIUtility.ExitGUI();
                    return;
                }
            }
            EditorGUILayout.EndHorizontal();


            if (isManager)
            {
                EditorGUILayout.HelpBox("These are default settings for highlighted objects. If the highlighted object already has a Highlight Effect component, those properties will be used.", MessageType.Info);
            }
            else
            {
                EditorGUILayout.PropertyField(previewInEditor);
            }

            EditorGUILayout.PropertyField(ignoreObjectVisibility);
            if (thisEffect.staticChildren)
            {
                EditorGUILayout.HelpBox("This GameObject or one of its children is marked as static. If highlight is not visible, add a MeshCollider to them.", MessageType.Warning);
            }

            EditorGUILayout.PropertyField(reflectionProbes);
            EditorGUILayout.PropertyField(normalsOption);
            EditorGUILayout.PropertyField(GPUInstancing);

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Highlight Options", EditorStyles.boldLabel);
            if (GUILayout.Button("Help", GUILayout.Width(50)))
            {
                EditorUtility.DisplayDialog("Quick Help", "Move the mouse over a setting for a short description.\n\nVisit kronnect.com's forum for support, questions and more cool assets.\n\nIf you like Highlight Plus please rate it or leave a review on the Asset Store! Thanks.", "Ok");
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            if (!isManager)
            {
                EditorGUILayout.PropertyField(ignore, new GUIContent("Ignore", "This object won't be highlighted."));
                if (!ignore.boolValue)
                {
                    EditorGUILayout.PropertyField(highlighted);
                }
            }
            if (!ignore.boolValue)
            {
                EditorGUILayout.PropertyField(effectGroup, new GUIContent("Include", "Additional objects to highlight. Pro tip: when highlighting multiple objects at the same time include them in the same layer or under the same parent."));
                if (effectGroup.intValue == (int)TargetOptions.LayerInScene || effectGroup.intValue == (int)TargetOptions.LayerInChildren)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(effectGroupLayer, new GUIContent("Layer"));
                    EditorGUI.indentLevel--;
                }
                if (effectGroup.intValue != (int)TargetOptions.OnlyThisObject && effectGroup.intValue != (int)TargetOptions.Scripting)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(effectNameFilter, new GUIContent("Object Name Filter"));
                    EditorGUILayout.PropertyField(combineMeshes);
                    EditorGUI.indentLevel--;
                }
                EditorGUILayout.PropertyField(alphaCutOff, new GUIContent("Alpha Cut Off", "Only for semi-transparent objects. Leave this to zero for normal opaque objects."));
                EditorGUILayout.PropertyField(cullBackFaces);
                EditorGUILayout.PropertyField(fadeInDuration);
                EditorGUILayout.PropertyField(fadeOutDuration);
                if ((PlayerSettings.virtualRealitySupported && ((outlineQuality.intValue == (int)QualityLevel.Highest && outline.floatValue > 0) || (glowQuality.intValue == (int)QualityLevel.Highest && glow.floatValue > 0))))
                {
                    EditorGUILayout.PropertyField(flipY, new GUIContent("Flip Y Fix", "Flips outline/glow effect to fix bug introduced in Unity 2019.1.0 when VR is enabled."));
                }
                if (glowQuality.intValue != (int)QualityLevel.Highest || outlineQuality.intValue != (int)QualityLevel.Highest)
                {
                    EditorGUILayout.PropertyField(constantWidth, new GUIContent("Constant Width", "Compensates outline/glow width with depth increase."));
                }
                EditorGUILayout.PropertyField(subMeshMask);
                EditorGUILayout.Separator();
                EditorGUILayout.LabelField("Effects", EditorStyles.boldLabel);

                EditorGUILayout.BeginVertical(GUI.skin.box);
                DrawSectionField(outline, "Outline", outline.floatValue > 0);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(outlineWidth, new GUIContent("Width"));
                EditorGUILayout.PropertyField(outlineColor, new GUIContent("Color"));
                EditorGUILayout.BeginHorizontal();
                QualityPropertyField(outlineQuality);
                if (outlineQuality.intValue == (int)QualityLevel.Highest)
                {
                    GUILayout.Label("(Screen-Space Effect)");
                }
                else
                {
                    GUILayout.Label("(Mesh-based Effect)");
                }
                EditorGUILayout.EndHorizontal();
                CheckVRSupport(outlineQuality.intValue);
                CheckDepthTextureSupport(outlineQuality.intValue);
                if (outlineQuality.intValue == (int)QualityLevel.Highest)
                {
                    EditorGUILayout.PropertyField(outlineDownsampling, new GUIContent("Downsampling"));
                }
                if (outlineQuality.intValue == (int)QualityLevel.Highest)
                {
                    EditorGUILayout.PropertyField(outlineBlitDebug, new GUIContent("Debug View", "Shows the blitting rectangle on the screen."));
                    if (!Application.isPlaying && outlineBlitDebug.boolValue && (!previewInEditor.boolValue || !highlighted.boolValue))
                    {
                        EditorGUILayout.HelpBox("Enable \"Preview In Editor\" and \"Highlighted\" to display the outline Debug View.", MessageType.Warning);
                    }
                }

                //GUI.enabled = outlineQuality.intValue != (int)QualityLevel.Highest || CheckForwardMSAA();
                if (outlineQuality.intValue == (int)QualityLevel.Highest && (glow.floatValue > 0 && glowQuality.intValue == (int)QualityLevel.Highest))
                {
                    outlineVisibility.intValue = glowVisibility.intValue;
                }
                EditorGUILayout.PropertyField(outlineVisibility, new GUIContent("Visibility"));
                EditorGUILayout.PropertyField(outlineIndependent, new GUIContent("Independent", "Do not combine outline with other highlighted objects."));
                GUI.enabled = true;

                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(GUI.skin.box);
                DrawSectionField(glow, "Outer Glow", glow.floatValue > 0);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(glowWidth, new GUIContent("Width"));
                EditorGUILayout.BeginHorizontal();
                QualityPropertyField(glowQuality);
                if (glowQuality.intValue == (int)QualityLevel.Highest)
                {
                    GUILayout.Label("(Screen-Space Effect)");
                }
                else
                {
                    GUILayout.Label("(Mesh-based Effect)");
                }
                EditorGUILayout.EndHorizontal();
                CheckVRSupport(glowQuality.intValue);
                CheckDepthTextureSupport(glowQuality.intValue);
                if (glowQuality.intValue == (int)QualityLevel.Highest)
                {
                    EditorGUILayout.PropertyField(glowDownsampling, new GUIContent("Downsampling"));
                    EditorGUILayout.PropertyField(glowHQColor, new GUIContent("Color"));
                }
                EditorGUILayout.PropertyField(glowAnimationSpeed, new GUIContent("Animation Speed"));
                if (glowQuality.intValue == (int)QualityLevel.Highest)
                {
                    EditorGUILayout.PropertyField(glowBlitDebug, new GUIContent("Debug View", "Shows the blitting rectangle on the screen."));
                    if (!Application.isPlaying && glowBlitDebug.boolValue && (!previewInEditor.boolValue || !highlighted.boolValue))
                    {
                        EditorGUILayout.HelpBox("Enable \"Preview In Editor\" and \"Highlighted\" to display the glow Debug View.", MessageType.Warning);
                    }
                    EditorGUILayout.PropertyField(glowVisibility, new GUIContent("Visibility"));
                }
                else
                {
                    EditorGUILayout.PropertyField(glowVisibility, new GUIContent("Visibility"));
                    EditorGUILayout.PropertyField(glowDithering, new GUIContent("Dithering"));
                    if (glowDithering.boolValue)
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(glowMagicNumber1, new GUIContent("Magic Number 1"));
                        EditorGUILayout.PropertyField(glowMagicNumber2, new GUIContent("Magic Number 2"));
                        EditorGUI.indentLevel--;
                    }
                    EditorGUILayout.PropertyField(glowBlendPasses, new GUIContent("Blend Passes"));
                    if (!glowBlendPasses.boolValue)
                    {
                        HighlightEffect ef = (HighlightEffect)target;
                        if (ef.glowPasses != null)
                        {
                            for (int k = 0; k < ef.glowPasses.Length - 1; k++)
                            {
                                if (ef.glowPasses[k].offset > ef.glowPasses[k + 1].offset)
                                {
                                    EditorGUILayout.HelpBox("Glow pass " + k + " has a greater offset than the next one. Reduce it to ensure the next glow pass is visible.", MessageType.Warning);
                                }
                            }
                        }
                    }
                    EditorGUILayout.PropertyField(glowPasses, true);
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(GUI.skin.box);
                DrawSectionField(innerGlow, "Inner Glow", innerGlow.floatValue > 0);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(innerGlowColor, new GUIContent("Color"));
                EditorGUILayout.PropertyField(innerGlowWidth, new GUIContent("Width"));
                EditorGUILayout.PropertyField(innerGlowVisibility, new GUIContent("Visibility"));
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(GUI.skin.box);
                DrawSectionField(overlay, "Overlay", overlay.floatValue > 0);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(overlayColor, new GUIContent("Color"));
                EditorGUILayout.PropertyField(overlayBlending, new GUIContent("Blending"));
                EditorGUILayout.PropertyField(overlayMinIntensity, new GUIContent("Min Intensity"));
                EditorGUILayout.PropertyField(overlayAnimationSpeed, new GUIContent("Animation Speed"));
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(GUI.skin.box);
                DrawSectionField(targetFX, "Target", targetFX.boolValue);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(targetFXTexture, new GUIContent("Texture", "The texture that contains the shape to be drawn over the highlighted object."));
                EditorGUILayout.PropertyField(targetFXColor, new GUIContent("Color"));
                EditorGUILayout.PropertyField(targetFXCenter, new GUIContent("Center", "Optionally assign a transform. Target will follow transform. If the object is skinned, you can also assign a bone to reflect currenct animation position."));
                EditorGUILayout.PropertyField(targetFXRotationSpeed, new GUIContent("Rotation Speed"));
                EditorGUILayout.PropertyField(targetFXInitialScale, new GUIContent("Initial Scale"));
                EditorGUILayout.PropertyField(targetFXEndScale, new GUIContent("End Scale"));
                EditorGUILayout.PropertyField(targetFXTransitionDuration, new GUIContent("Transition Duration"));
                EditorGUILayout.PropertyField(targetFXStayDuration, new GUIContent("Stay Duration"));
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.PropertyField(seeThrough);
            if (isManager && seeThrough.intValue == (int)SeeThroughMode.AlwaysWhenOccluded)
            {
                EditorGUILayout.HelpBox("This option is not valid in Manager.\nTo make an object always visible add a Highlight Effect component to the gameobject and enable this option on the component.", MessageType.Error);
            }
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(seeThroughIntensity, new GUIContent("Intensity"));
            EditorGUILayout.PropertyField(seeThroughTintColor, new GUIContent("Color"));
            EditorGUILayout.PropertyField(seeThroughTintAlpha, new GUIContent("Color Blend"));
            EditorGUILayout.PropertyField(seeThroughNoise, new GUIContent("Noise"));
            EditorGUILayout.PropertyField(seeThroughBorder, new GUIContent("Border When Hidden" + ((seeThroughBorder.floatValue > 0) ? " •" : "")));
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(seeThroughBorderWidth, new GUIContent("Width"));
            EditorGUILayout.PropertyField(seeThroughBorderColor, new GUIContent("Color"));
            EditorGUI.indentLevel--;
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.LabelField("Hit FX Sample");
            if (!Application.isPlaying)
            {
                EditorGUILayout.HelpBox("Enter Play Mode to test this feature. In your code, call effect.HitFX() method to execute this hit effect.", MessageType.Info);
            }
            else
            {
                EditorGUI.indentLevel++;
                hitColor        = EditorGUILayout.ColorField(new GUIContent("Color"), hitColor);
                hitDuration     = EditorGUILayout.FloatField(new GUIContent("Duration"), hitDuration);
                hitMinIntensity = EditorGUILayout.Slider(new GUIContent("Min Intensity"), hitMinIntensity, 0, 1);
                if (GUILayout.Button("Execute Hit"))
                {
                    thisEffect.HitFX(hitColor, hitDuration, hitMinIntensity);
                }
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndVertical();

            if (serializedObject.ApplyModifiedProperties() || profileChanged)
            {
                if (thisEffect.profile != null)
                {
                    if (profileChanged)
                    {
                        thisEffect.profile.Load(thisEffect);
                        profileChanged     = false;
                        enableProfileApply = false;
                    }
                    else
                    {
                        enableProfileApply = true;
                    }
                }

                foreach (HighlightEffect effect in targets)
                {
                    effect.Refresh();
                }
            }
        }
            static bool IsAnyRendererHasPostProcessingEnabled(UniversalRenderPipelineSerializedCamera p, UniversalRenderPipelineAsset rpAsset)
            {
                int selectedRendererOption = p.renderer.intValue;

                if (selectedRendererOption < -1 || selectedRendererOption > rpAsset.m_RendererDataList.Length || p.renderer.hasMultipleDifferentValues)
                {
                    return(false);
                }

                var rendererData = selectedRendererOption == -1 ? rpAsset.m_RendererData : rpAsset.m_RendererDataList[selectedRendererOption];

                var forwardRendererData = rendererData as UniversalRendererData;

                if (forwardRendererData != null && forwardRendererData.postProcessData == null)
                {
                    return(true);
                }

                var renderer2DData = rendererData as UnityEngine.Rendering.Universal.Renderer2DData;

                return(renderer2DData != null && renderer2DData.postProcessData == null);
            }
예제 #17
0
 /// <summary>
 ///     Allows editing of a URP assets, but it is easier
 /// </summary>
 public URPSettingsEditor(UniversalRenderPipelineAsset pipelineAsset)
 {
     urpPipelineAsset = pipelineAsset;
 }
        public override void Initialize()
        {
            base.Initialize();

            lightweightRenderPipelineAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
        }
예제 #19
0
        public static void InitializeCameraData(UniversalRenderPipelineAsset settings, Camera camera, UniversalAdditionalCameraData additionalCameraData, out CameraData cameraData)
        {
            const float kRenderScaleThreshold = 0.05f;

            cameraData                 = new CameraData();
            cameraData.camera          = camera;
            cameraData.isStereoEnabled = IsStereoEnabled(camera);

            int msaaSamples = 1;

            if (camera.allowMSAA && settings.msaaSampleCount > 1)
            {
                msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount;
            }

            cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView;
            cameraData.isHdrEnabled      = camera.allowHDR && settings.supportsHDR;

            Rect cameraRect = camera.rect;

            cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f ||
                                              Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f));

            // If XR is enabled, use XR renderScale.
            // Discard variations lesser than kRenderScaleThreshold.
            // Scale is only enabled for gameview.
            float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale;

            cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale;
            cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f;

            bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows;

            cameraData.maxShadowDistance = Mathf.Min(settings.shadowDistance, camera.farClipPlane);
            cameraData.maxShadowDistance = (anyShadowsEnabled && cameraData.maxShadowDistance >= camera.nearClipPlane) ?
                                           cameraData.maxShadowDistance : 0.0f;

            if (additionalCameraData != null)
            {
                cameraData.maxShadowDistance     = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f;
                cameraData.requiresDepthTexture  = additionalCameraData.requiresDepthTexture;
                cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture;
                cameraData.volumeLayerMask       = additionalCameraData.volumeLayerMask;
                cameraData.volumeTrigger         = additionalCameraData.volumeTrigger == null ? camera.transform : additionalCameraData.volumeTrigger;
                cameraData.postProcessEnabled    = additionalCameraData.renderPostProcessing;
                cameraData.isStopNaNEnabled      = cameraData.postProcessEnabled && additionalCameraData.stopNaN && SystemInfo.graphicsShaderLevel >= 35;
                cameraData.isDitheringEnabled    = cameraData.postProcessEnabled && additionalCameraData.dithering;
                cameraData.antialiasing          = cameraData.postProcessEnabled ? additionalCameraData.antialiasing : AntialiasingMode.None;
                cameraData.antialiasingQuality   = additionalCameraData.antialiasingQuality;
            }
            else if (camera.cameraType == CameraType.SceneView)
            {
                cameraData.requiresDepthTexture  = settings.supportsCameraDepthTexture;
                cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture;
                cameraData.volumeLayerMask       = 1; // "Default"
                cameraData.volumeTrigger         = null;
                cameraData.postProcessEnabled    = CoreUtils.ArePostProcessesEnabled(camera);
                cameraData.isStopNaNEnabled      = false;
                cameraData.isDitheringEnabled    = false;
                cameraData.antialiasing          = AntialiasingMode.None;
                cameraData.antialiasingQuality   = AntialiasingQuality.High;
            }
            else
            {
                cameraData.requiresDepthTexture  = settings.supportsCameraDepthTexture;
                cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture;
                cameraData.volumeLayerMask       = 1; // "Default"
                cameraData.volumeTrigger         = null;
                cameraData.postProcessEnabled    = false;
                cameraData.isStopNaNEnabled      = false;
                cameraData.isDitheringEnabled    = false;
                cameraData.antialiasing          = AntialiasingMode.None;
                cameraData.antialiasingQuality   = AntialiasingQuality.High;
            }

            // Disables post if GLes2
            cameraData.postProcessEnabled &= SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLES2;

            cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled;

            var  commonOpaqueFlags        = SortingCriteria.CommonOpaque;
            var  noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder;
            bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU;
            bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort;

            cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags;
            cameraData.captureActions         = CameraCaptureBridge.GetCaptureActions(camera);

            //bool needsAlphaChannel = camera.targetTexture == null && Graphics.preserveFramebufferAlpha && PlatformNeedsToKillAlpha();
            //cameraData.cameraTargetDescriptor = CreateRenderTextureDescriptor(camera, cameraData.renderScale,
            //    cameraData.isStereoEnabled, cameraData.isHdrEnabled, msaaSamples, needsAlphaChannel);
        }
예제 #20
0
        private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipelineAsset pipelineAsset)
        {
            ShaderFeatures shaderFeatures;

            shaderFeatures = ShaderFeatures.MainLight;

            if (pipelineAsset.supportsMainLightShadows)
            {
                shaderFeatures |= ShaderFeatures.MainLightShadows;
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerVertex)
            {
                shaderFeatures |= ShaderFeatures.VertexLighting;
            }
            else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
            {
                shaderFeatures |= ShaderFeatures.AdditionalLights;
            }

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              (shaderFeatures & ShaderFeatures.AdditionalLightShadows) != 0;

            if (pipelineAsset.supportsSoftShadows && anyShadows)
            {
                shaderFeatures |= ShaderFeatures.SoftShadows;
            }

            if (pipelineAsset.supportsMixedLighting)
            {
                shaderFeatures |= ShaderFeatures.MixedLighting;
            }

            if (pipelineAsset.supportsTerrainHoles)
            {
                shaderFeatures |= ShaderFeatures.TerrainHoles;
            }

            if (pipelineAsset.useFastSRGBLinearConversion)
            {
                shaderFeatures |= ShaderFeatures.UseFastSRGBLinearConversion;
            }

            if (pipelineAsset.supportsLightLayers)
            {
                shaderFeatures |= ShaderFeatures.LightLayers;
            }

            bool hasScreenSpaceShadows         = false;
            bool hasScreenSpaceOcclusion       = false;
            bool hasDeferredRenderer           = false;
            bool withAccurateGbufferNormals    = false;
            bool withoutAccurateGbufferNormals = false;
            bool clusteredRendering            = false;
            bool onlyClusteredRendering        = false;
            bool usesRenderPass = false;

            int rendererCount = pipelineAsset.m_RendererDataList.Length;

            for (int rendererIndex = 0; rendererIndex < rendererCount; ++rendererIndex)
            {
                ScriptableRenderer renderer = pipelineAsset.GetRenderer(rendererIndex);
                if (renderer is UniversalRenderer)
                {
                    UniversalRenderer universalRenderer = (UniversalRenderer)renderer;
                    if (universalRenderer.renderingMode == RenderingMode.Deferred)
                    {
                        hasDeferredRenderer           |= true;
                        withAccurateGbufferNormals    |= universalRenderer.accurateGbufferNormals;
                        withoutAccurateGbufferNormals |= !universalRenderer.accurateGbufferNormals;
                        usesRenderPass |= universalRenderer.useRenderPassEnabled;
                    }
                }

                var rendererClustered = false;

                ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
                if (rendererData != null)
                {
                    for (int rendererFeatureIndex = 0; rendererFeatureIndex < rendererData.rendererFeatures.Count; rendererFeatureIndex++)
                    {
                        ScriptableRendererFeature rendererFeature = rendererData.rendererFeatures[rendererFeatureIndex];

                        ScreenSpaceShadows ssshadows = rendererFeature as ScreenSpaceShadows;
                        hasScreenSpaceShadows |= ssshadows != null;

                        // Check for Screen Space Ambient Occlusion Renderer Feature
                        ScreenSpaceAmbientOcclusion ssao = rendererFeature as ScreenSpaceAmbientOcclusion;
                        hasScreenSpaceOcclusion |= ssao != null;

                        // Check for Decal Renderer Feature
                        DecalRendererFeature decal = rendererFeature as DecalRendererFeature;
                        if (decal != null)
                        {
                            var technique = decal.GetTechnique(renderer);
                            switch (technique)
                            {
                            case DecalTechnique.DBuffer:
                                shaderFeatures |= GetFromDecalSurfaceData(decal.GetDBufferSettings().surfaceData);
                                break;

                            case DecalTechnique.ScreenSpace:
                                shaderFeatures |= GetFromNormalBlend(decal.GetScreenSpaceSettings().normalBlend);
                                shaderFeatures |= ShaderFeatures.DecalScreenSpace;
                                break;

                            case DecalTechnique.GBuffer:
                                shaderFeatures |= GetFromNormalBlend(decal.GetScreenSpaceSettings().normalBlend);
                                shaderFeatures |= ShaderFeatures.DecalGBuffer;
                                break;
                            }
                        }
                    }

                    if (rendererData is UniversalRendererData universalRendererData)
                    {
                        rendererClustered = universalRendererData.renderingMode == RenderingMode.Forward &&
                                            universalRendererData.clusteredRendering;
                    }
                }

                clusteredRendering     |= rendererClustered;
                onlyClusteredRendering &= rendererClustered;
            }

            if (hasDeferredRenderer)
            {
                shaderFeatures |= ShaderFeatures.DeferredShading;
            }

            // We can only strip accurateGbufferNormals related variants if all DeferredRenderers use the same option.
            if (withAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithAccurateGbufferNormals;
            }

            if (withoutAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithoutAccurateGbufferNormals;
            }

            if (hasScreenSpaceShadows)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceShadows;
            }

            if (hasScreenSpaceOcclusion)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceOcclusion;
            }

            if (usesRenderPass)
            {
                shaderFeatures |= ShaderFeatures.RenderPassEnabled;
            }

            if (pipelineAsset.reflectionProbeBlending)
            {
                shaderFeatures |= ShaderFeatures.ReflectionProbeBlending;
            }

            if (pipelineAsset.reflectionProbeBoxProjection)
            {
                shaderFeatures |= ShaderFeatures.ReflectionProbeBoxProjection;
            }

            if (clusteredRendering)
            {
                shaderFeatures |= ShaderFeatures.ClusteredRendering;
            }

            if (onlyClusteredRendering)
            {
                shaderFeatures &= ~(ShaderFeatures.AdditionalLights | ShaderFeatures.VertexLighting);
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel || clusteredRendering)
            {
                if (pipelineAsset.supportsAdditionalLightShadows)
                {
                    shaderFeatures |= ShaderFeatures.AdditionalLightShadows;
                }
            }

            return(shaderFeatures);
        }
예제 #21
0
        public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList)
        {
#if PROFILE_BUILD
            Profiler.BeginSample(k_ProcessShaderTag);
#endif

            UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
            if (urpAsset == null || compilerDataList == null || compilerDataList.Count == 0)
            {
                return;
            }

            // Local Keywords need to be initialized with the shader
            InitializeLocalShaderKeywords(shader);

            m_stripTimer.Start();

            int prevVariantCount        = compilerDataList.Count;
            var inputShaderVariantCount = compilerDataList.Count;
            for (int i = 0; i < inputShaderVariantCount;)
            {
                bool removeInput = true;
                foreach (var supportedFeatures in ShaderBuildPreprocessor.supportedFeaturesList)
                {
                    if (!StripUnused(supportedFeatures, shader, snippetData, compilerDataList[i]))
                    {
                        removeInput = false;
                        break;
                    }
                }

                // Remove at swap back
                if (removeInput)
                {
                    compilerDataList[i] = compilerDataList[--inputShaderVariantCount];
                }
                else
                {
                    ++i;
                }
            }

            if (compilerDataList is List <ShaderCompilerData> inputDataList)
            {
                inputDataList.RemoveRange(inputShaderVariantCount, inputDataList.Count - inputShaderVariantCount);
            }
            else
            {
                for (int i = compilerDataList.Count - 1; i >= inputShaderVariantCount; --i)
                {
                    compilerDataList.RemoveAt(i);
                }
            }

            if (urpAsset.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled)
            {
                m_TotalVariantsInputCount  += prevVariantCount;
                m_TotalVariantsOutputCount += compilerDataList.Count;
                LogShaderVariants(shader, snippetData, urpAsset.shaderVariantLogLevel, prevVariantCount, compilerDataList.Count);
            }
            m_stripTimer.Stop();
            double stripTimeMs = m_stripTimer.Elapsed.TotalMilliseconds;
            m_stripTimer.Reset();

#if PROFILE_BUILD
            Profiler.EndSample();
#endif
            shaderPreprocessed?.Invoke(shader, snippetData, prevVariantCount, stripTimeMs);
        }
        private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipelineAsset pipelineAsset)
        {
            ShaderFeatures shaderFeatures;

            shaderFeatures = ShaderFeatures.MainLight;

            if (pipelineAsset.supportsMainLightShadows)
            {
                shaderFeatures |= ShaderFeatures.MainLightShadows;
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerVertex)
            {
                shaderFeatures |= ShaderFeatures.AdditionalLights;
                shaderFeatures |= ShaderFeatures.VertexLighting;
            }
            else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
            {
                shaderFeatures |= ShaderFeatures.AdditionalLights;

                if (pipelineAsset.supportsAdditionalLightShadows)
                {
                    shaderFeatures |= ShaderFeatures.AdditionalLightShadows;
                }
            }

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              CoreUtils.HasFlag(shaderFeatures, ShaderFeatures.AdditionalLightShadows);

            if (pipelineAsset.supportsSoftShadows && anyShadows)
            {
                shaderFeatures |= ShaderFeatures.SoftShadows;
            }

            if (pipelineAsset.supportsMixedLighting)
            {
                shaderFeatures |= ShaderFeatures.MixedLighting;
            }

            if (pipelineAsset.supportsTerrainHoles)
            {
                shaderFeatures |= ShaderFeatures.TerrainHoles;
            }

            bool hasDeferredRenderer           = false;
            bool withAccurateGbufferNormals    = false;
            bool withoutAccurateGbufferNormals = false;

            int rendererCount = pipelineAsset.m_RendererDataList.Length;

            for (int rendererIndex = 0; rendererIndex < rendererCount; ++rendererIndex)
            {
                ScriptableRenderer renderer = pipelineAsset.GetRenderer(rendererIndex);
                if (renderer is DeferredRenderer)
                {
                    hasDeferredRenderer |= true;
                    DeferredRenderer deferredRenderer = (DeferredRenderer)renderer;
                    withAccurateGbufferNormals    |= deferredRenderer.AccurateGbufferNormals;
                    withoutAccurateGbufferNormals |= !deferredRenderer.AccurateGbufferNormals;
                }
            }

            if (hasDeferredRenderer)
            {
                shaderFeatures |= ShaderFeatures.DeferredShading;
            }

            // We can only strip accurateGbufferNormals related variants if all DeferredRenderers use the same option.
            if (withAccurateGbufferNormals && !withoutAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithAccurateGbufferNormals;
            }
            if (!withAccurateGbufferNormals && withoutAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithoutAccurateGbufferNormals;
            }

            return(shaderFeatures);
        }
예제 #23
0
        private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipelineAsset pipelineAsset)
        {
            ShaderFeatures shaderFeatures;

            shaderFeatures = ShaderFeatures.MainLight;

            if (pipelineAsset.supportsMainLightShadows)
            {
                shaderFeatures |= ShaderFeatures.MainLightShadows;
            }

            if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerVertex)
            {
                shaderFeatures |= ShaderFeatures.VertexLighting;
            }
            else if (pipelineAsset.additionalLightsRenderingMode == LightRenderingMode.PerPixel)
            {
                shaderFeatures |= ShaderFeatures.AdditionalLights;

                if (pipelineAsset.supportsAdditionalLightShadows)
                {
                    shaderFeatures |= ShaderFeatures.AdditionalLightShadows;
                }
            }

            bool anyShadows = pipelineAsset.supportsMainLightShadows ||
                              (shaderFeatures & ShaderFeatures.AdditionalLightShadows) != 0;

            if (pipelineAsset.supportsSoftShadows && anyShadows)
            {
                shaderFeatures |= ShaderFeatures.SoftShadows;
            }

            if (pipelineAsset.supportsMixedLighting)
            {
                shaderFeatures |= ShaderFeatures.MixedLighting;
            }

            if (pipelineAsset.supportsTerrainHoles)
            {
                shaderFeatures |= ShaderFeatures.TerrainHoles;
            }

            if (pipelineAsset.useFastSRGBLinearConversion)
            {
                shaderFeatures |= ShaderFeatures.UseFastSRGBLinearConversion;
            }

            if (pipelineAsset.supportsLightLayers)
            {
                shaderFeatures |= ShaderFeatures.LightLayers;
            }

            bool hasScreenSpaceShadows         = false;
            bool hasScreenSpaceOcclusion       = false;
            bool hasDeferredRenderer           = false;
            bool withAccurateGbufferNormals    = false;
            bool withoutAccurateGbufferNormals = false;

            int rendererCount = pipelineAsset.m_RendererDataList.Length;

            for (int rendererIndex = 0; rendererIndex < rendererCount; ++rendererIndex)
            {
                ScriptableRenderer renderer = pipelineAsset.GetRenderer(rendererIndex);
                if (renderer is UniversalRenderer)
                {
                    UniversalRenderer universalRenderer = (UniversalRenderer)renderer;
                    if (universalRenderer.renderingMode == RenderingMode.Deferred)
                    {
                        hasDeferredRenderer           |= true;
                        withAccurateGbufferNormals    |= universalRenderer.accurateGbufferNormals;
                        withoutAccurateGbufferNormals |= !universalRenderer.accurateGbufferNormals;
                    }
                }

                // Check for Screen Space Ambient Occlusion Renderer Feature
                ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex];
                if (rendererData != null)
                {
                    for (int rendererFeatureIndex = 0; rendererFeatureIndex < rendererData.rendererFeatures.Count; rendererFeatureIndex++)
                    {
                        ScriptableRendererFeature rendererFeature = rendererData.rendererFeatures[rendererFeatureIndex];

                        ScreenSpaceShadows ssshadows = rendererFeature as ScreenSpaceShadows;
                        hasScreenSpaceShadows |= ssshadows != null;

                        ScreenSpaceAmbientOcclusion ssao = rendererFeature as ScreenSpaceAmbientOcclusion;
                        hasScreenSpaceOcclusion |= ssao != null;
                    }
                }
            }

            if (hasDeferredRenderer)
            {
                shaderFeatures |= ShaderFeatures.DeferredShading;
            }

            // We can only strip accurateGbufferNormals related variants if all DeferredRenderers use the same option.
            if (withAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithAccurateGbufferNormals;
            }

            if (withoutAccurateGbufferNormals)
            {
                shaderFeatures |= ShaderFeatures.DeferredWithoutAccurateGbufferNormals;
            }

            if (hasScreenSpaceShadows)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceShadows;
            }

            if (hasScreenSpaceOcclusion)
            {
                shaderFeatures |= ShaderFeatures.ScreenSpaceOcclusion;
            }

            return(shaderFeatures);
        }
예제 #24
0
 private static int GetDefaultRendererIndex(UniversalRenderPipelineAsset asset)
 {
     return((int)typeof(UniversalRenderPipelineAsset).GetField("m_DefaultRendererIndex", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(asset));;
 }
예제 #25
0
        public override void OnInspectorGUI()
        {
            BeautifySettings.ManageBuildOptimizationStatus(false);

            serializedObject.Update();

            SetStyles();

            Beautify.TonemapOperator prevTonemap = beautify.tonemap.value;
            bool prevDirectWrite = beautify.directWrite.value;

            EditorGUILayout.BeginVertical();
            {
                GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                GUILayout.BeginHorizontal(blackBack);
                GUILayout.Label(headerTex, GUILayout.ExpandWidth(true));
                GUI.skin.label.alignment = TextAnchor.MiddleLeft;
                GUILayout.EndHorizontal();

                Camera cam = Camera.main;
                if (cam != null)
                {
                    UniversalAdditionalCameraData data = cam.GetComponent <UniversalAdditionalCameraData>();
                    if (data != null && !data.renderPostProcessing)
                    {
                        EditorGUILayout.HelpBox("Post Processing option is disabled in the camera.", MessageType.Warning);
                        if (GUILayout.Button("Go to Camera"))
                        {
                            Selection.activeObject = cam;
                        }
                        EditorGUILayout.Separator();
                    }
                }

                UniversalRenderPipelineAsset pipe = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
                if (pipe == null)
                {
                    EditorGUILayout.HelpBox("Universal Rendering Pipeline asset is not set in 'Project Settings / Graphics' !", MessageType.Error);
                    EditorGUILayout.Separator();
                    GUI.enabled = false;
                }
                else if (!BeautifyRendererFeature.installed)
                {
                    EditorGUILayout.HelpBox("Beautify Render Feature must be added to the rendering pipeline renderer.", MessageType.Error);
                    if (GUILayout.Button("Go to Universal Rendering Pipeline Asset"))
                    {
                        Selection.activeObject = pipe;
                    }
                    EditorGUILayout.Separator();
                    GUI.enabled = false;
                }
                else if (beautify.RequiresDepthTexture())
                {
                    if (!pipe.supportsCameraDepthTexture)
                    {
                        EditorGUILayout.HelpBox("Depth Texture option may be required for certain effects. Check Universal Rendering Pipeline asset!", MessageType.Warning);
                        if (GUILayout.Button("Go to Universal Rendering Pipeline Asset"))
                        {
                            Selection.activeObject = pipe;
                        }
                        EditorGUILayout.Separator();
                    }
                }

                bool usesHDREffect = beautify.tonemap.value != Beautify.TonemapOperator.Linear;
                if (usesHDREffect && (QualitySettings.activeColorSpace != ColorSpace.Linear || (Camera.main != null && !Camera.main.allowHDR)))
                {
                    EditorGUILayout.HelpBox("Some effects, like bloom or tonemapping, works better with Linear Color Space and HDR enabled. Enable Linear color space in Player Settings and check your camera and pipeline HDR setting.", MessageType.Warning);
                }

                // sections
                foreach (var section in sections)
                {
                    bool printSectionHeader = true;

                    // individual properties
                    foreach (var field in section.Value.singleFields)
                    {
                        var parameter   = Unpack(propertyFetcher.Find(field.Name));
                        var displayName = parameter.displayName;
                        if (field.GetCustomAttribute(typeof(Beautify.DisplayName)) is Beautify.DisplayName displayNameAttrib)
                        {
                            displayName = displayNameAttrib.name;
                        }
                        bool indent;
                        if (!IsVisible(parameter, field, out indent))
                        {
                            continue;
                        }

                        if (printSectionHeader)
                        {
                            GUILayout.Space(6.0f);
                            Rect rect = GUILayoutUtility.GetRect(16f, 22f, sectionGroupStyle);
                            GUI.Box(rect, ObjectNames.NicifyVariableName(section.Key.GetType().Name), sectionGroupStyle);
                            printSectionHeader = false;
                        }

                        DrawPropertyField(parameter, field, indent);

                        if (beautify.disabled.value)
                        {
                            GUI.enabled = false;
                        }
                    }
                    GUILayout.Space(6.0f);

                    // grouped properties
                    foreach (var group in section.Value.groups)
                    {
                        Beautify.SettingsGroup settingsGroup = group.Key;
                        string groupName         = ObjectNames.NicifyVariableName(settingsGroup.GetType().Name);
                        bool   printGroupFoldout = true;
                        bool   firstField        = true;
                        bool   groupHasContent   = false;

                        foreach (var field in group.Value)
                        {
                            var  parameter = Unpack(propertyFetcher.Find(field.Name));
                            bool indent;
                            if (!IsVisible(parameter, field, out indent))
                            {
                                if (firstField)
                                {
                                    break;
                                }
                                continue;
                            }

                            firstField = false;
                            if (printSectionHeader)
                            {
                                GUILayout.Space(6.0f);
                                Rect rect = GUILayoutUtility.GetRect(16f, 22f, sectionGroupStyle);
                                GUI.Box(rect, ObjectNames.NicifyVariableName(section.Key.GetType().Name), sectionGroupStyle);
                                printSectionHeader = false;
                            }

                            if (printGroupFoldout)
                            {
                                printGroupFoldout        = false;
                                settingsGroup.IsExpanded = EditorGUILayout.Foldout(settingsGroup.IsExpanded, groupName, true, foldoutStyle);
                                if (!settingsGroup.IsExpanded)
                                {
                                    break;
                                }
                            }

                            DrawPropertyField(parameter, field, indent);
                            groupHasContent = true;

                            if (parameter.value.propertyType == SerializedPropertyType.Boolean)
                            {
                                if (!parameter.value.boolValue)
                                {
                                    var hasToggleSectionBegin = field.GetCustomAttributes(typeof(Beautify.ToggleAllFields)).Any();
                                    if (hasToggleSectionBegin)
                                    {
                                        break;
                                    }
                                }
                            }
                            else if (field.Name.Equals("depthOfFieldFocusMode"))
                            {
                                SerializedProperty prop = serializedObject.FindProperty(field.Name);
                                if (prop != null)
                                {
                                    var value = prop.FindPropertyRelative("m_Value");
                                    if (value != null && value.enumValueIndex == (int)Beautify.DoFFocusMode.FollowTarget)
                                    {
                                        EditorGUILayout.HelpBox("Assign target in the Beautify Settings component.", MessageType.Info);
                                    }
                                }
                            }
                        }
                        if (groupHasContent)
                        {
                            GUILayout.Space(6.0f);
                        }
                    }
                }
            }
            EditorGUILayout.EndVertical();

            if (serializedObject.ApplyModifiedProperties())
            {
                BeautifySettings.ManageBuildOptimizationStatus(true);
            }

            if (prevTonemap != beautify.tonemap.value && beautify.tonemap.value == Beautify.TonemapOperator.ACES)
            {
                beautify.saturate.value         = 0;
                beautify.saturate.overrideState = true;
                beautify.contrast.value         = 1f;
                beautify.contrast.overrideState = true;
            }

            if (beautify.directWrite.value != prevDirectWrite)
            {
                EditorApplication.delayCall += () =>
                                               UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            }
        }
        void UpdateRendererDatas(UniversalRenderPipelineAsset pipeline)
        {
            FieldInfo propertyInfo = pipeline.GetType(  ).GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.NonPublic);

            m_RendererDatas = ((ScriptableRendererData[])propertyInfo?.GetValue(pipeline));
        }
예제 #27
0
        public static void FadingOptions(Material material, MaterialEditor materialEditor, ParticleProperties properties)
        {
            // Z write doesn't work with fading
            bool hasZWrite = (material.GetInt("_ZWrite") != 0);

            if (!hasZWrite)
            {
                // Soft Particles
                {
                    EditorGUI.showMixedValue = properties.softParticlesEnabled.hasMixedValue;
                    var enabled = properties.softParticlesEnabled.floatValue;

                    EditorGUI.BeginChangeCheck();
                    enabled = EditorGUILayout.Toggle(Styles.softParticlesEnabled, enabled != 0.0f) ? 1.0f : 0.0f;
                    if (EditorGUI.EndChangeCheck())
                    {
                        materialEditor.RegisterPropertyChangeUndo("Soft Particles Enabled");
                        properties.softParticlesEnabled.floatValue = enabled;
                    }

                    if (enabled >= 0.5f)
                    {
                        UniversalRenderPipelineAsset urpAsset = UniversalRenderPipeline.asset;
                        if (urpAsset != null && !urpAsset.supportsCameraDepthTexture)
                        {
                            GUIStyle warnStyle = new GUIStyle(GUI.skin.label);
                            warnStyle.fontStyle = FontStyle.BoldAndItalic;
                            warnStyle.wordWrap  = true;
                            EditorGUILayout.HelpBox("Soft Particles require depth texture. Please enable \"Depth Texture\" in the Universal Render Pipeline settings.", MessageType.Warning);
                        }

                        EditorGUI.indentLevel++;
                        BaseShaderGUI.TwoFloatSingleLine(new GUIContent("Surface Fade"),
                                                         properties.softParticlesNearFadeDistance,
                                                         Styles.softParticlesNearFadeDistanceText,
                                                         properties.softParticlesFarFadeDistance,
                                                         Styles.softParticlesFarFadeDistanceText,
                                                         materialEditor);
                        EditorGUI.indentLevel--;
                    }
                }

                // Camera Fading
                {
                    EditorGUI.showMixedValue = properties.cameraFadingEnabled.hasMixedValue;
                    var enabled = properties.cameraFadingEnabled.floatValue;

                    EditorGUI.BeginChangeCheck();
                    enabled = EditorGUILayout.Toggle(Styles.cameraFadingEnabled, enabled != 0.0f) ? 1.0f : 0.0f;
                    if (EditorGUI.EndChangeCheck())
                    {
                        materialEditor.RegisterPropertyChangeUndo("Camera Fading Enabled");
                        properties.cameraFadingEnabled.floatValue = enabled;
                    }

                    if (enabled >= 0.5f)
                    {
                        EditorGUI.indentLevel++;
                        BaseShaderGUI.TwoFloatSingleLine(new GUIContent("Distance"),
                                                         properties.cameraNearFadeDistance,
                                                         Styles.cameraNearFadeDistanceText,
                                                         properties.cameraFarFadeDistance,
                                                         Styles.cameraFarFadeDistanceText,
                                                         materialEditor);
                        EditorGUI.indentLevel--;
                    }
                }

                // Distortion
                if (properties.distortionEnabled != null)
                {
                    EditorGUI.showMixedValue = properties.distortionEnabled.hasMixedValue;
                    var enabled = properties.distortionEnabled.floatValue;

                    EditorGUI.BeginChangeCheck();
                    enabled = EditorGUILayout.Toggle(Styles.distortionEnabled, enabled != 0.0f) ? 1.0f : 0.0f;
                    if (EditorGUI.EndChangeCheck())
                    {
                        materialEditor.RegisterPropertyChangeUndo("Distortion Enabled");
                        properties.distortionEnabled.floatValue = enabled;
                    }

                    if (enabled >= 0.5f)
                    {
                        EditorGUI.indentLevel++;
                        materialEditor.ShaderProperty(properties.distortionStrength, Styles.distortionStrength);
                        EditorGUI.BeginChangeCheck();
                        EditorGUI.showMixedValue = properties.distortionStrength.hasMixedValue;
                        var blend = EditorGUILayout.Slider(Styles.distortionBlend, properties.distortionBlend.floatValue, 0f, 1f);
                        if (EditorGUI.EndChangeCheck())
                        {
                            properties.distortionBlend.floatValue = blend;
                        }
                        EditorGUI.indentLevel--;
                    }
                }

                EditorGUI.showMixedValue = false;
            }
        }
예제 #28
0
        void DrawRendererListLayout(ReorderableList list, SerializedProperty prop)
        {
            list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect.y += 2;
                Rect indexRect = new Rect(rect.x, rect.y, 14, EditorGUIUtility.singleLineHeight);
                EditorGUI.LabelField(indexRect, index.ToString());
                Rect objRect = new Rect(rect.x + indexRect.width, rect.y, rect.width - 134, EditorGUIUtility.singleLineHeight);

                EditorGUI.BeginChangeCheck();
                EditorGUI.ObjectField(objRect, prop.GetArrayElementAtIndex(index), GUIContent.none);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(target);
                }

                Rect defaultButton   = new Rect(rect.width - 90, rect.y, 86, EditorGUIUtility.singleLineHeight);
                var  defaultRenderer = m_DefaultRendererProp.intValue;
                GUI.enabled = index != defaultRenderer;
                if (GUI.Button(defaultButton, !GUI.enabled ? Styles.rendererDefaultText : Styles.rendererSetDefaultText))
                {
                    m_DefaultRendererProp.intValue = index;
                    EditorUtility.SetDirty(target);
                }
                GUI.enabled = true;

                Rect selectRect = new Rect(rect.x + rect.width - 24, rect.y, 24, EditorGUIUtility.singleLineHeight);

                UniversalRenderPipelineAsset asset = target as UniversalRenderPipelineAsset;

                if (asset.ValidateRendererData(index))
                {
                    if (GUI.Button(selectRect, Styles.rendererSettingsText))
                    {
                        Selection.SetActiveObjectWithContext(prop.GetArrayElementAtIndex(index).objectReferenceValue,
                                                             null);
                    }
                }
                else // Missing ScriptableRendererData
                {
                    if (GUI.Button(selectRect, index == defaultRenderer ? Styles.rendererDefaultMissingText : Styles.rendererMissingText))
                    {
                        EditorGUIUtility.ShowObjectPicker <ScriptableRendererData>(null, false, null, index);
                    }
                }

                // If object selector chose an object, assign it to the correct ScriptableRendererData slot.
                if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == index)
                {
                    prop.GetArrayElementAtIndex(index).objectReferenceValue = EditorGUIUtility.GetObjectPickerObject();
                }
            };

            list.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, Styles.rendererHeaderText);
                list.index = list.count - 1;
            };

            list.onCanRemoveCallback = li => { return(li.count > 1); };

            list.onCanAddCallback = li => { return(li.count < UniversalRenderPipeline.maxScriptableRenderers); };

            list.onRemoveCallback = li =>
            {
                if (li.serializedProperty.arraySize - 1 != m_DefaultRendererProp.intValue)
                {
                    if (li.serializedProperty.GetArrayElementAtIndex(li.serializedProperty.arraySize - 1).objectReferenceValue != null)
                    {
                        li.serializedProperty.DeleteArrayElementAtIndex(li.serializedProperty.arraySize - 1);
                    }
                    li.serializedProperty.arraySize--;
                    li.index = li.count - 1;
                }
                else
                {
                    EditorUtility.DisplayDialog(Styles.rendererListDefaultMessage.text, Styles.rendererListDefaultMessage.tooltip,
                                                "Close");
                }
                EditorUtility.SetDirty(target);
            };
        }
예제 #29
0
        void DrawAdditionalShadowData()
        {
            bool hasChanged = false;
            int  selectedUseAdditionalData;

            if (m_AdditionalLightDataSO == null)
            {
                selectedUseAdditionalData = 1;
            }
            else
            {
                m_AdditionalLightDataSO.Update();
                selectedUseAdditionalData = !m_AdditionalLightData.usePipelineSettings ? 0 : 1;
            }

            Rect controlRectAdditionalData = EditorGUILayout.GetControlRect(true);

            if (m_AdditionalLightDataSO != null)
            {
                EditorGUI.BeginProperty(controlRectAdditionalData, Styles.shadowBias, m_UseAdditionalDataProp);
            }
            EditorGUI.BeginChangeCheck();

            selectedUseAdditionalData = EditorGUI.IntPopup(controlRectAdditionalData, Styles.shadowBias, selectedUseAdditionalData, Styles.displayedDefaultOptions, Styles.optionDefaultValues);
            if (EditorGUI.EndChangeCheck())
            {
                hasChanged = true;
            }
            if (m_AdditionalLightDataSO != null)
            {
                EditorGUI.EndProperty();
            }

            if (selectedUseAdditionalData != 1 && m_AdditionalLightDataSO != null)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.Slider(settings.shadowsBias, 0f, 10f, "Depth");
                EditorGUILayout.Slider(settings.shadowsNormalBias, 0f, 10f, "Normal");
                EditorGUI.indentLevel--;

                m_AdditionalLightDataSO.ApplyModifiedProperties();
            }

            if (hasChanged)
            {
                if (m_AdditionalLightDataSO == null)
                {
                    lightProperty.gameObject.AddComponent <UniversalAdditionalLightData>();
                    m_AdditionalLightData = lightProperty.gameObject.GetComponent <UniversalAdditionalLightData>();

                    UniversalRenderPipelineAsset asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
                    settings.shadowsBias.floatValue       = asset.shadowDepthBias;
                    settings.shadowsNormalBias.floatValue = asset.shadowNormalBias;

                    init(m_AdditionalLightData);
                }

                m_UseAdditionalDataProp.intValue = selectedUseAdditionalData;
                m_AdditionalLightDataSO.ApplyModifiedProperties();
            }
        }
예제 #30
0
        void DrawShadowsResolutionGUI()
        {
            int shadowResolutionTier;

            if (m_AdditionalLightDataSO == null)
            {
                shadowResolutionTier = UniversalAdditionalLightData.AdditionalLightsShadowDefaultResolutionTier;
            }
            else
            {
                m_AdditionalLightDataSO.Update();
                shadowResolutionTier = m_AdditionalLightData.additionalLightsShadowResolutionTier;
            }

            Rect controlRectAdditionalData = EditorGUILayout.GetControlRect(true);

            if (m_AdditionalLightDataSO != null)
            {
                EditorGUI.BeginProperty(controlRectAdditionalData, Styles.ShadowResolution, m_AdditionalLightsShadowResolutionTierProp);
            }

            EditorGUI.BeginChangeCheck();

            // UI code adapted from HDRP LevelFieldGUI in com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedScalableSettingValue.cs
            const int k_IndentPerLevel     = 15;
            const int k_PrefixPaddingRight = 2;
            const int k_ValueUnitSeparator = 2;
            const int k_EnumWidth          = 70;
            float     indent = k_IndentPerLevel * EditorGUI.indentLevel;

            Rect labelRect = controlRectAdditionalData;
            Rect levelRect = controlRectAdditionalData;
            Rect fieldRect = controlRectAdditionalData;

            labelRect.width = EditorGUIUtility.labelWidth;
            // Dealing with indentation add space before the actual drawing
            // Thus resize accordingly to have a coherent aspect
            levelRect.x     += labelRect.width - indent + k_PrefixPaddingRight;
            levelRect.width  = k_EnumWidth + indent;
            fieldRect.x      = levelRect.x + levelRect.width + k_ValueUnitSeparator - indent;
            fieldRect.width -= fieldRect.x - controlRectAdditionalData.x;

            EditorGUI.LabelField(labelRect, Styles.ShadowResolution);

            shadowResolutionTier = EditorGUI.IntPopup(levelRect, GUIContent.none, shadowResolutionTier, Styles.ShadowResolutionDefaultOptions, Styles.ShadowResolutionDefaultValues);

            bool hasResolutionTierChanged = EditorGUI.EndChangeCheck();

            if (m_AdditionalLightDataSO != null)
            {
                EditorGUI.EndProperty();
            }

            // Same logic as in DrawAdditionalShadowData
            if (shadowResolutionTier == UniversalAdditionalLightData.AdditionalLightsShadowResolutionTierCustom && m_AdditionalLightDataSO != null)
            {
                // show the custom value field GUI.
                var newResolution = EditorGUI.IntField(fieldRect, settings.shadowsResolution.intValue);
                settings.shadowsResolution.intValue = Mathf.Max(UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution, Mathf.NextPowerOfTwo(newResolution));

                m_AdditionalLightDataSO.ApplyModifiedProperties();
            }
            if (shadowResolutionTier != UniversalAdditionalLightData.AdditionalLightsShadowResolutionTierCustom)
            {
                // show resolution tier values defined in pipeline settings
                UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
                EditorGUI.LabelField(fieldRect, $"{urpAsset.GetAdditionalLightsShadowResolution(shadowResolutionTier)} ({urpAsset.name})");
            }

            if (hasResolutionTierChanged)
            {
                if (m_AdditionalLightDataSO == null)
                {
                    lightProperty.gameObject.AddComponent <UniversalAdditionalLightData>();
                    m_AdditionalLightData = lightProperty.gameObject.GetComponent <UniversalAdditionalLightData>();

                    UniversalRenderPipelineAsset asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset;
                    settings.shadowsBias.floatValue       = asset.shadowDepthBias;
                    settings.shadowsNormalBias.floatValue = asset.shadowNormalBias;
                    settings.shadowsResolution.intValue   = UniversalAdditionalLightData.AdditionalLightsShadowDefaultCustomResolution;

                    init(m_AdditionalLightData);
                }

                m_AdditionalLightsShadowResolutionTierProp.intValue = shadowResolutionTier;
                m_AdditionalLightDataSO.ApplyModifiedProperties();
            }
        }