浏览代码

Changing all Texture2D types to Teture to allow custom render textures to be added.

/main
vlad 8 年前
当前提交
12603c9a
共有 15 个文件被更改,包括 75 次插入51 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureAssetPresenter.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureLODNodePresenter.cs
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
  6. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  8. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs
  9. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs
  10. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureLODNode.cs
  11. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureNode.cs
  12. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewProperty.cs
  13. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs
  14. 10
      MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs
  15. 52
      MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs


{
switch (previewProperty.m_PropType)
{
case PropertyType.Texture2D:
case PropertyType.Texture:
mat.SetTexture(previewProperty.m_Name, previewProperty.m_Texture);
break;
case PropertyType.Cubemap:

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureAssetPresenter.cs


return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture2D), null) as Texture2D;
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureLODNodePresenter.cs


return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture2D), null) as Texture2D;
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TextureNodePresenter.cs


return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture2D), null) as Texture2D;
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture), null) as Texture;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta


fileFormatVersion: 2
guid: 9ab5e16c2083a4fe689209a8c1ae425e
timeCreated: 1495569001
timeCreated: 1495630928
defaultTextures: []
nonModifiableTextures: []
defaultTextures:
- TextureAsset_ebbe75eb_728a_4e6c_b8a1_994df86c74ad_Uniform: {fileID: 2800000, guid: 225a31f233f5b82488f996901413908d,
type: 3}
nonModifiableTextures:
- Texture_94ba0aed_e579_4ba0_b677_86c6deda72a2_Uniform: {fileID: 2800000, guid: 9c50a18d04437449b86568cfcbb668a7,
type: 3}
- Texture_65e72eb9_bdc7_4c17_b514_379aaeefd7ca_Uniform: {fileID: 2800000, guid: 84462bdfeee9d694bbebf34e5f3faa74,
type: 3}
userData:
assetBundleName:
assetBundleVariant:

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/PropertyNodeTests.cs


"MudDiffuse.tif"
};
private static Texture2D FindTestTexture()
private static Texture FindTestTexture()
return AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
return AssetDatabase.LoadAssetAtPath<Texture>(texturePath);
}
[SetUp]

[Test]
public void TestTextureNodeTypeIsCorrect()
{
Assert.AreEqual(PropertyType.Texture2D, m_TextureNode.propertyType);
Assert.AreEqual(PropertyType.Texture, m_TextureNode.propertyType);
}
[Test]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs


switch (slotValue)
{
case ConcreteSlotValueType.sampler2D:
return PropertyType.Texture2D;
return PropertyType.Texture;
case ConcreteSlotValueType.Vector1:
return PropertyType.Float;
case ConcreteSlotValueType.Vector2:

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/DepthTextureNode.cs


public override bool hasPreview { get { return true; } }
public Texture2D defaultTexture { get; set; }
public Texture defaultTexture { get; set; }
public DepthTextureNode()
{

return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}

return GetVariableNameForNode();
}
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/SceneData/MotionVectorTextureNode.cs


public override bool hasPreview { get { return true; } }
public Texture2D defaultTexture { get; set; }
public Texture defaultTexture { get; set; }
public MotionVectorTextureNode()
{

return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}

return GetVariableNameForNode();
}
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureLODNode.cs


[Serializable]
private class TextureHelper
{
public Texture2D texture;
public Texture texture;
public Texture2D defaultTexture
public Texture defaultTexture
{
get
{

}
}
#else
public Texture2D defaultTexture { get; set; }
public Texture defaultTexture { get; set; }
#endif
public TextureType textureType

return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_PropType = PropertyType.Texture,
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Texture/TextureNode.cs


[Serializable]
private class TextureHelper
{
public Texture2D texture;
public Texture texture;
public Texture2D defaultTexture
public Texture defaultTexture
{
get
{

}
}
#else
public Texture2D defaultTexture {get; set; }
public Texture defaultTexture {get; set; }
#endif
public TextureType textureType

return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_PropType = PropertyType.Texture,
public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public override PropertyType propertyType { get { return PropertyType.Texture; } }
public bool RequiresMeshUV(UVChannel channel)
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewProperty.cs


public PropertyType m_PropType;
public Color m_Color;
public Texture2D m_Texture;
public Texture m_Texture;
public Cubemap m_Cubemap;
public Vector4 m_Vector4;
public float m_Float;

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyType.cs


public enum PropertyType
{
Color,
Texture2D,
Texture,
Cubemap,
Float,
Vector2,

10
MaterialGraphProject/Assets/Vlad/TextureAssetNode.cs


[Serializable]
private class TextureHelper
{
public Texture2D texture;
public Texture texture;
public Texture2D defaultTexture
public Texture defaultTexture
{
get
{

}
}
#else
public Texture2D defaultTexture {get; set; }
public Texture defaultTexture {get; set; }
#endif
public TextureType textureType

return new PreviewProperty
{
m_Name = propertyName,
m_PropType = PropertyType.Texture2D,
m_PropType = PropertyType.Texture,
m_Texture = defaultTexture
};
}

public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public override PropertyType propertyType { get { return PropertyType.Texture; } }
}
}

52
MaterialGraphProject/Assets/Vlad/UVTriPlanar.cs


namespace UnityEngine.MaterialGraph
{
[Title("UV/Tri-Planar Mapping")]
public class UVTriPlanar : Function1Input, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition
public class UVTriPlanar : Function2Input, IGeneratesFunction, IMayRequireNormal, IMayRequireWorldPosition
private const string kBlendSlotName = "Blend";
protected override string GetFunctionName()
{

protected override MaterialSlot GetInputSlot()
protected override MaterialSlot GetInputSlot1()
return new MaterialSlot(InputSlotId, kTextureSlotName, kTextureSlotName, SlotType.Input, SlotValueType.sampler2D, Vector4.zero, false);
return new MaterialSlot(InputSlot1Id, kTextureSlotName, kTextureSlotName, SlotType.Input, SlotValueType.sampler2D, Vector4.zero, false);
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, kBlendSlotName, kBlendSlotName, SlotType.Input, SlotValueType.Vector1, Vector4.one);
}
protected override MaterialSlot GetOutputSlot()

}
}
protected override string GetFunctionPrototype(string argName)
protected override string GetFunctionPrototype(string arg1Name, string arg2Name)
+ "sampler2D " + argName + ", float3 normal, float3 pos)";
+ "sampler2D " + arg1Name + ", " + precision + " " + arg2Name + ", float3 normal, float3 pos)";
protected override string GetFunctionCallBody(string inputValue)
protected override string GetFunctionCallBody(string input1Value, string input2Value)
return GetFunctionName() + " (" + inputValue + "_Uniform" + ", IN.worldNormal, IN.worldPos)";
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ", IN.worldNormal, IN.worldPos)";
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

{
var outputString = new ShaderGenerator();
var textureSlot = FindInputSlot<MaterialSlot>(InputSlotId);
var textureSlot = FindInputSlot<MaterialSlot>(InputSlot1Id);
if (textureSlot == null)
return;

}
////////////////////////////////QQQ: Any better way of getting "_Uniform" at the end? //////////////////////////////////
// outputString.AddShaderChunk("sampler2D " + textureName + "_Uniform;", false);
// outputString.AddShaderChunk("", false);
outputString.AddShaderChunk(GetFunctionPrototype("arg"), false);
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();

//control the influence of the blend
outputString.AddShaderChunk("blend = lerp(0, 1, arg2);", false);
outputString.AddShaderChunk("fixed4 cx = tex2D(arg, pos.yz);", false);
outputString.AddShaderChunk("fixed4 cy = tex2D(arg, pos.xz);", false);
outputString.AddShaderChunk("fixed4 cz = tex2D(arg, pos.xy);", false);
outputString.AddShaderChunk("fixed4 cx = tex2D(arg1, pos.yz);", false);
outputString.AddShaderChunk("fixed4 cy = tex2D(arg1, pos.xz);", false);
outputString.AddShaderChunk("fixed4 cz = tex2D(arg1, pos.xy);", false);
// blend the textures based on weights

outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
//prevent validation errors when a sampler2D input is missing
//use on any input requiring a TextureAssetNode
public override void ValidateNode()
{
base.ValidateNode();
var slot = FindInputSlot<MaterialSlot>(InputSlot1Id);
if (slot == null)
return;
var edges = owner.GetEdges(slot.slotReference).ToList();
hasError |= edges.Count == 0;
}
public bool RequiresNormal()

正在加载...
取消
保存