|
|
|
|
|
|
protected NodePreviewPresenter() |
|
|
|
{} |
|
|
|
|
|
|
|
private MaterialGraphPreviewGenerator m_PreviewGenerator; |
|
|
|
MaterialGraphPreviewGenerator m_PreviewGenerator; |
|
|
|
private int m_LastShaderVersion = -1; |
|
|
|
int m_LastShaderVersion = -1; |
|
|
|
private Material m_PreviewMaterial; |
|
|
|
Material m_PreviewMaterial; |
|
|
|
private Shader m_PreviewShader; |
|
|
|
Shader m_PreviewShader; |
|
|
|
private AbstractMaterialNode m_Node; |
|
|
|
AbstractMaterialNode m_Node; |
|
|
|
private ModificationScope m_modificationScope; |
|
|
|
ModificationScope m_ModificationScope; |
|
|
|
|
|
|
|
// Null means no modification is currently in progress.
|
|
|
|
public ModificationScope modificationScope |
|
|
|
|
|
|
return m_modificationScope; |
|
|
|
return m_ModificationScope; |
|
|
|
if (m_modificationScope >= value) |
|
|
|
if (m_ModificationScope >= value) |
|
|
|
m_modificationScope = value; |
|
|
|
m_ModificationScope = value; |
|
|
|
private Texture m_texture; |
|
|
|
Texture m_Texture; |
|
|
|
private PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D; |
|
|
|
public Texture texture |
|
|
|
{ |
|
|
|
get { return m_Texture; } |
|
|
|
} |
|
|
|
|
|
|
|
PreviewMode m_GeneratedShaderMode = PreviewMode.Preview2D; |
|
|
|
|
|
|
|
public Material previewMaterial |
|
|
|
{ |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private MaterialGraphPreviewGenerator previewGenerator |
|
|
|
MaterialGraphPreviewGenerator previewGenerator |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
|
|
|
public void Initialize(AbstractMaterialNode node) |
|
|
|
{ |
|
|
|
m_Node = node; |
|
|
|
m_modificationScope = ModificationScope.Graph; |
|
|
|
m_ModificationScope = ModificationScope.Graph; |
|
|
|
public Texture Render(Vector2 dimension) |
|
|
|
public void UpdateTexture() |
|
|
|
return null; |
|
|
|
{ |
|
|
|
m_Texture = null; |
|
|
|
return; |
|
|
|
} |
|
|
|
return null; |
|
|
|
{ |
|
|
|
m_Texture = null; |
|
|
|
return; |
|
|
|
} |
|
|
|
var scope = m_modificationScope; |
|
|
|
m_modificationScope = ModificationScope.Nothing; |
|
|
|
var scope = m_ModificationScope; |
|
|
|
m_ModificationScope = ModificationScope.Nothing; |
|
|
|
bool status = false; |
|
|
|
status = UpdatePreviewShader(); |
|
|
|
var status = UpdatePreviewShader(); |
|
|
|
m_texture = RenderPreview(dimension); |
|
|
|
m_Texture = RenderPreview(new Vector2(256, 256)); |
|
|
|
else if (m_texture == null) |
|
|
|
else if (texture == null) |
|
|
|
m_texture = RenderPreview(dimension); |
|
|
|
m_Texture = RenderPreview(new Vector2(256, 256)); |
|
|
|
|
|
|
|
return m_texture; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual string GetPreviewShaderString() |
|
|
|
{ |
|
|
|
|
|
|
return ShaderGenerator.GeneratePreviewShader(m_Node, out m_GeneratedShaderMode); |
|
|
|
} |
|
|
|
|
|
|
|
private bool UpdatePreviewShader() |
|
|
|
bool UpdatePreviewShader() |
|
|
|
{ |
|
|
|
if (m_Node == null || m_Node.hasError) |
|
|
|
return false; |
|
|
|
|
|
|
/// RenderPreview gets called in OnPreviewGUI. Nodes can override
|
|
|
|
/// RenderPreview and do their own rendering to the render texture
|
|
|
|
/// </summary>
|
|
|
|
private Texture RenderPreview(Vector2 targetSize) |
|
|
|
Texture RenderPreview(Vector2 targetSize) |
|
|
|
{ |
|
|
|
previewMaterial.shader = m_PreviewShader; |
|
|
|
UpdateMaterialProperties(m_Node, previewMaterial); |
|
|
|
|
|
|
private static void SetPreviewMaterialProperty(PreviewProperty previewProperty, Material mat) |
|
|
|
static void SetPreviewMaterialProperty(PreviewProperty previewProperty, Material mat) |
|
|
|
{ |
|
|
|
switch (previewProperty.m_PropType) |
|
|
|
{ |
|
|
|