浏览代码

Merge branch 'master' into Branch_DebugLighting

# Conflicts:
#	Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
#	Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
/main
Julien Ignace 8 年前
当前提交
0da32ed1
共有 35 个文件被更改,包括 432 次插入314 次删除
  1. 4
      Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
  2. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
  3. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
  4. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs
  5. 25
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  6. 109
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  7. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
  8. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/LightingConvexHullUtils.hlsl
  9. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute
  10. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  11. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  12. 37
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  13. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  14. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  15. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
  16. 15
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  17. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  18. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  19. 17
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  20. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  21. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  22. 31
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  23. 29
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs
  24. 197
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs
  25. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
  26. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
  27. 2
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  28. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  29. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Metal.hlsl
  30. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl
  31. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl
  32. 72
      Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
  33. 83
      Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl
  34. 7
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  35. 2
      Assets/ScriptableRenderLoop/fptl/LightingConvexHullUtils.hlsl

4
Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs


var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("BasicPass"));
settings.sorting.flags = SortFlags.CommonOpaque;
settings.inputFilter.SetQueuesOpaque();
context.DrawRenderers(settings);
context.DrawRenderers(ref settings);
// Draw skybox
context.DrawSkybox(camera);

settings.inputFilter.SetQueuesTransparent();
context.DrawRenderers(settings);
context.DrawRenderers(ref settings);
context.Submit();
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader


DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
int _DebugViewMaterial;

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader


// variable declaration
//-------------------------------------------------------------------------------------
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
uint _ViewTilesFlags;

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs


{
CommonSettingsSingleton.overrideSettings = (CommonSettings)EditorGUILayout.ObjectField(new GUIContent("Common Settings"), CommonSettingsSingleton.overrideSettings, typeof(CommonSettings), false);
SkyParametersSingleton.overrideSettings = (SkyParameters)EditorGUILayout.ObjectField(new GUIContent("Sky Settings"), SkyParametersSingleton.overrideSettings, typeof(SkyParameters), false);
SubsurfaceScatteringSettings.overrideSettings = (SubsurfaceScatteringParameters)EditorGUILayout.ObjectField(new GUIContent("Subsurface Scattering Settings"), SubsurfaceScatteringSettings.overrideSettings, typeof(SubsurfaceScatteringParameters), false);
if (GUILayout.Button("Create new common settings"))
{

{
var instance = CreateInstance<ProceduralSkyParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewProceduralSkyParameters.asset");
}
if (GUILayout.Button("Create new SSS params"))
{
var instance = CreateInstance<SubsurfaceScatteringParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewSssParameters.asset");
}
}
}

25
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


public readonly GUIContent pointCookieSize = new GUIContent("Point cookie size");
public readonly GUIContent reflectionCubemapSize = new GUIContent("Reflection cubemap size");
public readonly GUIContent sssSettings = new GUIContent("Subsurface Scattering Settings");
// Shadow Settings
public readonly GUIContent shadowSettings = new GUIContent("Shadow Settings");
public readonly GUIContent shadowsAtlasWidth = new GUIContent("Atlas width");

public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop Settings");
public readonly string[] tileLightLoopDebugTileFlagStrings = new string[] { "Punctual Light", "Area Light", "Env Light" };
public readonly string[] tileLightLoopDebugTileFlagStrings = new string[] { "Punctual Light", "Area Light", "Env Light"};
public readonly GUIContent splitLightEvaluation = new GUIContent("Split light and reflection evaluation", "Toggle");
public readonly GUIContent bigTilePrepass = new GUIContent("Enable big tile prepass", "Toggle");
public readonly GUIContent clustered = new GUIContent("Enable clustered", "Toggle");

EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
private void SssSettingsUI(HDRenderPipeline pipe)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.sssSettings);
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
pipe.localSssParameters = (SubsurfaceScatteringParameters) EditorGUILayout.ObjectField(new GUIContent("Subsurface Scattering Parameters"), pipe.localSssParameters, typeof(SubsurfaceScatteringParameters), false);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(pipe); // Repaint
}
}
private void LightingDebugParametersUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)

if (!m_LightingDebugMode.hasMultipleDifferentValues)
{
if ((LightingDebugMode)m_LightingDebugMode.intValue != LightingDebugMode.None)
{
{
{
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothnessValue, styles.lightingDebugOverrideSmoothnessValue);
EditorGUI.indentLevel--;

renderContext.lightLoopProducer = (LightLoopProducer)EditorGUILayout.ObjectField(new GUIContent("Light Loop"), renderContext.lightLoopProducer, typeof(LightLoopProducer), false);
SkySettingsUI(renderContext);
SssSettingsUI(renderContext);
ShadowParametersUI(renderContext);
TextureParametersUI(renderContext);
RendereringParametersUI(renderContext);

109
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


public CommonSettings.Settings commonSettingsToUse
{
get
{
{
if (CommonSettingsSingleton.overrideSettings)
return CommonSettingsSingleton.overrideSettings.settings;

}
}
[SerializeField]
public SubsurfaceScatteringParameters localSssParameters;
public SubsurfaceScatteringParameters sssParameters
{
get
{
if (SubsurfaceScatteringSettings.overrideSettings != null)
{
return SubsurfaceScatteringSettings.overrideSettings;
}
if (localSssParameters == null)
{
localSssParameters = new SubsurfaceScatteringParameters();
}
return localSssParameters;
}
}
public void ApplyDebugParameters()
{
m_ShadowSettings.enabled = globalDebugParameters.lightingDebugParameters.enableShadows;

m_ShadowSettings.directionalLightCascadeCount = commonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(commonSettings.shadowCascadeSplit0, commonSettings.shadowCascadeSplit1, commonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
// TODO: how can we avoid dynamic memory allocation each frame?
m_SssParameters.profiles = new SubsurfaceScatteringProfile[SubsurfaceScatteringParameters.numProfiles];
m_SssParameters.profiles[0] = new SubsurfaceScatteringProfile();
m_SssParameters.profiles[0].stdDev1 = commonSettings.sssProfileStdDev1;
m_SssParameters.profiles[0].stdDev2 = commonSettings.sssProfileStdDev2;
m_SssParameters.profiles[0].lerpWeight = commonSettings.sssProfileLerpWeight;
m_SssParameters.bilateralScale = commonSettings.sssBilateralScale;
}
}

public Vector4 screenSize;
public Matrix4x4 viewProjectionMatrix;
public Matrix4x4 invViewProjectionMatrix;
}
}
public class GBufferManager
{
public const int MaxGbuffer = 8;
public void SetBufferDescription(int index, string stringId, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
public class GBufferManager
IDs[index] = Shader.PropertyToID(stringId);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
}
public const int MaxGbuffer = 8;
public void SetBufferDescription(int index, string stringId, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
{
IDs[index] = Shader.PropertyToID(stringId);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
}
public void InitGBuffers(int width, int height, CommandBuffer cmd)
{
for (int index = 0; index < gbufferCount; index++)
public void InitGBuffers(int width, int height, CommandBuffer cmd)
for (int index = 0; index < gbufferCount; index++)
{
}
}
public RenderTargetIdentifier[] GetGBuffers()
{
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
public RenderTargetIdentifier[] GetGBuffers()
colorMRTs[index] = RTIDs[index];
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
{
colorMRTs[index] = RTIDs[index];
}
return colorMRTs;
return colorMRTs;
}
/*
public void BindBuffers(Material mat)
{
for (int index = 0; index < gbufferCount; index++)
/*
public void BindBuffers(Material mat)
mat.SetTexture(IDs[index], RTs[index]);
for (int index = 0; index < gbufferCount; index++)
{
mat.SetTexture(IDs[index], RTs[index]);
}
}
*/
*/
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
{
{
private readonly HDRenderPipeline m_Owner;
// TODO: Find a way to automatically create/iterate through deferred material

sorting = { flags = SortFlags.CommonOpaque }
};
settings.inputFilter.SetQueuesOpaque();
renderContext.DrawRenderers(settings);
renderContext.DrawRenderers(ref settings);
}
void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)

sorting = { flags = SortFlags.CommonTransparent }
};
settings.inputFilter.SetQueuesTransparent();
renderContext.DrawRenderers(settings);
renderContext.DrawRenderers(ref settings);
}
void RenderDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader


DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
struct Attributes

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/LightingConvexHullUtils.hlsl


#if 1
float3 maxZdir = float3(-sphCen.z*sphCen.x, -sphCen.z*sphCen.y, sphCen.x*sphCen.x + sphCen.y*sphCen.y); // cross(sphCen,cross(Zaxis,sphCen))
float len = length(maxZdir);
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // since len>=(maxZdir.z/len) we can use len as an approximate value when len<=epsilon
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // if len<=0.0001 then either |sphCen|<sphRadius or sphCen is very closely aligned with Z axis in which case little to no additional offs needed.
float offs = scalarProj*sphRadiusIn;
#else
float offs = sphRadiusIn; // more false positives due to larger radius but works too

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute


DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
#ifdef OUTPUT_SPLIT_LIGHTING

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


var cmd = new CommandBuffer() { name = "" };
// generate screen-space AABBs (used for both fptl and clustered).
if (m_lightCount != 0)
{
temp.SetRow(0, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
temp.SetRow(1, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


public static GUIContent detailMapModeText = new GUIContent("Detail Map with Normal", "Detail Map with AO / Height");
public static GUIContent UVDetailMappingText = new GUIContent("UV set for Detail", "");
public static GUIContent materialIDText = new GUIContent("Material Class", "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
public static GUIContent emissiveColorModeText = new GUIContent("Emissive Color Usage", "Use emissive color or emissive mask");
public static string InputsText = "Inputs";

public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation shape (lerp factor)");
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Tesselation displacement will take into account the object scale - Only work with uniform positive scale");
public static GUIContent materialIDText = new GUIContent("Material Class", "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
public static GUIContent subsurfaceProfileText = new GUIContent("Subsurface scattering profile", "A profile determines the shape of the blur filter.");
public static GUIContent subsurfaceRadiusText = new GUIContent("Subsurface scattering radius", "Determines the range of the blur.");
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface scattering radius map", "Determines the range of the blur.");
public static GUIContent thicknessText = new GUIContent("Thickness", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
public static GUIContent thicknessMapText = new GUIContent("Thickness map", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
}
public enum SurfaceType

37
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


protected const string kUVDetail = "_UVDetail";
protected MaterialProperty UVDetailsMappingMask = null;
protected const string kUVDetailsMappingMask = "_UVDetailsMappingMask";
protected MaterialProperty materialID = null;
protected const string kMaterialID = "_MaterialID";
protected MaterialProperty emissiveColorMode = null;
protected const string kEmissiveColorMode = "_EmissiveColorMode";

protected MaterialProperty detailAOScale = null;
protected const string kDetailAOScale = "_DetailAOScale";
// MaterialProperty subSurfaceRadius = null;
// MaterialProperty subSurfaceRadiusMap = null;
protected MaterialProperty emissiveColor = null;
protected const string kEmissiveColor = "_EmissiveColor";
protected MaterialProperty emissiveColorMap = null;

protected MaterialProperty materialID = null;
protected const string kMaterialID = "_MaterialID";
protected MaterialProperty subsurfaceProfile = null;
protected const string kSubsurfaceProfile = "_SubsurfaceProfile";
protected MaterialProperty subsurfaceRadius = null;
protected const string kSubsurfaceRadius = "_SubsurfaceRadius";
protected MaterialProperty subsurfaceRadiusMap = null;
protected const string kSubsurfaceRadiusMap = "_SubsurfaceRadiusMap";
protected MaterialProperty thickness = null;
protected const string kThickness = "_Thickness";
protected MaterialProperty thicknessMap = null;
protected const string kThicknessMap = "_ThicknessMap";
// These are options that are shared with the LayeredLit shader. Don't put anything that can't be shared here:
// For instance, properties like BaseColor and such don't exist in the LayeredLit so don't put them here.

ppdMinSamples = FindProperty(kPpdMinSamples, props);
ppdMaxSamples = FindProperty(kPpdMaxSamples, props);
detailMapMode = FindProperty(kDetailMapMode, props);
materialID = FindProperty(kMaterialID, props);
emissiveColorMode = FindProperty(kEmissiveColorMode, props);
}

emissiveColor = FindProperty(kEmissiveColor, props);
emissiveColorMap = FindProperty(kEmissiveColorMap, props);
emissiveIntensity = FindProperty(kEmissiveIntensity, props);
materialID = FindProperty(kMaterialID, props);
subsurfaceProfile = FindProperty(kSubsurfaceProfile, props);
subsurfaceRadius = FindProperty(kSubsurfaceRadius, props);
subsurfaceRadiusMap = FindProperty(kSubsurfaceRadiusMap, props);
thickness = FindProperty(kThickness, props);
thicknessMap = FindProperty(kThicknessMap, props);
}
override protected void ShaderInputOptionsGUI()

m_MaterialEditor.ShaderProperty(ppdMinSamples, Styles.ppdMinSamplesText);
m_MaterialEditor.ShaderProperty(ppdMaxSamples, Styles.ppdMaxSamplesText);
ppdMinSamples.floatValue = Mathf.Min(ppdMinSamples.floatValue, ppdMaxSamples.floatValue);
m_MaterialEditor.ShaderProperty(materialID, Styles.materialIDText);
m_MaterialEditor.ShaderProperty(materialID, Styles.materialIDText);
m_MaterialEditor.ShaderProperty(subsurfaceProfile, Styles.subsurfaceProfileText);
m_MaterialEditor.ShaderProperty(subsurfaceRadius, Styles.subsurfaceRadiusText);
m_MaterialEditor.ShaderProperty(subsurfaceRadiusMap, Styles.subsurfaceRadiusMapText);
m_MaterialEditor.ShaderProperty(thickness, Styles.thicknessText);
m_MaterialEditor.ShaderProperty(thicknessMap, Styles.thicknessMapText);
EditorGUI.indentLevel--;
}

SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap));
SetKeyword(material, "_ANISOTROPYMAP", material.GetTexture(kAnisotropyMap));
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap));
SetKeyword(material, "_SUBSURFACE_RADIUS_MAP", material.GetTexture(kSubsurfaceRadiusMap));
SetKeyword(material, "_THICKNESS_MAP", material.GetTexture(kThicknessMap));
bool needUV2 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV2 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0;
bool needUV3 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV3 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0;

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


public float specular; // 0.02, 0.04, 0.16, 0.2
// SSS
[SurfaceDataAttributes("SubSurface Radius")]
public float subSurfaceRadius;
[SurfaceDataAttributes("Subsurface Radius")]
public float subsurfaceRadius;
[SurfaceDataAttributes("SubSurface Profile")]
public int subSurfaceProfile;
[SurfaceDataAttributes("Subsurface Profile")]
public int subsurfaceProfile;
// Clearcoat
[SurfaceDataAttributes("Coat Normal")]

// fold into fresnel0
// SSS
public float subSurfaceRadius;
public float subsurfaceRadius;
public int subSurfaceProfile;
public int subsurfaceProfile;
// Clearcoat
public Vector3 coatNormalWS;

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


float anisotropy;
float metallic;
float specular;
float subSurfaceRadius;
float subsurfaceRadius;
int subSurfaceProfile;
int subsurfaceProfile;
float3 coatNormalWS;
float coatPerceptualSmoothness;
float3 specularColor;

float roughnessT;
float roughnessB;
float anisotropy;
float subSurfaceRadius;
float subsurfaceRadius;
int subSurfaceProfile;
int subsurfaceProfile;
float3 coatNormalWS;
float coatRoughness;
};

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl


else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile
bsdfData.subSurfaceRadius = surfaceData.subSurfaceRadius;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceRadius = surfaceData.subsurfaceRadius;
bsdfData.subSurfaceProfile = surfaceData.subSurfaceProfile;
bsdfData.subsurfaceProfile = surfaceData.subsurfaceProfile;
}
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

}
else if (surfaceData.materialId == MATERIALID_LIT_SSS)
{
outGBuffer2 = float4(surfaceData.subSurfaceRadius, surfaceData.thickness, 0.0, surfaceData.subSurfaceProfile / 8.0); // Number of profile not define yet
outGBuffer2 = float4(surfaceData.subsurfaceRadius, surfaceData.thickness, 0.0, surfaceData.subsurfaceProfile / 8.0); // Number of profile not define yet
}
else if (surfaceData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile
bsdfData.subSurfaceRadius = inGBuffer2.r;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceRadius = inGBuffer2.r;
bsdfData.subSurfaceProfile = inGBuffer2.a * 8.0;
bsdfData.subsurfaceProfile = inGBuffer2.a * 8.0;
}
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{

result = surfaceData.specular.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_RADIUS:
result = surfaceData.subSurfaceRadius.xxx;
result = surfaceData.subsurfaceRadius.xxx;
result = GetIndexColor(surfaceData.subSurfaceProfile);
result = GetIndexColor(surfaceData.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS:
result = surfaceData.coatNormalWS * 0.5 + 0.5;

result = bsdfData.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_RADIUS:
result = bsdfData.subSurfaceRadius.xxx;
result = bsdfData.subsurfaceRadius.xxx;
result = GetIndexColor(bsdfData.subSurfaceProfile);
result = GetIndexColor(bsdfData.subsurfaceProfile);
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS:
result = bsdfData.coatNormalWS * 0.5 + 0.5;

15
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader


_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1
[Enum(Standard, 0, Subsurface Scattering, 1, Clear Coat, 2)] _MaterialID("Material Class", Int) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
_SubsurfaceProfile("Subsurface Profile", Int) = 0
_SubsurfaceRadius("Subsurface Radius", Range(0.0, 1.0)) = 0
_SubsurfaceRadiusMap("Subsurface Radius Map", 2D) = "white" {}
_Thickness("Thickness", Range(0.0, 1.0)) = 0
_ThicknessMap("Thickness Map", 2D) = "white" {}
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}

[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_HorizonFade("Horizon fade", Range(0.0, 5.0)) = 1.0

#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _TANGENTMAP
#pragma shader_feature _ANISOTROPYMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl


surfaceData.materialId = 0;
surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.subsurfaceRadius = 1.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.subsurfaceProfile = 0;
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);

18
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.thickness = 0.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.subsurfaceProfile = _SubsurfaceProfile;
#ifdef _Subsurface_RADIUS_MAP
surfaceData.subsurfaceProfile = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_SubsurfaceRadiusMap), ADD_ZERO_IDX(sampler_SubsurfaceRadiusMap), ADD_IDX(layerTexCoord.base)).r;
#else
surfaceData.subsurfaceRadius = _SubsurfaceRadius;
#endif
#ifdef _THICKNESS_MAP
surfaceData.thickness = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_ThicknessMap), ADD_ZERO_IDX(sampler_ThicknessMap), ADD_IDX(layerTexCoord.base)).r;
#else
surfaceData.thickness = _Thickness;
#endif
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;

surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.subsurfaceRadius = 1.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.subsurfaceProfile = 0;
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;

17
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl


TEXTURE2D(_AnisotropyMap);
SAMPLER2D(sampler_AnisotropyMap);
float _MaterialID;
//float _SubSurfaceRadius;
//TEXTURE2D(_SubSurfaceRadiusMap);
//SAMPLER2D(sampler_SubSurfaceRadiusMap);
// float _Thickness;
//TEXTURE2D(_ThicknessMap);
//SAMPLER2D(sampler_ThicknessMap);
int _MaterialID;
int _SubsurfaceProfile;
float _SubsurfaceRadius;
float _Thickness;
TEXTURE2D(_SubsurfaceRadiusMap);
SAMPLER2D(sampler_SubsurfaceRadiusMap);
TEXTURE2D(_ThicknessMap);
SAMPLER2D(sampler_ThicknessMap);
// float _CoatCoverage;
//TEXTURE2D(_CoatCoverageMap);

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader


_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1
[Enum(Standard, 0, Subsurface Scattering, 1, Clear Coat, 2)] _MaterialID("Material Class", Int) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
_SubsurfaceProfile("Subsurface Profile", Int) = 0
_SubsurfaceRadius("Subsurface Radius", Range(0.0, 1.0)) = 0
_SubsurfaceRadiusMap("Subsurface Radius Map", 2D) = "white" {}
_Thickness("Thickness", Range(0.0, 1.0)) = 0
_ThicknessMap("Thickness Map", 2D) = "white" {}
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}

#pragma shader_feature _TANGENTMAP
#pragma shader_feature _ANISOTROPYMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


float4 _FilterKernel[7]; // RGB = weights, A = radial distance
float _FilterRadius; // Uses world-space units
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
TEXTURE2D(_IrradianceSource);
SAMPLER2D(sampler_IrradianceSource);

31
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


public float shadowCascadeSplit1 { set { m_ShadowCascadeSplit1 = value; OnValidate(); } get { return m_ShadowCascadeSplit1; } }
public float shadowCascadeSplit2 { set { m_ShadowCascadeSplit2 = value; OnValidate(); } get { return m_ShadowCascadeSplit2; } }
// Subsurface scattering
[SerializeField] [ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_SssProfileStdDev1;
[SerializeField] [ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_SssProfileStdDev2;
[SerializeField]
float m_SssProfileLerpWeight;
[SerializeField]
float m_SssBilateralScale;
public Color sssProfileStdDev1 { set { m_SssProfileStdDev1 = value; OnValidate(); } get { return m_SssProfileStdDev1; } }
public Color sssProfileStdDev2 { set { m_SssProfileStdDev2 = value; OnValidate(); } get { return m_SssProfileStdDev2; } }
public float sssProfileLerpWeight { set { m_SssProfileLerpWeight = value; OnValidate(); } get { return m_SssProfileLerpWeight; } }
public float sssBilateralScale { set { m_SssBilateralScale = value; OnValidate(); } get { return m_SssBilateralScale; } }
void OnValidate()
{
m_ShadowMaxDistance = Mathf.Max(0.0f, m_ShadowMaxDistance);

m_ShadowCascadeSplit2 = Mathf.Clamp01(m_ShadowCascadeSplit2);
m_SssProfileStdDev1.r = Mathf.Max(0.05f, m_SssProfileStdDev1.r);
m_SssProfileStdDev1.g = Mathf.Max(0.05f, m_SssProfileStdDev1.g);
m_SssProfileStdDev1.b = Mathf.Max(0.05f, m_SssProfileStdDev1.b);
m_SssProfileStdDev1.a = 0.0f;
m_SssProfileStdDev2.r = Mathf.Max(0.05f, m_SssProfileStdDev2.r);
m_SssProfileStdDev2.g = Mathf.Max(0.05f, m_SssProfileStdDev2.g);
m_SssProfileStdDev2.b = Mathf.Max(0.05f, m_SssProfileStdDev2.b);
m_SssProfileStdDev2.a = 0.0f;
m_SssProfileLerpWeight = Mathf.Clamp01(m_SssProfileLerpWeight);
m_SssBilateralScale = Mathf.Clamp01(m_SssBilateralScale);
}
public static readonly Settings s_Defaultsettings = new Settings

m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x,
m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y,
m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z,
m_SssProfileStdDev1 = SubsurfaceScatteringProfile.Default.stdDev1,
m_SssProfileStdDev2 = SubsurfaceScatteringProfile.Default.stdDev2,
m_SssProfileLerpWeight = SubsurfaceScatteringProfile.Default.lerpWeight,
m_SssBilateralScale = SubsurfaceScatteringParameters.Default.bilateralScale
};
}

29
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs


public readonly int[] shadowsCascadeCountValues = new int[] { 1, 2, 3, 4 };
public readonly GUIContent shadowsCascades = new GUIContent("Cascade values");
public readonly GUIContent[] shadowSplits = new GUIContent[] { new GUIContent("Split 0"), new GUIContent("Split 1"), new GUIContent("Split 2") };
public readonly GUIContent sssCategory = new GUIContent("Subsurface scattering");
public readonly GUIContent sssProfileStdDev1 = new GUIContent("SSS profile standard deviation #1", "Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileStdDev2 = new GUIContent("SSS profile standard deviation #2", "Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileLerpWeight = new GUIContent("SSS profile filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent sssBilateralScale = new GUIContent("SSS bilateral filtering scale", "Larger values make the filter more tolerant to depth differences.");
}
private static Styles s_Styles = null;

private SerializedProperty m_ShadowCascadeCount;
private SerializedProperty[] m_ShadowCascadeSplits = new SerializedProperty[3];
// Subsurface scattering
private SerializedProperty m_SssProfileStdDev1;
private SerializedProperty m_SssProfileStdDev2;
private SerializedProperty m_SssProfileLerpWeight;
private SerializedProperty m_SssBilateralScale;
void OnEnable()
{
m_SkyRenderer = serializedObject.FindProperty("m_SkyRendererTypeName");

m_SkyRendererFullTypeNames.Add("");
m_SkyRendererTypeValues.Add(m_SkyRendererTypeValues.Count);
m_SkyRendererTypes.Add(null);
m_SssProfileStdDev1 = serializedObject.FindProperty("m_SssProfileStdDev1");
m_SssProfileStdDev2 = serializedObject.FindProperty("m_SssProfileStdDev2");
m_SssProfileLerpWeight = serializedObject.FindProperty("m_SssProfileLerpWeight");
m_SssBilateralScale = serializedObject.FindProperty("m_SssBilateralScale");
}
void OnSkyInspectorGUI()

EditorGUI.indentLevel--;
}
void OnSubsurfaceInspectorGUI()
{
EditorGUILayout.LabelField(styles.sssCategory);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_SssProfileStdDev1, styles.sssProfileStdDev1);
EditorGUILayout.PropertyField(m_SssProfileStdDev2, styles.sssProfileStdDev2);
EditorGUILayout.PropertyField(m_SssProfileLerpWeight, styles.sssProfileLerpWeight);
EditorGUILayout.PropertyField(m_SssBilateralScale, styles.sssBilateralScale);
EditorGUI.indentLevel--;
}
/*
public override void OnInspectorGUI()
{

OnShadowInspectorGUI();
OnSubsurfaceInspectorGUI();
serializedObject.ApplyModifiedProperties();
}

197
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs


using System;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public const int numSamples = 7;
public const int numSamples = 7; // Must be an odd number
[SerializeField, ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_StdDev1;
[SerializeField, ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_StdDev2;
[SerializeField]
float m_LerpWeight;
[SerializeField]
Vector4[] m_FilterKernel;
[SerializeField]
public bool m_KernelNeedsUpdate;
Color m_StdDev1;
Color m_StdDev2;
float m_LerpWeight;
Vector4[] m_FilterKernel;
bool m_KernelNeedsUpdate;
// --- Public Methods ---
// --- Methods ---
public SubsurfaceScatteringProfile()
{
m_StdDev1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
m_StdDev2 = new Color(1.0f, 1.0f, 1.0f, 0.0f);
m_LerpWeight = 0.5f;
ComputeKernel();
}
public Color stdDev1
{

get { if (m_KernelNeedsUpdate) ComputeKernel(); return m_FilterKernel; }
}
public static SubsurfaceScatteringProfile Default
public void SetDirtyFlag()
get
{
SubsurfaceScatteringProfile profile = new SubsurfaceScatteringProfile();
profile.m_StdDev1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
profile.m_StdDev2 = new Color(1.0f, 1.0f, 1.0f, 0.0f);
profile.m_LerpWeight = 0.5f;
profile.ComputeKernel();
return profile;
}
m_KernelNeedsUpdate = true;
// --- Private Methods ---
static float Gaussian(float x, float stdDev)
{

return Mathf.Lerp(NormalCdfInverse(p, stdDev1), NormalCdfInverse(p, stdDev2), lerpWeight);
}
// Ref: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
static float VanDerCorputBase2(uint i)
{
i = i + 1;
i = (i << 16) | (i >> 16);
i = ((i & 0x00ff00ff) << 8) | ((i & 0xff00ff00) >> 8);
i = ((i & 0x0f0f0f0f) << 4) | ((i & 0xf0f0f0f0) >> 4);
i = ((i & 0x33333333) << 2) | ((i & 0xcccccccc) >> 2);
i = ((i & 0x55555555) << 1) | ((i & 0xaaaaaaaa) >> 1);
return i * (1.0f / 4294967296);
}
if (m_FilterKernel == null)
if (m_FilterKernel == null || m_FilterKernel.Length != numSamples)
{
m_FilterKernel = new Vector4[numSamples];
}

// Importance sample the linear combination of two Gaussians.
for (uint i = 0; i < numSamples; i++)
{
float u = VanDerCorputBase2(i);
float u = (i + 0.5f) / numSamples;
float pos = GaussianCombinationCdfInverse(u, maxStdDev1, maxStdDev2, m_LerpWeight);
float pdf = GaussianCombination(pos, maxStdDev1, maxStdDev2, m_LerpWeight);

}
}
[System.Serializable]
public class SubsurfaceScatteringParameters
public class SubsurfaceScatteringParameters : ScriptableObject
{
const int m_maxNumProfiles = 8;
[SerializeField]
int m_NumProfiles;
[SerializeField]
SubsurfaceScatteringProfile[] m_Profiles;
[SerializeField]
float m_BilateralScale;
// --- Public Methods ---
public SubsurfaceScatteringParameters()
{
m_NumProfiles = 1;
m_Profiles = new SubsurfaceScatteringProfile[m_NumProfiles];
m_BilateralScale = 0.1f;
for (int i = 0; i < m_NumProfiles; i++)
{
m_Profiles[i] = new SubsurfaceScatteringProfile();
}
}
public SubsurfaceScatteringProfile[] profiles { set { m_Profiles = value; OnValidate(); } get { return m_Profiles; } }
public float bilateralScale { set { m_BilateralScale = value; OnValidate(); } get { return m_BilateralScale; } }
public void SetDirtyFlag()
{
for (int i = 0; i < m_Profiles.Length; i++)
{
m_Profiles[i].SetDirtyFlag();
}
}
// --- Private Methods ---
void OnValidate()
{
if (m_Profiles.Length > m_maxNumProfiles)
{
Array.Resize(ref m_Profiles, m_maxNumProfiles);
}
m_NumProfiles = m_Profiles.Length;
Color c = new Color();
for (int i = 0; i < m_NumProfiles; i++)
{
c.r = Mathf.Clamp(m_Profiles[i].stdDev1.r, 0.05f, 2.0f);
c.g = Mathf.Clamp(m_Profiles[i].stdDev1.g, 0.05f, 2.0f);
c.b = Mathf.Clamp(m_Profiles[i].stdDev1.b, 0.05f, 2.0f);
c.a = 0.0f;
m_Profiles[i].stdDev1 = c;
c.r = Mathf.Clamp(m_Profiles[i].stdDev2.r, 0.05f, 2.0f);
c.g = Mathf.Clamp(m_Profiles[i].stdDev2.g, 0.05f, 2.0f);
c.b = Mathf.Clamp(m_Profiles[i].stdDev2.b, 0.05f, 2.0f);
c.a = 0.0f;
m_Profiles[i].stdDev2 = c;
m_Profiles[i].lerpWeight = Mathf.Clamp01(m_Profiles[i].lerpWeight);
}
m_BilateralScale = Mathf.Clamp01(m_BilateralScale);
}
}
public class SubsurfaceScatteringSettings : Singleton<SubsurfaceScatteringSettings>
public const int numProfiles = 1;
public SubsurfaceScatteringProfile[] profiles;
public float bilateralScale;
SubsurfaceScatteringParameters settings { get; set; }
// --- Methods ---
public static SubsurfaceScatteringParameters overrideSettings
{
get { return instance.settings; }
set { instance.settings = value; }
}
}
public static SubsurfaceScatteringParameters Default
[CustomEditor(typeof(SubsurfaceScatteringParameters))]
public class SubsurfaceScatteringParametersEditor : Editor
{
private class Styles
{
public readonly GUIContent sssCategory = new GUIContent("Subsurface scattering");
public readonly GUIContent sssProfileStdDev1 = new GUIContent("SSS profile standard deviation #1", "Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileStdDev2 = new GUIContent("SSS profile standard deviation #2", "Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileLerpWeight = new GUIContent("SSS profile filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent sssBilateralScale = new GUIContent("SSS bilateral filtering scale", "Larger values make the filter more tolerant to depth differences.");
}
private static Styles s_Styles;
private SerializedProperty m_Profiles;
private SerializedProperty m_BilateralScale;
// --- Public Methods ---
private static Styles styles
SubsurfaceScatteringParameters parameters = new SubsurfaceScatteringParameters();
parameters.profiles = new SubsurfaceScatteringProfile[numProfiles];
for (int i = 0; i < numProfiles; i++)
if (s_Styles == null)
parameters.profiles[i] = SubsurfaceScatteringProfile.Default;
s_Styles = new Styles();
return s_Styles;
}
}
parameters.bilateralScale = 0.1f;
return parameters;
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Profiles, true);
EditorGUILayout.PropertyField(m_BilateralScale, styles.sssBilateralScale);
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
// Serialization ignores setters.
((SubsurfaceScatteringParameters)target).SetDirtyFlag();
}
// --- Private Methods ---
void OnEnable()
{
m_Profiles = serializedObject.FindProperty("m_Profiles");
m_BilateralScale = serializedObject.FindProperty("m_BilateralScale");
}
}
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl


CBUFFER_END
// TODO: Change code here so probe volume use only one transform instead of all this parameters!
TEXTURE3D(unity_ProbeVolumeSH);
TEXTURE3D_FLOAT(unity_ProbeVolumeSH);
SAMPLER3D(samplerunity_ProbeVolumeSH);
CBUFFER_START(UnityProbeVolume)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl


SAMPLER2D(sampler_CameraDepthTexture);
#define SRL_BilinearSampler sampler_CameraDepthTexture // Used for all textures
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
TEXTURE2D(_OcclusionTexture);
float HenyeyGreensteinPhase(float g, float cosTheta) {

2
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


commandBuffer.Dispose();
// Render
loop.DrawShadows(settings);
loop.DrawShadows(ref settings);
}
}
}

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D
#define TEXTURE3D_HALF TEXTURE3D
#define TEXTURE3D_FLOAT TEXTURE3D
#define SAMPLER2D_HALF SAMPLER2D
#define SAMPLER2D_FLOAT SAMPLER2D

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/Metal.hlsl


#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D
#define TEXTURE3D_HALF TEXTURE3D
#define TEXTURE3D_FLOAT TEXTURE3D
#define SAMPLER2D_HALF SAMPLER2D
#define SAMPLER2D_FLOAT SAMPLER2D

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl


#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D
#define TEXTURE3D_HALF TEXTURE3D
#define TEXTURE3D_FLOAT TEXTURE3D
#define SAMPLER2D_HALF SAMPLER2D
#define SAMPLER2D_FLOAT SAMPLER2D

2
Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl


float VanDerCorputBase2(uint i)
{
return float(ReverseBits32(i + 1)) * 2.3283064365386963e-10; // 0x100000000
return ReverseBits32(i) * rcp(4294967296.0); // 0x100000000
}
float2 Hammersley2dSeq(uint i, uint sequenceLength)

72
Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl


return roughness * lerp(saturate(NdotV * 2.0), 1.0, perceptualRoughness);
}
//-----------------------------------------------------------------------------
// Coordinate system conversion
//-----------------------------------------------------------------------------
// Transforms the unit vector from the spherical to the Cartesian (right-handed, Z up) coordinate.
float3 SphericalToCartesian(float phi, float cosTheta)
{
float sinPhi, cosPhi;
sincos(phi, sinPhi, cosPhi);
float sinTheta = sqrt(saturate(1.0 - cosTheta * cosTheta));
return float3(sinTheta * cosPhi, sinTheta * sinPhi, cosTheta);
}
// Converts Cartesian coordinates given in the right-handed coordinate system
// with Z pointing upwards (OpenGL style) to the coordinates in the left-handed
// coordinate system with Y pointing up and Z facing forward (DirectX style).
float3 TransformGLtoDX(float3 v)
{
return v.xzy;
}
// Performs conversion from equiareal map coordinates to Cartesian (DirectX cubemap) ones.
float3 ConvertEquiarealToCubemap(float u, float v)
{
float phi = TWO_PI - TWO_PI * u;
float cosTheta = 1.0 - 2.0 * v;
return TransformGLtoDX(SphericalToCartesian(phi, cosTheta));
}
// Performs uniform sampling of the unit disk.
// Ref: PBRT v3, p. 777.
float2 SampleDiskUniform(float2 u)
{
float r = sqrt(u.x);
float phi = TWO_PI * u.y;
float sinPhi, cosPhi;
sincos(phi, sinPhi, cosPhi);
return r * float2(cosPhi, sinPhi);
}
// Performs cosine-weighted sampling of the hemisphere.
// Ref: PBRT v3, p. 780.
void SampleHemisphereCosine(float2 u,
float3x3 localToWorld,
out float3 L,
out float NdotL)
{
float3 localL;
// Since we don't really care about the area distortion,
// we substitute uniform disk sampling for the concentric one.
localL.xy = SampleDiskUniform(u);
// Project the point from the disk onto the hemisphere.
localL.z = sqrt(1.0 - u.x);
NdotL = localL.z;
L = mul(localL, localToWorld);
}
void SampleGGXDir(float2 u,
float3 V,
float3x3 localToWorld,

out float NdotL,
out float weightOverPdf)
{
SampleHemisphereCosine(u, localToWorld, L, NdotL);
float3 localL = SampleHemisphereCosine(u.x, u.y);
NdotL = localL.z;
L = mul(localL, localToWorld);
// Importance sampling weight for each sample
// pdf = N.L / PI

83
Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl


}
//-----------------------------------------------------------------------------
// Coordinate system conversion
//-----------------------------------------------------------------------------
// Transforms the unit vector from the spherical to the Cartesian (right-handed, Z up) coordinate.
float3 SphericalToCartesian(float phi, float cosTheta)
{
float sinPhi, cosPhi;
sincos(phi, sinPhi, cosPhi);
float sinTheta = sqrt(saturate(1.0 - cosTheta * cosTheta));
return float3(sinTheta * cosPhi, sinTheta * sinPhi, cosTheta);
}
// Converts Cartesian coordinates given in the right-handed coordinate system
// with Z pointing upwards (OpenGL style) to the coordinates in the left-handed
// coordinate system with Y pointing up and Z facing forward (DirectX style).
float3 TransformGLtoDX(float3 v)
{
return v.xzy;
}
// Performs conversion from equiareal map coordinates to Cartesian (DirectX cubemap) ones.
float3 ConvertEquiarealToCubemap(float u, float v)
{
float phi = TWO_PI - TWO_PI * u;
float cosTheta = 1.0 - 2.0 * v;
return TransformGLtoDX(SphericalToCartesian(phi, cosTheta));
}
//-----------------------------------------------------------------------------
float3 UniformSampleSphere(float u1, float u2)
// Performs uniform sampling of the unit disk.
// Ref: PBRT v3, p. 777.
float2 SampleDiskUniform(float u1, float u2)
float r = sqrt(u1);
float cosTheta = 1.0 - 2.0 * u1;
float sinTheta = sqrt(max(0.0, 1.0 - cosTheta * cosTheta));
float sinPhi, cosPhi;
sincos(phi, sinPhi, cosPhi);
return r * float2(cosPhi, sinPhi);
}
return float3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta); // Light point backward (-Z)
// Performs cosine-weighted sampling of the hemisphere.
// Ref: PBRT v3, p. 780.
float3 SampleHemisphereCosine(float u1, float u2)
{
float3 localL;
// Since we don't really care about the area distortion,
// we substitute uniform disk sampling for the concentric one.
localL.xy = SampleDiskUniform(u1, u2);
// Project the point from the disk onto the hemisphere.
localL.z = sqrt(1.0 - u1);
return localL;
float3 UniformSampleHemisphere(float u1, float u2)
float3 SampleHemisphereUniform(float u1, float u2)
float phi = TWO_PI * u2;
float cosTheta = u1;
float sinTheta = sqrt(max(0.0, 1.0 - cosTheta * cosTheta));
float phi = TWO_PI * u2;
float cosTheta = 1.0 - u1;
return float3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta); // Light point backward (-Z)
return SphericalToCartesian(phi, cosTheta);
float3 UniformSampleDisk(float u1, float u2)
float3 SampleSphereUniform(float u1, float u2)
float r = sqrt(u1);
float phi = TWO_PI * u2;
float phi = TWO_PI * u2;
float cosTheta = 1.0 - 2.0 * u1;
return float3(r * cos(phi), r * sin(phi), 0); // Generate in XY plane as light point backward (-Z)
return SphericalToCartesian(phi, cosTheta);
}
void SampleSphere( float2 u,

float u1 = u.x;
float u2 = u.y;
Ns = UniformSampleSphere(u1, u2);
Ns = SampleSphereUniform(u1, u2);
// Transform from unit sphere to world space
P = radius * Ns + localToWorld[3].xyz;

float u2 = u.y;
// Random point at hemisphere surface
Ns = -UniformSampleHemisphere(u1, u2); // We want the y down hemisphere
Ns = -SampleHemisphereUniform(u1, u2); // We want the y down hemisphere
P = radius * Ns;
// Transform to world space

out float3 Ns)
{
// Random point at disk surface
P = UniformSampleDisk(u.x, u.y) * radius;
P = float3(radius * SampleDiskUniform(u.x, u.y), 0);
Ns = float3(0.0, 0.0, -1.0); // Light point backward (-Z)
// Transform to world space

7
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


//@TODO: need to get light probes + LPPV too?
settings.inputFilter.SetQueuesOpaque();
settings.rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe;
loop.DrawRenderers(settings);
loop.DrawRenderers(ref settings);
}
void RenderForward(CullResults cull, Camera camera, ScriptableRenderContext loop, bool opaquesOnly)

if (opaquesOnly) settings.inputFilter.SetQueuesOpaque();
else settings.inputFilter.SetQueuesTransparent();
loop.DrawRenderers(settings);
loop.DrawRenderers(ref settings);
}
static void DepthOnlyForForwardOpaques(CullResults cull, Camera camera, ScriptableRenderContext loop)

sorting = { flags = SortFlags.CommonOpaque }
};
settings.inputFilter.SetQueuesOpaque();
loop.DrawRenderers(settings);
loop.DrawRenderers(ref settings);
}
bool usingFptl

var cmd = new CommandBuffer() { name = "Build light list" };
// generate screen-space AABBs (used for both fptl and clustered).
if (numLights != 0)
{
var proj = CameraProjection(camera);
var temp = new Matrix4x4();

2
Assets/ScriptableRenderLoop/fptl/LightingConvexHullUtils.hlsl


#if 1
float3 maxZdir = float3(-sphCen.z*sphCen.x, -sphCen.z*sphCen.y, sphCen.x*sphCen.x + sphCen.y*sphCen.y); // cross(sphCen,cross(Zaxis,sphCen))
float len = length(maxZdir);
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // since len>=(maxZdir.z/len) we can use len as an approximate value when len<=epsilon
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // if len<=0.0001 then either |sphCen|<sphRadius or sphCen is very closely aligned with Z axis in which case little to no additional offs needed.
float offs = scalarProj*sphRadiusIn;
#else
float offs = sphRadiusIn; // more false positives due to larger radius but works too

正在加载...
取消
保存