{
var previewData = new PreviewData
node = node,
renderTexture = new RenderTexture(256, 256, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave }
};
if (m_Previews.ContainsKey(node.guid))
foreach (var edge in m_Graph.addedEdges)
m_DirtyShaders.Add(edge.inputSlot.nodeGuid);
}
List<PreviewData> m_RenderList2D = new List<PreviewData>();
List<PreviewData> m_RenderList3D = new List<PreviewData>();
public void RenderPreviews()
m_PreviewProperties.Clear();
var time = Time.realtimeSinceStartup;
if (previewData.shader == null)
previewData.texture = null;
previewData.texture = m_ErrorTexture;
continue;
var node = m_Graph.GetNodeFromGuid(nodeGuid);
m_PreviewMaterial.shader = previewData.shader;
if (previewData.previewMode == PreviewMode.Preview3D)
m_SceneResources.camera.transform.position = -Vector3.forward * 5;
m_SceneResources.camera.transform.rotation = Quaternion.identity;
m_SceneResources.camera.orthographic = false;
if (previewData.previewMode == PreviewMode.Preview2D)
m_RenderList2D.Add(previewData);
m_SceneResources.camera.transform.position = -Vector3.forward * 2;
m_SceneResources.camera.orthographicSize = 1;
m_SceneResources.camera.orthographic = true;
m_RenderList3D.Add(previewData);
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
foreach (var previewData in m_RenderList2D)
GL.Clear(true, true, Color.black);
Graphics.Blit(Texture2D.whiteTexture, previewData.renderTexture, m_SceneResources.checkerboardMaterial);
Graphics.DrawMesh(m_SceneResources.quad, Matrix4x4.identity, m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
var previousUseSRP = Unsupported.useScriptableRenderPipeline;
Unsupported.useScriptableRenderPipeline = false;
m_SceneResources.camera.Render();
Unsupported.useScriptableRenderPipeline = previousUseSRP;
RenderTexture.active = previousRenderTexure;
previewData.texture = previewData.renderTexture;
m_RenderList2D.Clear();
// Render 3D previews
foreach (var previewData in m_RenderList3D)
m_SceneResources.camera.targetTexture = previewData.renderTexture;
var previousRenderTexure = RenderTexture.active;
RenderTexture.active = previewData.renderTexture;
Mesh mesh = previewData.previewMode == PreviewMode.Preview2D ? m_SceneResources.quad : (previewData.mesh ?? m_SceneResources.sphere);
Graphics.DrawMesh(
mesh,
previewData.previewMode == PreviewMode.Preview3D ? Matrix4x4.TRS(-mesh.bounds.center, Quaternion.identity, Vector3.one) : Matrix4x4.identity,
m_PreviewMaterial,
1,
m_SceneResources.camera,
0,
m_PreviewPropertyBlock,
ShadowCastingMode.Off,
false,
null,
false);
var mesh = previewData.mesh ?? m_SceneResources.sphere;
Graphics.DrawMesh(mesh, Matrix4x4.TRS(-mesh.bounds.center, Quaternion.identity, Vector3.one), m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
Unsupported.useScriptableRenderPipeline = node is IMasterNode;
Unsupported.useScriptableRenderPipeline = previewData.node is IMasterNode;
m_SceneResources.light0.enabled = false;
m_SceneResources.light1.enabled = false;
m_RenderList3D.Clear();
foreach (var nodeGuid in m_DirtyPreviews)
public class PreviewData
public INode node { get; set; }
public Shader shader { get; set; }
public Mesh mesh { get; set; }
public string shaderString { get; set; }