浏览代码

[Shader graph]Add float input node

/main
Tim Cooper 9 年前
当前提交
94238998
共有 8 个文件被更改,包括 211 次插入7 次删除
  1. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  2. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  3. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/UVNode.cs
  4. 23
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs
  5. 110
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs
  6. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs.meta
  7. 49
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/FloatProperty.cs
  8. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/FloatProperty.cs.meta

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs


public Color m_Color;
public Texture2D m_Texture;
public Vector4 m_Vector4;
public float m_Float;
}
public enum PreviewMode

break;
case PropertyType.Vector4:
mat.SetVector(previewProperty.m_Name, previewProperty.m_Vector4);
break;
case PropertyType.Float:
mat.SetFloat(previewProperty.m_Name, previewProperty.m_Float);
break;
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs


var resultShader = ShaderGenerator.GenerateSurfaceShader(pixelGraph.owner, shaderName, true, out defaultTextures);
m_GeneratedShaderMode = PreviewMode.Preview3D;
InternalUpdatePreviewShader(resultShader);
/*
pixelGraph.owner.UpdateShaderSource(shader, defaultTextures);*/
pixelGraph.owner.UpdateShaderSource(shader, defaultTextures);
return true;
}
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/UVNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{

23
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs


}
}
public class FloatPropertyChunk : PropertyChunk
{
private readonly float m_DefaultValue;
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, bool hidden)
: base(propertyName, propertyDescription, hidden)
{
m_DefaultValue = defaultValue;
}
public override string GetPropertyString()
{
var result = new StringBuilder();
result.Append(m_PropertyName);
result.Append("(\"");
result.Append(m_PropertyDescription);
result.Append("\", Float) = ");
result.Append(m_DefaultValue);
return result.ToString();
}
}
private Vector4 m_DefaultVector;
private readonly Vector4 m_DefaultVector;
public VectorPropertyChunk(string propertyName, string propertyDescription, Vector4 defaultVector, bool hidden)
: base(propertyName, propertyDescription, hidden)
{

110
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs


using System;
using UnityEditor.Graphs;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
[Title("Generate/Vector 1 Node")]
class Vector1Node : PropertyNode, IGeneratesBodyCode
{
[SerializeField]
private float m_Value;
private const string kOutputSlotName = "Value";
public override void Init()
{
base.Init();
name = "V1Node";
AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName));
}
public override PropertyType propertyType
{
get { return PropertyType.Float; }
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (HasBoundProperty() || !generationMode.IsPreview())
return;
visitor.AddShaderProperty(new FloatPropertyChunk(GetPropertyName(), GetPropertyName(), m_Value, true));
}
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
return GetPropertyName();
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
if (HasBoundProperty() || !generationMode.IsPreview())
return;
visitor.AddShaderChunk("float " + GetPropertyName() + ";", true);
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
if (HasBoundProperty() || generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + " " + GetPropertyName() + " = " + m_Value + ";", true);
}
public override float GetNodeUIHeight(float width)
{
return 2*EditorGUIUtility.singleLineHeight;
}
public override bool NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
EditorGUI.BeginChangeCheck();
m_Value = EditorGUI.FloatField(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Value", m_Value);
if (EditorGUI.EndChangeCheck())
{
var boundProp = boundProperty as FloatProperty;
if (boundProp != null)
{
boundProp.defaultValue = m_Value;
}
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
return true;
}
return false;
}
public override void BindProperty(ShaderProperty property, bool rebuildShaders)
{
base.BindProperty(property, rebuildShaders);
var vectorProp = property as FloatProperty;
if (vectorProp)
{
m_Value = vectorProp.defaultValue;
}
if (rebuildShaders)
RegeneratePreviewShaders();
else
{
UpdatePreviewProperties();
ForwardPreviewMaterialPropertyUpdate();
}
}
public override PreviewProperty GetPreviewProperty()
{
return new PreviewProperty
{
m_Name = GetPropertyName(),
m_PropType = PropertyType.Float,
m_Float = m_Value
};
}
}
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs.meta


fileFormatVersion: 2
guid: 87c4299b09d95d64c99884296038ceeb
timeCreated: 1445864587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

49
UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/FloatProperty.cs


using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class FloatProperty : ShaderProperty
{
[SerializeField] private float m_DefaultValue;
public override object value
{
get { return m_DefaultValue; }
set { m_DefaultValue = (float)value; }
}
public float defaultValue
{
get { return m_DefaultValue; }
set { m_DefaultValue = value; }
}
public override void PropertyOnGUI(out bool nameChanged, out bool valuesChanged)
{
base.PropertyOnGUI(out nameChanged, out valuesChanged);
EditorGUI.BeginChangeCheck();
m_DefaultValue = EditorGUILayout.FloatField("Vector", m_DefaultValue);
valuesChanged |= EditorGUI.EndChangeCheck();
}
public override PropertyType propertyType
{
get { return PropertyType.Float; }
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderProperty(new FloatPropertyChunk(name, m_PropertyDescription, m_DefaultValue, false));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk("float4 " + name + ";", true);
}
public override string GenerateDefaultValue()
{
return "half4 (" + m_DefaultValue + "," + m_DefaultValue + "," + m_DefaultValue + "," + m_DefaultValue + ")";
}
}
}

12
UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/FloatProperty.cs.meta


fileFormatVersion: 2
guid: 20e6a2fccb2d4c84680ac4ded12a8957
timeCreated: 1445864587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存