浏览代码

Temp fix for various nodes

/main
Peter Bay Bastian 7 年前
当前提交
914403a2
共有 5 个文件被更改,包括 66 次插入57 次删除
  1. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ChannelMixerNode.cs
  2. 33
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Normal/NormalCreateNode.cs
  3. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/FlipNode.cs
  4. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SwizzleNode.cs
  5. 59
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/ChannelMixerNode.cs


public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(GetFunctionPrototype("In", "Red", "Green", "Blue", "Out"), false);
visitor.AddShaderChunk("{", false);
visitor.Indent();
var sg = new ShaderGenerator();
sg.AddShaderChunk(GetFunctionPrototype("In", "Red", "Green", "Blue", "Out"), false);
sg.AddShaderChunk("{", false);
sg.Indent();
visitor.AddShaderChunk(string.Format("Out = {0} (dot(In, Red), dot(In, Green), dot(In, Blue));",
sg.AddShaderChunk(string.Format("Out = {0} (dot(In, Red), dot(In, Green), dot(In, Blue));",
visitor.Deindent();
visitor.AddShaderChunk("}", false);
sg.Deindent();
sg.AddShaderChunk("}", false);
visitor.AddShaderChunk(sg.GetShaderString(0), true);
}
}
}

33
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Normal/NormalCreateNode.cs


public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(GetFunctionPrototype("Texture", "Sampler", "UV", "Offset", "Strength", "Out"), true);
visitor.AddShaderChunk("{", true);
visitor.Indent();
var sg = new ShaderGenerator();
sg.AddShaderChunk(GetFunctionPrototype("Texture", "Sampler", "UV", "Offset", "Strength", "Out"), false);
sg.AddShaderChunk("{", false);
sg.Indent();
sg.AddShaderChunk("Offset = pow(Offset, 3) * 0.1;", false);
sg.AddShaderChunk(string.Format("{0}2 offsetU = float2(UV.x + Offset, UV.y);", precision), false);
sg.AddShaderChunk(string.Format("{0}2 offsetV = float2(UV.x, UV.y + Offset);", precision), false);
visitor.AddShaderChunk("Offset = pow(Offset, 3) * 0.1;", true);
visitor.AddShaderChunk(string.Format("{0}2 offsetU = float2(UV.x + Offset, UV.y);", precision), true);
visitor.AddShaderChunk(string.Format("{0}2 offsetV = float2(UV.x, UV.y + Offset);", precision), true);
sg.AddShaderChunk(string.Format("{0} normalSample = Texture.Sample(Sampler, UV);", precision), false);
sg.AddShaderChunk(string.Format("{0} uSample = Texture.Sample(Sampler, offsetU);", precision), false);
sg.AddShaderChunk(string.Format("{0} vSample = Texture.Sample(Sampler, offsetV);", precision), false);
visitor.AddShaderChunk(string.Format("{0} normalSample = Texture.Sample(Sampler, UV);", precision), true);
visitor.AddShaderChunk(string.Format("{0} uSample = Texture.Sample(Sampler, offsetU);", precision), true);
visitor.AddShaderChunk(string.Format("{0} vSample = Texture.Sample(Sampler, offsetV);", precision), true);
sg.AddShaderChunk(string.Format("{0}3 va = float3(1, 0, (uSample - normalSample) * Strength);", precision), false);
sg.AddShaderChunk(string.Format("{0}3 vb = float3(0, 1, (vSample - normalSample) * Strength);", precision), false);
sg.AddShaderChunk("Out = normalize(cross(va, vb));", false);
visitor.AddShaderChunk(string.Format("{0}3 va = float3(1, 0, (uSample - normalSample) * Strength);", precision), true);
visitor.AddShaderChunk(string.Format("{0}3 vb = float3(0, 1, (vSample - normalSample) * Strength);", precision), true);
visitor.AddShaderChunk("Out = normalize(cross(va, vb));", true);
sg.Deindent();
sg.AddShaderChunk("}", false);
visitor.Deindent();
visitor.AddShaderChunk("}", true);
visitor.AddShaderChunk(sg.GetShaderString(0), true);
}
public bool RequiresMeshUV(UVChannel channel)

return false;
}
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/FlipNode.cs


public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("In", "Flip", "Out"), true);
outputString.AddShaderChunk("{", true);
outputString.AddShaderChunk(GetFunctionPrototype("In", "Flip", "Out"), false);
outputString.AddShaderChunk("{", false);
outputString.AddShaderChunk("Out = abs(Flip - In);", true);
outputString.AddShaderChunk("Out = abs(Flip - In);", false);
outputString.AddShaderChunk("}", true);
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Channel/SwizzleNode.cs


{
ValidateChannelCount();
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("In", "Out"), true);
outputString.AddShaderChunk("{", true);
outputString.AddShaderChunk(GetFunctionPrototype("In", "Out"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk(string.Format("Out = {0} ({1}, {2}, {3}, {4});",

kInputSlotName + m_ComponentList[m_BlueChannel],
kInputSlotName + m_ComponentList[m_AlphaChannel]), true);
kInputSlotName + m_ComponentList[m_AlphaChannel]), false);
outputString.AddShaderChunk("}", true);
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}

59
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs


public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(GetFunctionPrototype("ObjectSpacePosition", "Color", "Density"), false);
visitor.AddShaderChunk("{", false);
visitor.Indent();
var sg = new ShaderGenerator();
sg.AddShaderChunk(GetFunctionPrototype("ObjectSpacePosition", "Color", "Density"), false);
sg.AddShaderChunk("{", false);
sg.Indent();
sg.AddShaderChunk("Color = unity_FogColor;", false);
visitor.AddShaderChunk("Color = unity_FogColor;", true);
sg.AddShaderChunk(string.Format("{0} clipZ_01 = UNITY_Z_0_FAR_FROM_CLIPSPACE(UnityObjectToClipPos(ObjectSpacePosition).z);", precision), false);
sg.AddShaderChunk("#if defined(FOG_LINEAR)", false);
sg.Indent();
sg.AddShaderChunk(string.Format("{0} fogFactor = saturate(clipZ_01 * unity_FogParams.z + unity_FogParams.w);", precision), false);
sg.AddShaderChunk("Density = fogFactor;", false);
sg.Deindent();
sg.AddShaderChunk("#elif defined(FOG_EXP)", false);
sg.Indent();
sg.AddShaderChunk(string.Format("{0} fogFactor = unity_FogParams.y * clipZ_01;", precision), false);
sg.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor)));", false);
sg.Deindent();
sg.AddShaderChunk("#elif defined(FOG_EXP2)", false);
sg.Indent();
sg.AddShaderChunk(string.Format("{0} fogFactor = unity_FogParams.x * clipZ_01;", precision), false);
sg.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor*fogFactor)));", false);
sg.Deindent();
sg.AddShaderChunk("#else", false);
sg.Indent();
sg.AddShaderChunk("Density = 0.0h;", false);
sg.Deindent();
sg.AddShaderChunk("#endif", false);
visitor.AddShaderChunk(string.Format("{0} clipZ_01 = UNITY_Z_0_FAR_FROM_CLIPSPACE(UnityObjectToClipPos(ObjectSpacePosition).z);", precision), true);
visitor.AddShaderChunk("#if defined(FOG_LINEAR)", true);
visitor.Indent();
visitor.AddShaderChunk(string.Format("{0} fogFactor = saturate(clipZ_01 * unity_FogParams.z + unity_FogParams.w);", precision), true);
visitor.AddShaderChunk("Density = fogFactor;", true);
visitor.Deindent();
visitor.AddShaderChunk("#elif defined(FOG_EXP)", true);
visitor.Indent();
visitor.AddShaderChunk(string.Format("{0} fogFactor = unity_FogParams.y * clipZ_01;", precision), true);
visitor.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor)));", true);
visitor.Deindent();
visitor.AddShaderChunk("#elif defined(FOG_EXP2)", true);
visitor.Indent();
visitor.AddShaderChunk(string.Format("{0} fogFactor = unity_FogParams.x * clipZ_01;", precision), true);
visitor.AddShaderChunk("Density = {2}(saturate(exp2(-fogFactor*fogFactor)));", true);
visitor.Deindent();
visitor.AddShaderChunk("#else", true);
visitor.Indent();
visitor.AddShaderChunk("Density = 0.0h;", true);
visitor.Deindent();
visitor.AddShaderChunk("#endif", true);
sg.Deindent();
sg.AddShaderChunk("}", false);
visitor.Deindent();
visitor.AddShaderChunk("}", false);
visitor.AddShaderChunk(sg.GetShaderString(0), true);
}
public NeededCoordinateSpace RequiresPosition()

}
}
}
正在加载...
取消
保存