public void Initialize(VolumetricLightBeam master)
        {
            Debug.Assert(master != null);

            var customHideFlags = Consts.ProceduralObjectsHideFlags;

            m_Master = master;

            transform.SetParent(master.transform, false);

            meshRenderer                      = gameObject.GetOrAddComponent <MeshRenderer>();
            meshRenderer.hideFlags            = customHideFlags;
            meshRenderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows       = false;
            meshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; // different reflection probes could break batching with GPU Instancing
#if UNITY_5_4_OR_NEWER
            meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
#else
            meshRenderer.useLightProbes = false;
#endif

            if (!shouldUseGPUInstancedMaterial)
            {
                m_CustomMaterial = MaterialManager.NewMaterial(gpuInstanced: false);
                ApplyMaterial();
            }

            if (SortingLayer.IsValid(m_Master.sortingLayerID))
            {
                sortingLayerID = m_Master.sortingLayerID;
            }
            else
            {
                Debug.LogError(string.Format("Beam '{0}' has an invalid sortingLayerID ({1}). Please fix it by setting a valid layer.", Utils.GetPath(m_Master.transform), m_Master.sortingLayerID));
            }

            sortingOrder = m_Master.sortingOrder;

            meshFilter           = gameObject.GetOrAddComponent <MeshFilter>();
            meshFilter.hideFlags = customHideFlags;

            gameObject.hideFlags = customHideFlags;

#if UNITY_EDITOR
            UnityEditor.GameObjectUtility.SetStaticEditorFlags(gameObject, master.GetStaticEditorFlagsForSubObjects());
            gameObject.SetSameSceneVisibilityStatesThan(master.gameObject);
#endif

            RestartFadeOutCoroutine();
        }
Exemple #2
0
        public void Initialize(VolumetricLightBeam master)
        {
            var hideFlags = Consts.ProceduralObjectsHideFlags;

            m_Master = master;

            transform.SetParent(master.transform, false);

            meshRenderer                   = gameObject.GetOrAddComponent <MeshRenderer>();
            meshRenderer.hideFlags         = hideFlags;
            meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows    = false;
#if UNITY_5_4_OR_NEWER
            meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
#else
            meshRenderer.useLightProbes = false;
#endif

            if (Config.Instance.actualRenderingMode != RenderingMode.GPUInstancing)
            {
                m_CustomMaterial = MaterialManager.NewMaterial(gpuInstanced: false);
                ApplyMaterial();
            }

            if (SortingLayer.IsValid(m_Master.sortingLayerID))
            {
                sortingLayerID = m_Master.sortingLayerID;
            }
            else
            {
                Debug.LogError(string.Format("Beam '{0}' has an invalid sortingLayerID ({1}). Please fix it by setting a valid layer.", Utils.GetPath(m_Master.transform), m_Master.sortingLayerID));
            }

            sortingOrder = m_Master.sortingOrder;

            meshFilter           = gameObject.GetOrAddComponent <MeshFilter>();
            meshFilter.hideFlags = hideFlags;

            gameObject.hideFlags = hideFlags;

#if UNITY_EDITOR
            // Apply the same static flags to the BeamGeometry than the VLB GAO
            var flags = UnityEditor.GameObjectUtility.GetStaticEditorFlags(master.gameObject);
            flags &= ~(UnityEditor.StaticEditorFlags.ContributeGI); // remove the Lightmap static flag since it will generate error messages when selecting the BeamGeometry GAO in the editor
            UnityEditor.GameObjectUtility.SetStaticEditorFlags(gameObject, flags);
#endif

            RestartFadeOutCoroutine();
        }
Exemple #3
0
#pragma warning restore 0162

        bool ApplyMaterial()
        {
            var colorGradient = MaterialManager.ColorGradient.Off;

            if (m_Master.colorMode == ColorMode.Gradient)
            {
                var precision = Utils.GetFloatPackingPrecision();
                colorGradient = precision == Utils.FloatPackingPrecision.High ? MaterialManager.ColorGradient.MatrixHigh : MaterialManager.ColorGradient.MatrixLow;
            }

            Debug.Assert((int)BlendingMode.Additive == (int)MaterialManager.BlendingMode.Additive);
            Debug.Assert((int)BlendingMode.SoftAdditive == (int)MaterialManager.BlendingMode.SoftAdditive);
            Debug.Assert((int)BlendingMode.TraditionalTransparency == (int)MaterialManager.BlendingMode.TraditionalTransparency);

            var staticProps = new MaterialManager.StaticProperties
            {
                blendingMode     = (MaterialManager.BlendingMode)m_Master.blendingMode,
                noise3D          = isNoiseEnabled ? MaterialManager.Noise3D.On : MaterialManager.Noise3D.Off,
                depthBlend       = isDepthBlendEnabled ? MaterialManager.DepthBlend.On : MaterialManager.DepthBlend.Off,
                colorGradient    = colorGradient,
                dynamicOcclusion = m_Master._INTERNAL_DynamicOcclusionMode_Runtime,
                meshSkewing      = m_Master.hasMeshSkewing ? MaterialManager.MeshSkewing.On : MaterialManager.MeshSkewing.Off,
                shaderAccuracy   = (m_Master.shaderAccuracy == ShaderAccuracy.Fast) ? MaterialManager.ShaderAccuracy.Fast : MaterialManager.ShaderAccuracy.High
            };

            Material mat = null;

            if (!shouldUseGPUInstancedMaterial)
            {
                mat = m_CustomMaterial;
                if (mat)
                {
                    staticProps.ApplyToMaterial(mat);
                }
            }
            else
            {
                mat = MaterialManager.GetInstancedMaterial(m_Master._INTERNAL_InstancedMaterialGroupID, staticProps);
            }

            meshRenderer.material = mat;
            return(mat != null);
        }
Exemple #4
0
        public void Initialize(VolumetricLightBeam master)
        {
            var hideFlags = Consts.ProceduralObjectsHideFlags;

            m_Master = master;

            transform.SetParent(master.transform, false);

            meshRenderer                   = gameObject.GetOrAddComponent <MeshRenderer>();
            meshRenderer.hideFlags         = hideFlags;
            meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows    = false;
#if UNITY_5_4_OR_NEWER
            meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
#else
            meshRenderer.useLightProbes = false;
#endif

            if (Config.Instance.actualRenderingMode != RenderingMode.GPUInstancing)
            {
                m_CustomMaterial = MaterialManager.NewMaterial(gpuInstanced: false);
                ApplyMaterial();
            }

            if (SortingLayer.IsValid(m_Master.sortingLayerID))
            {
                sortingLayerID = m_Master.sortingLayerID;
            }
            else
            {
                Debug.LogError(string.Format("Beam '{0}' has an invalid sortingLayerID ({1}). Please fix it by setting a valid layer.", Utils.GetPath(m_Master.transform), m_Master.sortingLayerID));
            }

            sortingOrder = m_Master.sortingOrder;

            meshFilter           = gameObject.GetOrAddComponent <MeshFilter>();
            meshFilter.hideFlags = hideFlags;

            gameObject.hideFlags = hideFlags;

            RestartFadeOutCoroutine();
        }
Exemple #5
0
#pragma warning restore 0162

        bool ApplyMaterial()
        {
            var colorGradient = MaterialManager.ColorGradient.Off;

            if (m_Master.colorMode == ColorMode.Gradient)
            {
                var precision = Utils.GetFloatPackingPrecision();
                colorGradient = precision == Utils.FloatPackingPrecision.High ? MaterialManager.ColorGradient.MatrixHigh : MaterialManager.ColorGradient.MatrixLow;
            }

            Debug.Assert((int)BlendingMode.Additive == (int)MaterialManager.BlendingMode.Additive);
            Debug.Assert((int)BlendingMode.SoftAdditive == (int)MaterialManager.BlendingMode.SoftAdditive);
            Debug.Assert((int)BlendingMode.TraditionalTransparency == (int)MaterialManager.BlendingMode.TraditionalTransparency);

            var staticProps = new MaterialManager.StaticProperties
            {
                blendingMode  = (MaterialManager.BlendingMode)m_Master.blendingMode,
                noise3D       = isNoiseEnabled ? MaterialManager.Noise3D.On : MaterialManager.Noise3D.Off,
                depthBlend    = isDepthBlendEnabled ? MaterialManager.DepthBlend.On : MaterialManager.DepthBlend.Off,
                colorGradient = colorGradient,
                clippingPlane = isClippingPlaneEnabled ? MaterialManager.ClippingPlane.On : MaterialManager.ClippingPlane.Off
            };

            Material mat = null;

            if (Config.Instance.actualRenderingMode != RenderingMode.GPUInstancing)
            {
                mat = m_CustomMaterial;
                if (mat)
                {
                    staticProps.ApplyToMaterial(mat);
                }
            }
            else
            {
                mat = MaterialManager.GetInstancedMaterial(m_Master._INTERNAL_InstancedMaterialGroupID, staticProps);
            }

            meshRenderer.material = mat;
            return(mat != null);
        }
Exemple #6
0
        /// <summary>
        /// Create a dummy material with the proper instancing flag to prevent from stripping away needed shader variants when exporting build
        /// </summary>
        public static Material Create(Shader shader, bool gpuInstanced)
        {
            if (shader == null)
            {
                return(null);
            }

            string path     = GetPath(shader);
            var    dummyMat = AssetDatabase.LoadAssetAtPath <Material>(path);

            if (dummyMat == null ||
                dummyMat.shader != shader ||
                BatchingHelper.IsGpuInstancingEnabled(dummyMat) != gpuInstanced)
            {
                dummyMat = MaterialManager.NewMaterialPersistent(shader, gpuInstanced);
                if (dummyMat)
                {
                    AssetDatabase.CreateAsset(dummyMat, path);
                }
            }

            return(dummyMat);
        }