void DirtyNodes() { foreach (var node in m_Graph.GetNodes <PropertyNode>()) { node.Dirty(ModificationScope.Node); } }
public PreviewManager(AbstractMaterialGraph graph) { m_Graph = graph; m_PreviewMaterial = new Material(Shader.Find("Unlit/Color")) { hideFlags = HideFlags.HideInHierarchy }; m_PreviewMaterial.hideFlags = HideFlags.HideAndDontSave; m_PreviewPropertyBlock = new MaterialPropertyBlock(); m_ErrorTexture = new Texture2D(2, 2); m_ErrorTexture.SetPixel(0, 0, Color.magenta); m_ErrorTexture.SetPixel(0, 1, Color.black); m_ErrorTexture.SetPixel(1, 0, Color.black); m_ErrorTexture.SetPixel(1, 1, Color.magenta); m_ErrorTexture.filterMode = FilterMode.Point; m_ErrorTexture.Apply(); m_SceneResources = new PreviewSceneResources(); m_ColorShader = ShaderUtil.CreateShaderAsset(k_EmptyShader); m_ColorShader.hideFlags = HideFlags.HideAndDontSave; m_MasterRenderData = new PreviewRenderData { renderTexture = new RenderTexture(400, 400, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave } }; m_MasterRenderData.renderTexture.Create(); foreach (var node in m_Graph.GetNodes <INode>()) { AddPreview(node); } }
public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph, string assetName) { m_Graph = graph; AddStyleSheetPath("Styles/MaterialGraph"); previewManager = new PreviewManager(graph); var content = new VisualElement { name = "content" }; { m_GraphView = new MaterialGraphView(graph) { name = "GraphView", persistenceKey = "MaterialGraphView" }; m_GraphView.SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); m_GraphView.AddManipulator(new ContentDragger()); m_GraphView.AddManipulator(new SelectionDragger()); m_GraphView.AddManipulator(new RectangleSelector()); m_GraphView.AddManipulator(new ClickSelector()); m_GraphView.AddManipulator(new GraphDropTarget(graph)); content.Add(m_GraphView); m_GraphInspectorView = new GraphInspectorView(assetName, previewManager, graph) { name = "inspector" }; m_GraphInspectorView.AddManipulator(new Draggable(OnMouseDrag, true)); m_GraphView.RegisterCallback <PostLayoutEvent>(OnPostLayout); m_GraphInspectorView.RegisterCallback <PostLayoutEvent>(OnPostLayout); m_GraphView.Add(m_GraphInspectorView); m_GraphView.graphViewChanged = GraphViewChanged; } m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>(); m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView); m_GraphView.nodeCreationRequest = (c) => { m_SearchWindowProvider.connectedPort = null; SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider); }; m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider); foreach (var node in graph.GetNodes <INode>()) { AddNode(node); } foreach (var edge in graph.edges) { AddEdge(edge); } Add(content); }
public void RenderPreviews() { m_NodesWith3DPreview.Clear(); m_NodesWithWireframePreview.Clear(); foreach (var node in m_Graph.GetNodes <AbstractMaterialNode>()) { if (node.previewMode == PreviewMode.Preview3D) { m_NodesWith3DPreview.Add(node.tempId.index); } else if (node.previewMode == PreviewMode.Wireframe) { m_NodesWithWireframePreview.Add(node.tempId.index); } } PropagateNodeSet(m_NodesWith3DPreview); PropagateNodeSet(m_NodesWithWireframePreview); m_NodesWith3DPreview.UnionWith(m_NodesWithWireframePreview); UpdateShaders(); // Union time dependent previews into dirty previews m_DirtyPreviews.UnionWith(m_TimeDependentPreviews); PropagateNodeSet(m_DirtyPreviews); foreach (var index in m_DirtyPreviews) { var renderData = m_RenderDatas[index]; renderData.previewMode = m_NodesWith3DPreview.Contains(renderData.shaderData.node.tempId.index) ? PreviewMode.Preview3D : PreviewMode.Preview2D; } // Find nodes we need properties from m_PropertyNodes.Clear(); m_PropertyNodes.UnionWith(m_DirtyPreviews); PropagateNodeSet(m_PropertyNodes, false); // Fill MaterialPropertyBlock m_PreviewPropertyBlock.Clear(); m_PreviewPropertyBlock.SetFloat(m_OutputIdName, -1); foreach (var index in m_PropertyNodes) { var node = m_Graph.GetNodeFromTempId(m_Identifiers[index]) as AbstractMaterialNode; if (node == null) { continue; } node.CollectPreviewMaterialProperties(m_PreviewProperties); foreach (var prop in m_Graph.properties) { m_PreviewProperties.Add(prop.GetPreviewMaterialProperty()); } foreach (var previewProperty in m_PreviewProperties) { m_PreviewPropertyBlock.SetPreviewProperty(previewProperty); } m_PreviewProperties.Clear(); } foreach (var i in m_DirtyPreviews) { var renderData = m_RenderDatas[i]; if (renderData.shaderData.shader == null) { renderData.texture = null; continue; } if (renderData.shaderData.hasError) { renderData.texture = m_ErrorTexture; continue; } if (renderData.previewMode == PreviewMode.Preview2D) { m_RenderList2D.Add(renderData); } else { m_RenderList3D.Add(renderData); } } m_RenderList3D.Sort((data1, data2) => data1.shaderData.shader.GetInstanceID().CompareTo(data2.shaderData.shader.GetInstanceID())); m_RenderList2D.Sort((data1, data2) => data1.shaderData.shader.GetInstanceID().CompareTo(data2.shaderData.shader.GetInstanceID())); var time = Time.realtimeSinceStartup; EditorUtility.SetCameraAnimateMaterialsTime(m_SceneResources.camera, time); m_SceneResources.light0.enabled = true; m_SceneResources.light0.intensity = 1.0f; m_SceneResources.light0.transform.rotation = Quaternion.Euler(50f, 50f, 0); m_SceneResources.light1.enabled = true; m_SceneResources.light1.intensity = 1.0f; m_SceneResources.camera.clearFlags = CameraClearFlags.Depth; // Render 2D previews m_SceneResources.camera.transform.position = -Vector3.forward * 2; m_SceneResources.camera.transform.rotation = Quaternion.identity; m_SceneResources.camera.orthographicSize = 0.5f; m_SceneResources.camera.orthographic = true; foreach (var renderData in m_RenderList2D) { RenderPreview(renderData, m_SceneResources.quad, Matrix4x4.identity); } // Render 3D previews m_SceneResources.camera.transform.position = -Vector3.forward * 5; m_SceneResources.camera.transform.rotation = Quaternion.identity; m_SceneResources.camera.orthographic = false; foreach (var renderData in m_RenderList3D) { RenderPreview(renderData, m_SceneResources.sphere, Matrix4x4.identity); } var renderMasterPreview = masterRenderData.shaderData != null && m_DirtyPreviews.Contains(masterRenderData.shaderData.node.tempId.index); if (renderMasterPreview) { if (m_NewMasterPreviewSize.HasValue) { if (masterRenderData.renderTexture != null) { Object.DestroyImmediate(masterRenderData.renderTexture, true); } masterRenderData.renderTexture = new RenderTexture((int)m_NewMasterPreviewSize.Value.x, (int)m_NewMasterPreviewSize.Value.y, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave }; masterRenderData.renderTexture.Create(); masterRenderData.texture = masterRenderData.renderTexture; m_NewMasterPreviewSize = null; } var mesh = m_Graph.previewData.serializedMesh.mesh ? m_Graph.previewData.serializedMesh.mesh : m_SceneResources.sphere; var previewTransform = Matrix4x4.Rotate(m_Graph.previewData.rotation); var scale = m_Graph.previewData.scale; previewTransform *= Matrix4x4.Scale(scale * Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude); previewTransform *= Matrix4x4.Translate(-mesh.bounds.center); RenderPreview(masterRenderData, mesh, previewTransform); } m_SceneResources.light0.enabled = false; m_SceneResources.light1.enabled = false; foreach (var renderData in m_RenderList2D) { renderData.NotifyPreviewChanged(); } foreach (var renderData in m_RenderList3D) { renderData.NotifyPreviewChanged(); } if (renderMasterPreview) { masterRenderData.NotifyPreviewChanged(); } m_RenderList2D.Clear(); m_RenderList3D.Clear(); m_DirtyPreviews.Clear(); }
public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph) { m_Graph = graph; AddStyleSheetPath("Styles/GraphEditorView"); previewManager = new PreviewManager(graph); string serializedWindowLayout = EditorUserSettings.GetConfigValue(k_FloatingWindowsLayoutKey); if (!string.IsNullOrEmpty(serializedWindowLayout)) { m_FloatingWindowsLayout = JsonUtility.FromJson <FloatingWindowsLayout>(serializedWindowLayout); if (m_FloatingWindowsLayout.masterPreviewSize.x > 0f && m_FloatingWindowsLayout.masterPreviewSize.y > 0f) { previewManager.ResizeMasterPreview(m_FloatingWindowsLayout.masterPreviewSize); } } previewManager.RenderPreviews(); var toolbar = new IMGUIContainer(() => { GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Save Asset", EditorStyles.toolbarButton)) { if (saveRequested != null) { saveRequested(); } } GUILayout.Space(6); if (GUILayout.Button("Show In Project", EditorStyles.toolbarButton)) { if (showInProjectRequested != null) { showInProjectRequested(); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }); Add(toolbar); var content = new VisualElement { name = "content" }; { m_GraphView = new MaterialGraphView(graph) { name = "GraphView", persistenceKey = "MaterialGraphView" }; m_GraphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale); m_GraphView.AddManipulator(new ContentDragger()); m_GraphView.AddManipulator(new SelectionDragger()); m_GraphView.AddManipulator(new RectangleSelector()); m_GraphView.AddManipulator(new ClickSelector()); m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown); content.Add(m_GraphView); m_BlackboardProvider = new BlackboardProvider(graph); m_GraphView.Add(m_BlackboardProvider.blackboard); Rect blackboardLayout = m_BlackboardProvider.blackboard.layout; blackboardLayout.x = 10f; blackboardLayout.y = 10f; m_BlackboardProvider.blackboard.layout = blackboardLayout; m_MasterPreviewView = new MasterPreviewView(previewManager, graph) { name = "masterPreview" }; WindowDraggable masterPreviewViewDraggable = new WindowDraggable(null, this); m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable); m_GraphView.Add(m_MasterPreviewView); //m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout; //m_BlackboardProvider.onResizeFinished += UpdateSerializedWindowLayout; masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout; m_MasterPreviewView.previewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; m_GraphView.graphViewChanged = GraphViewChanged; RegisterCallback <GeometryChangedEvent>(ApplySerializewindowLayouts); } m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>(); m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView); m_GraphView.nodeCreationRequest = (c) => { m_SearchWindowProvider.connectedPort = null; SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider); }; m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider); foreach (var node in graph.GetNodes <INode>()) { AddNode(node); } foreach (var edge in graph.edges) { AddEdge(edge); } Add(content); }
public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph, string assetName) { m_Graph = graph; AddStyleSheetPath("Styles/MaterialGraph"); m_EditorWindow = editorWindow; previewManager = new PreviewManager(graph); var toolbar = new IMGUIContainer(() => { GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Save Asset", EditorStyles.toolbarButton)) { if (saveRequested != null) { saveRequested(); } } GUILayout.Space(6); if (GUILayout.Button("Show In Project", EditorStyles.toolbarButton)) { if (showInProjectRequested != null) { showInProjectRequested(); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }); Add(toolbar); var content = new VisualElement { name = "content" }; { m_GraphView = new MaterialGraphView(graph) { name = "GraphView", persistenceKey = "MaterialGraphView" }; m_GraphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale); m_GraphView.AddManipulator(new ContentDragger()); m_GraphView.AddManipulator(new SelectionDragger()); m_GraphView.AddManipulator(new RectangleSelector()); m_GraphView.AddManipulator(new ClickSelector()); m_GraphView.AddManipulator(new GraphDropTarget(graph)); m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown); content.Add(m_GraphView); m_BlackboardProvider = new BlackboardProvider(assetName, graph); m_GraphView.Add(m_BlackboardProvider.blackboard); m_BlackboardProvider.blackboard.layout = new Rect(new Vector2(10f, 10f), m_BlackboardProvider.blackboard.layout.size); m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph) { name = "masterPreview" }; WindowDraggable masterPreviewViewDraggable = new WindowDraggable(); m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable); m_GraphView.Add(m_MasterPreviewView); ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" }; masterPreviewResizeBorderFrame.stayWithinParentBounds = true; masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; m_MasterPreviewView.Add(masterPreviewResizeBorderFrame); m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout; m_BlackboardProvider.onResizeFinished += UpdateSerializedWindowLayout; masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout; masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; m_GraphView.graphViewChanged = GraphViewChanged; m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout"; string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey); if (!String.IsNullOrEmpty(serializedWindowLayout)) { m_FloatingWindowsLayout = JsonUtility.FromJson <FloatingWindowsLayout>(serializedWindowLayout); m_MasterPreviewView.layout = m_FloatingWindowsLayout.previewLayout; if (m_FloatingWindowsLayout.blackboardLayout.width > 0) { m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout; } } else { m_FloatingWindowsLayout = new FloatingWindowsLayout(); } } m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>(); m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView); m_GraphView.nodeCreationRequest = (c) => { m_SearchWindowProvider.connectedPort = null; SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider); }; m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider); foreach (var node in graph.GetNodes <INode>()) { AddNode(node); } foreach (var edge in graph.edges) { AddEdge(edge); } Add(content); }
public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph, string assetName) { m_Graph = graph; AddStyleSheetPath("Styles/GraphEditorView"); m_EditorWindow = editorWindow; previewManager = new PreviewManager(graph); var toolbar = new IMGUIContainer(() => { GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Save Asset", EditorStyles.toolbarButton)) { if (saveRequested != null) { saveRequested(); } } GUILayout.Space(6); if (GUILayout.Button("Show In Project", EditorStyles.toolbarButton)) { if (showInProjectRequested != null) { showInProjectRequested(); } } GUILayout.Space(6); if (GUILayout.Button("Reset Layout", EditorStyles.toolbarButton)) { m_MasterPreviewView.layout = m_FloatingWindowsLayout.defaultPreviewLayout.GetLayout(layout); m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.defaultBlackboardLayout.GetLayout(layout); m_MasterPreviewView.UpdateRenderTextureOnNextLayoutChange(); UpdateSerializedWindowLayout(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }); Add(toolbar); var content = new VisualElement { name = "content" }; { m_GraphView = new MaterialGraphView(graph) { name = "GraphView", persistenceKey = "MaterialGraphView" }; m_GraphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale); m_GraphView.AddManipulator(new ContentDragger()); m_GraphView.AddManipulator(new SelectionDragger()); m_GraphView.AddManipulator(new RectangleSelector()); m_GraphView.AddManipulator(new ClickSelector()); m_GraphView.AddManipulator(new GraphDropTarget(graph)); m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown); content.Add(m_GraphView); // Uncomment to enable pixel caching profiler // m_ProfilerView = new PixelCacheProfilerView(this); // m_GraphView.Add(m_ProfilerView); m_BlackboardProvider = new BlackboardProvider(assetName, graph); m_GraphView.Add(m_BlackboardProvider.blackboard); m_BlackboardProvider.blackboard.layout = new Rect(new Vector2(10f, 10f), m_BlackboardProvider.blackboard.layout.size); m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph) { name = "masterPreview" }; WindowDraggable masterPreviewViewDraggable = new WindowDraggable(); m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable); m_GraphView.Add(m_MasterPreviewView); ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" }; masterPreviewResizeBorderFrame.stayWithinParentBounds = true; masterPreviewResizeBorderFrame.maintainAspectRatio = true; masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; m_MasterPreviewView.Add(masterPreviewResizeBorderFrame); m_BlackboardProvider.onDragFinished += UpdateSerializedWindowLayout; m_BlackboardProvider.onResizeFinished += UpdateSerializedWindowLayout; masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout; masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; m_GraphView.graphViewChanged = GraphViewChanged; RegisterCallback <PostLayoutEvent>(ApplySerializewindowLayouts); } m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>(); m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView); m_GraphView.nodeCreationRequest = (c) => { m_SearchWindowProvider.connectedPort = null; SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider); }; m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider); foreach (var node in graph.GetNodes <INode>()) { AddNode(node); } foreach (var edge in graph.edges) { AddEdge(edge); } Add(content); }
public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph, string assetName) { m_Graph = graph; AddStyleSheetPath("Styles/MaterialGraph"); m_EditorWindow = editorWindow; previewManager = new PreviewManager(graph); var content = new VisualElement { name = "content" }; { m_GraphView = new MaterialGraphView(graph) { name = "GraphView", persistenceKey = "MaterialGraphView" }; m_GraphView.SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); m_GraphView.AddManipulator(new ContentDragger()); m_GraphView.AddManipulator(new SelectionDragger()); m_GraphView.AddManipulator(new RectangleSelector()); m_GraphView.AddManipulator(new ClickSelector()); m_GraphView.AddManipulator(new GraphDropTarget(graph)); content.Add(m_GraphView); m_GraphInspectorView = new GraphInspectorView(assetName, previewManager, graph) { name = "inspector" }; m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown); m_GraphView.Add(m_GraphInspectorView); m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph) { name = "masterPreview" }; WindowDraggable masterPreviewViewDraggable = new WindowDraggable(); masterPreviewViewDraggable.OnDragFinished += UpdateSerializedWindowLayout; m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable); m_GraphView.Add(m_MasterPreviewView); ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView) { name = "resizeBorderFrame" }; masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout; m_MasterPreviewView.Add(masterPreviewResizeBorderFrame); m_GraphView.graphViewChanged = GraphViewChanged; m_FloatingWindowsLayoutKey = "UnityEditor.ShaderGraph.FloatingWindowsLayout"; string serializedWindowLayout = EditorUserSettings.GetConfigValue(m_FloatingWindowsLayoutKey); if (!String.IsNullOrEmpty(serializedWindowLayout)) { m_FLoatingWindowsLayout = JsonUtility.FromJson <FloatingWindowsLayout>(serializedWindowLayout); m_GraphInspectorView.layout = m_FLoatingWindowsLayout.inspectorLayout; m_MasterPreviewView.layout = m_FLoatingWindowsLayout.previewLayout; } else { m_FLoatingWindowsLayout = new FloatingWindowsLayout(); } } m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>(); m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView); m_GraphView.nodeCreationRequest = (c) => { m_SearchWindowProvider.connectedPort = null; SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider); }; m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider); foreach (var node in graph.GetNodes <INode>()) { AddNode(node); } foreach (var edge in graph.edges) { AddEdge(edge); } Add(content); }
public void RenderPreviews() { UpdateShaders(); m_PreviewPropertyBlock.Clear(); m_PreviewPropertyBlock.SetFloat(m_OutputIdName, -1); foreach (var node in m_Graph.GetNodes <AbstractMaterialNode>()) { var renderData = GetRenderData(node.tempId); renderData.previewMode = PreviewMode.Preview3D; if (node.previewMode == PreviewMode.Preview2D) { renderData.previewMode = PreviewMode.Preview2D; } node.CollectPreviewMaterialProperties(m_PreviewProperties); foreach (var prop in m_Graph.properties) { m_PreviewProperties.Add(prop.GetPreviewMaterialProperty()); } foreach (var previewProperty in m_PreviewProperties) { m_PreviewPropertyBlock.SetPreviewProperty(previewProperty); } m_PreviewProperties.Clear(); if (renderData.shaderData.shader == null) { renderData.texture = null; renderData.NotifyPreviewChanged(); continue; } if (renderData.shaderData.hasError) { renderData.texture = m_ErrorTexture; renderData.NotifyPreviewChanged(); continue; } if (renderData.previewMode == PreviewMode.Preview2D) { m_RenderList2D.Add(renderData); } else { m_RenderList3D.Add(renderData); } } var time = Time.realtimeSinceStartup; EditorUtility.SetCameraAnimateMaterialsTime(m_SceneResources.camera, time); m_SceneResources.light0.enabled = true; m_SceneResources.light0.intensity = 1.0f; m_SceneResources.light0.transform.rotation = Quaternion.Euler(50f, 50f, 0); m_SceneResources.light1.enabled = true; m_SceneResources.light1.intensity = 1.0f; m_SceneResources.camera.clearFlags = CameraClearFlags.Depth; // Render 2D previews m_SceneResources.camera.transform.position = -Vector3.forward * 2; m_SceneResources.camera.transform.rotation = Quaternion.identity; m_SceneResources.camera.orthographicSize = 0.5f; m_SceneResources.camera.orthographic = true; foreach (var renderData in m_RenderList2D) { RenderPreview(renderData, m_SceneResources.quad, Matrix4x4.identity); } // Render 3D previews m_SceneResources.camera.transform.position = -Vector3.forward * 5; m_SceneResources.camera.transform.rotation = Quaternion.identity; m_SceneResources.camera.orthographic = false; foreach (var renderData in m_RenderList3D) { RenderPreview(renderData, m_SceneResources.sphere, Matrix4x4.identity); } var renderMasterPreview = masterRenderData.shaderData != null; if (renderMasterPreview) { if (m_NewMasterPreviewSize.HasValue) { if (masterRenderData.renderTexture != null) { Object.DestroyImmediate(masterRenderData.renderTexture, true); } masterRenderData.renderTexture = new RenderTexture((int)m_NewMasterPreviewSize.Value.x, (int)m_NewMasterPreviewSize.Value.y, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave }; masterRenderData.renderTexture.Create(); masterRenderData.texture = masterRenderData.renderTexture; m_NewMasterPreviewSize = null; } var mesh = m_Graph.previewData.serializedMesh.mesh ? m_Graph.previewData.serializedMesh.mesh : m_SceneResources.sphere; var previewTransform = Matrix4x4.Rotate(m_Graph.previewData.rotation); var scale = m_Graph.previewData.scale; previewTransform *= Matrix4x4.Scale(scale * Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude); previewTransform *= Matrix4x4.Translate(-mesh.bounds.center); RenderPreview(masterRenderData, mesh, previewTransform); } m_SceneResources.light0.enabled = false; m_SceneResources.light1.enabled = false; foreach (var renderData in m_RenderList2D) { renderData.NotifyPreviewChanged(); } foreach (var renderData in m_RenderList3D) { renderData.NotifyPreviewChanged(); } if (renderMasterPreview) { masterRenderData.NotifyPreviewChanged(); } m_RenderList2D.Clear(); m_RenderList3D.Clear(); }