浏览代码

Shader generation now working

/Improve-shader-generator
Sebastien Lagarde 6 年前
当前提交
946c1494
共有 3 个文件被更改,包括 17 次插入31 次删除
  1. 2
      ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/CSharpToHLSL.cs
  2. 40
      ScriptableRenderPipeline/Core/CoreRP/Editor/ShaderGenerator/ShaderTypeGeneration.cs
  3. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightDefinition.cs

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


if (File.Exists(customFile))
writer.Write("#include \"{0}\"", Path.GetFileName(customFile));
writer.Write(Environment.NewLine); // TODO: we should use this everywhere ?
}
}
}

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


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

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

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

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


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

};
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
[GenerateHLSL]
[GenerateHLSL(PackingRules.AtomicElement)]
public struct LightData
{
public Vector3 positionWS;

// 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
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
[GenerateHLSL]
[GenerateHLSL(PackingRules.AtomicElement)]
public struct EnvLightData
{
// Packing order depends on chronological access to avoid cache misses

正在加载...
取消
保存