浏览代码

Fixes for PR

/main
Matt Dean 7 年前
当前提交
5863364b
共有 3 个文件被更改,包括 45 次插入66 次删除
  1. 27
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PBR/DielectricSpecularNode.cs
  2. 56
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PBR/MetalReflectanceNode.cs
  3. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/UV/TriplanarNode.cs

27
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PBR/DielectricSpecularNode.cs


}
}
static Dictionary<DielectricMaterialType, string> m_MaterialList = new Dictionary<DielectricMaterialType, string>
{
{DielectricMaterialType.RustedMetal, "(0.030, 0.030, 0.030)"},
{DielectricMaterialType.Water, "(0.020, 0.020, 0.020)"},
{DielectricMaterialType.Ice, "(0.018, 0.018, 0.018)"},
{DielectricMaterialType.Glass, "(0.040, 0.040, 0.040)"}
};
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";

}
switch (material.type)
{
case DielectricMaterialType.RustedMetal:
sb.AppendLine(string.Format("{0}3 {1} = {0}3(0.030, 0.030, 0.030);", precision, GetVariableNameForSlot(kOutputSlotId)), true);
break;
case DielectricMaterialType.Water:
sb.AppendLine(string.Format("{0}3 {1} = {0}3(0.020, 0.020, 0.020);", precision, GetVariableNameForSlot(kOutputSlotId)), true);
break;
case DielectricMaterialType.Ice:
sb.AppendLine(string.Format("{0}3 {1} = {0}3(0.018, 0.018, 0.018);", precision, GetVariableNameForSlot(kOutputSlotId)), true);
break;
case DielectricMaterialType.Glass:
sb.AppendLine(string.Format("{0}3 {1} = {0}3(0.040, 0.040, 0.040);", precision, GetVariableNameForSlot(kOutputSlotId)), true);
case DielectricMaterialType.Common:
sb.AppendLine("{0}3 {1} = lerp(0.034, 0.048, _{2}_Range);", precision, GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
sb.AppendLine(string.Format("{0}3 {1} = pow({2} - 1, 2) / pow({2} + 1, 2);", precision, GetVariableNameForSlot(kOutputSlotId),
string.Format("_{0}_IOR", GetVariableNameForNode())), true);
sb.AppendLine("{0}3 {1} = pow(_{2}_IOR - 1, 2) / pow(_{2}_IOR + 1, 2);", precision, GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
sb.AppendLine(string.Format("{0}3 {1} = lerp(0.034, 0.048, {2});", precision, GetVariableNameForSlot(kOutputSlotId),
string.Format("_{0}_Range", GetVariableNameForNode())), true);
sb.AppendLine("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material.type]);
break;
}
visitor.AddShaderChunk(sb.ToString(), false);

56
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/PBR/MetalReflectanceNode.cs


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);
}
}
}

28
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/UV/TriplanarNode.cs


public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var sb = new ShaderStringBuilder();
sb.AppendLine(string.Format("{0}3 {1}_UV = {2} * {3};", precision, GetVariableNameForNode(),
GetSlotValue(PositionInputId, generationMode), GetSlotValue(TileInputId, generationMode)));
sb.AppendLine("{0}3 {1}_UV = {2} * {3};", precision, GetVariableNameForNode(),
GetSlotValue(PositionInputId, generationMode), GetSlotValue(TileInputId, generationMode));
sb.AppendLine(string.Format("{0}3 {1}_Blend = pow(abs({2}), {3});", precision, GetVariableNameForNode(),
GetSlotValue(NormalInputId, generationMode), GetSlotValue(BlendInputId, generationMode)));
sb.AppendLine("{0}3 {1}_Blend = pow(abs({2}), {3});", precision, GetVariableNameForNode(),
GetSlotValue(NormalInputId, generationMode), GetSlotValue(BlendInputId, generationMode));
sb.AppendLine(string.Format("{0}_Blend /= dot({0}_Blend, 1.0);", GetVariableNameForNode()));
sb.AppendLine("{0}_Blend /= dot({0}_Blend, 1.0);", GetVariableNameForNode());
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInputId);

sb.AppendLine(string.Format("{0}4 {1}_X = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.yz);"
sb.AppendLine("{0}4 {1}_X = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.yz);"
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id));
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine(string.Format("{0}4 {1}_Y = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xz);"
sb.AppendLine("{0}4 {1}_Y = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xz);"
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id));
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine(string.Format("{0}4 {1}_Z = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xy);"
sb.AppendLine("{0}4 {1}_Z = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xy);"
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id));
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine(string.Format("{0}4 {1} = {2}_X * {2}_Blend.x + {2}_Y * {2}_Blend.y + {2}_Z * {2}_Blend.z;"
sb.AppendLine("{0}4 {1} = {2}_X * {2}_Blend.x + {2}_Y * {2}_Blend.y + {2}_Z * {2}_Blend.z;"
, GetVariableNameForNode()));
, GetVariableNameForNode());
sb.AppendLine(string.Format("{0}.rgb = UnpackNormalmapRGorAG({0});", GetVariableNameForSlot(OutputSlotId)), true);
sb.AppendLine("{0}.rgb = UnpackNormalmapRGorAG({0});", GetVariableNameForSlot(OutputSlotId));
visitor.AddShaderChunk(sb.ToString(), false);
}

正在加载...
取消
保存