|
|
|
|
|
|
using System.Reflection; |
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEditor.Graphing; |
|
|
|
using UnityEditor.ShaderGraph.Drawing.Controls; |
|
|
|
|
|
|
public enum MetalMaterial |
|
|
|
public enum MetalMaterialType |
|
|
|
{ |
|
|
|
Iron, |
|
|
|
Silver, |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
private MetalMaterial m_Material = MetalMaterial.Iron; |
|
|
|
private MetalMaterialType m_Material = MetalMaterialType.Iron; |
|
|
|
public MetalMaterial material |
|
|
|
public MetalMaterialType material |
|
|
|
{ |
|
|
|
get { return m_Material; } |
|
|
|
set |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static Dictionary<MetalMaterialType, string> m_MaterialList = new Dictionary<MetalMaterialType, string> |
|
|
|
{ |
|
|
|
{MetalMaterialType.Iron, "(0.560, 0.570, 0.580)"}, |
|
|
|
{MetalMaterialType.Silver, "(0.972, 0.960, 0.915)"}, |
|
|
|
{MetalMaterialType.Aluminium, "(0.913, 0.921, 0.925)"}, |
|
|
|
{MetalMaterialType.Gold, "(1.000, 0.766, 0.336)"}, |
|
|
|
{MetalMaterialType.Copper, "(0.955, 0.637, 0.538)"}, |
|
|
|
{MetalMaterialType.Chromium, "(0.550, 0.556, 0.554)"}, |
|
|
|
{MetalMaterialType.Nickel, "(0.660, 0.609, 0.526)"}, |
|
|
|
{MetalMaterialType.Titanium, "(0.542, 0.497, 0.449)"}, |
|
|
|
{MetalMaterialType.Cobalt, "(0.662, 0.655, 0.634)"}, |
|
|
|
{MetalMaterialType.Platinum, "(0.672, 0.637, 0.585)"} |
|
|
|
}; |
|
|
|
|
|
|
|
private const int kOutputSlotId = 0; |
|
|
|
private const string kOutputSlotName = "Out"; |
|
|
|
|
|
|
|
|
|
|
get { return PreviewMode.Preview2D; } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public sealed override void UpdateNodeAfterDeserialization() |
|
|
|
{ |
|
|
|
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero)); |
|
|
|
|
|
|
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|
|
|
{ |
|
|
|
switch (m_Material) |
|
|
|
{ |
|
|
|
case MetalMaterial.Silver: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.972, 0.960, 0.915);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Aluminium: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.913, 0.921, 0.925);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Gold: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(1.000, 0.766, 0.336);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Copper: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.955, 0.637, 0.538);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Chromium: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.550, 0.556, 0.554);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Nickel: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.660, 0.609, 0.526);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Titanium: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.542, 0.497, 0.449);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Cobalt: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.662, 0.655, 0.634);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
case MetalMaterial.Platinum: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.672, 0.637, 0.585);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
default: |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3(0.560, 0.570, 0.580);", precision, GetVariableNameForSlot(kOutputSlotId)), true); |
|
|
|
break; |
|
|
|
} |
|
|
|
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material]), true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |