GitHub
7 年前
当前提交
5d9b28af
共有 27 个文件被更改,包括 614 次插入 和 2 次删除
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Texture2DNode.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/GraphDropTarget.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
79MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapInputMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapInputMaterialSlot.cs.meta
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapMaterialSlot.cs.meta
-
65MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs.meta
-
40MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs.meta
-
67MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapAssetNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapAssetNode.cs.meta
-
81MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/CubemapNode.cs.meta
-
55MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/CubemapControl.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/CubemapControl.cs.meta
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/CubemapSlotControlView.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/CubemapSlotControlView.cs.meta
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Slots; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class CubemapInputMaterialSlot : CubemapMaterialSlot |
|||
{ |
|||
[SerializeField] |
|||
private SerializableCubemap m_Cubemap = new SerializableCubemap(); |
|||
|
|||
public Cubemap cubemap |
|||
{ |
|||
get { return m_Cubemap.cubemap; } |
|||
set { m_Cubemap.cubemap = value; } |
|||
} |
|||
|
|||
public CubemapInputMaterialSlot() |
|||
{} |
|||
|
|||
public CubemapInputMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override VisualElement InstantiateControl() |
|||
{ |
|||
return new CubemapSlotControlView(this); |
|||
} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
return matOwner.GetVariableNameForSlot(id); |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
var prop = new CubemapShaderProperty(); |
|||
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
prop.modifiable = false; |
|||
prop.generatePropertyBlock = true; |
|||
prop.value.cubemap = cubemap; |
|||
properties.AddShaderProperty(prop); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = PropertyType.Cubemap, |
|||
m_Cubemap = cubemap |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as CubemapInputMaterialSlot; |
|||
if (slot != null) |
|||
m_Cubemap = slot.m_Cubemap; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7b961f6f7e2617446afb6a8e329d84d4 |
|||
timeCreated: 1509276977 |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class CubemapMaterialSlot : MaterialSlot |
|||
{ |
|||
public CubemapMaterialSlot() |
|||
{} |
|||
|
|||
public CubemapMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
SlotType slotType, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override SlotValueType valueType { get { return SlotValueType.Cubemap; } } |
|||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Cubemap; } } |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ada5a840e90db5e4d901c686dca382ab |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class CubemapShaderProperty : AbstractShaderProperty<SerializableCubemap> |
|||
{ |
|||
[SerializeField] |
|||
private bool m_Modifiable = true; |
|||
|
|||
public CubemapShaderProperty() |
|||
{ |
|||
value = new SerializableCubemap(); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Cubemap; } |
|||
} |
|||
|
|||
public bool modifiable |
|||
{ |
|||
get { return m_Modifiable; } |
|||
set { m_Modifiable = value; } |
|||
} |
|||
|
|||
public override Vector4 defaultValue |
|||
{ |
|||
get { return new Vector4(); } |
|||
} |
|||
|
|||
public override string GetPropertyBlockString() |
|||
{ |
|||
var result = new StringBuilder(); |
|||
if (!m_Modifiable) |
|||
{ |
|||
result.Append("[NonModifiableTextureData] "); |
|||
} |
|||
result.Append("[NoScaleOffset] "); |
|||
|
|||
result.Append(referenceName); |
|||
result.Append("(\""); |
|||
result.Append(displayName); |
|||
result.Append("\", CUBE) = \"\" {}"); |
|||
return result.ToString(); |
|||
} |
|||
|
|||
public override string GetPropertyDeclarationString() |
|||
{ |
|||
return "samplerCUBE " + referenceName + ";"; |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewMaterialProperty() |
|||
{ |
|||
return new PreviewProperty() |
|||
{ |
|||
m_Name = referenceName, |
|||
m_PropType = PropertyType.Cubemap, |
|||
m_Cubemap = value.cubemap |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ca5ddce766d5ae24f8be282b4f7a21bd |
|||
timeCreated: 1505346949 |
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class SerializableCubemap |
|||
{ |
|||
[SerializeField] |
|||
private string m_SerializedCubemap; |
|||
|
|||
[Serializable] |
|||
private class CubemapHelper |
|||
{ |
|||
public Cubemap cubemap; |
|||
} |
|||
|
|||
public Cubemap cubemap |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedCubemap)) |
|||
return null; |
|||
|
|||
var cube = new CubemapHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube); |
|||
return cube.cubemap; |
|||
} |
|||
set |
|||
{ |
|||
if (cubemap == value) |
|||
return; |
|||
|
|||
var cube = new CubemapHelper(); |
|||
cube.cubemap = value; |
|||
m_SerializedCubemap = EditorJsonUtility.ToJson(cube, true); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 01e80e004e94f5e48ad1cb83d5701300 |
|||
timeCreated: 1505346945 |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Texture/Cubemap Asset")] |
|||
public class CubemapAssetNode : AbstractMaterialNode |
|||
{ |
|||
public const int OutputSlotId = 0; |
|||
|
|||
const string kOutputSlotName = "Out"; |
|||
|
|||
public CubemapAssetNode() |
|||
{ |
|||
name = "Cubemap Asset"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new CubemapMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId }); |
|||
} |
|||
|
|||
[SerializeField] |
|||
private SerializableCubemap m_Cubemap = new SerializableCubemap(); |
|||
|
|||
[CubemapControl("")] |
|||
public Cubemap cubemap |
|||
{ |
|||
get { return m_Cubemap.cubemap; } |
|||
set |
|||
{ |
|||
if (m_Cubemap.cubemap == value) |
|||
return; |
|||
m_Cubemap.cubemap = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
properties.AddShaderProperty(new CubemapShaderProperty() |
|||
{ |
|||
overrideReferenceName = GetVariableNameForSlot(OutputSlotId), |
|||
generatePropertyBlock = true, |
|||
value = m_Cubemap, |
|||
modifiable = false |
|||
}); |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(new PreviewProperty |
|||
{ |
|||
m_Name = GetVariableNameForSlot(OutputSlotId), |
|||
m_PropType = PropertyType.Cubemap, |
|||
m_Cubemap = cubemap |
|||
}); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 968ed0a541658844486b1ac5ab57ee2d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Input/Texture/Cubemap")] |
|||
public class CubemapNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireViewDirection, IMayRequireNormal |
|||
{ |
|||
public const int OutputSlotId = 0; |
|||
public const int CubemapInputId = 1; |
|||
public const int ViewDirInputId = 2; |
|||
public const int NormalInputId = 3; |
|||
public const int LODInputId = 4; |
|||
|
|||
const string kOutputSlotName = "Out"; |
|||
const string kCubemapInputName = "Cube"; |
|||
const string kViewDirInputName = "ViewDir"; |
|||
const string kNormalInputName = "Normal"; |
|||
const string kLODInputName = "LOD"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public CubemapNode() |
|||
{ |
|||
name = "Cubemap"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero)); |
|||
AddSlot(new CubemapInputMaterialSlot(CubemapInputId, kCubemapInputName, kCubemapInputName)); |
|||
AddSlot(new ViewDirectionMaterialSlot(ViewDirInputId, kViewDirInputName, kViewDirInputName, CoordinateSpace.Object)); |
|||
AddSlot(new NormalMaterialSlot(NormalInputId, kNormalInputName, kNormalInputName, CoordinateSpace.Object)); |
|||
AddSlot(new Vector1MaterialSlot(LODInputId, kLODInputName, kLODInputName, SlotType.Input, 0)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotId, CubemapInputId, ViewDirInputId, NormalInputId, LODInputId }); |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get { return PreviewMode.Preview3D; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
string result = string.Format("{0}4 {1} = texCUBElod ({2}, {0}4(reflect(-{3}, {4}), {5}));" |
|||
, precision |
|||
, GetVariableNameForSlot(OutputSlotId) |
|||
, GetSlotValue(CubemapInputId, generationMode) |
|||
, GetSlotValue(ViewDirInputId, generationMode) |
|||
, GetSlotValue(NormalInputId, generationMode) |
|||
, GetSlotValue(LODInputId, generationMode)); |
|||
|
|||
visitor.AddShaderChunk(result, true); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresViewDirection() |
|||
{ |
|||
var viewDirSlot = FindInputSlot<MaterialSlot>(ViewDirInputId); |
|||
var edgesViewDir = owner.GetEdges(viewDirSlot.slotReference); |
|||
if (!edgesViewDir.Any()) |
|||
return CoordinateSpace.Object.ToNeededCoordinateSpace(); |
|||
else |
|||
return NeededCoordinateSpace.None; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
var normalSlot = FindInputSlot<MaterialSlot>(NormalInputId); |
|||
var edgesNormal = owner.GetEdges(normalSlot.slotReference); |
|||
if (!edgesNormal.Any()) |
|||
return CoordinateSpace.Object.ToNeededCoordinateSpace(); |
|||
else |
|||
return NeededCoordinateSpace.None; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6eaeb9c846408f74daeadcc3314810e4 |
|||
timeCreated: 1495637741 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using UnityEditor.ShaderGraph; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Controls |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Property)] |
|||
public class CubemapControlAttribute : Attribute, IControlAttribute |
|||
{ |
|||
string m_Label; |
|||
|
|||
public CubemapControlAttribute(string label = null) |
|||
{ |
|||
m_Label = label; |
|||
} |
|||
|
|||
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
return new CubemapControlView(m_Label, node, propertyInfo); |
|||
} |
|||
} |
|||
|
|||
public class CubemapControlView : VisualElement |
|||
{ |
|||
AbstractMaterialNode m_Node; |
|||
PropertyInfo m_PropertyInfo; |
|||
|
|||
public CubemapControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo) |
|||
{ |
|||
m_Node = node; |
|||
m_PropertyInfo = propertyInfo; |
|||
if (propertyInfo.PropertyType != typeof(Cubemap)) |
|||
throw new ArgumentException("Property must be of type Texture.", "propertyInfo"); |
|||
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name); |
|||
|
|||
if (!string.IsNullOrEmpty(label)) |
|||
Add(new Label(label)); |
|||
|
|||
var cubemapField = new ObjectField { value = (Cubemap) m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Cubemap) }; |
|||
cubemapField.OnValueChanged(OnChange); |
|||
Add(cubemapField); |
|||
} |
|||
|
|||
void OnChange(ChangeEvent<UnityEngine.Object> evt) |
|||
{ |
|||
m_Node.owner.owner.RegisterCompleteObjectUndo("Cubemap Change"); |
|||
m_PropertyInfo.SetValue(m_Node, evt.newValue, null); |
|||
Dirty(ChangeType.Repaint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: abdad6e5c36e0994290fcacce2fab066 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Experimental.UIElements.StyleSheets; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.ShaderGraph.Drawing.Slots |
|||
{ |
|||
public class CubemapSlotControlView : VisualElement |
|||
{ |
|||
CubemapInputMaterialSlot m_Slot; |
|||
|
|||
public CubemapSlotControlView(CubemapInputMaterialSlot slot) |
|||
{ |
|||
m_Slot = slot; |
|||
var objectField = new ObjectField { objectType = typeof(Cubemap), value = m_Slot.cubemap }; |
|||
objectField.OnValueChanged(OnValueChanged); |
|||
Add(objectField); |
|||
} |
|||
|
|||
void OnValueChanged(ChangeEvent<Object> evt) |
|||
{ |
|||
var cubemap = evt.newValue as Cubemap; |
|||
if (cubemap != m_Slot.cubemap) |
|||
{ |
|||
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Cubemap"); |
|||
m_Slot.cubemap = cubemap; |
|||
if (m_Slot.owner.onModified != null) |
|||
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b54f542a9d5f7b84e974b54d625d73ea |
|||
timeCreated: 1509718979 |
撰写
预览
正在加载...
取消
保存
Reference in new issue