GitHub
6 年前
当前提交
74d0a872
共有 32 个文件被更改,包括 1067 次插入 和 350 次删除
-
183com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/LightWeightPBRSubShader.cs
-
183com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/LightWeightUnlitSubShader.cs
-
44com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/lightweightPBRExtraPasses.template
-
44com.unity.render-pipelines.lightweight/LWRP/Editor/ShaderGraph/lightweightUnlitExtraPasses.template
-
27com.unity.shadergraph/CHANGELOG.md
-
2com.unity.shadergraph/Editor/Data/Graphs/TextureShaderProperty.cs
-
13com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromTextureNode.cs
-
10com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture2DArrayNode.cs
-
2com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture3DNode.cs
-
12com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs
-
2com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs
-
3com.unity.shadergraph/.data/normal_derive_nodes.PNG
-
3com.unity.shadergraph/.data/texel_size_node.PNG
-
436com.unity.shadergraph/.data/wave_form_nodes.PNG
-
131com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromHeightNode.cs.meta
-
39com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalReconstructZNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalReconstructZNode.cs.meta
-
52com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs.meta
-
8com.unity.shadergraph/Editor/Data/Nodes/Math/Wave.meta
-
41com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/NoiseSineWaveNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/NoiseSineWaveNode.cs.meta
-
35com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/SawtoothWaveNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/SawtoothWaveNode.cs.meta
-
35com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/SquareWaveNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/SquareWaveNode.cs.meta
-
35com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/TriangleWaveNode.cs
-
11com.unity.shadergraph/Editor/Data/Nodes/Math/Wave/TriangleWaveNode.cs.meta
-
0/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromTextureNode.cs.meta
-
0/com.unity.shadergraph/Editor/Data/Nodes/Artistic/Normal/NormalFromTextureNode.cs
|
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:2c14e830338ddf74ff5479bb56e8aa4a4d0f9274e96390d9897d97228f281d8e |
|||
size 54715 |
|
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:7502c3fdf5b201b4460a317b577d4e0490e500a6926ba35c53e236afa15ab76a |
|||
size 82906 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
|
|||
public enum OutputSpace |
|||
{ |
|||
Tangent, |
|||
World |
|||
}; |
|||
|
|||
[Title("Artistic", "Normal", "Normal From Height")] |
|||
public class NormalFromHeightNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireTangent, IMayRequireBitangent, IMayRequireNormal, IMayRequirePosition |
|||
{ |
|||
public NormalFromHeightNode() |
|||
{ |
|||
name = "Normal From Height"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Normal-From-Heightmap-Node"; } |
|||
} |
|||
|
|||
[SerializeField] |
|||
private OutputSpace m_OutputSpace = OutputSpace.Tangent; |
|||
|
|||
[EnumControl("Output Space")] |
|||
public OutputSpace outputSpace |
|||
{ |
|||
get { return m_OutputSpace; } |
|||
set |
|||
{ |
|||
if (m_OutputSpace == value) |
|||
return; |
|||
|
|||
m_OutputSpace = value; |
|||
Dirty(ModificationScope.Graph); |
|||
} |
|||
} |
|||
|
|||
const int InputSlotId = 0; |
|||
const int OutputSlotId = 1; |
|||
const string kInputSlotName = "In"; |
|||
const string kOutputSlotName = "Out"; |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
string GetFunctionName() |
|||
{ |
|||
return string.Format("Unity_NormalFromHeight_{0}", outputSpace.ToString()); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector1MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, 0)); |
|||
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero)); |
|||
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId }); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var sb = new ShaderStringBuilder(); |
|||
|
|||
var inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
var outputValue = GetSlotValue(OutputSlotId, generationMode); |
|||
sb.AppendLine("{0} {1};", FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToString(precision), GetVariableNameForSlot(OutputSlotId)); |
|||
sb.AppendLine("{0}3x3 _{1}_TangentMatrix = {0}3x3(IN.{2}SpaceTangent, IN.{2}SpaceBiTangent, IN.{2}SpaceNormal);", precision, GetVariableNameForNode(), NeededCoordinateSpace.World.ToString()); |
|||
sb.AppendLine("{0}3 _{1}_Position = IN.{2}SpacePosition;", precision, GetVariableNameForNode(), NeededCoordinateSpace.World.ToString()); |
|||
|
|||
sb.AppendLine("{0}({1},_{2}_Position,_{2}_TangentMatrix, {3});", GetFunctionName(), inputValue, GetVariableNameForNode(), outputValue); |
|||
|
|||
visitor.AddShaderChunk(sb.ToString(), false); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(FunctionRegistry registry, GraphContext graphContext, GenerationMode generationMode) |
|||
{ |
|||
registry.ProvideFunction(GetFunctionName(), s => |
|||
{ |
|||
s.AppendLine("void {0}({2} In, {1}3 Position, {1}3x3 TangentMatrix, out {3} Out)", |
|||
GetFunctionName(), |
|||
precision, |
|||
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToString(precision), |
|||
FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToString(precision)); |
|||
using (s.BlockScope()) |
|||
{ |
|||
s.AppendLine("{0}3 worldDirivativeX = ddx(Position * 100);", precision); |
|||
s.AppendLine("{0}3 worldDirivativeY = ddy(Position * 100);", precision); |
|||
s.AppendNewLine(); |
|||
s.AppendLine("{0}3 crossX = cross(TangentMatrix[2].xyz, worldDirivativeX);", precision); |
|||
s.AppendLine("{0}3 crossY = cross(TangentMatrix[2].xyz, worldDirivativeY);", precision); |
|||
s.AppendLine("{0}3 d = abs(dot(crossY, worldDirivativeX));", precision); |
|||
s.AppendLine("{0}3 inToNormal = ((((In + ddx(In)) - In) * crossY) + (((In + ddy(In)) - In) * crossX)) * sign(d);", precision); |
|||
s.AppendLine("inToNormal.y *= -1.0;", precision); |
|||
s.AppendNewLine(); |
|||
s.AppendLine("Out = normalize((d * TangentMatrix[2].xyz) - inToNormal);", precision); |
|||
|
|||
if(outputSpace == OutputSpace.Tangent) |
|||
s.AppendLine("Out = TransformWorldToTangent(Out, TangentMatrix);"); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability) |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent(ShaderStageCapability stageCapability) |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability) |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability) |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3bf617c1fe220684696e5bf3850bc423 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Artistic", "Normal", "Normal Reconstruct Z")] |
|||
public class NormalReconstructZNode : CodeFunctionNode |
|||
{ |
|||
public NormalReconstructZNode() |
|||
{ |
|||
name = "Normal Reconstruct Z"; |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Normal-Reconstruct-Z-Node"; } |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("NormalReconstructZ", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string NormalReconstructZ( |
|||
[Slot(0, Binding.None)] Vector2 In, |
|||
[Slot(2, Binding.None, ShaderStageCapability.Fragment)] out Vector3 Out) |
|||
|
|||
{ |
|||
Out = Vector3.zero; |
|||
return |
|||
@"
|
|||
{ |
|||
{precision} reconstructZ = sqrt(1 - ( In.x * In.x + In.y * In.y)); |
|||
{precision}3 normalVector = {precision}3(In.x, In.y, reconstructZ); |
|||
Out = normalize(normalVector); |
|||
}";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 27615ef3e2e760b45b15895bd39d0954 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ShaderGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
|
|||
[Title("Input", "Texture", "Texel Size")] |
|||
public class Texture2DPropertiesNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
public const int OutputSlotWId = 0; |
|||
public const int OutputSlotHId = 2; |
|||
public const int TextureInputId = 1; |
|||
const string kOutputSlotWName = "Width"; |
|||
const string kOutputSlotHName = "Height"; |
|||
const string kTextureInputName = "Texture"; |
|||
|
|||
public override bool hasPreview { get { return false; } } |
|||
|
|||
public Texture2DPropertiesNode() |
|||
{ |
|||
name = "Texel Size"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Texel-Size-Node"; } |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector1MaterialSlot(OutputSlotWId, kOutputSlotWName, kOutputSlotWName, SlotType.Output, 0, ShaderStageCapability.Fragment)); |
|||
AddSlot(new Vector1MaterialSlot(OutputSlotHId, kOutputSlotHName, kOutputSlotHName, SlotType.Output, 0, ShaderStageCapability.Fragment)); |
|||
AddSlot(new Texture2DInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName)); |
|||
RemoveSlotsNameNotMatching(new[] { OutputSlotWId, OutputSlotHId, TextureInputId }); |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk(string.Format("{0}2 {1} = {2}_TexelSize.z;", precision, GetVariableNameForSlot(OutputSlotWId), GetSlotValue(TextureInputId, generationMode)), true); |
|||
visitor.AddShaderChunk(string.Format("{0}2 {1} = {2}_TexelSize.w;", precision, GetVariableNameForSlot(OutputSlotHId), GetSlotValue(TextureInputId, generationMode)), true); |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability) |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ab454fbbbc9f31d4083c178cf885c672 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 24b10579e42f5f845a9f2ab79f921476 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using System.Reflection; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Wave", "Noise Sine Wave")] |
|||
class NoiseSineWaveNode : CodeFunctionNode |
|||
{ |
|||
public NoiseSineWaveNode() |
|||
{ |
|||
name = "Noise Sine Wave"; |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Noise-Sine-Wave-Node"; } |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("NoiseSineWave", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string NoiseSineWave( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None, -0.5f, 0.5f, 1, 1)] Vector2 MinMax, |
|||
[Slot(2, Binding.None)] out DynamicDimensionVector Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
{precision} sinIn = sin(In); |
|||
{precision} sinInOffset = sin(In + 1.0); |
|||
{precision} randomno = frac(sin((sinIn - sinInOffset) * (12.9898 + 78.233))*43758.5453); |
|||
{precision} noise = lerp(MinMax.x, MinMax.y, randomno); |
|||
Out = sinIn + noise; |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ee4eb305b2f727b47bbac99de0772c18 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Wave", "Sawtooth Wave")] |
|||
class SawtoothWaveNode : CodeFunctionNode |
|||
{ |
|||
public SawtoothWaveNode() |
|||
{ |
|||
name = "Sawtooth Wave"; |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Sawtooth-Wave-Node"; } |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("SawtoothWave", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string SawtoothWave( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out DynamicDimensionVector Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = 2 * (In - floor(0.5 + In)); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ebd730c94c4864d4f84382b17d49447f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Wave", "Square Wave")] |
|||
class SquareWaveNode : CodeFunctionNode |
|||
{ |
|||
public SquareWaveNode() |
|||
{ |
|||
name = "Square Wave"; |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Square-Wave-Node"; } |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("SquareWave", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string SquareWave( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out DynamicDimensionVector Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = 1.0 - 2.0 * round(frac(In)); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0f19d607a01d3694e84c04c8eab68f9a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Title("Math", "Wave", "Triangle Wave")] |
|||
class TriangleWaveNode : CodeFunctionNode |
|||
{ |
|||
public TriangleWaveNode() |
|||
{ |
|||
name = "Triangle Wave"; |
|||
} |
|||
|
|||
public override string documentationURL |
|||
{ |
|||
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Triangle-Wave-Node"; } |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("TriangleWave", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string TriangleWave( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector In, |
|||
[Slot(1, Binding.None)] out DynamicDimensionVector Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = 2.0 * abs( 2 * (In - floor(0.5 + In)) ) - 1.0; |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6fb595d58ba0d304cac4cf188f4e8282 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue