public void GenerateTextures() { rTexture = MaterialUtils.GenerateGradientTexture(100, 20, new Color(0.0f, currentColor.g, currentColor.b, 1.0f), new Color(1.0f, currentColor.g, currentColor.b, 1.0f)); gTexture = MaterialUtils.GenerateGradientTexture(100, 20, new Color(currentColor.r, 0f, currentColor.b, 1.0f), new Color(currentColor.r, 1f, currentColor.b, 1.0f)); bTexture = MaterialUtils.GenerateGradientTexture(100, 20, new Color(currentColor.r, currentColor.g, 0f, 1.0f), new Color(currentColor.r, currentColor.g, 1f, 1.0f)); swatch = MaterialUtils.GenerateColorTexture(60, 20, currentColor); }
protected void InitializeShaderProperties(Material m) { colorValues = new Dictionary <string, Color>(); floatValues = new Dictionary <string, float>(); textureValues = new Dictionary <string, string>(); textureEdits = new Dictionary <string, bool>(); textureScaleValues = new Dictionary <string, Vector2>(); textureOffsetValues = new Dictionary <string, Vector2>(); vec4Values = new Dictionary <string, Vector4>(); colorStrings = new Dictionary <string, string[]>(); colorEdits = new Dictionary <string, bool>(); floatStrings = new Dictionary <string, string>(); textureOffsetStrings = new Dictionary <string, string[]>(); textureScaleStrings = new Dictionary <string, string[]>(); vec4Strings = new Dictionary <string, string[]>(); colorTextures = new Dictionary <string, Texture2D>(); foreach (KeyValuePair <string, MaterialData> mProp in WaterfallConstants.ShaderPropertyMap) { if (m.HasProperty(mProp.Key)) { if (mProp.Value.type == WaterfallMaterialPropertyType.Color) { colorValues.Add(mProp.Key, m.GetColor(mProp.Key)); colorEdits.Add(mProp.Key, false); colorStrings.Add(mProp.Key, MaterialUtils.ColorToStringArray(m.GetColor(mProp.Key))); colorTextures.Add(mProp.Key, MaterialUtils.GenerateColorTexture(32, 32, m.GetColor(mProp.Key))); } if (mProp.Value.type == WaterfallMaterialPropertyType.Float) { floatValues.Add(mProp.Key, m.GetFloat(mProp.Key)); floatStrings.Add(mProp.Key, m.GetFloat(mProp.Key).ToString()); } if (mProp.Value.type == WaterfallMaterialPropertyType.Vector4) { Vector4 vec4 = m.GetVector(mProp.Key); vec4Values.Add(mProp.Key, vec4); vec4Strings.Add(mProp.Key, new string[] { $"{vec4.x}", $"{vec4.y}", $"{vec4.z}", $"{vec4.w}" }); } if (mProp.Value.type == WaterfallMaterialPropertyType.Texture) { textureValues.Add(mProp.Key, m.GetTexture(mProp.Key).name); textureEdits.Add(mProp.Key, false); textureScaleValues.Add(mProp.Key, m.GetTextureScale(mProp.Key)); textureOffsetValues.Add(mProp.Key, m.GetTextureOffset(mProp.Key)); textureOffsetStrings.Add(mProp.Key, new string[] { $"{m.GetTextureOffset(mProp.Key).x}", $"{m.GetTextureOffset(mProp.Key).y}" }); textureScaleStrings.Add(mProp.Key, new string[] { $"{m.GetTextureScale(mProp.Key).x}", $"{m.GetTextureScale(mProp.Key).y}" }); } } } }
void GetLightValues() { intensityValue = light.intensity; intensityString = light.intensity.ToString(); rangeString = light.range.ToString(); rangeValue = light.range; angleString = light.angle.ToString(); angleValue = light.angle; colorValue = light.color; colorString = MaterialUtils.ColorToStringArray(colorValue); colorTexture = MaterialUtils.GenerateColorTexture(32, 32, colorValue); if (light.lightType == LightType.Point) { typeFlag = 1; } else { typeFlag = 0; } }
protected void DrawMaterialEdit() { float headerWidth = 120f; bool delta = false; GUILayout.Label("<b>Textures</b>"); foreach (KeyValuePair <string, string> kvp in textureValues.ToList()) { GUILayout.BeginHorizontal(); GUILayout.Label($"{kvp.Key}", GUILayout.Width(headerWidth)); GUILayout.Label("Texture Path"); // Button to set that we are toggling the texture picker if (GUILayout.Button(kvp.Value)) { textureEdits[kvp.Key] = !textureEdits[kvp.Key]; Utils.Log($"[TP] Edit flag state {textureEdits[kvp.Key]}", LogType.UI); // if yes, open the window if (textureEdits[kvp.Key]) { WaterfallUI.Instance.OpenTextureEditWindow(kvp.Key, textureValues[kvp.Key]); Utils.Log("[TP] Open Window", LogType.UI); } } // If picker open if (textureEdits[kvp.Key]) { // Close all other pickers foreach (KeyValuePair <string, bool> kvp2 in textureEdits.ToList()) { if (kvp2.Key != kvp.Key) { textureEdits[kvp2.Key] = false; } } string newTex = WaterfallUI.Instance.GetTextureFromPicker(); if (newTex != kvp.Value) { textureValues[kvp.Key] = newTex; Utils.Log($"[MaterialEditWindow] Changed {kvp.Key} to {textureValues[kvp.Key]}", LogType.UI); model.SetTexture(matl, kvp.Key, textureValues[kvp.Key]); } } GUILayout.EndHorizontal(); delta = false; GUILayout.BeginHorizontal(); GUILayout.Space(headerWidth); GUILayout.Label($"UV Scale", GUILayout.Width(headerWidth)); textureScaleValues[kvp.Key] = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), textureScaleValues[kvp.Key], textureScaleStrings[kvp.Key], GUI.skin.label, GUI.skin.textArea, out delta); if (delta) { model.SetTextureScale(matl, kvp.Key, textureScaleValues[kvp.Key]); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(headerWidth); GUILayout.Label($"UV Offset", GUILayout.Width(headerWidth)); textureOffsetValues[kvp.Key] = UIUtils.Vector2InputField(GUILayoutUtility.GetRect(200f, 30f), textureOffsetValues[kvp.Key], textureOffsetStrings[kvp.Key], GUI.skin.label, GUI.skin.textArea, out delta); if (delta) { model.SetTextureOffset(matl, kvp.Key, textureOffsetValues[kvp.Key]); } GUILayout.EndHorizontal(); } GUILayout.Label("<b>Material Parameters</b>"); foreach (KeyValuePair <string, Color> kvp in colorValues.ToList()) { GUILayout.BeginHorizontal(); GUILayout.Label(kvp.Key, GUILayout.Width(headerWidth)); GUILayout.Space(10); // Button to set that we are toggling the color picker if (GUILayout.Button("", GUILayout.Width(60))) { colorEdits[kvp.Key] = !colorEdits[kvp.Key]; Utils.Log($"[CP] Edit flag state {colorEdits[kvp.Key]}", LogType.UI); // if yes, open the window if (colorEdits[kvp.Key]) { WaterfallUI.Instance.OpenColorEditWindow(colorValues[kvp.Key]); Utils.Log("[CP] Open Window", LogType.UI); } } // If picker open if (colorEdits[kvp.Key]) { // Close all other pickers foreach (KeyValuePair <string, bool> kvp2 in colorEdits.ToList()) { if (kvp2.Key != kvp.Key) { colorEdits[kvp2.Key] = false; } } Color c = WaterfallUI.Instance.GetColorFromPicker(); if (!c.IsEqualTo(colorValues[kvp.Key])) { colorValues[kvp.Key] = c; delta = true; } } Rect tRect = GUILayoutUtility.GetLastRect(); tRect = new Rect(tRect.x + 3, tRect.y + 3, tRect.width - 6, tRect.height - 6); GUI.DrawTexture(tRect, colorTextures[kvp.Key]); //GUILayout.Space(10); //colorValues[kvp.Key] = UIUtils.ColorInputField(GUILayoutUtility.GetRect(200f, 30f), colorValues[kvp.Key], colorStrings[kvp.Key], GUI.skin.label, GUI.skin.textArea, out delta); if (delta) { colorTextures[kvp.Key] = MaterialUtils.GenerateColorTexture(64, 32, colorValues[kvp.Key]); model.SetColor(matl, kvp.Key, colorValues[kvp.Key]); } GUILayout.EndHorizontal(); } foreach (KeyValuePair <string, float> kvp in floatValues.ToList()) { float sliderVal; string textVal; GUILayout.BeginHorizontal(); GUILayout.Label(kvp.Key, GUILayout.Width(headerWidth)); sliderVal = GUILayout.HorizontalSlider(floatValues[kvp.Key], WaterfallConstants.ShaderPropertyMap[kvp.Key].floatRange.x, WaterfallConstants.ShaderPropertyMap[kvp.Key].floatRange.y); if (sliderVal != floatValues[kvp.Key]) { floatValues[kvp.Key] = sliderVal; floatStrings[kvp.Key] = sliderVal.ToString(); model.SetFloat(matl, kvp.Key, floatValues[kvp.Key]); } textVal = GUILayout.TextArea(floatStrings[kvp.Key], GUILayout.Width(90f)); if (textVal != floatStrings[kvp.Key]) { float outVal; if (float.TryParse(textVal, out outVal)) { floatValues[kvp.Key] = outVal; model.SetFloat(matl, kvp.Key, floatValues[kvp.Key]); } floatStrings[kvp.Key] = textVal; } //float parsed = kvp.Value; //if (float.TryParse(textVal, out parsed)) //{ // if (parsed != floatValues[kvp.Key]) // { // floatValues[kvp.Key] = parsed; // matl.SetFloat(kvp.Key, parsed); // } //} GUILayout.EndHorizontal(); } foreach (KeyValuePair <string, Vector4> kvp in vec4Values.ToList()) { Vector3 vecVal; string textVal; GUILayout.BeginHorizontal(); GUILayout.Label(kvp.Key, GUILayout.Width(headerWidth)); vecVal = UIUtils.Vector3InputField(GUILayoutUtility.GetRect(200f, 30f), kvp.Value, vec4Strings[kvp.Key], GUI.skin.label, GUI.skin.textArea); Vector4 temp = new Vector4(vecVal.x, vecVal.y, vecVal.z, 0f); if (temp != vec4Values[kvp.Key]) { vec4Values[kvp.Key] = temp; matl.SetVector4(kvp.Key, temp); } GUILayout.EndHorizontal(); } }
protected void DrawLightEdit() { float headerWidth = 120f; bool delta = false; float sliderVal; string textVal; GUILayout.Label("<b>Light Parameters</b>"); GUILayout.BeginHorizontal(); GUILayout.Label("Light Color", GUILayout.Width(headerWidth)); GUILayout.Space(10); // Button to set that we are toggling the color picker if (GUILayout.Button("", GUILayout.Width(60))) { colorEdit = !colorEdit; Utils.Log($"[CP] Edit flag state {colorEdit}", LogType.UI); // if yes, open the window if (colorEdit) { WaterfallUI.Instance.OpenColorEditWindow(colorValue); Utils.Log("[CP] Open Window", LogType.UI); } } // If picker open if (colorEdit) { // Close all other pickers Color c = WaterfallUI.Instance.GetColorFromPicker(); if (!c.IsEqualTo(colorValue)) { colorValue = c; delta = true; } if (delta) { colorTexture = MaterialUtils.GenerateColorTexture(64, 32, colorValue); model.SetLightColor(light, colorValue); } } Rect tRect = GUILayoutUtility.GetLastRect(); tRect = new Rect(tRect.x + 3, tRect.y + 3, tRect.width - 6, tRect.height - 6); GUI.DrawTexture(tRect, colorTexture); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Light Type", GUILayout.Width(headerWidth)); int newFlag = GUILayout.SelectionGrid(typeFlag, typeOptions, 2, GUIResources.GetStyle("radio_text_button")); if (newFlag != typeFlag) { typeFlag = newFlag; if (typeFlag == 1) { model.SetLightType(light, LightType.Point); } if (typeFlag == 0) { model.SetLightType(light, LightType.Spot); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Intensity", GUILayout.Width(headerWidth)); sliderVal = GUILayout.HorizontalSlider(intensityValue, 0f, 10f); if (sliderVal != intensityValue) { intensityValue = sliderVal; intensityString = sliderVal.ToString(); model.SetLightIntensity(light, intensityValue); } textVal = GUILayout.TextArea(intensityString, GUILayout.Width(90f)); if (textVal != intensityString) { float outVal; if (float.TryParse(textVal, out outVal)) { intensityValue = outVal; model.SetLightIntensity(light, intensityValue); } intensityString = textVal; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Range", GUILayout.Width(headerWidth)); sliderVal = GUILayout.HorizontalSlider(rangeValue, 0f, 100f); if (sliderVal != rangeValue) { rangeValue = sliderVal; rangeString = sliderVal.ToString(); model.SetLightRange(light, rangeValue); } textVal = GUILayout.TextArea(rangeString, GUILayout.Width(90f)); if (textVal != rangeString) { float outVal; if (float.TryParse(textVal, out outVal)) { rangeValue = outVal; model.SetLightRange(light, rangeValue); } rangeString = textVal; } GUILayout.EndHorizontal(); if (typeFlag == 0) { GUILayout.BeginHorizontal(); GUILayout.Label("Spot Angle", GUILayout.Width(headerWidth)); sliderVal = GUILayout.HorizontalSlider(angleValue, 0f, 100f); if (sliderVal != angleValue) { angleValue = sliderVal; angleString = sliderVal.ToString(); model.SetLightAngle(light, angleValue); } textVal = GUILayout.TextArea(angleString, GUILayout.Width(90f)); if (textVal != angleString) { float outVal; if (float.TryParse(textVal, out outVal)) { angleValue = outVal; model.SetLightAngle(light, angleValue); } angleString = textVal; } GUILayout.EndHorizontal(); } }