|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[Serializable] |
|
|
|
public abstract class AbstractHDRenderLoopMasterNode : AbstractMasterNode, IMayRequireNormal, IMayRequireTangent |
|
|
|
public abstract class AbstractHDRenderLoopMasterNode : AbstractMasterNode, IMayRequireNormal, IMayRequireTangent, IMayRequireMeshUV, IMayRequireWorldPosition |
|
|
|
{ |
|
|
|
public AbstractHDRenderLoopMasterNode() |
|
|
|
{ |
|
|
|
|
|
|
priority = attribute.priority, |
|
|
|
displayName = attribute.displayName, |
|
|
|
materialID = attribute.filter, |
|
|
|
semantic = attribute.semantic, |
|
|
|
shaderOutputName = field.Name, |
|
|
|
valueType = valueType |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
foreach (var slot in slots) |
|
|
|
{ |
|
|
|
if (slot.semantic == SurfaceDataAttributes.Semantic.BakeDiffuseLighting && !IncludeBuiltInLitData()) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
AddSlot(new MaterialSlot(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, Vector4.zero)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
return Requires(SurfaceDataAttributes.Semantic.Tangent); |
|
|
|
} |
|
|
|
|
|
|
|
public bool RequiresMeshUV(int index) |
|
|
|
{ |
|
|
|
if (index == 1 || index == 2) |
|
|
|
{ |
|
|
|
return Requires(SurfaceDataAttributes.Semantic.BakeDiffuseLighting); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public bool RequiresWorldPosition() |
|
|
|
{ |
|
|
|
return Requires(SurfaceDataAttributes.Semantic.BakeDiffuseLighting); |
|
|
|
} |
|
|
|
|
|
|
|
private class Vayring |
|
|
|
{ |
|
|
|
public string attributeName; |
|
|
|
|
|
|
var vayrings = new List<Vayring>(); |
|
|
|
for (int iTexCoord = 0; iTexCoord < 4; ++iTexCoord) |
|
|
|
{ |
|
|
|
if (needFragInputRegex.IsMatch("texCoord" + iTexCoord) || (iTexCoord == 0 && activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV()))) |
|
|
|
if (needFragInputRegex.IsMatch("texCoord" + iTexCoord) || activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(iTexCoord))) |
|
|
|
{ |
|
|
|
vayrings.Add(new Vayring() |
|
|
|
{ |
|
|
|
|
|
|
type = SlotValueType.Vector2, |
|
|
|
vertexCode = string.Format("output.texCoord{0} = input.texCoord{0};", iTexCoord), |
|
|
|
pixelCode = string.Format("float4 {0} = float4(fragInput.texCoord{1}, 0, 0);", ShaderGeneratorNames.UV0.Replace("0", iTexCoord.ToString()), iTexCoord) |
|
|
|
pixelCode = string.Format("float4 {0} = float4(fragInput.texCoord{1}, 0, 0);", ShaderGeneratorNames.UV[iTexCoord], iTexCoord) |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var pixelShaderBodyVisitor = new ShaderGenerator(); |
|
|
|
var pixelShaderBodyVisitor = new ShaderGenerator[] { new ShaderGenerator(), new ShaderGenerator() }; |
|
|
|
(node as IGeneratesBodyCode).GenerateNodeCode(pixelShaderBodyVisitor, mode); |
|
|
|
(node as IGeneratesBodyCode).GenerateNodeCode(pixelShaderBodyVisitor[0], mode); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var slot in GetInputSlots<MaterialSlot>()) |
|
|
|
|
|
|
var currentField = surfaceField != null ? surfaceField : builtinField; |
|
|
|
|
|
|
|
string variableName = null; |
|
|
|
int visitorIndex = 0; |
|
|
|
var egdes = owner.GetEdges(slot.slotReference).ToArray(); |
|
|
|
if (egdes.Length == 1) |
|
|
|
{ |
|
|
|
|
|
|
case SurfaceDataAttributes.Semantic.Tangent: |
|
|
|
variableName = ShaderGeneratorNames.WorldSpaceTangent; |
|
|
|
break; |
|
|
|
case SurfaceDataAttributes.Semantic.BakeDiffuseLighting: |
|
|
|
variableName = string.Format("SampleBakedGI({0}, surfaceData.normalWS, {1}, {2})", ShaderGeneratorNames.WorldSpacePosition, ShaderGeneratorNames.UV[1], ShaderGeneratorNames.UV[2]); |
|
|
|
visitorIndex = 1; //it depends of surfaceData.normalWS, do it last
|
|
|
|
break; |
|
|
|
default: break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(variableName)) |
|
|
|
{ |
|
|
|
pixelShaderBodyVisitor.AddShaderChunk(string.Format("{0}.{1} = {2};", surfaceField != null ? "surfaceData" : "builtinData", slotOutputName, variableName), false); |
|
|
|
pixelShaderBodyVisitor[visitorIndex].AddShaderChunk(string.Format("{0}.{1} = {2};", surfaceField != null ? "surfaceData" : "builtinData", slotOutputName, variableName), false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var enumValue = Enum.ToObject(materialIdField.FieldType, GetMatchingMaterialID()).ToString(); |
|
|
|
var define = string.Format("{0}_{1}", materialIdField.Name, ShaderGeneratorHelper.InsertUnderscore(enumValue)); |
|
|
|
define = define.ToUpper(); |
|
|
|
pixelShaderBodyVisitor.AddShaderChunk(string.Format("surfaceData.{0} = {1};", materialIdField.Name, define), false); |
|
|
|
pixelShaderBodyVisitor[1].AddShaderChunk(string.Format("surfaceData.{0} = {1};", materialIdField.Name, define), false); |
|
|
|
resultShader = resultShader.Replace("${PixelShaderBody}", pixelShaderBodyVisitor.GetShaderString(1)); |
|
|
|
resultShader = resultShader.Replace("${PixelShaderBody}", pixelShaderBodyVisitor.Select(o => o.GetShaderString(1)).Aggregate((a, b) => a + b)); |
|
|
|
resultShader = resultShader.Replace("${VertexAttributes}", vertexAttributeVisitor.GetShaderString(1)); |
|
|
|
resultShader = resultShader.Replace("${PackedVaryingAttributes}", packedVarying.GetShaderString(1)); |
|
|
|
resultShader = resultShader.Replace("${PackingVaryingCode}", packInterpolatorVisitor.GetShaderString(1)); |
|
|
|
|
|
|
protected abstract int GetMatchingMaterialID(); |
|
|
|
protected abstract string GetTemplateText(); |
|
|
|
protected abstract string GetTemplatePassText(); |
|
|
|
protected abstract bool IncludeBuiltInLitData(); |
|
|
|
} |
|
|
|
|
|
|
|
[Serializable] |
|
|
|
|
|
|
return typeof(Lit.SurfaceData); |
|
|
|
} |
|
|
|
|
|
|
|
protected sealed override bool IncludeBuiltInLitData() |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
protected sealed override string GetTemplateText() |
|
|
|
{ |
|
|
|
var templatePath = "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.template"; |
|
|
|
|
|
|
protected override int GetMatchingMaterialID() |
|
|
|
{ |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
protected sealed override bool IncludeBuiltInLitData() |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
protected sealed override string GetTemplateText() |
|
|
|