//public Texture m_Cached; public override Node Create(Vector2 pos) { CreateOpCol node = CreateInstance <CreateOpCol>(); node.rect = new Rect(pos.x, pos.y, m_NodeWidth, m_NodeHeight); node.name = "CreateOpCol"; node.CreateOutput("Texture", "TextureParam", NodeSide.Right, 50); node.m_Value1 = new FloatRemap(0.5f, 0, 1); node.m_Value2 = new FloatRemap(0.5f, 0, 1); node.m_Value3 = new FloatRemap(0.5f, 0, 1); node.m_ShaderOp = ShaderOp.SetCol; node.m_TexMode = TexMode.ColorRGB; return(node); }
void OnGUI() { EditorGUILayout.LabelField("\n Warning: Erases Current Canvas", EditorStyles.wordWrappedLabel); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Width"); m_Width = EditorGUILayout.IntField(m_Width); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Height"); m_Height = EditorGUILayout.IntField(m_Height); EditorGUILayout.EndHorizontal(); m_PixelDepth = (ChannelType)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Pixel Depth", "bytes Per pixel/accuracy"), m_PixelDepth, GUILayout.MaxWidth(300)); EditorGUILayout.Separator(); m_CreateUnityTex = EditorGUILayout.Toggle("Create UnityTextureOutput nodes and textures", m_CreateUnityTex); m_LoadTestCubeScene = EditorGUILayout.Toggle("Throw Away current Scene and load test cube", m_LoadTestCubeScene); GUI.enabled = m_CreateUnityTex; m_CreateMaterial = EditorGUILayout.BeginToggleGroup("Create new material ", m_CreateMaterial); EditorGUI.indentLevel++; var text = new string[] { "Create new standard Unity material with new textures", "Create new tesselated dx11 material with new textures" }; m_CreateMaterialType = GUILayout.SelectionGrid(m_CreateMaterialType, text, 1, EditorStyles.radioButton); EditorGUI.indentLevel--; //m_CreateUnityMaterial = EditorGUILayout.Toggle("Create new standard Unity material with new textures",m_CreateUnityMaterial); //m_CreateTesselatedMaterial = EditorGUILayout.Toggle("Create new tesselated dx11 material with new textures", m_CreateTesselatedMaterial); EditorGUILayout.EndToggleGroup(); m_Path = EditorGUILayout.TextField(m_Path); if (GUILayout.Button(new GUIContent("Browse Output Path", "Path to Output Textures to"))) { m_Path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", "", "png", "", m_Path); } GUI.enabled = true; EditorGUILayout.Separator(); // m_Height = EditorGUILayout.IntField(m_Height); // m_Noise = EditorGUILayout.FloatField(m_Noise); GUILayout.BeginHorizontal(); if (GUILayout.Button("Cancel")) { this.Close(); } if (GUILayout.Button("Create")) { m_Parent.NewNodeCanvas(m_Width, m_Height); if (m_CreateUnityTex) { if (m_Path.EndsWith("_albedo.png")) { m_Path = m_Path.Replace("_albedo.png", ".png"); } if (m_Path.EndsWith("_normal.png")) { m_Path = m_Path.Replace("_albedo.png", ".png"); } if (m_Path.EndsWith("_MetalAndRoughness.png")) { m_Path = m_Path.Replace("_MetalAndRoughness.png", ".png"); } if (m_Path.EndsWith("_height.png")) { m_Path = m_Path.Replace("_height.png", ".png"); } if (m_Path.EndsWith("_occlusion.png")) { m_Path = m_Path.Replace("_occlusion.png", ".png"); } if (m_LoadTestCubeScene) { if (m_CreateMaterial && m_CreateMaterialType == 1) { EditorSceneManager.OpenScene("Assets/TextureWang/Scenes/DoNotEdit/testplaneTesselated.unity"); } else { EditorSceneManager.OpenScene("Assets/TextureWang/Scenes/DoNotEdit/testcube.unity"); } } //Sigh, unity destroys scriptable objects when you call OpenScene, and you cant use dontdestroyonload NodeEditor.ReInit(true); m_Parent.NewNodeCanvas(m_Width, m_Height, m_PixelDepth); //required to add nodes to canvas NodeEditor.curNodeCanvas = NodeEditorTWWindow.canvasCache.nodeCanvas; float yOffset = 200; Node node; var albedo = MakeTextureNodeAndTexture("_albedo", new Vector2(0, 0), false, "UnityTextureOutput", out node); var norms = MakeTextureNodeAndTexture("_normal", new Vector2(0, 1 * yOffset), true, "UnityTextureOutput", out node); Node calcNorm = Node.Create("CalcNormal", node.rect.position - new Vector2(250, 0)); node.Inputs[0].ApplyConnection(calcNorm.Outputs[0]); var height = MakeTextureNodeAndTexture("_height", new Vector2(0, 2 * yOffset), false, "UnityTextureOutput", out node); var metal = MakeTextureNodeAndTexture("_MetalAndRoughness", new Vector2(0, 3 * yOffset), false, "OutputMetalicAndRoughness", out node); CreateOpCol col = Node.Create("CreateOpCol", node.rect.position - new Vector2(250, -100)) as CreateOpCol; col.m_TexMode = TextureNode.TexMode.Greyscale; node.Inputs[1].ApplyConnection(col.Outputs[0]); CreateOpCol col2 = Node.Create("CreateOpCol", node.rect.position - new Vector2(250, 100)) as CreateOpCol; col2.m_TexMode = TextureNode.TexMode.Greyscale; node.Inputs[0].ApplyConnection(col2.Outputs[0]); Texture2D occ = null; if (m_CreateMaterialType == 0 || !m_CreateMaterial) { occ = MakeTextureNodeAndTexture("_occlusion", new Vector2(0, 4 * yOffset), false, "UnityTextureOutput", out node); } if (m_CreateMaterial) { Material m; if (m_CreateMaterialType == 0) { m = new Material(Shader.Find("Standard")); m.mainTexture = albedo; m.SetTexture("_BumpMap", norms); m.SetTexture("_ParallaxMap", height); m.SetTexture("_MetallicGlossMap", metal); m.SetTexture("_OcclusionMap", occ); } else //if (m_CreateTesselatedMaterial) { m = new Material(Shader.Find("Tessellation/Standard Fixed")); if (m != null) { m.mainTexture = albedo; m.SetTexture("_NormalMap", norms); m.SetTexture("_DispTex", height); m.SetTexture("_MOS", metal); m.SetFloat("_Metallic", 1.0f); m.SetFloat("_Glossiness", 1.0f); m.SetFloat("_Tess", 100.0f); } } if (m != null) { m.EnableKeyword("_NORMALMAP"); m.EnableKeyword("_METALLICGLOSSMAP"); string matPath = m_Path.Replace(".png", "_material.mat"); AssetDatabase.CreateAsset(m, matPath); AssetDatabase.ImportAsset(matPath, ImportAssetOptions.ForceSynchronousImport); EditorUtility.SetDirty(m); var mr = FindObjectOfType <MeshRenderer>(); if (mr != null) { mr.material = m; } } } } m_Parent.Repaint(); this.Close(); } GUILayout.EndHorizontal(); }