public ColorGenerator(ColorSettings settings, int resolution) { Settings = settings; Resolution = resolution; texture = new GradientTexture(); texture.Width = textureResolution; }
private void UpdateMaterialProperties() { if (properties == null) { properties = new MaterialPropertyBlock(); } /* * Vector3 halfExtent = 0.5f * Vector3.one; * Vector3 boundsMax = transform.TransformPoint(halfExtent); * Vector3 boundsMin = transform.TransformPoint(-halfExtent);*/ properties.SetInt("_useGradient", (this.Mode == VolumeMode.Gradient ? 1 : 0)); //properties.SetVector("boundsMax", boundsMax); //properties.SetVector("boundsMin", boundsMin); //properties.SetVector("up", transform.up); //properties.SetVector("forward", transform.forward); //properties.SetVector("right", transform.right); //properties.SetVector("origin", transform.position); properties.SetVector("scale", transform.lossyScale); properties.SetMatrix("transformMatrix", transform.worldToLocalMatrix); if (this.Mode == VolumeMode.Color) { properties.SetColor("_Color", Color); } else { GradientTexture.UpdateTexture(Gradient, ref gradientTexture, SampleCount, GradientOffset, InvertGradient); properties.SetTexture("_gradient", gradientTexture); properties.SetInt("_gradientMode", (int)GradientType); } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { GradientTexture gradientTexture = target as GradientTexture; Texture2D texture = gradientTexture.GetTexture(); if (texture != null) { Rect previewRect = new Rect(r); float textureAspectRatio = gradientTexture.resolution.x / gradientTexture.resolution.y; float previewAspectRatio = r.width / r.height; if (textureAspectRatio >= previewAspectRatio) { float scale = gradientTexture.resolution.x / r.width; float newHeight = gradientTexture.resolution.y / scale; previewRect.width = r.width; previewRect.height = newHeight; previewRect.y = (r.height / 2.0f) - (newHeight / 2.0f); } else { float scale = gradientTexture.resolution.y / r.height; float newWidth = gradientTexture.resolution.x / scale; previewRect.width = newWidth; previewRect.height = r.height; previewRect.x = (r.width / 2.0f) - (newWidth / 2.0f); } EditorGUI.DrawPreviewTexture(previewRect, texture); } }
public void SetEnemyGroupColors(Color spriteColor, GradientTexture particlesGradient) { _interactionSprite.SetSelfModulate(spriteColor); _interactionParticles.ProcessMaterial.Set("color_ramp", particlesGradient); _spawnGradientTexture = particlesGradient; }
public void InterpolatesBetweenColors() { var texture = new GradientTexture(Colors.White, Colors.Black); texture.LocalColorAt(new Point(0, 0, 0)).Should().Be(Colors.White); texture.LocalColorAt(new Point(0.25f, 0, 0)).Should().Be(new Color(0.75f, 0.75f, 0.75f)); texture.LocalColorAt(new Point(0.5f, 0, 0)).Should().Be(new Color(0.5f, 0.5f, 0.5f)); texture.LocalColorAt(new Point(0.75f, 0, 0)).Should().Be(new Color(0.25f, 0.25f, 0.25f)); }
public override void OnInspectorGUI() { DrawDefaultInspector(); if (GUILayout.Button("Generate Texture") == true) { GradientTexture gradientTexture = target as GradientTexture; gradientTexture.CreateTexture(); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); GradientTexture myScript = (GradientTexture)target; if (GUILayout.Button("Generate Texture")) { myScript.Refresh(); myScript.GenerateFile(); } }
public override void _Ready() { _world = (World)GetNode("/root/World"); _light = (Light2D)GetNode("Light2D"); var mat = (ParticlesMaterial)ProcessMaterial; _sound = (AudioStreamPlayer)FindNode("ExtinguishSound"); var gradient = new Gradient(); gradient.AddPoint(2048 * 0.0f, new Color(255, 0, 0)); gradient.AddPoint(2048 * 0.2f, new Color(255, 90, 0)); gradient.AddPoint(2048 * 0.4f, new Color(255, 109, 0)); gradient.AddPoint(2048 * 0.6f, new Color(255, 154, 0)); gradient.AddPoint(2048 * 0.8f, new Color(255, 206, 0)); gradient.AddPoint(2048 * 1.0f, new Color(255, 226, 6)); var gradientTex = new GradientTexture(); gradientTex.SetGradient(gradient); gradientTex.SetWidth(2048); var scale = new Curve(); scale.AddPoint(new Vector2(0.0f, 1.0f)); scale.AddPoint(new Vector2(1.0f, 0.5f)); var scaleTex = new CurveTexture(); scaleTex.SetCurve(scale); var matCopy = new ParticlesMaterial() { EmissionShape = ParticlesMaterial.EMISSION_SHAPE_SPHERE, EmissionSphereRadius = 10, FlagDisableZ = true, Spread = 180, Gravity = new Vector3(0, -98, 0), InitialVelocity = 2, InitialVelocityRandom = 1, AngularVelocity = 10, RadialAccel = -15, Scale = 3, ColorRamp = gradientTex, ScaleCurve = scaleTex }; this.ProcessMaterial = matCopy; }
public override void OnInspectorGUI() { PlanetGenerator planetGen = (PlanetGenerator)target; GradientTexture gradientTexture = planetGen.GetComponent <GradientTexture> (); base.OnInspectorGUI(); if (GUILayout.Button("Generate")) { ScreenCapture.CaptureScreenshot(i++.ToString() + ".png"); planetGen.CreatePlanet(); //planetGen.CreateDetailedPlanet (); //gradientTexture.ChangeColor (); } if (GUILayout.Button("Recreate")) { planetGen.icosphere = null; planetGen.CreatePlanet(); //planetGen.CreateDetailedPlanet (); } }
public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); SerializedProperty gradient = serializedObject.FindProperty("gradient"); SerializedProperty wrapMode = serializedObject.FindProperty("wrapMode"); SerializedProperty filterMode = serializedObject.FindProperty("filterMode"); SerializedProperty resolution = serializedObject.FindProperty("resolution"); SerializedProperty useSharedMaterial = serializedObject.FindProperty("useSharedMaterial"); SerializedProperty anisoLevel = serializedObject.FindProperty("anisoLevel"); GradientTexture ct = target as GradientTexture; Renderer r = ct.GetComponent <Renderer>(); if (r == null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("global name"); ct.globalName = EditorGUILayout.TextField(ct.globalName); EditorGUILayout.EndHorizontal(); } else { Material mat = r.sharedMaterial; Shader s = mat.shader; int count = ShaderUtil.GetPropertyCount(s); List <string> textureNames = new List <string>(); for (int i = 0; i < count; ++i) { if (ShaderUtil.GetPropertyType(s, i) == ShaderUtil.ShaderPropertyType.TexEnv) { textureNames.Add(ShaderUtil.GetPropertyName(s, i)); } } int index = textureNames.IndexOf(ct.propertyName); int newIdx = EditorGUILayout.Popup(index, textureNames.ToArray()); if (newIdx != index) { ct.propertyName = textureNames[newIdx]; } } EditorGUILayout.PropertyField(gradient); EditorGUILayout.PropertyField(wrapMode); EditorGUILayout.PropertyField(filterMode); EditorGUILayout.PropertyField(resolution); if (r != null) { EditorGUILayout.PropertyField(useSharedMaterial); } EditorGUILayout.PropertyField(anisoLevel); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); ct.Refresh(); } if (GUILayout.Button("Save Texture")) { string path = EditorUtility.SaveFilePanel("Save Texture", Application.dataPath, "curve", "png"); if (!string.IsNullOrEmpty(path)) { Texture2D tex = ct.Generate(false); byte[] bytes = tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); DestroyImmediate(tex); AssetImporter ai = AssetImporter.GetAtPath(path); if (ai != null) { TextureImporter ti = ai as TextureImporter; ti.anisoLevel = ct.anisoLevel; ti.linearTexture = true; ti.generateMipsInLinearSpace = true; ti.filterMode = ct.filterMode; ti.wrapMode = ct.wrapMode; ti.textureFormat = TextureImporterFormat.ARGB32; ti.SaveAndReimport(); } } } }
public void SetEffectGradient(GradientTexture effectGradientTexture) => _deathEffect_1.ProcessMaterial.Set("color_ramp", effectGradientTexture);