浏览代码

[Shader Graph]Fix minor issues as they are encountered

/main
Tim Cooper 9 年前
当前提交
3138de7e
共有 10 个文件被更改,包括 997 次插入128 次删除
  1. 7
      UnityProject/Assets/Editor/Material/AssetCallbacks/CreateShaderGraph.cs
  2. 8
      UnityProject/Assets/Editor/Material/MaterialGraph.cs
  3. 6
      UnityProject/Assets/Editor/Material/Nodes/ScreenPosNode.cs
  4. 2
      UnityProject/Assets/Editor/Material/Nodes/TextureNode.cs
  5. 64
      UnityProject/Assets/Editor/Material/Nodes/UVNode.cs
  6. 8
      UnityProject/Assets/Editor/Material/Prop/MaterialProperties.cs
  7. 980
      UnityProject/Assets/Graphs/FresnelFromSGraph.ShaderGraph
  8. 3
      UnityProject/Assets/MaterialGraph/shader.template
  9. 4
      UnityProject/Assets/TestData/TestMat1.mat.meta
  10. 43
      UnityProject/Assets/TestData/TestMat1.mat

7
UnityProject/Assets/Editor/Material/AssetCallbacks/CreateShaderGraph.cs


using System.IO;
using System.IO;
using UnityEditor.ProjectWindowCallback;
/*public class CreateShaderGraph : EndNameEditActionCallback
public class CreateShaderGraph : EndNameEditAction
{
[MenuItem("Assets/Create/Shader Graph", false, 208)]
public static void CreateMaterialGraph()

AssetDatabase.CreateAsset(graph, pathName);
graph.CreateSubAssets();
}
}*/
}
}

8
UnityProject/Assets/Editor/Material/MaterialGraph.cs


[SerializeField]
private Shader m_Shader;
public int GetShaderInstanceID()
{
Debug.Log("Returning: " + m_Shader.GetInstanceID());
return m_Shader.GetInstanceID();
}
public MaterialProperties materialProperties { get { return m_MaterialProperties; } }
public MaterialOptions materialOptions { get { return m_MaterialOptions; } }

m_Shader = UnityEditor.ShaderUtil.CreateShaderAsset(shaderSource);
m_Shader.name = name;
m_Shader.hideFlags = HideFlags.HideInHierarchy;
//m_Shader.hideFlags = HideFlags.HideInHierarchy;
}
AssetDatabase.AddObjectToAsset (m_Shader, this);

6
UnityProject/Assets/Editor/Material/Nodes/ScreenPosNode.cs


public void GenerateVertexToFragmentBlock(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + "4 screenPos;", true);
string temp = precision + "4 screenPos";
if (generationMode == GenerationMode.Preview2D)
temp += " : TEXCOORD1";
temp += ";";
visitor.AddShaderChunk(temp, true);
}
}
}

2
UnityProject/Assets/Editor/Material/Nodes/TextureNode.cs


return;
if (uvSlot.edges.Count == 0)
UVNode.GenerateVertexToFragmentBlock (visitor);
UVNode.StaticGenerateVertexToFragmentBlock(visitor, generationMode);
}
public void GenerateVertexShaderBlock (ShaderGenerator visitor, GenerationMode generationMode)

64
UnityProject/Assets/Editor/Material/Nodes/UVNode.cs


private const string kOutputSlotName = "UV";
public override bool hasPreview { get { return true; } }
[SerializeField]
private ShaderProperty m_BoundProperty;
public override void Init ()
{
base.Init ();

public static void GenerateVertexToFragmentBlock (ShaderGenerator visitor)
public static void StaticGenerateVertexToFragmentBlock (ShaderGenerator visitor, GenerationMode generationMode)
visitor.AddShaderChunk("half4 meshUV0;", true);
string temp = "half4 meshUV0";
if (generationMode == GenerationMode.Preview2D)
temp += " : TEXCOORD0";
temp += ";";
visitor.AddShaderChunk(temp, true);
GenerateVertexToFragmentBlock (visitor);
StaticGenerateVertexToFragmentBlock (visitor, generationMode);
}
public static void GenerateVertexShaderBlock(ShaderGenerator visitor)

var outputSlot = FindOutputSlot (kOutputSlotName);
string uvValue = "IN.meshUV0";
if (m_BoundProperty != null && m_BoundProperty is TextureProperty)
uvValue = precision + "4 (TRANSFORM_TEX(IN.meshUV0, " + m_BoundProperty.name + "), 0.0, 0.0)";
}
// UI Shizz
public override void NodeUI(GraphGUI host)
{
base.NodeUI(host);
var configuredTextureProperties = new ShaderProperty[0];
if (graph is IGenerateGraphProperties)
configuredTextureProperties = (graph as IGenerateGraphProperties).GetPropertiesForPropertyType(PropertyType.Texture2D).ToArray ();
var names = new List<string> { "none" };
names.AddRange(configuredTextureProperties.Select(x => x.name));
var currentIndex = names.IndexOf(m_BoundProperty == null ? "none" : m_BoundProperty.name);
EditorGUI.BeginChangeCheck();
currentIndex = EditorGUILayout.Popup("Bound Property", currentIndex, names.ToArray());
if (EditorGUI.EndChangeCheck())
{
m_BoundProperty = null;
if (currentIndex > 0)
m_BoundProperty = configuredTextureProperties[currentIndex - 1];
RegeneratePreviewShaders();
}
}
public virtual void RefreshBoundProperty (ShaderProperty toRefresh, bool rebuildShader)
{
if (m_BoundProperty != null && m_BoundProperty == toRefresh)
{
if (rebuildShader)
RegeneratePreviewShaders();
else
UpdatePreviewProperties();
}
}
public void UnbindProperty (ShaderProperty prop)
{
if (m_BoundProperty != null && m_BoundProperty == prop)
{
m_BoundProperty = null;
RegeneratePreviewShaders();
}
}
}
}

8
UnityProject/Assets/Editor/Material/Prop/MaterialProperties.cs


{
node.RefreshBoundProperty (property, nameChanged);
}
foreach (var node in nodes.Where(x => x is UVNode).Cast<UVNode>())
{
node.RefreshBoundProperty (property, nameChanged);
}
}
if (GUILayout.Button ("Remove"))
{

foreach (var prop in propsToRemove)
{
foreach (var node in nodes.Where(x => x is PropertyNode).Cast<PropertyNode>())
{
node.UnbindProperty (prop);
}
foreach (var node in nodes.Where(x => x is UVNode).Cast<UVNode>())
{
node.UnbindProperty (prop);
}

980
UnityProject/Assets/Graphs/FresnelFromSGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

3
UnityProject/Assets/MaterialGraph/shader.template


LOD 200
CGPROGRAM
#pragma exclude_renderers ps3 flash xbox360 gles d3d11 d3d11_9x
#pragma target 3.0
#pragma surface surf ${LightingFunctionName} ${VertexShaderDecl}
#pragma glsl

ENDCG
}
FallBack "Diffuse"
}
}

4
UnityProject/Assets/TestData/TestMat1.mat.meta


fileFormatVersion: 2
guid: 84169261e50a2ce4fbbe8756bffa498f
NativeFormatImporter:
userData:

43
UnityProject/Assets/TestData/TestMat1.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 3
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: TestMat1
m_Shader: {fileID: 4800000, guid: 764177c77373b424eaa9aa1a634a3cba, type: 2}
m_ShaderKeywords: []
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
data:
first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats: {}
m_Colors:
data:
first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
data:
first:
name: FrenelPower
second: {r: 1.74000001, g: 0, b: 4.26000023, a: 0}
data:
first:
name: FresnelColor
second: {r: 0, g: 1, b: 1, a: 0}
data:
first:
name: MyProp
second: {r: 2.08999991, g: 0, b: 0, a: 0}
data:
first:
name: FresnelPower
second: {r: 1.74000001, g: 0, b: 4.26000023, a: 0}
正在加载...
取消
保存