Пример #1
0
        /// <summary>
        /// Set vertex stream.
        /// </summary>
        /// <param name="particleSystemRenderer"></param>
        /// <param name="material"></param>
        protected virtual void SetVertexStream(ParticleSystemRenderer particleSystemRenderer, Material material)
        {
            bool useLighting         = (material.GetFloat(UniStandardParticle.Utils.PropLightingEnabled) > 0.0f);
            bool useFlipbookBlending = (material.GetFloat(UniStandardParticle.Utils.PropFlipbookMode) > 0.0f);
            bool useTangents         = useLighting && material.GetTexture(UniStandardParticle.Utils.PropBumpMap);

            //bool useGPUInstancing = ShaderUtil.HasProceduralInstancing(material.shader);
            bool useGPUInstancing = particleSystemRenderer.enableGPUInstancing;

            List <ParticleSystemVertexStream> streams = new List <ParticleSystemVertexStream>();

            streams.Add(ParticleSystemVertexStream.Position);

            if (useLighting)
            {
                streams.Add(ParticleSystemVertexStream.Normal);
            }

            streams.Add(ParticleSystemVertexStream.Color);
            streams.Add(ParticleSystemVertexStream.UV);

            if (useTangents)
            {
                streams.Add(ParticleSystemVertexStream.Tangent);
            }

            if (useFlipbookBlending)
            {
                streams.Add(ParticleSystemVertexStream.UV2);
                streams.Add(ParticleSystemVertexStream.AnimBlend);
            }

            List <ParticleSystemVertexStream> instancedStreams = new List <ParticleSystemVertexStream>(streams);

            if (useGPUInstancing)
            {
                instancedStreams.Add(ParticleSystemVertexStream.AnimFrame);
            }

            // Set the streams on all systems using this material
            //if (useGPUInstancing &&
            //    particleSystemRenderer.renderMode == ParticleSystemRenderMode.Mesh &&
            //    particleSystemRenderer.supportsMeshInstancing)
            if (useGPUInstancing && (particleSystemRenderer.renderMode == ParticleSystemRenderMode.Mesh))
            {
                particleSystemRenderer.SetActiveVertexStreams(instancedStreams);
            }
            else
            {
                particleSystemRenderer.SetActiveVertexStreams(streams);
            }
        }
Пример #2
0
    void SetData()
    {
        var                    obj = Selection.activeGameObject;
        ParticleSystem         ps  = obj.GetComponent <ParticleSystem> ();
        ParticleSystemRenderer psr = obj.GetComponent <ParticleSystemRenderer> ();

        psr.SetActiveVertexStreams(new List <ParticleSystemVertexStream>(new ParticleSystemVertexStream[] {
            ParticleSystemVertexStream.Position,
            ParticleSystemVertexStream.Normal,
            ParticleSystemVertexStream.Color,
            ParticleSystemVertexStream.UV,
            ParticleSystemVertexStream.UV2,
            ParticleSystemVertexStream.Custom1XYZW,
            ParticleSystemVertexStream.Custom2XYZW,
            ParticleSystemVertexStream.StableRandomXY
        }));

        var customData = ps.customData;

        customData.enabled = true;
        customData.SetMode(ParticleSystemCustomData.Custom1, ParticleSystemCustomDataMode.Vector);
        customData.SetVectorComponentCount(ParticleSystemCustomData.Custom1, 4);
        customData.SetMode(ParticleSystemCustomData.Custom2, ParticleSystemCustomDataMode.Vector);
        customData.SetVectorComponentCount(ParticleSystemCustomData.Custom2, 4);
    }
    public void UpdateGrid()
    {
        GenerateGrid();
        GenerateParticles();
        CreateOffsetVector();

        ParticleSystemRenderer psrend = GetComponent <ParticleSystemRenderer>();

        if (rewriteVertexStreams == true)
        {
            psrend.SetActiveVertexStreams(new List <ParticleSystemVertexStream>(new ParticleSystemVertexStream[] { ParticleSystemVertexStream.Position, ParticleSystemVertexStream.Normal, ParticleSystemVertexStream.Color, ParticleSystemVertexStream.UV, ParticleSystemVertexStream.Center, ParticleSystemVertexStream.Tangent, ParticleSystemVertexStream.Custom1XYZ }));
        }
        psrend.alignment = ParticleSystemRenderSpace.Local;
    }
Пример #4
0
    public void UpdateGrid()
    {
        this.GenerateGrid();
        this.GenerateParticles();
        this.CreateOffsetVector();
        ParticleSystemRenderer component = base.GetComponent <ParticleSystemRenderer>();

        if (this.rewriteVertexStreams)
        {
            ParticleSystemRenderer       particleSystemRenderer = component;
            ParticleSystemVertexStream[] array = new ParticleSystemVertexStream[7];
            RuntimeHelpers.InitializeArray(array, fieldof(< PrivateImplementationDetails >.B084C67FF0B307B33AF49050A3B2138803BE2C60).FieldHandle);
            particleSystemRenderer.SetActiveVertexStreams(new List <ParticleSystemVertexStream>(array));
        }
        component.alignment = ParticleSystemRenderSpace.Local;
    }
Пример #5
0
    protected void Init(ParticleSystem ps, int count, Mesh targetMesh, Material targetMaterial)
    {
        m_ParticleSys = ps;
        var Main = m_ParticleSys.main;

        Main.maxParticles    = count;
        Main.startLifetime   = 10000000.0f;
        Main.simulationSpeed = 0.0f;
        Main.startSpeed      = 0.0f;
        Main.simulationSpace = ParticleSystemSimulationSpace.Local;

        m_ParticleSysRender                   = m_ParticleSys.GetComponent <ParticleSystemRenderer>();
        Main.startSizeMultiplier              = 1.0f;
        m_ParticleSysRender.sortMode          = ParticleSystemSortMode.None;
        m_ParticleSysRender.renderMode        = ParticleSystemRenderMode.Mesh;
        m_ParticleSysRender.material          = targetMaterial;
        m_ParticleSysRender.mesh              = targetMesh;
        m_ParticleSysRender.alignment         = ParticleSystemRenderSpace.Local;
        m_ParticleSysRender.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
        m_ParticleSysRender.receiveShadows    = false;

        // send custom data to the shader
        m_ParticleSysRender.SetActiveVertexStreams(new List <ParticleSystemVertexStream>(
                                                       new ParticleSystemVertexStream[] { ParticleSystemVertexStream.Position,
                                                                                          ParticleSystemVertexStream.UV,
                                                                                          ParticleSystemVertexStream.Custom1X }));

        Main.startSizeMultiplier = 0.5f;
        // Get the emission module.
        var EmissionModule = m_ParticleSys.emission;

        EmissionModule.rateOverTime = 0;
        m_ParticleSys.Emit(ActorNum);
        m_ParticleSys.Stop();
        m_ParticleSys.Pause();
    }
        public void SpawnParticle(Vector3 position, string message, Color color, float?startSize = null)
        {
            var texCords      = new Vector2[24]; //массив из 24 элемент - 23 символа + длина сообщения
            var messageLenght = Mathf.Min(23, message.Length);

            texCords[texCords.Length - 1] = new Vector2(0, messageLenght);
            for (int i = 0; i < texCords.Length; i++)
            {
                if (i >= messageLenght)
                {
                    break;
                }
                //Вызываем метод GetTextureCoordinates() из SymbolsTextureData для получения позиции символа
                texCords[i] = textureData.GetTextureCoordinates(message[i]);
            }

            var custom1Data = CreateCustomData(texCords);
            var custom2Data = CreateCustomData(texCords, 12);

            //Кэшируем ссылку на ParticleSystem
            if (particleSystem == null)
            {
                particleSystem = GetComponent <ParticleSystem>();
            }

            if (particleSystemRenderer == null)
            {
                //Если ссылка на ParticleSystemRenderer, кэшируем и убеждаемся в наличии нужных потоков
                particleSystemRenderer = particleSystem.GetComponent <ParticleSystemRenderer>();
                var streams = new List <ParticleSystemVertexStream>();
                particleSystemRenderer.GetActiveVertexStreams(streams);
                //Добавляем лишний поток Vector2(UV2, SizeXY, etc.), чтобы координаты в скрипте соответствовали координатам в шейдере
                if (!streams.Contains(ParticleSystemVertexStream.UV2))
                {
                    streams.Add(ParticleSystemVertexStream.UV2);
                }
                if (!streams.Contains(ParticleSystemVertexStream.Custom1XYZW))
                {
                    streams.Add(ParticleSystemVertexStream.Custom1XYZW);
                }
                if (!streams.Contains(ParticleSystemVertexStream.Custom2XYZW))
                {
                    streams.Add(ParticleSystemVertexStream.Custom2XYZW);
                }
                particleSystemRenderer.SetActiveVertexStreams(streams);
            }

            //Инициализируем параметры эммишена
            //Цвет и позицию получаем из параметров метода
            //Устанавливаем startSize3D по X, чтобы символы не растягивались и не сжимались
            //при изменении длины сообщения
            var emitParams = new ParticleSystem.EmitParams
            {
                startColor           = color,
                position             = position,
                applyShapeToPosition = true,
                startSize3D          = new Vector3(messageLenght, 1, 1)
            };

            //Если мы хотим создавать частицы разного размера, то в параметрах SpawnParticle неоходимо
            //передать нужное значение startSize
            if (startSize.HasValue)
            {
                emitParams.startSize3D *= startSize.Value * particleSystem.main.startSizeMultiplier;
            }
            //Непосредственно спаун частицы
            particleSystem.Emit(emitParams, 1);

            //Передаем кастомные данные в нужные потоки
            var customData = new List <Vector4>();

            //Получаем поток ParticleSystemCustomData.Custom1 из ParticleSystem
            particleSystem.GetCustomParticleData(customData, ParticleSystemCustomData.Custom1);
            //Меняем данные последнего элемент, т.е. той частицы, которую мы только что создали
            customData[customData.Count - 1] = custom1Data;
            //Возвращаем данные в ParticleSystem
            particleSystem.SetCustomParticleData(customData, ParticleSystemCustomData.Custom1);

            //Аналогично для ParticleSystemCustomData.Custom2
            particleSystem.GetCustomParticleData(customData, ParticleSystemCustomData.Custom2);
            customData[customData.Count - 1] = custom2Data;
            particleSystem.SetCustomParticleData(customData, ParticleSystemCustomData.Custom2);
        }
Пример #7
0
 /// <summary>
 /// VertexStreamの設定
 /// </summary>
 public static void SetVertexStream(ParticleSystemRenderer psr, ShaderPresetData param)
 {
     psr.SetActiveVertexStreams(param.VertexStreams.ToList());
 }
Пример #8
0
        /// <summary>
        /// Initialize the particle system. Any existing particle system on the
        /// game object will be modified to be compatible with the tile grid material.
        /// If no particle system exists, then one will be created.
        /// </summary>
        void InitParticleSystem()
        {
            // Get the local particle system or create one if it doesn't exist.
            localParticleSystem = GetComponent <ParticleSystem>();
            bool hasLocalParticleSytem = localParticleSystem != null;

            if (hasLocalParticleSytem == false)
            {
                localParticleSystem = gameObject.AddComponent <ParticleSystem>();
            }

            // Stop the particle system before modifying its modules.
            LocalParticleSystem.Stop();

            // Modify the main module.
            ParticleSystem.MainModule main = LocalParticleSystem.main;
            main.playOnAwake     = false;
            main.startLifetime   = hasLocalParticleSytem ? main.startLifetime : defaultStartLifetime;
            main.duration        = main.startLifetime.constantMax;
            main.loop            = false;
            main.startSize       = GetMaxParticleSize() * GetParticleSystemScale();
            main.startColor      = hasLocalParticleSytem ? main.startColor : LocalSpriteRenderer.color;
            main.maxParticles    = GetMaxParticleCount();
            main.simulationSpace = ParticleSystemSimulationSpace.World;
            main.gravityModifier = GravityModifier;

            // Modify the emission module to be disabled since we'll manually be emitting particles.
            ParticleSystem.EmissionModule emission = LocalParticleSystem.emission;
            emission.enabled = false;

            // Modify the shape module so that it's disabled. We'll be manually be emitting the particles
            // at specific locations.
            ParticleSystem.ShapeModule shape = LocalParticleSystem.shape;
            shape.enabled = false;

            // Modify the collision module. Some properties retain their original settings
            // if a prexisting component existed. Otherwise, use default values.
            ParticleSystem.CollisionModule collision = LocalParticleSystem.collision;
            collision.enabled      = IsCollisionEnabled;
            collision.type         = ParticleSystemCollisionType.World;
            collision.mode         = CollisionMode == SpriteExploderCollisionMode.Collision3D ? ParticleSystemCollisionMode.Collision3D : ParticleSystemCollisionMode.Collision2D;
            collision.dampen       = hasLocalParticleSytem ? collision.dampen : new ParticleSystem.MinMaxCurve(defaultMinDampen, defaultMaxDampen);
            collision.bounce       = hasLocalParticleSytem ? collision.bounce : new ParticleSystem.MinMaxCurve(defaultMinBounce, defaultMaxBounce);
            collision.lifetimeLoss = hasLocalParticleSytem ? collision.lifetimeLoss : defaultLifetimeLoss;

            // Modify the particle system renderer component. In particular, setting the material,
            // enabling gpu instancing, and setting the active vertex streams.
            ParticleSystemRenderer particleSystemRenderer = GetComponent <ParticleSystemRenderer>();

            particleSystemRenderer.renderMode          = ParticleSystemRenderMode.Mesh;
            particleSystemRenderer.mesh                = Resources.GetBuiltinResource <Mesh>("Quad.fbx");
            particleSystemRenderer.enableGPUInstancing = true;
            particleSystemRenderer.minParticleSize     = 0.0f;
            particleSystemRenderer.maxParticleSize     = 1.0f;

            Material material = Resources.Load <Material>(materialResourcePath);

            particleSystemRenderer.material = material;

            MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

            materialPropertyBlock.SetTexture("_GridTex", GetTexture());
            materialPropertyBlock.SetInt("_SubdivisionCountX", GetSubdivisionCountX());
            materialPropertyBlock.SetInt("_SubdivisionCountY", GetSubdivisionCountY());
            materialPropertyBlock.SetFloat("_Rotation", GetMaterialRotaion());
            materialPropertyBlock.SetVector("_Flip", GetFlipVector4());
            particleSystemRenderer.SetPropertyBlock(materialPropertyBlock);

            List <ParticleSystemVertexStream> streams = new List <ParticleSystemVertexStream>();

            streams.Add(ParticleSystemVertexStream.Position);
            streams.Add(ParticleSystemVertexStream.UV);
            streams.Add(ParticleSystemVertexStream.Color);
            streams.Add(ParticleSystemVertexStream.Custom1X); // Used to pass tile data to the shader

            particleSystemRenderer.SetActiveVertexStreams(streams);

            // Play the particle system now that the modules and renderer are setup.
            LocalParticleSystem.Play();
        }
        public void SpawnParticle(string message, Color color, Vector3 position, float?startSize = null)
        {
            var texCords      = new Vector2[24]; // An array of 24 elements - 23 symbols + the length of the mesage
            var messageLenght = Mathf.Min(23, message.Length);

            texCords[texCords.Length - 1] = new Vector2(0, messageLenght);
            for (int i = 0; i < texCords.Length; i++)
            {
                if (i >= messageLenght)
                {
                    break;
                }
                // Calling the method GetTextureCoordinates() from SymbolsTextureData to obtain the symbol's position
                texCords[i] = textureData.GetTextureCoordinates(message[i]);
            }

            var custom1Data = CreateCustomData(texCords);
            var custom2Data = CreateCustomData(texCords, 12);

            // Caching link to ParticleSystem
            if (ps == null)
            {
                ps = GetComponent <ParticleSystem>();
            }

            if (particleSystemRenderer == null)
            {
                // If the link is to ParticleSystemRenderer, cash it and make sure we have right streams
                particleSystemRenderer = ps.GetComponent <ParticleSystemRenderer>();
                var streams = new List <ParticleSystemVertexStream>();
                particleSystemRenderer.GetActiveVertexStreams(streams);
                // Adding additional stream to Vector2(UV2, SizeXY, etc.), so that the coordinates in the script match the coordinates in the shader
                if (!streams.Contains(ParticleSystemVertexStream.UV2))
                {
                    streams.Add(ParticleSystemVertexStream.UV2);
                }
                if (!streams.Contains(ParticleSystemVertexStream.Custom1XYZW))
                {
                    streams.Add(ParticleSystemVertexStream.Custom1XYZW);
                }
                if (!streams.Contains(ParticleSystemVertexStream.Custom2XYZW))
                {
                    streams.Add(ParticleSystemVertexStream.Custom2XYZW);
                }
                particleSystemRenderer.SetActiveVertexStreams(streams);
            }

            // Initializing emission parameters
            // The color and position are obtained from the method parameters
            // Set startSize3D to X so that the characters are not stretched or compressed
            // when changing the length of the message
            var emitParams = new ParticleSystem.EmitParams
            {
                startColor           = color,
                position             = position,
                applyShapeToPosition = true,
                startSize3D          = new Vector3(messageLenght, 1, 1)
            };

            // If we want to create particles of different sizes, then in the parameters of SpawnParticle it is necessary
            // to transfer the desired startSize value
            if (startSize.HasValue)
            {
                emitParams.startSize3D *= startSize.Value * ps.main.startSizeMultiplier;
            }
            // Directly the spawn of the particles
            ps.Emit(emitParams, 1);

            // Transferring the custom data to the needed streams
            var customData = new List <Vector4>();

            // Getting the stream ParticleSystemCustomData.Custom1 from ParticleSystem
            ps.GetCustomParticleData(customData, ParticleSystemCustomData.Custom1);
            // Changing the data of the last element, i.e. the particle, that we have just created
            customData[customData.Count - 1] = custom1Data;
            // Returning the data to ParticleSystem
            ps.SetCustomParticleData(customData, ParticleSystemCustomData.Custom1);

            // The same for ParticleSystemCustomData.Custom2
            ps.GetCustomParticleData(customData, ParticleSystemCustomData.Custom2);
            customData[customData.Count - 1] = custom2Data;
            ps.SetCustomParticleData(customData, ParticleSystemCustomData.Custom2);
        }
    void DrawMainSettings()
    {
        Particle_Render = FindProperty("Particle_Render", _props);
        _MinRange       = FindProperty("_MinRange", _props);
        _MaxRange       = FindProperty("_MaxRange", _props);

        _materialEditor.ShaderProperty(Particle_Render, "Setup for Particle System");

        GameObject go = Selection.activeObject as GameObject;

        if (go != null)
        {
            ParticleSystemRenderer particles = go.GetComponent <ParticleSystemRenderer>();
            bool setupForParticles           = Particle_Render.floatValue != 0.0f;
            if (setupForParticles)
            {
                if (particles != null)
                {
                    List <ParticleSystemVertexStream> streams = new List <ParticleSystemVertexStream>();
                    particles.GetActiveVertexStreams(streams);
                    bool correctSetup = particles.activeVertexStreamsCount >= 2 && streams.Contains(ParticleSystemVertexStream.Position) && streams.Contains(ParticleSystemVertexStream.Center);
                    if (!correctSetup)
                    {
                        EditorGUILayout.HelpBox("Particle System Renderer is using this material with incorrect Vertex Streams. Use Apply to System button to fix this", MessageType.Warning);
                        if (GUILayout.Button("Apply to System"))
                        {
                            if (!streams.Contains(ParticleSystemVertexStream.Position))
                            {
                                streams.Add(ParticleSystemVertexStream.Position);
                            }
                            if (!streams.Contains(ParticleSystemVertexStream.Center))
                            {
                                streams.Add(ParticleSystemVertexStream.Center);
                            }
                            particles.SetActiveVertexStreams(streams);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Shader rendered by Mesh Renderer, but using setup for particles. Shader will be appearing incorrectly!", MessageType.Warning);
                    if (GUILayout.Button("Fix now"))
                    {
                        Particle_Render.floatValue = 0.0f;
                    }
                }
            }
            else
            {
                if (particles != null)
                {
                    EditorGUILayout.HelpBox("Shader rendered by Particle System, but using setup for meshes. Shader will be appearing incorrectly!", MessageType.Warning);
                    if (GUILayout.Button("Fix now"))
                    {
                        Particle_Render.floatValue = 1.0f;
                    }
                }
            }
        }

        GUILayout.Label("Fade settings", EditorStyles.boldLabel);
        _materialEditor.ShaderProperty(_MinRange, "Start fading");
        _materialEditor.ShaderProperty(_MaxRange, "End fading");
        GUILayout.Label("Editor settings", EditorStyles.boldLabel);
        useSliders = EditorGUILayout.Toggle("More SLIDERS!!!", useSliders);
        if (GUILayout.Button("[Experimental] Setup random effects"))
        {
            Glitch.floatValue                = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Magnification.floatValue         = Mathf.RoundToInt(UnityEngine.Random.Range(0, 5));
            _SizeGirls.floatValue            = UnityEngine.Random.value * 0.6f;
            ScreenRotation.floatValue        = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            _ScreenHorizontalFlip.floatValue = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            _ScreenVerticalFlip.floatValue   = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Shake.floatValue        = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Pixelization.floatValue = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Distorsion.floatValue   = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Blur.floatValue         = Mathf.RoundToInt(UnityEngine.Random.Range(0, 4));
            if (Blur.floatValue == 0)
            {
                Chromatic_Aberration.floatValue = Mathf.RoundToInt(UnityEngine.Random.Range(0, 2));
            }
            Neon.floatValue            = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            HSV_Selection.floatValue   = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            HSV_Transform.floatValue   = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Color_Tint.floatValue      = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Posterization.floatValue   = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Dithering.floatValue       = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Overlay_Texture.floatValue = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Static_Noise.floatValue    = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Vignette.floatValue        = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
            Mask_Texture.floatValue    = Mathf.RoundToInt(UnityEngine.Random.value * 0.6f);
        }
    }