比较提交

...
此合并请求有变更与目标分支冲突。
/ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/CSharpToHLSL.cs
/ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/ShaderTypeGeneration.cs
/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs
/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Builtin/BuiltinData.cs
/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/Unlit.cs
/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs
/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs

2 次代码提交

作者 SHA1 备注 提交日期
Sebastien Lagarde 946c1494 Shader generation now working 7 年前
Sebastien Lagarde ea8ce865 First draft 7 年前
共有 8 个文件被更改,包括 95 次插入260 次删除
  1. 9
      ScriptableRenderPipeline/Core/CoreRP/ShaderGenerator/ShaderGeneratorAttributes.cs
  2. 2
      ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/CSharpToHLSL.cs
  3. 59
      ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/ShaderTypeGeneration.cs
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Builtin/BuiltinData.cs
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs
  6. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  7. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/Unlit.cs
  8. 267
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs

9
ScriptableRenderPipeline/Core/CoreRP/ShaderGenerator/ShaderGeneratorAttributes.cs


{
public enum PackingRules
{
Exact,
Aggressive
Exact, // Do nothing
AtomicElement, // Generate accessor to access element that are declare as individual parameters (i.e vecX, vecY, vecZ instead of vec)
Aggressive // ?
};
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Enum)]

public bool needAccessors; // Whether or not to generate the accessors
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool needAccessors = true, bool needParamDebug = false, int paramDefinesStart = 1)
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool needParamDebug = false, int paramDefinesStart = 1)
this.needAccessors = needAccessors;
this.needParamDebug = needParamDebug;
this.paramDefinesStart = paramDefinesStart;
}

2
ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/CSharpToHLSL.cs


writer.Write("\n#endif\n");
// User can specify a custom file to add at the end of the generated file by creating a file name: "filename.custom.hlsl" in the same directory
if (File.Exists(customFile))
writer.Write("#include \"{0}\"", Path.GetFileName(customFile));
}

59
ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/ShaderTypeGeneration.cs


return mergedFields;
}
public static readonly string[] CoordString = { "X", "Y", "Z", "W" };
public string EmitTypeDecl()
{
string shaderText = string.Empty;

shaderText += "struct " + type.Name + "\n";
shaderText += "{\n";
foreach (var shaderFieldInfo in m_PackedFields)
if (attr.packingRules == PackingRules.AtomicElement)
{
foreach (var shaderFieldInfo in m_PackedFields)
{
for (int i = 0; i < shaderFieldInfo.rows; ++i)
{
for (int j = 0; j < shaderFieldInfo.cols; ++j)
{
shaderText += " " + PrimitiveToString(shaderFieldInfo.type, 0, 0) + " " + shaderFieldInfo.name +
(shaderFieldInfo.rows == 1 ? "" : CoordString[i]) +
(shaderFieldInfo.cols == 1 ? "" : CoordString[j]) +
";\n";
}
}
shaderText += "\n";
}
}
else
shaderText += " " + shaderFieldInfo.ToString() + "\n";
foreach (var shaderFieldInfo in m_PackedFields)
{
shaderText += " " + shaderFieldInfo.ToString() + "\n";
}
}
shaderText += "};\n";

}
}
shaderText += "\treturn value." + acc.name + swizzle + ";\n";
if (attr.packingRules == PackingRules.AtomicElement)
{
if (shaderField.rows == 1 && shaderField.cols == 1)
{
shaderText += "\treturn value." + acc.name + ";\n";
}
else
{
shaderText += "\treturn " + PrimitiveToString(shaderField.type, shaderField.rows, shaderField.cols) + "(";
for (int i = 0; i < shaderField.rows; ++i)
{
for (int j = 0; j < shaderField.cols; ++j)
{
shaderText += "value." + shaderField.name + (shaderField.rows == 1 ? "" : CoordString[i]) + (shaderField.cols == 1 ? "" : CoordString[j]);
if (i < shaderField.rows - 1 || j < shaderField.cols - 1)
shaderText += ", ";
else
shaderText += ");\n";
}
}
}
}
else
{
shaderText += "\treturn value." + acc.name + swizzle + ";\n";
}
shaderText += "}\n";
}

public bool needAccessors
{
get { return attr.needAccessors; }
get { return attr.packingRules != PackingRules.Exact; }
}
public bool needParamDebug
{

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Builtin/BuiltinData.cs


// and are independent from the BSDF parametrization.
// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, false, true, 100)]
[GenerateHLSL(PackingRules.Exact, true, 100)]
public struct BuiltinData
{
[SurfaceDataAttributes("Opacity")]

// LightTransportData
// This struct is use to store information for Enlighten/Progressive light mapper. both at runtime or off line.
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, false, true, 120)]
[GenerateHLSL(PackingRules.Exact, true, 120)]
public struct LightTransportData
{
[SurfaceDataAttributes("", false, true)]

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs


public partial class Decal
{
// Main structure that store the user data (i.e user input of master node in material graph)
[GenerateHLSL(PackingRules.Exact, false, true, 10000)]
[GenerateHLSL(PackingRules.Exact, true, 10000)]
public struct DecalSurfaceData
{
[SurfaceDataAttributes("Base Color", false, true)]

[SurfaceDataAttributes("Mask", true)]
public Vector4 mask;
[SurfaceDataAttributes("HTileMask")]
public uint HTileMask;
public uint HTileMask;
};
[GenerateHLSL(PackingRules.Exact)]

[GenerateHLSL(PackingRules.Exact)]
public enum DBufferHTileBit
{
{
Diffuse = 1,
Normal = 2,
Mask = 4

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs


//-----------------------------------------------------------------------------
// Main structure that store the user data (i.e user input of master node in material graph)
[GenerateHLSL(PackingRules.Exact, false, true, 1000)]
[GenerateHLSL(PackingRules.Exact, true, 1000)]
public struct SurfaceData
{
[SurfaceDataAttributes("MaterialFeatures")]

// BSDFData
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, false, true, 1030)]
[GenerateHLSL(PackingRules.Exact, true, 1030)]
public struct BSDFData
{
public uint materialFeatures;

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Unlit/Unlit.cs


//-----------------------------------------------------------------------------
// Main structure that store the user data (i.e user input of master node in material graph)
[GenerateHLSL(PackingRules.Exact, false, true, 1100)]
[GenerateHLSL(PackingRules.Exact, true, 1100)]
public struct SurfaceData
{
[SurfaceDataAttributes("Color", false, true)]

// BSDFData
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, false, true, 1130)]
[GenerateHLSL(PackingRules.Exact, true, 1130)]
public struct BSDFData
{
[SurfaceDataAttributes("", false, true)]

267
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs


};
// These structures share between C# and hlsl need to be align on float4, so we pad them.
[GenerateHLSL]
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
[GenerateHLSL(PackingRules.AtomicElement)]
public struct DirectionalLightData
{
public Vector3 positionWS;

public Vector4 shadowMaskSelector; // Use with ShadowMask feature
};
[GenerateHLSL]
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
[GenerateHLSL(PackingRules.AtomicElement)]
public struct LightData
{
public Vector3 positionWS;

// It allow to have more coherence for the dynamic if in shader code.
// Users can also chose to not have any projection, in this case we use the property minProjectionDistance to minimize code change. minProjectionDistance is set to huge number
// that simulate effect of no shape projection
[GenerateHLSL]
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
[GenerateHLSL(PackingRules.AtomicElement)]
public float capturePositionWSX;
public float capturePositionWSY;
public float capturePositionWSZ;
public Vector3 capturePositionWS;
public float proxyExtentsX;
public float proxyExtentsY;
public float proxyExtentsZ;
public Vector3 proxyExtents;
public float proxyPositionWSX;
public float proxyPositionWSY;
public float proxyPositionWSZ;
public float proxyForwardX;
public float proxyForwardY;
public float proxyForwardZ;
public float proxyUpX;
public float proxyUpY;
public float proxyUpZ;
public float proxyRightX;
public float proxyRightY;
public float proxyRightZ;
public Vector3 proxyPositionWS;
public Vector3 proxyForward;
public Vector3 proxyUp;
public Vector3 proxyRight;
public float influencePositionWSX;
public float influencePositionWSY;
public float influencePositionWSZ;
public float influenceForwardX;
public float influenceForwardY;
public float influenceForwardZ;
public float influenceUpX;
public float influenceUpY;
public float influenceUpZ;
public float influenceRightX;
public float influenceRightY;
public float influenceRightZ;
public Vector3 influencePositionWS;
public Vector3 influenceForward;
public Vector3 influenceUp;
public Vector3 influenceRight;
public float influenceExtentsX;
public float influenceExtentsY;
public float influenceExtentsZ;
public Vector3 influenceExtents;
public float blendDistancePositiveX;
public float blendDistancePositiveY;
public float blendDistancePositiveZ;
public float blendDistanceNegativeX;
public float blendDistanceNegativeY;
public float blendDistanceNegativeZ;
public float blendNormalDistancePositiveX;
public float blendNormalDistancePositiveY;
public float blendNormalDistancePositiveZ;
public float blendNormalDistanceNegativeX;
public float blendNormalDistanceNegativeY;
public float blendNormalDistanceNegativeZ;
public Vector3 blendDistancePositive;
public Vector3 blendDistanceNegative;
public Vector3 blendNormalDistancePositive;
public Vector3 blendNormalDistanceNegative;
public float boxSideFadePositiveX;
public float boxSideFadePositiveY;
public float boxSideFadePositiveZ;
public float boxSideFadeNegativeX;
public float boxSideFadeNegativeY;
public float boxSideFadeNegativeZ;
public Vector3 boxSideFadePositive;
public Vector3 boxSideFadeNegative;
public float sampleDirectionDiscardWSX;
public float sampleDirectionDiscardWSY;
public float sampleDirectionDiscardWSZ;
public Vector3 sampleDirectionDiscardWS;
public Vector3 capturePositionWS
{
get { return new Vector3(capturePositionWSX, capturePositionWSY, capturePositionWSZ); }
set
{
capturePositionWSX = value.x;
capturePositionWSY = value.y;
capturePositionWSZ = value.z;
}
}
public Vector3 proxyExtents
{
get { return new Vector3(proxyExtentsX, proxyExtentsY, proxyExtentsZ); }
set
{
proxyExtentsX = value.x;
proxyExtentsY = value.y;
proxyExtentsZ = value.z;
}
}
public Vector3 proxyPositionWS
{
get { return new Vector3(proxyPositionWSX, proxyPositionWSY, proxyPositionWSZ); }
set
{
proxyPositionWSX = value.x;
proxyPositionWSY = value.y;
proxyPositionWSZ = value.z;
}
}
public Vector3 proxyForward
{
get { return new Vector3(proxyForwardX, proxyForwardY, proxyForwardZ); }
set
{
proxyForwardX = value.x;
proxyForwardY = value.y;
proxyForwardZ = value.z;
}
}
public Vector3 proxyUp
{
get { return new Vector3(proxyUpX, proxyUpY, proxyUpZ); }
set
{
proxyUpX = value.x;
proxyUpY = value.y;
proxyUpZ = value.z;
}
}
public Vector3 proxyRight
{
get { return new Vector3(proxyRightX, proxyRightY, proxyRightZ); }
set
{
proxyRightX = value.x;
proxyRightY = value.y;
proxyRightZ = value.z;
}
}
public Vector3 influenceExtents
{
get { return new Vector3(influenceExtentsX, influenceExtentsY, influenceExtentsZ); }
set
{
influenceExtentsX = value.x;
influenceExtentsY = value.y;
influenceExtentsZ = value.z;
}
}
public Vector3 influencePositionWS
{
get { return new Vector3(influencePositionWSX, influencePositionWSY, influencePositionWSZ); }
set
{
influencePositionWSX = value.x;
influencePositionWSY = value.y;
influencePositionWSZ = value.z;
}
}
public Vector3 influenceForward
{
get { return new Vector3(influenceForwardX, influenceForwardY, influenceForwardZ); }
set
{
influenceForwardX = value.x;
influenceForwardY = value.y;
influenceForwardZ = value.z;
}
}
public Vector3 influenceUp
{
get { return new Vector3(influenceUpX, influenceUpY, influenceUpZ); }
set
{
influenceUpX = value.x;
influenceUpY = value.y;
influenceUpZ = value.z;
}
}
public Vector3 influenceRight
{
get { return new Vector3(influenceRightX, influenceRightY, influenceRightZ); }
set
{
influenceRightX = value.x;
influenceRightY = value.y;
influenceRightZ = value.z;
}
}
public Vector3 blendDistancePositive
{
get { return new Vector3(blendDistancePositiveX, blendDistancePositiveY, blendDistancePositiveZ); }
set
{
blendDistancePositiveX = value.x;
blendDistancePositiveY = value.y;
blendDistancePositiveZ = value.z;
}
}
public Vector3 blendDistanceNegative
{
get { return new Vector3(blendDistanceNegativeX, blendDistanceNegativeY, blendDistanceNegativeZ); }
set
{
blendDistanceNegativeX = value.x;
blendDistanceNegativeY = value.y;
blendDistanceNegativeZ = value.z;
}
}
public Vector3 blendNormalDistancePositive
{
get { return new Vector3(blendNormalDistancePositiveX, blendNormalDistancePositiveY, blendNormalDistancePositiveZ); }
set
{
blendNormalDistancePositiveX = value.x;
blendNormalDistancePositiveY = value.y;
blendNormalDistancePositiveZ = value.z;
}
}
public Vector3 blendNormalDistanceNegative
{
get { return new Vector3(blendNormalDistanceNegativeX, blendNormalDistanceNegativeY, blendNormalDistanceNegativeZ); }
set
{
blendNormalDistanceNegativeX = value.x;
blendNormalDistanceNegativeY = value.y;
blendNormalDistanceNegativeZ = value.z;
}
}
public Vector3 boxSideFadePositive
{
get { return new Vector3(boxSideFadePositiveX, boxSideFadePositiveY, boxSideFadePositiveZ); }
set
{
boxSideFadePositiveX = value.x;
boxSideFadePositiveY = value.y;
boxSideFadePositiveZ = value.z;
}
}
public Vector3 boxSideFadeNegative
{
get { return new Vector3(boxSideFadeNegativeX, boxSideFadeNegativeY, boxSideFadeNegativeZ); }
set
{
boxSideFadeNegativeX = value.x;
boxSideFadeNegativeY = value.y;
boxSideFadeNegativeZ = value.z;
}
}
public Vector3 sampleDirectionDiscardWS
{
get { return new Vector3(sampleDirectionDiscardWSX, sampleDirectionDiscardWSY, sampleDirectionDiscardWSZ); }
set
{
sampleDirectionDiscardWSX = value.x;
sampleDirectionDiscardWSY = value.y;
sampleDirectionDiscardWSZ = value.z;
}
}
};
[GenerateHLSL]

正在加载...
取消
保存