void CreateShader() { if (ShaderTemplateManager.Instance().IsExist(shaderName)) { return; } var st = new ShaderTemplate(shaderName, @" varying vec2 vUv; void main() { vUv = uv; gl_Position = vec4( position, 1.0 ); } ", @" varying vec2 vUv; uniform float time; void main() { vec2 p = - 1.0 + 2.0 * vUv; float a = time * 40.0; float d, e, f, g = 1.0 / 40.0 ,h ,i ,r ,q; e = 400.0 * ( p.x * 0.5 + 0.5 ); f = 400.0 * ( p.y * 0.5 + 0.5 ); i = 200.0 + sin( e * g + a / 150.0 ) * 20.0; d = 200.0 + cos( f * g / 2.0 ) * 18.0 + cos( e * g ) * 7.0; r = sqrt( pow( abs( i - e ), 2.0 ) + pow( abs( d - f ), 2.0 ) ); q = f / r; e = ( r * cos( q ) ) - a / 2.0; f = ( r * sin( q ) ) - a / 2.0; d = sin( e * g ) * 176.0 + sin( e * g ) * 164.0 + r; h = ( ( f + d ) + a / 2.0 ) * g; i = cos( h + r * p.x / 1.3 ) * ( e + e + a ) + cos( q * g * 6.0 ) * ( r + h / 3.0 ); h = sin( f * g ) * 144.0 - sin( e * g ) * 212.0 * p.x; h = ( h + ( f - e ) * q + sin( r - ( a + h ) / 7.0 ) * 10.0 + i / 4.0 ) * g; i += cos( h * 2.3 * sin( a / 350.0 - q ) ) * 184.0 * sin( q - ( r * 4.3 + a / 12.0 ) * g ) + tan( r * g + h ) * 184.0 * cos( r * g + h ); i = mod( i / 5.6, 256.0 ) / 64.0; if ( i < 0.0 ) i += 4.0; if ( i >= 2.0 ) i = 4.0 - i; d = r / 350.0; d += sin( d * d * 8.0 ) * 0.52; f = ( sin( a * g ) + 1.0 ) / 2.0; gl_FragColor = vec4( vec3( f * i / 1.6, i / 2.0 + d / 13.0, i ) * d * p.x + vec3( i / 1.3 + d / 8.0, i / 2.0 + d / 18.0, i ) * d * ( 1.0 - p.x ), 1.0 ); } " , @" float time 1.0; " ); ShaderTemplateManager.Instance().Add(st); }
internal void DrawVertexDataStream(MaterialEditor materialEditor, ShaderTemplate shaderTemplate) { EditorHelper.VerticalSpace(); EditorGUI.BeginChangeCheck(); { foreach (Material mat in _colorBlend.targets) { VertexStreamsArea(mat, m_RenderersUsingThisMaterial, shaderTemplate); } } EditorGUI.EndChangeCheck(); }
///////////////// // Advanced // ///////////////// private static void VertexStreamsArea(Material material, List <ParticleSystemRenderer> renderers, ShaderTemplate shaderTemplate) { bool useLighting, isPBS; useLighting = shaderTemplate != ShaderTemplate.Unlit ? true : false; isPBS = shaderTemplate == ShaderTemplate.PhysicallyBased ? true : false; EditorGUILayout.Space(); // Display list of streams required to make this shader work bool useNormalMap = false; bool useFlipbookBlending = Properties.flipbook.GetValue(material); if (useLighting) { useNormalMap = Properties.normalMap.GetValue(material) != null; } bool useHeightMap = false; if (isPBS) { useHeightMap = Properties.heightMap.GetValue(material) != null; } bool useDetailNormalMap = false; if (isPBS) { useDetailNormalMap = Properties.detailNormalMap.GetValue(material) != null && isPBS; } bool useAnisotropicSpecular = false; if (useLighting) { useAnisotropicSpecular = Properties.specular.GetValue(material) != Specular.Anisotropic && isPBS; } // Build the list of expected vertex streams List <ParticleSystemVertexStream> streams = new List <ParticleSystemVertexStream>(); List <string> streamList = new List <string>(); streams.Add(ParticleSystemVertexStream.Position); streamList.Add(EditorHelper.EditorStyles.streamPositionText); if (useLighting) { streams.Add(ParticleSystemVertexStream.Normal); streamList.Add(EditorHelper.EditorStyles.streamNormalText); if (useNormalMap || useDetailNormalMap || useDetailNormalMap || useHeightMap) { streams.Add(ParticleSystemVertexStream.Tangent); streamList.Add(EditorHelper.EditorStyles.streamTangentText); } } streams.Add(ParticleSystemVertexStream.Color); streamList.Add(EditorHelper.EditorStyles.streamColorText); streams.Add(ParticleSystemVertexStream.UV); streamList.Add(EditorHelper.EditorStyles.streamUVText); if (useFlipbookBlending) { streams.Add(ParticleSystemVertexStream.UV2); streamList.Add(EditorHelper.EditorStyles.streamUV2Text); streams.Add(ParticleSystemVertexStream.AnimBlend); streamList.Add(EditorHelper.EditorStyles.streamAnimBlendText); } vertexStreamList = new ReorderableList(streamList, typeof(string), false, true, false, false); vertexStreamList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Vertex Streams"); }; vertexStreamList.DoLayoutList(); // Display a warning if any renderers have incorrect vertex streams string Warnings = ""; List <ParticleSystemVertexStream> rendererStreams = new List <ParticleSystemVertexStream>(); foreach (ParticleSystemRenderer renderer in renderers) { renderer.GetActiveVertexStreams(rendererStreams); if (!rendererStreams.SequenceEqual(streams)) { Warnings += "-" + renderer.name + "\n"; } } if (!string.IsNullOrEmpty(Warnings)) { EditorGUILayout.HelpBox( "The following Particle System Renderers are using this material with incorrect Vertex Streams:\n" + Warnings, MessageType.Error, true); // Set the streams on all systems using this material if (GUILayout.Button(EditorHelper.EditorStyles.streamApplyToAllSystemsText, EditorStyles.miniButton, GUILayout.ExpandWidth(true))) { Undo.RecordObjects(renderers.Where(r => r != null).ToArray(), EditorHelper.EditorStyles.undoApplyCustomVertexStreams); foreach (ParticleSystemRenderer renderer in renderers) { renderer.SetActiveVertexStreams(streams); } } } }
internal void DrawParticles(MaterialEditor materialEditor, MaterialProperty[] properties, MaterialProperty surface, ShaderTemplate shaderTemplate) { //All refraction properties needs to be available on the material //the refraction tab is used for check if (_particlesBehavior != null) { if (EditorHelper.HandleBehavior(UI.particlesTab.text, "", _particlesBehavior, null, materialEditor, false)) { DrawColorBlend(materialEditor); DrawFlipbookMode(materialEditor); DrawSoftFadeMode(materialEditor, (Surface)surface.floatValue); DrawCameraFadeMode(materialEditor, (Surface)surface.floatValue); DrawVertexDataStream(materialEditor, shaderTemplate); } EditorHelper.DrawSplitter(); } }