public static void DrawMultiBezierConnection(SF_Editor editor, Vector2 p0, Vector2 p1, int count, Color col, bool railway = false) { float partOffset = partOffsetFactor / count; float mainOffset = -(count - 1) * 0.5f * partOffset; for (int i = 0; i < count; i++) { float offset = mainOffset + partOffset * i; DrawBezierConnection(editor, p0, p1, offset, col); } if (railway) { DrawBezierConnection(editor, p0, p1, 0, col, true); } }
public SF_PassSettings Initialize(SF_Editor materialEditor) { this.editor = materialEditor; fChecker = ScriptableObject.CreateInstance <SF_FeatureChecker>().Initialize(this, materialEditor); cats = new List <SFPS_Category>(); cats.Add(catMeta = NewCat <SFPSC_Meta> ("Shader Settings")); cats.Add(catProperties = NewCat <SFPSC_Properties> ("Properties")); cats.Add(catLighting = NewCat <SFPSC_Lighting> ("Lighting")); cats.Add(catGeometry = NewCat <SFPSC_Geometry> ("Geometry")); cats.Add(catBlending = NewCat <SFPSC_Blending> ("Blending")); cats.Add(catExperimental = NewCat <SFPSC_Experimental> ("Experimental")); cats.Add(catConsole = NewCat <SFPSC_Console> ("Console")); return(this); }
public static void DrawDashedLine(SF_Editor editor, Vector2 p0, Vector2 p1, Color col, float dashLength) { // p0 = editor.nodeView.ZoomSpaceToScreenSpace( p0 ); // p1 = editor.nodeView.ZoomSpaceToScreenSpace( p1 ); float frac = dashLength / (p0 - p1).magnitude; //int segcount = Mathf.Max(1, Mathf.RoundToInt(1f/frac)); for (float t = 0; t < 1; t += frac * 2f) { float tNext = Mathf.Min(1f, t + frac); GUILines.DrawLine(Vector2.Lerp(p0, p1, t), Vector2.Lerp(p0, p1, tNext), col, connectionWidth, true); } }
// this is the same as the ShaderProperty function, show here so // you can see how it works /* * private void ShaderPropertyImpl(Shader shader, int propertyIndex) * { * int i = propertyIndex; * string label = ShaderUtil.GetPropertyDescription(shader, i); * string propertyName = ShaderUtil.GetPropertyName(shader, i); * * * * * switch (ShaderUtil.GetPropertyType(shader, i)) * { * case ShaderUtil.ShaderPropertyType.Range: // float ranges * { * GUILayout.BeginHorizontal(); * float v2 = ShaderUtil.GetRangeLimits(shader, i, 1); * float v3 = ShaderUtil.GetRangeLimits(shader, i, 2); * * * * RangeProperty(propertyName, label, v2, v3); * GUILayout.EndHorizontal(); * * break; * } * case ShaderUtil.ShaderPropertyType.Float: // floats * { * FloatProperty(propertyName, label); * break; * } * case ShaderUtil.ShaderPropertyType.Color: // colors * { * ColorProperty(propertyName, label); * break; * } * case ShaderUtil.ShaderPropertyType.TexEnv: // textures * { * ShaderUtil.ShaderPropertyTexDim desiredTexdim = ShaderUtil.GetTexDim(shader, i); * TextureProperty(propertyName, label, desiredTexdim); * * GUILayout.Space(6); * break; * } * case ShaderUtil.ShaderPropertyType.Vector: // vectors * { * VectorProperty(propertyName, label); * break; * } * default: * { * GUILayout.Label("Unknown property " + label + " : " + ShaderUtil.GetPropertyType(shader, i)); * break; * } * } * }*/ public override void OnInspectorGUI() { base.serializedObject.Update(); var theShader = serializedObject.FindProperty("m_Shader"); if (isVisible && !theShader.hasMultipleDifferentValues && theShader.objectReferenceValue != null) { Shader shader = theShader.objectReferenceValue as Shader; // SHADER FORGE BUTTONS if (GUILayout.Button("Open shader in Shader Forge")) { SF_Editor.Init(shader); } if (SF_Tools.advancedInspector) { GUILayout.BeginHorizontal(); { GUIStyle btnStyle = "MiniButton"; if (GUILayout.Button("Open shader code", btnStyle)) { UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(AssetDatabase.GetAssetPath(shader), 1); } //if( GUILayout.Button( "Open compiled shader", btnStyle ) ) { // ShaderForgeInspector.OpenCompiledShader( shader ); //} } GUILayout.EndHorizontal(); } Material mat = target as Material; mat.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)EditorGUILayout.EnumPopup("Emission GI", mat.globalIlluminationFlags); GUILayout.Space(6); if (this.PropertiesGUI()) { this.PropertiesChanged(); } } }
public static void DrawRectilinearConnection(SF_Editor editor, Vector2 p0, Vector2 p1, float offset, Color col) { p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0); p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1); p0 += new Vector2(0f, offset); p1 += new Vector2(0f, offset); Vector2 p0t = new Vector2((p0.x + p1.x) / 2f + (p0.y < p1.y ? -offset : offset), p0.y); Vector2 p1t = new Vector2(p0t.x, p1.y); GUILines.DrawLine(p0, p0t, col, connectionWidth, true); GUILines.DrawLine(p0t, p1t, col, connectionWidth, true); GUILines.DrawLine(p1t, p1, col, connectionWidth, true); }
public static void DrawBezierConnection(SF_Editor editor, Vector2 p0, Vector2 p1, float offset, Color col, bool railway = false) { p0 = editor.nodeView.ZoomSpaceToScreenSpace(p0); p1 = editor.nodeView.ZoomSpaceToScreenSpace(p1); Vector2 p0t = p0; Vector2 p1t = p1; bool reversed = p0.x < p1.x; float hDist = Mathf.Max(20f, Mathf.Abs(p0.x - p1.x) * 0.5f); p0t.x = p0.x - hDist; p1t.x = p1.x + hDist; int segments = 25; if (!reversed) { if (offset == 0) { GUILines.DrawCubicBezier(p0, p0t, p1t, p1, col, connectionWidth, true, segments, railway); } else { GUILines.DrawCubicBezierOffset(offset, p0, p0t, p1t, p1, col, connectionWidth, true, segments); } } else { Vector2 mid = (p0 + p1) * 0.5f; Vector2 mid0t = new Vector2(p0t.x, mid.y); Vector2 mid1t = new Vector2(p1t.x, mid.y); if (offset == 0) { GUILines.DrawCubicBezier(p0, p0t, mid0t, mid, col, connectionWidth, true, segments, railway); GUILines.DrawCubicBezier(mid, mid1t, p1t, p1, col, connectionWidth, true, segments, railway); } else { GUILines.DrawCubicBezierOffset(offset, p0, p0t, mid0t, mid, col, connectionWidth, true, segments); GUILines.DrawCubicBezierOffset(offset, mid, mid1t, p1t, p1, col, connectionWidth, true, segments); } } }
public void Initialize(SF_Editor editor) { this.editor = editor; labelStyle = new GUIStyle(EditorStyles.label); labelStyle.margin = new RectOffset(0, 0, 0, 0); labelStyle.padding = new RectOffset(8, 0, 3, 1); labelStyleCentered = new GUIStyle(labelStyle); labelStyleCentered.alignment = TextAnchor.MiddleCenter; holderStyle = new GUIStyle(); holderStyle.margin = new RectOffset(0, 0, 0, 0); holderStyle.padding = new RectOffset(0, 0, 0, 0); headerStyle = new GUIStyle(EditorStyles.toolbar); headerStyle.alignment = TextAnchor.MiddleLeft; headerStyle.fontSize = 10; //headerStyle.fontStyle = FontStyle.Bold; }
public SF_Node CreateInstance() { Type fType = Type.GetType(type); // Might be dynamic... if (fType == null) { if (SF_Debug.dynamicNodeLoad) { Debug.Log("CreateInstance couldn't use GetType, attempting dynamic load..."); } fType = SF_Editor.GetNodeType(type); if (SF_Debug.dynamicNodeLoad && fType == null) { Debug.Log("Failed to load dynamic load fType is null"); } } SF_Node node = (SF_Node)ScriptableObject.CreateInstance(fType); node.Initialize(); return(node); }
public SF_FeatureChecker Initialize(SF_PassSettings ps, SF_Editor editor) { this.ps = ps; this.editor = editor; return(this); }
public void CheckConnection(SF_Editor editor) { if (ShouldBeInvisible()) { return; } if (conType == ConType.cInput && Event.current.type == EventType.Repaint) { DrawConnection(editor); } if (enableState == EnableState.Disabled || availableState == AvailableState.Unavailable) { return; } if (Clicked()) { SF_NodeConnector.pendingConnectionSource = this; editor.nodeView.selection.DeselectAll(registerUndo: false); foreach (SF_Node iNode in editor.nodes) { foreach (SF_NodeConnector con in iNode.connectors) { con.UpdateCanValidlyConnectToPending(); } } Event.current.Use(); } if (Clicked(1) && SF_GUI.HoldingAlt()) { Disconnect(); } if (!ConnectionInProgress()) { if (Released()) { TryMakeConnection(); } return; } // Active connection: editor.ResetRunningOutdatedTimer(); //if(Event.current.type == EventType.repaint) //node.Repaint(); bool hovering = false; foreach (SF_Node n in editor.nodes) { foreach (SF_NodeConnector con in n.connectors) { if (con.CanConnectToPending() && con.Hovering(false)) { hovering = true; break; } } if (hovering) { break; } } if (Event.current.type == EventType.Repaint) { Color c = hovering ? Color.green : GetConnectionLineColor(); bool input = (conType == ConType.cInput); Vector2 start = input ? GetConnectionPoint() : MousePos(); Vector2 end = input ? MousePos() : GetConnectionPoint();; if (valueType == ValueType.VTm4x4 || valueType == ValueType.VTv4m4x4) { GUILines.DrawMatrixConnection(editor, start, end, c); } else { GUILines.DrawStyledConnection(editor, start, end, GetCompCount(), c); } } //Drawing.DrawLine(rect.center,MousePos(),Color.white,2,true); }
public SF_NodeTreeStatus Initialize(SF_Editor editor) { this.editor = editor; return(this); }
public bool CheckCanCompile() { editor.nodeView.RefreshRelaySources(); if (Errors == null) { Errors = new List <SF_ErrorEntry>(); } else if (Errors.Count > 0) { for (int i = 0; i < Errors.Count; i++) { DestroyImmediate(Errors[i]); } Errors.Clear(); } List <SF_Node> cNodes = GetListOfConnectedNodesWithGhosts(out editor.shaderEvaluator.ghostNodes); // If any properties are now outside the node graph, remove them from the property list /*if(!SF_Parser.settingUp) * for( int i = propertyList.Count - 1; i >= 0; i-- ) { * if( !cNodes.Contains( propertyList[i] ) ) { * propertyList.RemoveAt( i ); * } * }*/ //if( editor.shaderEvaluator.ghostNodes != null ) //Debug.Log( "Ghost nodes: " + editor.shaderEvaluator.ghostNodes.Count ); texturesInVertShader = false; bool foundMipUsed = false; //SF_Node mipNode = null; usesSceneData = false; bool hasFacingNode = false; foreach (SF_Node n in cNodes) { // Refresh property list if (n.IsProperty()) { if (!n.IsGlobalProperty()) { // Add if it's local and doesn't contain it already if (!propertyList.Contains(n)) { propertyList.Add(n); } } else { // Remove it if it's global and inside the list if (propertyList.Contains(n)) { propertyList.Remove(n); } } } if (n is SFN_SceneColor) { usesSceneData = true; } if (n is SFN_FaceSign) { hasFacingNode = true; } if (n is SFN_Tex2d || n is SFN_Cubemap) // Check MIP input { if (n.GetInputIsConnected("MIP")) { foundMipUsed = true; //mipNode = n; } } //if(SF_Debug.dynamicNodeLoad) if (SF_Editor.NodeExistsAndIs(n, "SFN_SkyshopSpec")) { //if(n.GetInputIsConnected("GLOSS")){ foundMipUsed = true; //mipNode = n; //} } foreach (SF_NodeConnector con in n.connectors) { if (con.conType == ConType.cOutput) { continue; } if (con.required && !con.IsConnected()) { string err = "Missing required"; err += string.IsNullOrEmpty(con.label) ? " " : " [" + con.label + "] "; err += "input on " + con.node.nodeName; Errors.Add(SF_ErrorEntry.Create(err, con, false)); } } } // WARNINGS if (editor.ps.catBlending.autoSort) { bool alphaConnected = editor.ps.HasAlpha(); if (editor.ps.catLighting.transparencyMode == SFPSC_Lighting.TransparencyMode.Fade) { bool usingAlphaBlend = editor.ps.catBlending.blendSrc == BlendMode.SrcAlpha && editor.ps.catBlending.blendDst == BlendMode.OneMinusSrcAlpha; if (alphaConnected && !usingAlphaBlend) { SF_ErrorEntry error = SF_ErrorEntry.Create("Opacity is connected, but your shader isn't alpha blended, which is required by the fade transparency mode. Click the icon to make it alpha blended!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catBlending, "error correction"); editor.ps.catBlending.blendModePreset = BlendModePreset.AlphaBlended; editor.ps.catBlending.ConformBlendsToPreset(); }; Errors.Add(error); } if (!alphaConnected && usingAlphaBlend) { SF_ErrorEntry error = SF_ErrorEntry.Create("Opacity is not connected, but your shader is alpha blended. Click the icon to make it opaque!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catBlending, "error correction"); editor.ps.catBlending.blendModePreset = BlendModePreset.Opaque; editor.ps.catBlending.ConformBlendsToPreset(); }; Errors.Add(error); } } if (editor.ps.catLighting.transparencyMode == SFPSC_Lighting.TransparencyMode.Reflective) { bool usingAlphaBlendPremul = editor.ps.catBlending.blendSrc == BlendMode.One && editor.ps.catBlending.blendDst == BlendMode.OneMinusSrcAlpha; if (alphaConnected && !usingAlphaBlendPremul) { SF_ErrorEntry error = SF_ErrorEntry.Create("Opacity is connected, but your shader isn't using premultiplied alpha blending, which is required by the reflective transparency mode. Click the icon to use premultiplied alpha blending!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catBlending, "error correction"); editor.ps.catBlending.blendModePreset = BlendModePreset.AlphaBlendedPremultiplied; editor.ps.catBlending.ConformBlendsToPreset(); }; Errors.Add(error); } if (!alphaConnected && usingAlphaBlendPremul) { SF_ErrorEntry error = SF_ErrorEntry.Create("Opacity is not connected, but your shader is using premultiplied alpha blending. Click the icon to make it opaque!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catBlending, "error correction"); editor.ps.catBlending.blendModePreset = BlendModePreset.Opaque; editor.ps.catBlending.ConformBlendsToPreset(); }; Errors.Add(error); } } } /* * true, // - Direct3D 9 * true, // - Direct3D 11 * true, // - OpenGL * true, // - OpenGL ES 2.0 * false, // - Xbox 360 * false, // - PlayStation 3 * false, // - Flash * false // - Direct3D 11 for Windows RT */ bool osx = Application.platform == RuntimePlatform.OSXEditor; bool windows = !osx; bool ogl = editor.ps.catMeta.usedRenderers[2]; bool dx9 = editor.ps.catMeta.usedRenderers[0]; bool dx11 = editor.ps.catMeta.usedRenderers[1]; #if UNITY_5_0 bool inDx11Mode = UnityEditor.PlayerSettings.useDirect3D11; #else bool inDx11Mode = true; #endif if (osx && !ogl) { SF_ErrorEntry error = SF_ErrorEntry.Create("Your shader will not render properly on your workstation - you need to have OpenGL enabled when working in OSX. Click the icon to enable OpenGL!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catMeta, "error correction - enable OpenGL"); editor.ps.catMeta.usedRenderers[2] = true; editor.OnShaderModified(NodeUpdateType.Hard); }; Errors.Add(error); } else if (windows) { if (inDx11Mode && !dx11) { SF_ErrorEntry error = SF_ErrorEntry.Create("Your shader might not render properly on your workstation - you need to have Direct3D 11 enabled when working in DX11 mode on Windows. Click the icon to enable Direct3D 11!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catMeta, "error correction - enable Direct3D 11"); editor.ps.catMeta.usedRenderers[1] = true; editor.OnShaderModified(NodeUpdateType.Soft); }; Errors.Add(error); } else if (!inDx11Mode && !dx9) { SF_ErrorEntry error = SF_ErrorEntry.Create("Your shader might not render properly on your workstation - you need to have Direct3D 9 enabled when working on Windows. Click the icon to enable Direct3D 9!", true); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catMeta, "error correction - enable Direct3D 9"); editor.ps.catMeta.usedRenderers[0] = true; editor.OnShaderModified(NodeUpdateType.Soft); }; Errors.Add(error); } } if (editor.ps.catLighting.lightMode == SFPSC_Lighting.LightMode.PBL) { if (editor.ps.HasDiffuse() && !editor.ps.HasSpecular()) { Errors.Add(SF_ErrorEntry.Create("Using PBL requires metallic/specular to be connected", false)); } if (!editor.ps.HasDiffuse() && editor.ps.HasSpecular()) { Errors.Add(SF_ErrorEntry.Create("Using PBL requires metallic/specular to be connected", false)); } } List <SF_Node> dupes = new List <SF_Node>(); SF_Node[] propNodes = cNodes.Where(x => x.IsProperty()).ToArray(); for (int i = 0; i < propNodes.Length; i++) { for (int j = i + 1; j < propNodes.Length; j++) { string nameA = propNodes[i].property.nameInternal; string nameB = propNodes[j].property.nameInternal; if (nameA == nameB) { dupes.Add(propNodes[j]); } } } if (dupes.Count > 0) { foreach (SF_Node dupe in dupes) { Errors.Add(SF_ErrorEntry.Create("You have property nodes with conflicting internal names. Please rename one of the " + dupe.property.nameInternal + " nodes", dupe, false)); } } List <SF_Node> dupesVarname = new List <SF_Node>(); for (int i = 0; i < cNodes.Count; i++) { for (int j = i + 1; j < cNodes.Count; j++) { string nameAvar = cNodes[i].variableName; string nameBvar = cNodes[j].variableName; if (nameAvar == nameBvar && dupes.Contains(cNodes[j]) == false) { dupesVarname.Add(cNodes[j]); } } } if (dupesVarname.Count > 0) { foreach (SF_Node dupeVarname in dupesVarname) { Errors.Add(SF_ErrorEntry.Create("You have nodes with conflicting variable names. Please rename one of the " + dupeVarname.variableName + " nodes", dupeVarname, false)); } } // Make sure you set the shader to double sided if (!editor.ps.catGeometry.IsDoubleSided() && hasFacingNode) { SF_ErrorEntry error = SF_ErrorEntry.Create("You are using the Face Sign node, but your shader isn't double-sided. Click the icon to fix", false); error.action = () => { UnityEditor.Undo.RecordObject(editor.ps.catGeometry, "error correction - fix double sided"); editor.ps.catGeometry.cullMode = SFPSC_Geometry.CullMode.DoubleSided; editor.OnShaderModified(NodeUpdateType.Hard); }; Errors.Add(error); } // Check if there are any textures in the vertex input texturesInVertShader = HasNodeInput <SFN_Tex2d>(editor.mainNode.vertexOffset) || HasNodeInput <SFN_Tex2d>(editor.mainNode.outlineWidth); viewDirectionInVertOffset = HasNodeInput <SFN_ViewVector>(editor.mainNode.vertexOffset); editor.shaderEvaluator.RemoveGhostNodes(); if (foundMipUsed) { //if( !mipInputUsed ) // This should be fixed with #pragma glsl // errors.Add( new SF_ErrorEntry( "MIP input is only supported in Direct X", mipNode ) ); mipInputUsed = true; } else { mipInputUsed = false; } int errorCount = Errors.Count(x => !x.isWarning); // Let it compile, even though it has warnings if (errorCount == 0) { return(true); } //DisplayErrors(); return(false); }
public override void OnInspectorGUI() { GUI.enabled = true; Shader shader = base.target as Shader; if (!SF_Tools.CanRunShaderForge()) { SF_Tools.UnityOutOfDateGUI(); return; } //EditorGUILayout.InspectorTitlebar( false, base.target ); if (hasShaderForgeData) { if (GUILayout.Button("Open in Shader Forge")) { if (Event.current.rawType != EventType.MouseDown) { SF_Editor.Init(shader); } } } else { GUILayout.BeginHorizontal(); { //GUILayout.Label(SF_Styles.IconWarningSmall,GUILayout.Width(18),GUILayout.Height(18)); GUI.color = Color.gray; GUILayout.Label("No Shader Forge data found!", EditorStyles.miniLabel); GUI.color = Color.white; } GUILayout.EndHorizontal(); //GUILayout.Label( "Opening this will clear the shader", EditorStyles.miniLabel ); //GUI.color = new Color( 1f, 0.8f, 0.8f ); if (GUILayout.Button(new GUIContent("Replace with Shader Forge shader", SF_Styles.IconWarningSmall, "This will erase any existing shader code"), hasShaderForgeData ? "Button" : "MiniButton")) { if (SF_GUI.AcceptedNewShaderReplaceDialog()) { SF_Editor.Init(shader); SF_Editor.instance.ps.fChecker.UpdateAvailability(); SF_Editor.instance.OnShaderModified(NodeUpdateType.Hard); } } //GUI.color = Color.white; } if (SF_Tools.advancedInspector) { GUILayout.BeginHorizontal(); { GUIStyle btnStyle = hasShaderForgeData ? "MiniButton" : "Button"; if (GUILayout.Button("Open shader code", btnStyle)) { UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(AssetDatabase.GetAssetPath(shader), 1); } //if( GUILayout.Button( "Open compiled", btnStyle ) ) { // OpenCompiledShader( shader ); //} } GUILayout.EndHorizontal(); } DrawUnitysInspector(); }
public SF_SelectionManager Initialize(SF_Editor editor) { this.editor = editor; return(this); }
public SF_NodeConnectionLine Initialize(SF_Editor editor, SF_NodeConnector connector) { this.connector = connector; this.editor = editor; return(this); }
public static void DrawMatrixConnection(SF_Editor editor, Vector2 a, Vector2 b, Color col) { DrawMultiBezierConnection(editor, a, b, 2, col, true); }