浏览代码

Add mesh selection for master node preveiw

/main
Jens Holm 7 年前
当前提交
0f07c1c0
共有 5 个文件被更改,包括 14 次插入5 次删除
  1. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  2. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


VisualElement m_PropertyItems;
VisualElement m_LayerItems;
VisualElement m_ContentContainer;
Experimental.UIElements.ObjectField m_PreviewMeshPicker;
AbstractNodeEditorView m_EditorView;
TypeMapper m_TypeMapper;

m_Preview = new PreviewView {name = "preview", image = Texture2D.blackTexture};
bottomContainer.Add(m_Preview);
m_PreviewMeshPicker = new Experimental.UIElements.ObjectField() { objectType = typeof(Mesh) };
bottomContainer.Add(m_PreviewMeshPicker);
}
Add(bottomContainer);

if (m_MasterNode != null)
{
m_PreviewHandle = m_PreviewSystem.GetPreview(m_MasterNode);
m_PreviewHandle.mesh = null;
m_PreviewHandle.onPreviewChanged += OnPreviewChanged;
}
}

void OnPreviewChanged()
{
m_Preview.image = m_PreviewHandle.texture ?? Texture2D.blackTexture;
m_PreviewHandle.mesh = m_PreviewMeshPicker.value as Mesh;
}
public void UpdateSelection(IEnumerable<INode> nodes)

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs


}
}
public void DoRenderPreview(RenderTexture renderTexture, Material mat, PreviewMode mode, bool allowSRP, float time, MaterialPropertyBlock properties = null)
public void DoRenderPreview(RenderTexture renderTexture, Material mat, Mesh mesh, PreviewMode mode, bool allowSRP, float time, MaterialPropertyBlock properties = null)
{
if (mat == null || mat.shader == null)
return;

Light1.intensity = 1.0f;
m_Camera.clearFlags = CameraClearFlags.Depth;
Mesh previewMesh = mesh == null ? s_Meshes[0] : mesh;
mode == PreviewMode.Preview3D ? s_Meshes[0] : quad,
mode == PreviewMode.Preview3D ? previewMesh : quad,
Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one),
mat,
1,

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs


var modified = false;
foreach (var slot in node.GetSlots<MaterialSlot>())
modified |= IMGUISlotEditorView.SlotField(slot);
GUILayout.Space(10);
return modified ? ModificationScope.Node : ModificationScope.Nothing;

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs


}
var node = m_Graph.GetNodeFromGuid(nodeGuid);
m_PreviewMaterial.shader = previewData.shader;
m_PreviewGenerator.DoRenderPreview(previewData.renderTexture, m_PreviewMaterial, previewData.previewMode, node is IMasterNode, time, m_PreviewPropertyBlock);
m_PreviewGenerator.DoRenderPreview(previewData.renderTexture, m_PreviewMaterial, previewData.mesh, previewData.previewMode, node is IMasterNode, time, m_PreviewPropertyBlock);
previewData.texture = previewData.renderTexture;
}

public class PreviewData
{
public Shader shader { get; set; }
public Mesh mesh { get; set; }
public string shaderString { get; set; }
public PreviewMode previewMode { get; set; }
public RenderTexture renderTexture { get; set; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs


using (var generator = new MaterialGraphPreviewGenerator())
{
var renderTexture = new RenderTexture(res, res, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave };
generator.DoRenderPreview(renderTexture, m_PreviewMaterial, PreviewMode.Preview3D, true, 10);
generator.DoRenderPreview(renderTexture, m_PreviewMaterial, null, PreviewMode.Preview3D, true, 10);
Assert.IsNotNull(renderTexture, "Render failed");

正在加载...
取消
保存