}
Stack < Guid > m_Wavefront = new Stack < Guid > ( ) ;
List < IEdge > m_Edges = new List < IEdge > ( ) ;
List < MaterialSlot > m_Slots = new List < MaterialSlot > ( ) ;
void PropagateNodeSet ( HashSet < Guid > nodeGuidSet , bool forward = true , IEnumerable < Guid > initialWavefront = null )
{
continue ;
// Loop through all nodes that the node feeds into.
foreach ( var slot in forward ? node . GetOutputSlots < ISlot > ( ) : node . GetInputSlots < ISlot > ( ) )
m_Slots . Clear ( ) ;
if ( forward )
node . GetOutputSlots ( m_Slots ) ;
else
node . GetInputSlots ( m_Slots ) ;
foreach ( var slot in m_Slots )
foreach ( var edge in m_Graph . GetEdges ( slot . slotReference ) )
m_Edges . Clear ( ) ;
m_Graph . GetEdges ( slot . slotReference , m_Edges ) ;
foreach ( var edge in m_Edges )
{
// We look at each node we feed into.
var connectedSlot = forward ? edge . inputSlot : edge . outputSlot ;
ShaderUtil . UpdateShaderAsset ( m_UberShader , m_UberShaderString ) ;
File . WriteAllText ( Application . dataPath + "/../UberShader.shader" , ( m_UberShaderString ? ? "null" ) . Replace ( "UnityEngine.MaterialGraph" , "Generated" ) ) ;
var message = "RecreateUberShader: " + Environment . NewLine + m_UberShaderString ;
bool uberShaderHasError = false ;
uberShaderHasError = true ;
}
foreach ( var node in uberNodes )
continue ;
shaderData . previewMode = m_NodesWith3DPreview . Contains ( node . guid ) ? PreviewMode . Preview3D : PreviewMode . Preview2D ;
shaderData . shader = m_UberShader ;
shaderData . hasError = uberShaderHasError ;
}
i + + ;
EditorUtility . DisplayProgressBar ( "Shader Graph" , string . Format ( "Compiling preview shaders ({0}/{1})" , i , count ) , 0f ) ;
foreach ( var previewProperty in m_PreviewProperties )
{
if ( previewProperty . m_P ropType = = PropertyType . Texture & & previewProperty . m_Textur e ! = null )
m_PreviewPropertyBlock . SetTexture ( previewProperty . m_N ame, previewProperty . m_Textur e) ;
else if ( previewProperty . m_P ropType = = PropertyType . Cubemap & & previewProperty . m_Cubemap ! = null )
m_PreviewPropertyBlock . SetTexture ( previewProperty . m_N ame, previewProperty . m_Cubemap ) ;
else if ( previewProperty . m_P ropType = = PropertyType . Color )
m_PreviewPropertyBlock . SetColor ( previewProperty . m_N ame, previewProperty . m_Color ) ;
else if ( previewProperty . m_P ropType = = PropertyType . Vector2 )
m_PreviewPropertyBlock . SetVector ( previewProperty . m_N ame, previewProperty . m_Vector4 ) ;
else if ( previewProperty . m_P ropType = = PropertyType . Vector3 )
m_PreviewPropertyBlock . SetVector ( previewProperty . m_N ame, previewProperty . m_Vector4 ) ;
else if ( previewProperty . m_P ropType = = PropertyType . Vector4 )
m_PreviewPropertyBlock . SetVector ( previewProperty . m_N ame, previewProperty . m_Vector4 ) ;
else if ( previewProperty . m_P ropType = = PropertyType . Float )
m_PreviewPropertyBlock . SetFloat ( previewProperty . m_N ame, previewProperty . m_Float ) ;
if ( previewProperty . p ropType = = PropertyType . Texture & & previewProperty . textureValu e ! = null )
m_PreviewPropertyBlock . SetTexture ( previewProperty . n ame, previewProperty . textureValu e) ;
else if ( previewProperty . p ropType = = PropertyType . Cubemap & & previewProperty . cubemapValue ! = null )
m_PreviewPropertyBlock . SetTexture ( previewProperty . n ame, previewProperty . cubemapValue ) ;
else if ( previewProperty . p ropType = = PropertyType . Color )
m_PreviewPropertyBlock . SetColor ( previewProperty . n ame, previewProperty . colorValue ) ;
else if ( previewProperty . p ropType = = PropertyType . Vector2 )
m_PreviewPropertyBlock . SetVector ( previewProperty . n ame, previewProperty . vector4Value ) ;
else if ( previewProperty . p ropType = = PropertyType . Vector3 )
m_PreviewPropertyBlock . SetVector ( previewProperty . n ame, previewProperty . vector4Value ) ;
else if ( previewProperty . p ropType = = PropertyType . Vector4 )
m_PreviewPropertyBlock . SetVector ( previewProperty . n ame, previewProperty . vector4Value ) ;
else if ( previewProperty . p ropType = = PropertyType . Float )
m_PreviewPropertyBlock . SetFloat ( previewProperty . n ame, previewProperty . floatValue ) ;
}
m_PreviewProperties . Clear ( ) ;
}
renderData . texture = null ;
continue ;
}
if ( MaterialGraphAsset . ShaderHasError ( renderData . shaderData . shader ) )
if ( renderData . shaderData . hasError )
{
renderData . texture = m_ErrorTexture ;
continue ;
m_SceneResources . camera . transform . rotation = Quaternion . identity ;
m_SceneResources . camera . orthographicSize = 1 ;
m_SceneResources . camera . orthographic = true ;
m_RenderList2D . Sort ( ( data1 , data2 ) = > data1 . shaderData . shader . GetInstanceID ( ) . CompareTo ( data2 . shaderData . shader . GetInstanceID ( ) ) ) ;
m_PreviewMaterial . shader = renderData . shaderData . shader ;
if ( m_PreviewMaterial . shader ! = renderData . shaderData . shader )
m_PreviewMaterial . shader = renderData . shaderData . shader ;
m_SceneResources . camera . targetTexture = renderData . renderTexture ;
var previousRenderTexure = RenderTexture . active ;
RenderTexture . active = renderData . renderTexture ;
m_SceneResources . camera . transform . position = - Vector3 . forward * 5 ;
m_SceneResources . camera . transform . rotation = Quaternion . identity ;
m_SceneResources . camera . orthographic = false ;
foreach ( var previewData in m_RenderList3D )
m_RenderList3D . Sort ( ( data1 , data2 ) = > data1 . shaderData . shader . GetInstanceID ( ) . CompareTo ( data2 . shaderData . shader . GetInstanceID ( ) ) ) ;
foreach ( var renderData in m_RenderList3D )
if ( m_UberShaderIds . TryGetValue ( previewData . shaderData . node . guid , out outputId ) )
if ( m_UberShaderIds . TryGetValue ( renderData . shaderData . node . guid , out outputId ) )
m_PreviewMaterial . shader = previewData . shaderData . shader ;
m_SceneResources . camera . targetTexture = previewData . renderTexture ;
if ( m_PreviewMaterial . shader ! = renderData . shaderData . shader )
m_PreviewMaterial . shader = renderData . shaderData . shader ;
m_SceneResources . camera . targetTexture = renderData . renderTexture ;
RenderTexture . active = previewData . renderTexture ;
RenderTexture . active = renderData . renderTexture ;
Graphics . Blit ( Texture2D . whiteTexture , previewData . renderTexture , m_SceneResources . checkerboardMaterial ) ;
var mesh = previewData . mesh ? ? m_SceneResources . sphere ;
Graphics . Blit ( Texture2D . whiteTexture , renderData . renderTexture , m_SceneResources . checkerboardMaterial ) ;
var mesh = renderData . mesh ? ? m_SceneResources . sphere ;
Unsupported . useScriptableRenderPipeline = previewData . shaderData . node is IMasterNode ;
Unsupported . useScriptableRenderPipeline = renderData . shaderData . node is IMasterNode ;
previewData . texture = previewData . renderTexture ;
renderData . texture = renderData . renderTexture ;
foreach ( var previewRenderData in m_RenderList2D . Union ( m_RenderList3D ) )
{
if ( previewRenderData . onPreviewChanged ! = null )
previewRenderData . onPreviewChanged ( ) ;
}
foreach ( var renderData in m_RenderList2D )
renderData . NotifyPreviewChanged ( ) ;
foreach ( var renderData in m_RenderList3D )
renderData . NotifyPreviewChanged ( ) ;
m_RenderList2D . Clear ( ) ;
m_RenderList3D . Clear ( ) ;
if ( string . IsNullOrEmpty ( shaderData . shaderString ) )
{
if ( shaderData . shader ! = null )
{
ShaderUtil . ClearShaderErrors ( shaderData . shader ) ;
shaderData . shader = null ;
shaderData . shader = null ;
}
}
if ( shaderData . shader ! = null & & MaterialGraphAsset . ShaderHasError ( shaderData . shader ) )
{
ShaderUtil . ClearShaderErrors ( shaderData . shader ) ;
Object . DestroyImmediate ( shaderData . shader , true ) ;
shaderData . shader = null ;
}
if ( shaderData . shader = = null )
// Debug output
var message = "RecreateShader: " + node . GetVariableNameForNode ( ) + Environment . NewLine + shaderData . shaderString ;
if ( MaterialGraphAsset . ShaderHasError ( shaderData . shader ) )
{
shaderData . hasError = true ;
ShaderUtil . ClearShaderErrors ( shaderData . shader ) ;
Object . DestroyImmediate ( shaderData . shader , true ) ;
shaderData . shader = null ;
}
else
{
shaderData . hasError = false ;
}
}
void DestroyPreview ( Guid nodeGuid , PreviewRenderData previewRenderData )
public Shader shader { get ; set ; }
public string shaderString { get ; set ; }
public PreviewMode previewMode { get ; set ; }
public bool hasError { get ; set ; }
}
public class PreviewRenderData
public RenderTexture renderTexture { get ; set ; }
public Texture texture { get ; set ; }
public OnPreviewChanged onPreviewChanged ;
public void NotifyPreviewChanged ( )
{
if ( onPreviewChanged ! = null )
onPreviewChanged ( ) ;
}
}
}