浏览代码

Merge pull request #122 from Unity-Technologies/node-bugfixes

Node bugfixes
/main
GitHub 7 年前
当前提交
6a80fdeb
共有 16 个文件被更改,包括 155 次插入295 次删除
  1. 43
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs
  3. 44
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
  4. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs
  5. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/HueNode.cs
  6. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Blend/BlendNode.cs
  7. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Derivative/DDXNode.cs
  8. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Derivative/DDXYNode.cs
  9. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Derivative/DDYNode.cs
  10. 65
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs
  11. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/PropertyCollector.cs
  12. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
  13. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete.meta
  14. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Time.meta

43
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


surfaceDescriptionStruct.AddShaderChunk("};", false);
}
internal static void GenerateApplicationVertexInputs(ShaderGraphRequirements graphRequiements, ShaderGenerator vertexInputs, int vertexInputStartIndex, int maxVertexInputs)
{
int vertexInputIndex = vertexInputStartIndex;
vertexInputs.AddShaderChunk("struct GraphVertexInput", false);
vertexInputs.AddShaderChunk("{", false);
vertexInputs.Indent();
vertexInputs.AddShaderChunk("float4 vertex : POSITION;", false);
vertexInputs.AddShaderChunk("float3 normal : NORMAL;", false);
vertexInputs.AddShaderChunk("float4 tangent : TANGENT;", false);
if (graphRequiements.requiresVertexColor)
{
vertexInputs.AddShaderChunk("float4 color : COLOR;", false);
}
foreach (var channel in graphRequiements.requiresMeshUVs.Distinct())
{
vertexInputs.AddShaderChunk(string.Format("float4 texcoord{0} : TEXCOORD{1};", ((int)channel).ToString(), vertexInputIndex.ToString()), false);
vertexInputIndex++;
}
vertexInputs.AddShaderChunk("UNITY_VERTEX_INPUT_INSTANCE_ID", false);
vertexInputs.Deindent();
vertexInputs.AddShaderChunk("};", false);
}
internal static void GenerateSurfaceDescription(
List<INode> activeNodeList,
AbstractMaterialNode masterNode,

{
bool isUber = node == null;
var vertexInputs = new ShaderGenerator();
var vertexShader = new ShaderGenerator();
var surfaceDescriptionFunction = new ShaderGenerator();
var surfaceDescriptionStruct = new ShaderGenerator();

var graphVertexInput = @"
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);
surfaceInputs.Indent();

}
var requirements = GetRequirements(activeNodeList);
GenerateApplicationVertexInputs(requirements, vertexInputs, 0, 8);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs);

finalShader.AddShaderChunk("CGINCLUDE", false);
finalShader.AddShaderChunk("#include \"UnityCG.cginc\"", false);
finalShader.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false);
finalShader.AddShaderChunk(graphVertexInput, false);
finalShader.AddShaderChunk(vertexInputs.GetShaderString(2), false);
finalShader.AddShaderChunk(surfaceInputs.GetShaderString(2), false);
finalShader.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false);
finalShader.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false);

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableCubemap.cs


namespace UnityEditor.ShaderGraph
{
[Serializable]
public class SerializableCubemap
public class SerializableCubemap : ISerializationCallbackReceiver
{
[SerializeField]
private string m_SerializedCubemap;

public Cubemap cubemap;
}
Cubemap m_Cubemap;
if (string.IsNullOrEmpty(m_SerializedCubemap))
return null;
var cube = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube);
return cube.cubemap;
if (m_Cubemap == null && !string.IsNullOrEmpty(m_SerializedCubemap))
{
var cube = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, cube);
m_Cubemap = cube.cubemap;
m_SerializedCubemap = null;
}
return m_Cubemap;
set
{
if (cubemap == value)
return;
set { m_Cubemap = value; }
}
var cube = new CubemapHelper();
cube.cubemap = value;
m_SerializedCubemap = EditorJsonUtility.ToJson(cube, true);
}
public void OnBeforeSerialize()
{
var cube = new CubemapHelper { cubemap = cubemap };
m_SerializedCubemap = EditorJsonUtility.ToJson(cube, true);
}
public void OnAfterDeserialize()
{
}
}
}

44
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs


}
};
private static void GenerateApplicationVertexInputs(ShaderGraphRequirements graphRequiements, ShaderGenerator vertexInputs, int vertexInputStartIndex, int maxVertexInputs)
{
int vertexInputIndex = vertexInputStartIndex;
vertexInputs.AddShaderChunk("struct GraphVertexInput", false);
vertexInputs.AddShaderChunk("{", false);
vertexInputs.Indent();
vertexInputs.AddShaderChunk("float4 vertex : POSITION;", false);
vertexInputs.AddShaderChunk("float3 normal : NORMAL;", false);
vertexInputs.AddShaderChunk("float4 tangent : TANGENT;", false);
vertexInputs.AddShaderChunk("float4 lightmapUV : TEXCOORD0;", false);
if (graphRequiements.requiresVertexColor)
{
vertexInputs.AddShaderChunk("float4 color : COLOR;", false);
}
foreach (var channel in graphRequiements.requiresMeshUVs.Distinct())
{
vertexInputs.AddShaderChunk(string.Format("float4 texcoord{0} : TEXCOORD{1};", ((int)channel).ToString(), vertexInputIndex.ToString()), false);
vertexInputIndex++;
}
vertexInputs.AddShaderChunk("UNITY_VERTEX_INPUT_INSTANCE_ID", false);
vertexInputs.Deindent();
vertexInputs.AddShaderChunk("};", false);
}
var vertexInputs = new ShaderGenerator();
var surfaceVertexShader = new ShaderGenerator();
var surfaceDescriptionFunction = new ShaderGenerator();
var surfaceDescriptionStruct = new ShaderGenerator();

var shaderProperties = new PropertyCollector();
var graphVertexInput = @"
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);
surfaceInputs.Indent();

var requirements = AbstractMaterialGraph.GetRequirements(activeNodeList);
GenerateApplicationVertexInputs(requirements, vertexInputs, 1, 8);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs);

var graph = new ShaderGenerator();
graph.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false);
graph.AddShaderChunk(graphVertexInput, false);
graph.AddShaderChunk(vertexInputs.GetShaderString(2), false);
graph.AddShaderChunk(surfaceInputs.GetShaderString(2), false);
graph.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false);
graph.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false);

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs


private static string GetShaderPassFromTemplate(string template, UnlitMasterNode masterNode, Pass pass, GenerationMode mode)
{
var vertexInputs = new ShaderGenerator();
var surfaceVertexShader = new ShaderGenerator();
var surfaceDescriptionFunction = new ShaderGenerator();
var surfaceDescriptionStruct = new ShaderGenerator();

var shaderProperties = new PropertyCollector();
var graphVertexInput = @"
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};";
surfaceInputs.AddShaderChunk("struct SurfaceInputs{", false);
surfaceInputs.Indent();

var requirements = AbstractMaterialGraph.GetRequirements(activeNodeList);
AbstractMaterialGraph.GenerateApplicationVertexInputs(requirements, vertexInputs, 0, 8);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresNormal, InterpolatorType.Normal, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresTangent, InterpolatorType.Tangent, surfaceInputs);
ShaderGenerator.GenerateSpaceTranslationSurfaceInputs(requirements.requiresBitangent, InterpolatorType.BiTangent, surfaceInputs);

var graph = new ShaderGenerator();
graph.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false);
graph.AddShaderChunk(graphVertexInput, false);
graph.AddShaderChunk(vertexInputs.GetShaderString(2), false);
graph.AddShaderChunk(surfaceInputs.GetShaderString(2), false);
graph.AddShaderChunk(surfaceDescriptionStruct.GetShaderString(2), false);
graph.AddShaderChunk(shaderProperties.GetPropertiesDeclaration(2), false);

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/HueNode.cs


static string Unity_Hue_Degrees(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] Vector1 Hue,
[Slot(1, Binding.None)] Vector1 Offset,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;

{precision} E = 1e-10;
{precision}3 hsv = {precision}3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
{precision} hue = hsv.x + Hue / 360;
{precision} hue = hsv.x + Offset / 360;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)

static string Unity_Hue_Normalized(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector1 Hue,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector1 Offset,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;

{precision} E = 1e-10;
{precision}3 hsv = {precision}3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
{precision} hue = hsv.x + Hue;
{precision} hue = hsv.x + Offset;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Blend/BlendNode.cs


return
@"
{
Out = B / (A + 0.000000000001);
Out = A / (B + 0.000000000001);
}";
}

return
@"
{
Out = B - A;
Out = A - B;
}
";
}

68
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Derivative/DDXNode.cs


namespace UnityEditor.ShaderGraph
{
public enum PartialDerivativePrecision
{
Coarse,
Default,
Fine
};
[Title("Math", "Derivative", "DDX")]
public class DDXNode : CodeFunctionNode
{

}
[SerializeField]
private PartialDerivativePrecision m_PartialDerivativePrecision = PartialDerivativePrecision.Default;
[EnumControl("Precision")]
public PartialDerivativePrecision partialDerivativePrecision
{
get { return m_PartialDerivativePrecision; }
set
{
if (m_PartialDerivativePrecision == value)
return;
m_PartialDerivativePrecision = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
string GetCurrentPrecision()
{
return System.Enum.GetName(typeof(PartialDerivativePrecision), m_PartialDerivativePrecision);
}
switch (m_PartialDerivativePrecision)
{
case PartialDerivativePrecision.Fine:
return GetType().GetMethod("Unity_DDX_Fine", BindingFlags.Static | BindingFlags.NonPublic);
case PartialDerivativePrecision.Coarse:
return GetType().GetMethod("Unity_DDX_Coarse", BindingFlags.Static | BindingFlags.NonPublic);
default:
return GetType().GetMethod("Unity_DDX_Default", BindingFlags.Static | BindingFlags.NonPublic);
}
return GetType().GetMethod("Unity_DDX", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_DDX_Default(
static string Unity_DDX(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{

Out = ddx(In);
}
";
}
static string Unity_DDX_Coarse(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = ddx_coarse(In);
}
";
}
static string Unity_DDX_Fine(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = ddx_fine(In);
}
";
}

61
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Derivative/DDXYNode.cs


name = "DDXY";
}
[SerializeField]
private PartialDerivativePrecision m_PartialDerivativePrecision = PartialDerivativePrecision.Default;
[EnumControl("Precision")]
public PartialDerivativePrecision partialDerivativePrecision
{
get { return m_PartialDerivativePrecision; }
set
{
if (m_PartialDerivativePrecision == value)
return;
m_PartialDerivativePrecision = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
string GetCurrentPrecision()
{
return System.Enum.GetName(typeof(PartialDerivativePrecision), m_PartialDerivativePrecision);
}
switch (m_PartialDerivativePrecision)
{
case PartialDerivativePrecision.Fine:
return GetType().GetMethod("Unity_DDXY_Fine", BindingFlags.Static | BindingFlags.NonPublic);
case PartialDerivativePrecision.Coarse:
return GetType().GetMethod("Unity_DDXY_Coarse", BindingFlags.Static | BindingFlags.NonPublic);
default:
return GetType().GetMethod("Unity_DDXY_Default", BindingFlags.Static | BindingFlags.NonPublic);
}
return GetType().GetMethod("Unity_DDXY", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_DDXY_Default(
static string Unity_DDXY(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{

Out = abs(ddx(In) + ddy(In));
}
";
}
static string Unity_DDXY_Coarse(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = abs(ddx_coarse(In) + ddy_coarse(In));
}
";
}
static string Unity_DDXY_Fine(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = abs(ddx_fine(In) + ddy_fine(In));
}
";
}

61
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Derivative/DDYNode.cs


name = "DDY";
}
[SerializeField]
private PartialDerivativePrecision m_PartialDerivativePrecision = PartialDerivativePrecision.Default;
[EnumControl("Precision")]
public PartialDerivativePrecision partialDerivativePrecision
{
get { return m_PartialDerivativePrecision; }
set
{
if (m_PartialDerivativePrecision == value)
return;
m_PartialDerivativePrecision = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
string GetCurrentPrecision()
{
return System.Enum.GetName(typeof(PartialDerivativePrecision), m_PartialDerivativePrecision);
}
switch (m_PartialDerivativePrecision)
{
case PartialDerivativePrecision.Fine:
return GetType().GetMethod("Unity_DDY_Fine", BindingFlags.Static | BindingFlags.NonPublic);
case PartialDerivativePrecision.Coarse:
return GetType().GetMethod("Unity_DDY_Coarse", BindingFlags.Static | BindingFlags.NonPublic);
default:
return GetType().GetMethod("Unity_DDY_Default", BindingFlags.Static | BindingFlags.NonPublic);
}
return GetType().GetMethod("Unity_DDY", BindingFlags.Static | BindingFlags.NonPublic);
static string Unity_DDY_Default(
static string Unity_DDY(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{

Out = ddy(In);
}
";
}
static string Unity_DDY_Coarse(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = ddy_coarse(In);
}
";
}
static string Unity_DDY_Fine(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = ddy_fine(In);
}
";
}

65
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs


public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(GetInputSlot());
AddSlot(GetOutputSlot());
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlotId, OutputSlotId }; }
}
protected virtual MaterialSlot GetInputSlot()
{
return new Vector3MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero);
}
protected virtual MaterialSlot GetOutputSlot()
{
return new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero);
AddSlot(new Vector3MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
string inputValue = GetSlotValue(InputSlotId, generationMode);
string inputValue = string.Format("{0}.xyz", GetSlotValue(InputSlotId, generationMode));
string targetTransformString = "tangentTransform_" + conversion.from.ToString();
string transposeTargetTransformString = "transposeTangent";
string tangentTransformSpace = conversion.from.ToString();
bool requiresTransposeTangentTransform = false;
if (conversion.from == CoordinateSpace.World)
{

else if (conversion.to == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul(tangentTransform, " + inputValue + ").xyz";
transformString = "mul(" + inputValue + ", " + targetTransformString + ").xyz";
}
else if (conversion.to == CoordinateSpace.View)
{

else if (conversion.to == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul( tangentTransform, mul( unity_ObjectToWorld, float4(" + inputValue + ", 0) ).xyz).xyz";
transformString = "mul(float4(" + inputValue + ", 0).xyz, " + targetTransformString + ").xyz";
}
else if (conversion.to == CoordinateSpace.View)
{

else if (conversion.from == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul( " + inputValue + ", tangentTransform ).xyz";
requiresTransposeTangentTransform = true;
transformString = "mul( " + inputValue + ", " + transposeTargetTransformString + " ).xyz";
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz";
requiresTransposeTangentTransform = true;
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", " + transposeTargetTransformString + " ),0) ).xyz";
}
else if (conversion.to == CoordinateSpace.Tangent)
{

{
transformString = "mul( UNITY_MATRIX_V, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz";
requiresTransposeTangentTransform = true;
transformString = "mul( UNITY_MATRIX_V, float4(mul(" + inputValue + ", " + transposeTargetTransformString + " ),0) ).xyz";
}
}
else if (conversion.from == CoordinateSpace.View)

else if (conversion.to == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul( tangentTransform, mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz ).xyz";
tangentTransformSpace = CoordinateSpace.World.ToString();
transformString = "mul( mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz, " + targetTransformString + ").xyz";
}
else if (conversion.to == CoordinateSpace.View)
{

if (requiresTangentTransform)
visitor.AddShaderChunk("float3x3 tangentTransform = float3x3(" + conversion.from.ToString() + "SpaceTangent, " + conversion.from.ToString() + "SpaceBiTangent, " + conversion.from.ToString() + "SpaceNormal);", false);
if (requiresTransposeTangentTransform)
visitor.AddShaderChunk("float3x3 " + transposeTargetTransformString + " = transpose(float3x3(" + CoordinateSpace.World.ToString() + "SpaceTangent, " + CoordinateSpace.World.ToString() + "SpaceBiTangent, " + CoordinateSpace.World.ToString() + "SpaceNormal));", true);
else if (requiresTangentTransform)
visitor.AddShaderChunk("float3x3 " + targetTransformString + " = float3x3(" + tangentTransformSpace + "SpaceTangent, " + tangentTransformSpace + "SpaceBiTangent, " + tangentTransformSpace + "SpaceNormal);", true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};",
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType),

bool RequiresWorldSpaceTangentTransform()
{
if (conversion.from == CoordinateSpace.View && conversion.to == CoordinateSpace.Tangent
|| conversion.from == CoordinateSpace.Tangent)
return true;
else
return false;
}
if(RequiresWorldSpaceTangentTransform())
return NeededCoordinateSpace.World;
if (RequiresWorldSpaceTangentTransform())
return NeededCoordinateSpace.World;
if (RequiresWorldSpaceTangentTransform())
return NeededCoordinateSpace.World;
return conversion.from.ToNeededCoordinateSpace();
}
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/PropertyCollector.cs


result.Add(textureInfo);
}
}
foreach (var prop in m_Properties.OfType<CubemapShaderProperty>())
{
if (prop.referenceName != null)
{
var textureInfo = new TextureInfo
{
name = prop.referenceName,
textureId = prop.value.cubemap != null ? prop.value.cubemap.GetInstanceID() : 0,
modifiable = prop.modifiable
};
result.Add(textureInfo);
}
}
return result;
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs


}
}
public static string EmitTransform(TransformDesc[] matrices, TransformDesc[] invMatrices, string variable, bool isAffine, bool inverseTranspose)
public static string EmitTransform(TransformDesc[] matrices, TransformDesc[] invMatrices, string variable, bool isAffine, bool noMatrixCast, bool inverseTranspose)
{
if (inverseTranspose)
matrices = invMatrices;

foreach (var m in matrices)
{
var matrix = m.name;
if (!isAffine)
if (!isAffine && !noMatrixCast)
{
matrix = "(float3x3)" + matrix;
}

// Ensure that the transform graph is initialized
InitTransforms();
bool isNormal = false;
bool affine = (inputType == InputType.Position);
bool affine = (inputType == InputType.Position && to != CoordinateSpace.World);
bool noMatrixCast = (inputType == InputType.Position && to == CoordinateSpace.World);
if (inputType == InputType.Normal)
{
inputType = InputType.Vector;

variable = EmitTransform(
GetTransformPath(CoordinateSpace.Tangent, tangentMatrixSpace),
GetTransformPath(tangentMatrixSpace, CoordinateSpace.Tangent),
variable, affine, !isNormal);
variable, affine, noMatrixCast, !isNormal);
return EmitTransform(GetTransformPath(from, to), GetTransformPath(to, from), variable, affine, isNormal);
return EmitTransform(GetTransformPath(from, to), GetTransformPath(to, from), variable, affine, noMatrixCast, isNormal);
}
public static void GenerateSpaceTranslationSurfaceInputs(

{
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.Position);
interpolators.AddShaderChunk(string.Format("float3 {0} : TEXCOORD{1};", name, interpolatorIndex), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace("v.vertex", CoordinateSpace.Object, preferedCoordinateSpace, InputType.Vector)), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace("v.vertex", CoordinateSpace.Object, preferedCoordinateSpace, InputType.Position)), false);
pixelShader.AddShaderChunk(string.Format("float3 {0} = IN.{0};", name), false);
interpolatorIndex++;
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/Delete.meta


fileFormatVersion: 2
guid: 394a8fe944cfd6b488bf5491e4622c7b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Time.meta


fileFormatVersion: 2
guid: 5d0ea40228d32a44c94e79db32eb2060
folderAsset: yes
timeCreated: 1495529303
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存