浏览代码

Merge branch 'master' into HDRP-Tests

# Conflicts:
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1102_Unlit_Distortion.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1103_Unlit_Distortion_DepthTest.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1202_Lit_DoubleSideNormalMode.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1204_Lit_Transparent_Fog.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1208_Lit_Displacement_POM.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1209_Lit_Displacement_Vertex.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1210_Lit_BentNormal.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/1302_SSS_MaxRadius.png
#	TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/Window...
/main
Remy 6 年前
当前提交
540d190a
共有 165 个文件被更改,包括 9836 次插入14610 次删除
  1. 118
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0006_Std_Empty_Deferred_HDR.png
  2. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0100_Std_FXAA.png
  3. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0101_Std_FXAA_Fast.png
  4. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0102_Std_SMAA.png
  5. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0200_Std_Vignette.png
  6. 797
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0201_Std_LensDistort.png
  7. 764
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0202_Std_LensUnDistort.png
  8. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0203_Std_ChromaticAberration.png
  9. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0204_Std_ChromaticAberration_Fast.png
  10. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0205_Std_Grain.png
  11. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0206_Std_Grain_Colored.png
  12. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0207_Std_Bloom_HDR.png
  13. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0208_Std_Bloom_HDR_Fast.png
  14. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0209_Std_Bloom_LDR.png
  15. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0210_Std_Bloom_LDR_Fast.png
  16. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0211_Std_LensDirt.png
  17. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0212_Std_ColorGrading_HDR_Neutral.png
  18. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0213_Std_ColorGrading_LDR_Neutral.png
  19. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0214_Std_ColorGrading_HDR_Mix.png
  20. 999
      TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0215_Std_ColorGrading_LDR_Mix.png
  21. 3
      com.unity.render-pipelines.core/CHANGELOG.md
  22. 4
      com.unity.render-pipelines.core/CoreRP/Editor/com.unity.render-pipelines.core.Editor.asmdef
  23. 22
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/BSDF.hlsl
  24. 23
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Common.hlsl
  25. 33
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/CommonLighting.hlsl
  26. 2
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/CommonMaterial.hlsl
  27. 17
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl
  28. 8
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Macros.hlsl
  29. 5
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Sampling/Sampling.hlsl
  30. 52
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/ShadowSampling.hlsl
  31. 13
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/UnityInstancing.hlsl
  32. 100
      com.unity.render-pipelines.core/CoreRP/Shadow/Shadow.cs
  33. 9
      com.unity.render-pipelines.core/CoreRP/Shadow/ShadowBase.cs
  34. 1
      com.unity.render-pipelines.core/CoreRP/Shadow/ShadowBase.cs.hlsl
  35. 15
      com.unity.render-pipelines.core/CoreRP/Utilities/CoreUtils.cs
  36. 3
      com.unity.render-pipelines.core/CoreRP/com.unity.render-pipelines.core.Runtime.asmdef
  37. 5
      com.unity.render-pipelines.core/package.json
  38. 18
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  39. 2
      com.unity.render-pipelines.high-definition/HDRP/Camera/HDCamera.cs
  40. 8
      com.unity.render-pipelines.high-definition/HDRP/Editor/BuildProcessors/HDRPreprocessShaders.cs
  41. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  42. 131
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  43. 24
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  44. 21
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs
  45. 7
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitShaderPreprocessor.cs
  46. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitUI.cs
  47. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs
  48. 127
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs
  49. 5
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDEditorUtils.cs
  50. 10
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs
  51. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs
  52. 40
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs
  53. 7
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedShadowInitParameters.cs
  54. 24
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/ShadowInitParametersUI.cs
  55. 38
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRPass.template
  56. 29
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRSubShader.cs
  57. 18
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDSubShaderUtilities.cs
  58. 32
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitPassForward.template
  59. 9
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitSubShader.cs
  60. 20
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/VolumetricFogEditor.cs
  61. 17
      com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset
  62. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs
  63. 69
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs
  64. 289
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl
  65. 196
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl
  66. 62
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs
  67. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl
  68. 21
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl
  69. 8
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/VolumeProjection.hlsl
  70. 13
      com.unity.render-pipelines.high-definition/HDRP/Lighting/SphericalHarmonics.cs
  71. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/DensityVolume.cs
  72. 23
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs
  73. 133
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  74. 97
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute
  75. 132
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  76. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs
  77. 28
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl
  78. 15
      com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl
  79. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/GGXConvolution/RuntimeFilterIBL.cs
  80. 22
      com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LTCAreaLight.cs
  81. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LTCAreaLight.hlsl
  82. 998
      com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LtcData.DisneyDiffuse.cs
  83. 992
      com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LtcData.GGX.cs
  84. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitData.hlsl
  85. 521
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl
  86. 10
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitBuiltinData.hlsl
  87. 11
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitData.hlsl
  88. 10
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitDataDisplacement.hlsl
  89. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitDataIndividualLayer.hlsl
  90. 21
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitDataMeshModification.hlsl
  91. 8
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitReference.hlsl
  92. 16
      com.unity.render-pipelines.high-definition/HDRP/Material/MaterialUtilities.hlsl
  93. 3
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs
  94. 34
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs.hlsl
  95. 741
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl
  96. 125
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader
  97. 75
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl
  98. 67
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitProperties.hlsl
  99. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute
  100. 109
      com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl

118
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0006_Std_Empty_Deferred_HDR.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0100_Std_FXAA.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0101_Std_FXAA_Fast.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0102_Std_SMAA.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0200_Std_Vignette.png
文件差异内容过多而无法显示
查看文件

797
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0201_Std_LensDistort.png
文件差异内容过多而无法显示
查看文件

764
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0202_Std_LensUnDistort.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0203_Std_ChromaticAberration.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0204_Std_ChromaticAberration_Fast.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0205_Std_Grain.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0206_Std_Grain_Colored.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0207_Std_Bloom_HDR.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0208_Std_Bloom_HDR_Fast.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0209_Std_Bloom_LDR.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0210_Std_Bloom_LDR_Fast.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0211_Std_LensDirt.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0212_Std_ColorGrading_HDR_Neutral.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0213_Std_ColorGrading_LDR_Neutral.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0214_Std_ColorGrading_HDR_Mix.png
文件差异内容过多而无法显示
查看文件

999
TestProjects/PostProcessing/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/0215_Std_ColorGrading_LDR_Mix.png
文件差异内容过多而无法显示
查看文件

3
com.unity.render-pipelines.core/CHANGELOG.md


## [Unreleased]
### Added
- Add PCSS shadow filter
### Improvements
- Improved volume UI & styling

4
com.unity.render-pipelines.core/CoreRP/Editor/com.unity.render-pipelines.core.Editor.asmdef


{
"name": "com.unity.render-pipelines.core.Editor",
"references": [
"com.unity.render-pipelines.core.Runtime",
"com.unity.postprocessing.Runtime",
"com.unity.postprocessing.Editor"
"com.unity.render-pipelines.core.Runtime"
],
"optionalUnityReferences": [],
"includePlatforms": [

22
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/BSDF.hlsl


}
// Evaluate the reflectance for a thin-film layer on top of a dielectric medum.
real3 EvalIridescence(real eta_1, real cosTheta1, real iridescenceThickness, real3 baseLayerFresnel0)
real3 EvalIridescence(real eta_1, real cosTheta1, real iridescenceThickness, real3 baseLayerFresnel0, real iorOverBaseLayer = 0.0)
{
// iridescenceThickness unit is micrometer for this equation here. Mean 0.5 is 500nm.
real Dinc = 3.0 * iridescenceThickness;

// Force eta_2 -> eta_1 when Dinc -> 0.0
// real eta_2 = lerp(eta_1, eta_2, smoothstep(0.0, 0.03, Dinc));
// Evaluate the cosTheta on the base layer (Snell law)
real cosTheta2 = sqrt(1.0 - Sq(eta_1 / eta_2) * (1.0 - Sq(cosTheta1)));
real sinTheta2 = Sq(eta_1 / eta_2) * (1.0 - Sq(cosTheta1));
// Handle TIR
if (sinTheta2 > 1.0)
return real3(1.0, 1.0, 1.0);
//Or use this "artistic hack" to get more continuity even though wrong (test with dual normal maps to understand the difference)
//if( sinTheta2 > 1.0 ) { sinTheta2 = 2 - sinTheta2; }
real cosTheta2 = sqrt(1.0 - sinTheta2);
// First interface
real R0 = IorToFresnel0(eta_2, eta_1);

real phi21 = PI - phi12;
// Second interface
// The f0 or the base should account for the new computed eta_2 on top.
// This is optionally done if we are given the needed current ior over the base layer that is accounted for
// in the baseLayerFresnel0 parameter:
if (iorOverBaseLayer > 0.0)
{
// Fresnel0ToIor will give us a ratio of baseIor/topIor, hence we * iorOverBaseLayer to get the baseIor
real3 baseIor = iorOverBaseLayer * Fresnel0ToIor(baseLayerFresnel0 + 0.0001); // guard against 1.0
baseLayerFresnel0 = IorToFresnel0(baseIor, eta_2);
}
real3 R23 = F_Schlick(baseLayerFresnel0, cosTheta2);
real phi23 = 0.0;

23
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Common.hlsl


// space at the end of the variable name
// WS: world space
// RWS: Camera-Relative world space. A space where the translation of the camera have already been substract in order to improve precision
// VS: view space
// OS: object space
// CS: Homogenous clip spaces

{
data ^= 1u << offset;
}
#ifndef INTRINSIC_WAVEREADFIRSTLANE
// Warning: for correctness, the argument's value must be the same across all lanes of the wave.

return ComputeTextureLOD(uv);
}
float ComputeTextureLOD(float3 Px, float3 Py, float3 Pz)
// LOD clamp is optional and happens outside the function.
float ComputeTextureLOD(float3 duvw_dx, float3 duvw_dy, float3 duvw_dz, float scale)
float d = max(dot(Px, Px), max(dot(Py, Py), dot(Pz, Pz)));
return max(0.0, 0.5 * log2(d));
float d = Max3(dot(duvw_dx, duvw_dx), dot(duvw_dy, duvw_dy), dot(duvw_dz, duvw_dz));
return 0.5 * log2(d * (scale * scale));
}

// Misc utilities
// ----------------------------------------------------------------------------
// Simple function to test a bitfield
bool HasFlag(uint bitfield, uint flag)
{
return (bitfield & flag) != 0;
}
}
// Division which returns 1 for (inf/inf) and (0/0).
// If any of the input parameters are NaNs, the result is a NaN.
real SafeDiv(real numer, real denom)
{
return (numer != denom) ? numer / denom : 1;
}
// Generates a triangle in homogeneous clip space, s.t.

33
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/CommonLighting.hlsl


// Non physically based hack to limit light influence to attenuationRadius.
// SmoothInfluenceAttenuation must be use, InfluenceAttenuation is just for optimization with SmoothQuadraticDistanceAttenuation
real InfluenceAttenuation(real distSquare, real invSqrAttenuationRadius)
real InfluenceAttenuation(real distSquare, real rangeAttenuationScale, real rangeAttenuationBias)
real factor = distSquare * invSqrAttenuationRadius;
return saturate(1.0 - factor * factor);
// Apply the saturate here as we can have negative number
real factor = saturate(distSquare * rangeAttenuationScale + rangeAttenuationBias);
return 1.0 - factor * factor;
real SmoothInfluenceAttenuation(real distSquare, real invSqrAttenuationRadius)
real SmoothInfluenceAttenuation(real distSquare, real rangeAttenuationScale, real rangeAttenuationBias)
real smoothFactor = InfluenceAttenuation(distSquare, invSqrAttenuationRadius);
real smoothFactor = InfluenceAttenuation(distSquare, rangeAttenuationScale, rangeAttenuationBias);
return Sq(smoothFactor);
}

real SmoothQuadraticDistanceAttenuation(real distSquare, real distRcp, real invSqrAttenuationRadius)
real SmoothQuadraticDistanceAttenuation(real distSquare, real distRcp, real rangeAttenuationScale, real rangeAttenuationBias)
attenuation *= InfluenceAttenuation(distSquare, invSqrAttenuationRadius);
attenuation *= InfluenceAttenuation(distSquare, rangeAttenuationScale, rangeAttenuationBias);
real SmoothQuadraticDistanceAttenuation(real3 unL, real invSqrAttenuationRadius)
real SmoothQuadraticDistanceAttenuation(real3 unL, real rangeAttenuationScale, real rangeAttenuationBias)
return SmoothQuadraticDistanceAttenuation(distSquare, distRcp, invSqrAttenuationRadius);
return SmoothQuadraticDistanceAttenuation(distSquare, distRcp, rangeAttenuationScale, rangeAttenuationBias);
}
real AngleAttenuation(real cosFwd, real lightAngleScale, real lightAngleOffset)

// Combines SmoothQuadraticDistanceAttenuation() and SmoothAngleAttenuation() in an efficient manner.
// distances = {d, d^2, 1/d, d_proj}, where d_proj = dot(lightToSample, lightData.forward).
real SmoothPunctualLightAttenuation(real4 distances, real invSqrAttenuationRadius,
real SmoothPunctualLightAttenuation(real4 distances, real rangeAttenuationScale, real rangeAttenuationBias,
real lightAngleScale, real lightAngleOffset)
{
real distSq = distances.y;

real attenuation = min(distRcp, 1.0 / PUNCTUAL_LIGHT_THRESHOLD);
attenuation *= InfluenceAttenuation(distSq, invSqrAttenuationRadius);
attenuation *= AngleAttenuation(cosFwd, lightAngleScale, lightAngleOffset);
attenuation *= InfluenceAttenuation(distSq, rangeAttenuationScale, rangeAttenuationBias);
attenuation *= AngleAttenuation(cosFwd, lightAngleScale, lightAngleOffset);
return Sq(attenuation);
}

// The transformation is performed along the major axis of the ellipsoid (corresponding to 'r1').
// Both the ellipsoid (e.i. 'axis') and 'unL' should be in the same coordinate system.
// 'unL' should be computed from the center of the ellipsoid.
real EllipsoidalDistanceAttenuation(real3 unL, real invSqRadius,
real EllipsoidalDistanceAttenuation(real3 unL, real rangeAttenuationScale, real rangeAttenuationBias,
real3 axis, real invAspectRatio)
{
// Project the unnormalized light vector onto the axis.

unL -= diff * axis;
real sqDist = dot(unL, unL);
return SmoothInfluenceAttenuation(sqDist, invSqRadius);
return SmoothInfluenceAttenuation(sqDist, rangeAttenuationScale, rangeAttenuationBias);
}
// Applies SmoothInfluenceAttenuation() using the axis-aligned ellipsoid of the given dimensions.

unL *= invHalfDim;
real sqDist = dot(unL, unL);
return SmoothInfluenceAttenuation(sqDist, 1.0);
return SmoothInfluenceAttenuation(sqDist, 1.0, 0.0);
}
// Applies SmoothInfluenceAttenuation() after mapping the axis-aligned box to a sphere.

if (Max3(abs(unL.x), abs(unL.y), abs(unL.z)) > 1.0) return 0.0;
real sqDist = ComputeCubeToSphereMapSqMagnitude(unL);
return SmoothInfluenceAttenuation(sqDist, 1.0);
return SmoothInfluenceAttenuation(sqDist, 1.0, 0.0);
}
//-----------------------------------------------------------------------------

2
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/CommonMaterial.hlsl


//
// avgNormalLength gives the dispersion information for the covered normals.
//
// Note that hw filtering on the normal map should be trilinear to be conservative, while anisotropic
// Note that hw filtering on the normal map should be trilinear to be conservative, while anisotropic
// risk underfiltering. Could also compute average normal on the fly with a proper normal map format,
// like Toksvig.
float TextureNormalVariance(float avgNormalLength)

17
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl


return normalize(lerp(N, grainNormal, anisotropy));
}
// For GGX aniso and IBL we have done an empirical (eye balled) approximation compare to the reference.
// We use a single fetch, and we stretch the normal to use based on various criteria.
// result are far away from the reference but better than nothing
// Anisotropic ratio (0->no isotropic; 1->full anisotropy in tangent direction) - positive use bitangentWS - negative use tangentWS
// Note: returned iblPerceptualRoughness shouldn't be use for sampling FGD texture in a pre-integration
void GetGGXAnisotropicModifiedNormalAndRoughness(real3 bitangentWS, real3 tangentWS, real3 N, real3 V, real anisotropy, real perceptualRoughness, out real3 iblN, out real iblPerceptualRoughness)
{
// For positive anisotropy values: tangent = highlight stretch (anisotropy) direction, bitangent = grain (brush) direction.
float3 grainDirWS = (anisotropy >= 0.0) ? bitangentWS : tangentWS;
// Reduce stretching for (perceptualRoughness < 0.2).
float stretch = abs(anisotropy) * saturate(5.0 * perceptualRoughness);
// NOTE: If we follow the theory we should use the modified normal for the different calculation implying a normal (like NdotV)
// However modified normal is just a hack. The goal is just to stretch a cubemap, no accuracy here. Let's save performance instead.
iblN = GetAnisotropicModifiedNormal(grainDirWS, N, V, stretch);
iblPerceptualRoughness = perceptualRoughness * saturate(1.2 - abs(anisotropy));
}
// Ref: "Moving Frostbite to PBR", p. 69.
real3 GetSpecularDominantDir(real3 N, real3 R, real perceptualRoughness, real NdotV)
{

8
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Macros.hlsl


#define TRANSFORM_TEX(tex, name) ((tex.xy) * name##_ST.xy + name##_ST.zw)
#define GET_TEXELSIZE_NAME(name) (name##_TexelSize)
#if UNITY_REVERSED_Z
# define COMPARE_DEVICE_DEPTH_CLOSER(shadowMapDepth, zDevice) (shadowMapDepth > zDevice)
# define COMPARE_DEVICE_DEPTH_CLOSEREQUAL(shadowMapDepth, zDevice) (shadowMapDepth >= zDevice)
#else
# define COMPARE_DEVICE_DEPTH_CLOSER(shadowMapDepth, zDevice) (shadowMapDepth < zDevice)
# define COMPARE_DEVICE_DEPTH_CLOSEREQUAL(shadowMapDepth, zDevice) (shadowMapDepth <= zDevice)
#endif
#endif // UNITY_MACROS_INCLUDED

5
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Sampling/Sampling.hlsl


//-----------------------------------------------------------------------------
// Sampling function
// Reference : http://www.cs.virginia.edu/~jdl/bib/globillum/mis/shirley96.pdf + PBRT
// Caution: Our light point backward (-Z), these sampling function follow this convention
//-----------------------------------------------------------------------------
// Performs uniform sampling of the unit disk.

{
// Random point at rectangle surface
P = real3((u.x - 0.5) * width, (u.y - 0.5) * height, 0);
Ns = real3(0, 0, -1); // Light point backward (-Z)
Ns = real3(0, 0, -1); // Light down (-Z)
// Transform to world space
P = mul(real4(P, 1.0), localToWorld).xyz;

{
// Random point at disk surface
P = real3(radius * SampleDiskUniform(u.x, u.y), 0);
Ns = real3(0.0, 0.0, -1.0); // Light point backward (-Z)
Ns = real3(0.0, 0.0, -1.0); // Light down (-Z)
// Transform to world space
P = mul(real4(P, 1.0), localToWorld).xyz;

52
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/ShadowSampling.hlsl


return (z[1] < 0.0 || z[2] > 1.0) ? ShadowMoments_SolveDelta4MSM( z, b, lightLeakBias ) : ShadowMoments_SolveDelta3MSM( z, b.xy, lightLeakBias );
}
#include "PCSS.hlsl"
real SampleShadow_PCSS( ShadowContext shadowContext, inout uint payloadOffset, real3 tcs, real4 scaleOffset, real2 sampleBias, float slice, uint texIdx, uint sampIdx )
{
real2 params = asfloat(shadowContext.payloads[payloadOffset].xy);
real shadowSoftnesss = params.x;
int sampleCount = params.y;
payloadOffset++;
real2 sampleJitter = real2(sin(GenerateHashedRandomFloat(tcs.x)),
cos(GenerateHashedRandomFloat(tcs.y)));
//1) Blocker Search
real averageBlockerDepth = 0.0;
real numBlockers = 0.0;
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.000001, tcs, sampleJitter, sampleBias, shadowContext, slice, texIdx, sampIdx, sampleCount))
return 1.0;
//2) Penumbra Estimation
real filterSize = shadowSoftnesss * PenumbraSize(tcs.z, averageBlockerDepth);
filterSize = max(filterSize, 0.000001);
//3) Filter
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, sampleJitter, shadowContext, texIdx, sampIdx, sampleCount);
}
real SampleShadow_PCSS( ShadowContext shadowContext, inout uint payloadOffset, real3 tcs, real4 scaleOffset, real2 sampleBias, float slice, Texture2DArray tex, SamplerComparisonState compSamp, SamplerState samp )
{
real2 params = asfloat(shadowContext.payloads[payloadOffset].xy);
real shadowSoftnesss = params.x;
int sampleCount = params.y;
payloadOffset++;
real2 sampleJitter = real2(sin(GenerateHashedRandomFloat(tcs.x)),
cos(GenerateHashedRandomFloat(tcs.y)));
//1) Blocker Search
real averageBlockerDepth = 0.0;
real numBlockers = 0.0;
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.000001, tcs, slice, sampleJitter, sampleBias, tex, samp, sampleCount))
return 1.0;
//2) Penumbra Estimation
real filterSize = shadowSoftnesss * PenumbraSize(tcs.z, averageBlockerDepth);
filterSize = max(filterSize, 0.000001);
//3) Filter
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, sampleJitter, tex, compSamp, sampleCount);
}
//-----------------------------------------------------------------------------------------------------
// helper function to dispatch a specific shadow algorithm
real SampleShadow_SelectAlgorithm( ShadowContext shadowContext, ShadowData shadowData, inout uint payloadOffset, real3 posTC, real2 sampleBias, uint algorithm, uint texIdx, uint sampIdx )

case GPUSHADOWALGORITHM_PCF_TENT_3X3 : return SampleShadow_PCF_Tent_3x3( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, texIdx, sampIdx );
case GPUSHADOWALGORITHM_PCF_TENT_5X5 : return SampleShadow_PCF_Tent_5x5( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, texIdx, sampIdx );
case GPUSHADOWALGORITHM_PCF_TENT_7X7 : return SampleShadow_PCF_Tent_7x7( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, texIdx, sampIdx );
case GPUSHADOWALGORITHM_PCSS : return SampleShadow_PCSS( shadowContext, payloadOffset, posTC, shadowData.scaleOffset, sampleBias, shadowData.slice, texIdx, sampIdx );
case GPUSHADOWALGORITHM_VSM : return SampleShadow_VSM_1tap( shadowContext, payloadOffset, posTC, shadowData.slice, texIdx, sampIdx );
case GPUSHADOWALGORITHM_EVSM_2 : return SampleShadow_EVSM_1tap( shadowContext, payloadOffset, posTC, shadowData.slice, texIdx, sampIdx, false );
case GPUSHADOWALGORITHM_EVSM_4 : return SampleShadow_EVSM_1tap( shadowContext, payloadOffset, posTC, shadowData.slice, texIdx, sampIdx, true );

case GPUSHADOWALGORITHM_PCF_TENT_3X3 : return SampleShadow_PCF_Tent_3x3( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, tex, compSamp );
case GPUSHADOWALGORITHM_PCF_TENT_5X5 : return SampleShadow_PCF_Tent_5x5( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, tex, compSamp );
case GPUSHADOWALGORITHM_PCF_TENT_7X7 : return SampleShadow_PCF_Tent_7x7( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, tex, compSamp );
case GPUSHADOWALGORITHM_PCSS : return SampleShadow_PCSS( shadowContext, payloadOffset, posTC, shadowData.scaleOffset, sampleBias, shadowData.slice, tex, compSamp, s_point_clamp_sampler );
default: return 1.0;
}

13
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/UnityInstancing.hlsl


#endif
UNITY_INSTANCING_BUFFER_END(unity_Builtins2)
#define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)
#ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING
#define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray))
#else
#define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)
#endif
#define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)
#ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING
#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray))
#else
#define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)
#endif
#else // UNITY_INSTANCING_ENABLED

100
com.unity.render-pipelines.core/CoreRP/Shadow/Shadow.cs


readonly ValRange m_DefPCF_DepthBias = new ValRange("Depth Bias", 0.0f, 0.0f, 1.0f, 000.1f);
readonly ValRange m_DefPCF_FilterSize = new ValRange("Filter Size", 1.0f, 1.0f, 10.0f, 1.0f);
readonly ValRange m_DefPCSS_ShadowSoftness = new ValRange("Shadow Softness", 0.0f, 0.5f, 1.0f, 0.01f);
readonly ValRange m_DefPCSS_SampleCount = new ValRange("Sample Count", 1, 32, 64, 1);
public ShadowAtlas(ref AtlasInit init) : base(ref init.baseInit)
{

override protected void Register(GPUShadowType type, ShadowRegistry registry)
{
ShadowPrecision precision = m_ShadowmapBits == 32 ? ShadowPrecision.High : ShadowPrecision.Low;
m_SupportedAlgorithms.Reserve(5);
m_SupportedAlgorithms.Reserve(6);
m_SupportedAlgorithms.AddUniqueUnchecked((int)ShadowUtils.Pack(ShadowAlgorithm.PCSS, ShadowVariant.V0, precision));
ShadowRegistry.VariantDelegate del = (Light l, ShadowAlgorithm dataAlgorithm, ShadowVariant dataVariant, ShadowPrecision dataPrecision, ref int[] dataBlock) =>
{

if (dataVariant == ShadowVariant.V1)
m_DefPCF_FilterSize.Slider(ref dataBlock[1]);
};
ShadowRegistry.VariantDelegate pcssDel = (Light l, ShadowAlgorithm dataAlgorithm, ShadowVariant dataVariant, ShadowPrecision dataPrecision, ref int[] dataBlock) =>
{
CheckDataIntegrity(dataAlgorithm, dataVariant, dataPrecision, ref dataBlock);
m_DefPCSS_ShadowSoftness.Slider(ref dataBlock[0]);
m_DefPCSS_SampleCount.Slider(ref dataBlock[1]);
dataBlock[1] = ShadowUtils.Asint(Mathf.RoundToInt(ShadowUtils.Asfloat(dataBlock[1])));
};
registry.Register(type, precision, ShadowAlgorithm.PCSS, "Percentage Closer Soft Shadows (PCSS)",
new ShadowVariant[] { ShadowVariant.V0 },
new string[] { "poisson 64" },
new ShadowRegistry.VariantDelegate[] { pcssDel });
if (algorithm != ShadowAlgorithm.PCF ||
if ((algorithm != ShadowAlgorithm.PCF && algorithm != ShadowAlgorithm.PCSS) ||
(variant != ShadowVariant.V0 &&
variant != ShadowVariant.V1 &&
variant != ShadowVariant.V2 &&

const int k_BlockSize = 2;
if (dataBlock == null || dataBlock.Length != k_BlockSize)
switch (algorithm)
// set defaults
dataBlock = new int[k_BlockSize];
dataBlock[0] = m_DefPCF_DepthBias.Default();
dataBlock[1] = m_DefPCF_FilterSize.Default();
return false;
case ShadowAlgorithm.PCF:
const int k_PcfBlockSize = 2;
if (dataBlock == null || dataBlock.Length != k_PcfBlockSize)
{
// set defaults
dataBlock = new int[k_PcfBlockSize];
dataBlock[0] = m_DefPCF_DepthBias.Default();
dataBlock[1] = m_DefPCF_FilterSize.Default();
return false;
}
break;
case ShadowAlgorithm.PCSS:
const int k_PcssBlockSize = 2;
if (dataBlock == null || dataBlock.Length != k_PcssBlockSize)
{
// set defaults
dataBlock = new int[k_PcssBlockSize];
dataBlock[0] = m_DefPCSS_ShadowSoftness.Default();
dataBlock[1] = m_DefPCSS_SampleCount.Default();
return false;
}
break;
}
return true;
}

virtual protected uint ReservePayload(ShadowRequest sr)
{
uint payloadSize = sr.shadowType == GPUShadowType.Directional ? (1 + k_MaxCascadesInShader + ((uint)m_TmpBorders.Length / 4)) : 0;
payloadSize += ShadowUtils.ExtractAlgorithm(sr.shadowAlgorithm) == ShadowAlgorithm.PCF ? 1u : 0;
switch (ShadowUtils.ExtractAlgorithm(sr.shadowAlgorithm))
{
case ShadowAlgorithm.PCF:
payloadSize += 1;
break;
case ShadowAlgorithm.PCSS:
payloadSize += 1;
break;
default:
break;
}
return payloadSize;
}

}
ShadowAlgorithm algo; ShadowVariant vari; ShadowPrecision prec;
ShadowUtils.Unpack(sr.shadowAlgorithm, out algo, out vari, out prec);
if (algo == ShadowAlgorithm.PCF)
if (algo == ShadowAlgorithm.PCF || algo == ShadowAlgorithm.PCSS)
{
AdditionalShadowData asd = lights[sr.index].light.GetComponent<AdditionalShadowData>();
if (!asd)

Debug.Log("Fixed up shadow data for algorithm " + algo + ", variant " + vari);
}
switch (vari)
if (algo == ShadowAlgorithm.PCF)
case ShadowVariant.V0:
case ShadowVariant.V1:
case ShadowVariant.V2:
case ShadowVariant.V3:
case ShadowVariant.V4:
switch (vari)
sp.Set(shadowData[0] | (SystemInfo.usesReversedZBuffer ? 1 : 0), shadowData[1], 0, 0);
payload[payloadOffset] = sp;
payloadOffset++;
case ShadowVariant.V0:
case ShadowVariant.V1:
case ShadowVariant.V2:
case ShadowVariant.V3:
case ShadowVariant.V4:
{
sp.Set(shadowData[0] | (SystemInfo.usesReversedZBuffer ? 1 : 0), shadowData[1], 0, 0);
payload[payloadOffset] = sp;
payloadOffset++;
}
break;
break;
}
else if (algo == ShadowAlgorithm.PCSS)
{
sp.Set(shadowData[0], shadowData[1], 0, 0);
payload[payloadOffset] = sp;
payloadOffset++;
}
}
}

9
com.unity.render-pipelines.core/CoreRP/Shadow/ShadowBase.cs


public class ShadowInitParameters
{
public const int kDefaultShadowAtlasSize = 4096;
public const int kDefaultMaxPointLightShadows = 6;
public const int kDefaultMaxSpotLightShadows = 12;
public const int kDefaultMaxDirectionalLightShadows = 1;
public int maxPointLightShadows = kDefaultMaxPointLightShadows;
public int maxSpotLightShadows = kDefaultMaxSpotLightShadows;
public int maxDirectionalLightShadows = kDefaultMaxDirectionalLightShadows;
}
// Class used to pass parameters to the shadow system on a per frame basis.

VSM,
EVSM,
MSM,
PCSS,
Custom = 32
};

EVSM_4 = ShadowAlgorithm.EVSM << 3 | ShadowVariant.V1,
MSM_Ham = ShadowAlgorithm.MSM << 3 | ShadowVariant.V0,
MSM_Haus = ShadowAlgorithm.MSM << 3 | ShadowVariant.V1,
PCSS = ShadowAlgorithm.PCSS << 3 | ShadowVariant.V0,
Custom = ShadowAlgorithm.Custom << 3
}

1
com.unity.render-pipelines.core/CoreRP/Shadow/ShadowBase.cs.hlsl


#define GPUSHADOWALGORITHM_EVSM_4 (17)
#define GPUSHADOWALGORITHM_MSM_HAM (24)
#define GPUSHADOWALGORITHM_MSM_HAUS (25)
#define GPUSHADOWALGORITHM_PCSS (32)
#define GPUSHADOWALGORITHM_CUSTOM (256)
// Generated from UnityEngine.Experimental.Rendering.ShadowData

15
com.unity.render-pipelines.core/CoreRP/Utilities/CoreUtils.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
namespace UnityEngine.Experimental.Rendering
{

// we pass the first color target as the depth target. If it has 0 depth bits,
// no depth target ends up being bound.
DrawFullScreen(commandBuffer, material, colorBuffers, colorBuffers[0], properties, shaderPassId);
}
// Post-processing misc
public static bool IsPostProcessingActive(PostProcessLayer layer)
{
return layer != null
&& layer.enabled;
}
public static bool IsTemporalAntialiasingActive(PostProcessLayer layer)
{
return IsPostProcessingActive(layer)
&& layer.antialiasingMode == PostProcessLayer.Antialiasing.TemporalAntialiasing
&& layer.temporalAntialiasing.IsSupported();
}
// Color space utilities

3
com.unity.render-pipelines.core/CoreRP/com.unity.render-pipelines.core.Runtime.asmdef


{
"name": "com.unity.render-pipelines.core.Runtime",
"references": [
"com.unity.postprocessing.Runtime"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],

5
com.unity.render-pipelines.core/package.json


"description": "Core library for Unity render pipelines.",
"version": "3.0.0-preview",
"unity": "2018.2",
"displayName": "Render Pipeline Core Library",
"dependencies": {
"com.unity.postprocessing": "2.0.7-preview"
}
"displayName": "Render Pipeline Core Library"
}

18
com.unity.render-pipelines.high-definition/CHANGELOG.md


### Fixed
- Fixed a shader preprocessor issue when compiling DebugViewMaterialGBuffer.shader against Metal target
- Added a temporary workaround to Lit.hlsl to avoid broken lighting code with Metal/AMD
- Fixed compilation errors on Nintendo Switch (limited XRSetting support).
- Fixed apply range attenuation option on punctual light
- Fixed issue when using more than one volume mask texture with density volumes.
- Fixed an error which prevented volumetric lighting from working if no density volumes with 3D textures were present.
- Add PCSS shadow filter support (from SRP Core)
- Exposed shadow budget parameters in HDRP asset
- Add an option to generate an emissive mesh for area lights (currently rectangle light only). The mesh fits the size, intensity and color of the light.
- Add an option to the HDRP asset to increase the resolution of volumetric lighting.
- SSS and Transmission code have been refactored to be able to share it between various material. Guidelines are in SubsurfaceScattering.hlsl
- Change code in area light with LTC for Lit shader. Magnitude is now take from FGD texture instead of a separate texture
- Improve camera relative rendering: We now apply camera translation on the model matrix, so before the TransformObjectToWorld(). Note: unity_WorldToObject and unity_ObjectToWorld must never be used directly.
- Rename positionWS to positionRWS (Camera relative world position) at a lot of places (mainly in interpolator and FragInputs). In case of custom shader user will be required to update their code.
- Rename positionWS, capturePositionWS, proxyPositionWS, influencePositionWS to positionRWS, capturePositionRWS, proxyPositionRWS, influencePositionRWS (Camera relative world position) in LightDefinition struct.
- Improve the quality of trilinear filtering of density volume textures.
### Fixed
- Fix contact shadows applied on transmission
- Fix issue with forward opaque lit shader variant being removed by the shader preprocessor
## [2.0.4-preview]

2
com.unity.render-pipelines.high-definition/HDRP/Camera/HDCamera.cs


// If TAA is enabled projMatrix will hold a jittered projection matrix. The original,
// non-jittered projection matrix can be accessed via nonJitteredProjMatrix.
bool taaEnabled = camera.cameraType == CameraType.Game &&
CoreUtils.IsTemporalAntialiasingActive(postProcessLayer) &&
HDUtils.IsTemporalAntialiasingActive(postProcessLayer) &&
m_frameSettings.enablePostprocess;
var nonJitteredCameraProj = camera.projectionMatrix;

8
com.unity.render-pipelines.high-definition/HDRP/Editor/BuildProcessors/HDRPreprocessShaders.cs


int inputShaderVariantCount = inputData.Count;
ShaderCompilerData workaround = inputData[0];
for (int i = 0; i < inputData.Count; ++i)
{
ShaderCompilerData input = inputData[i];

i--;
}
}
// Currently if a certain snippet is completely stripped (for example if you remove a whole pass) other passes might get broken
// To work around that, we make sure that we always have at least one variant.
// TODO: Remove this one it is fixed
if (inputData.Count == 0)
inputData.Add(workaround);
}
}
}

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent shapeWidthBox = new GUIContent("Size X", "");
public readonly GUIContent shapeHeightBox = new GUIContent("Size Y", "");
public readonly GUIContent applyRangeAttenuation = new GUIContent("Apply Range Attenuation", "Allows disabling range attenuation. This is useful indoor (like a room) to avoid having to setup a large range for a light to get correct inverse square attenuation that may leak out of the indoor");
public readonly GUIContent displayAreaLightEmissiveMesh = new GUIContent("Display Emissive Mesh", "Generate an emissive mesh using the size, color and intensity of the area light");
public readonly GUIContent shape = new GUIContent("Type", "Specifies the current type of light. Possible types are Directional, Spot, Point, Rectangle and Line lights.");
public readonly GUIContent[] shapeNames;

131
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Experimental.Rendering;

public SerializedProperty maxSmoothness;
public SerializedProperty applyRangeAttenuation;
public SerializedProperty volumetricDimmer;
public SerializedProperty displayAreaLightEmissiveMesh;
// Editor stuff
public SerializedProperty useOldInspector;

// Used for UI only; the processing code must use LightTypeExtent and LightType
LightShape m_LightShape;
HDAdditionalLightData[] m_AdditionalLightDatas;
AdditionalShadowData[] m_AdditionalShadowDatas;
// Used to detect if the scale have been changed via the transform component
Vector3 m_OldAreaLightSize;
bool m_UpdateAreaLightEmissiveMesh;
protected override void OnEnable()
{

var lightData = CoreEditorUtils.GetAdditionalData<HDAdditionalLightData>(targets, HDAdditionalLightData.InitDefaultHDAdditionalLightData);
var shadowData = CoreEditorUtils.GetAdditionalData<AdditionalShadowData>(targets, HDAdditionalShadowData.InitDefaultHDAdditionalShadowData);
m_SerializedAdditionalLightData = new SerializedObject(lightData);
m_SerializedAdditionalShadowData = new SerializedObject(shadowData);
m_AdditionalLightDatas = CoreEditorUtils.GetAdditionalData<HDAdditionalLightData>(targets, HDAdditionalLightData.InitDefaultHDAdditionalLightData);
m_AdditionalShadowDatas = CoreEditorUtils.GetAdditionalData<AdditionalShadowData>(targets, HDAdditionalShadowData.InitDefaultHDAdditionalShadowData);
m_SerializedAdditionalLightData = new SerializedObject(m_AdditionalLightDatas);
m_SerializedAdditionalShadowData = new SerializedObject(m_AdditionalShadowDatas);
using (var o = new PropertyFetcher<HDAdditionalLightData>(m_SerializedAdditionalLightData))
m_AdditionalLightData = new SerializedLightData

spotInnerPercent = o.Find(x => x.m_InnerSpotPercent),
lightDimmer = o.Find(x => x.lightDimmer),
volumetricDimmer = o.Find(x => x.volumetricDimmer),
displayAreaLightEmissiveMesh = o.Find(x => x.displayAreaLightEmissiveMesh),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),

CoreEditorUtils.DrawSplitter();
EditorGUILayout.Space();
UpdateAreaLightEmissiveMeshSize();
if (m_UpdateAreaLightEmissiveMesh)
UpdateAreaLightEmissiveMesh();
}
void DrawFoldout(SerializedProperty foldoutProperty, string title, Action func)

if (EditorGUI.EndChangeCheck())
{
UpdateLightIntensity();
m_UpdateAreaLightEmissiveMesh = true;
bool IsAreaLightShape(LightShape shape)
{
return shape == LightShape.Rectangle || shape == LightShape.Line;
}
void UpdateAreaLightEmissiveMesh()
{
foreach (var lightData in m_AdditionalLightDatas)
{
GameObject lightGameObject = lightData.gameObject;
MeshRenderer emissiveMeshRenderer = lightData.GetComponent<MeshRenderer>();
MeshFilter emissiveMeshFilter = lightData.GetComponent<MeshFilter>();
Light light = lightGameObject.GetComponent<Light>();
bool displayAreaLightEmissiveMesh = IsAreaLightShape(m_LightShape) && m_LightShape != LightShape.Line && m_AdditionalLightData.displayAreaLightEmissiveMesh.boolValue;
// Ensure that the emissive mesh components are here
if (displayAreaLightEmissiveMesh)
{
if (emissiveMeshRenderer == null)
emissiveMeshRenderer = lightGameObject.AddComponent<MeshRenderer>();
if (emissiveMeshFilter == null)
emissiveMeshFilter = lightGameObject.AddComponent<MeshFilter>();
}
else // Or remove them if the option is disabled
{
if (emissiveMeshRenderer != null)
DestroyImmediate(emissiveMeshRenderer);
if (emissiveMeshFilter != null)
DestroyImmediate(emissiveMeshFilter);
// Skip to the next light
continue;
}
float areaLightIntensity = 0.0f;
// Update Mesh emissive value
switch (m_LightShape)
{
case LightShape.Rectangle:
emissiveMeshFilter.mesh = HDEditorUtils.LoadAsset< Mesh >("RenderPipelineResources/Quad.FBX");
lightGameObject.transform.localScale = new Vector3(lightData.shapeWidth, lightData.shapeHeight, 0);
// Do the same conversion as for light intensity
areaLightIntensity = LightUtils.ConvertRectLightIntensity(
m_AdditionalLightData.areaIntensity.floatValue,
lightData.shapeWidth,
lightData.shapeHeight);
break;
default:
break;
}
if (emissiveMeshRenderer.sharedMaterial == null)
emissiveMeshRenderer.material = new Material(Shader.Find("HDRenderPipeline/Unlit"));
emissiveMeshRenderer.sharedMaterial.SetColor("_UnlitColor", Color.black);
// Note that we must use the light in linear RGB
emissiveMeshRenderer.sharedMaterial.SetColor("_EmissiveColor", light.color.linear * areaLightIntensity);
}
}
// This function updates the area light size when the local scale of the gameobject changes
void UpdateAreaLightEmissiveMeshSize()
{
// Early exit if the light type is not an area
if (!IsAreaLightShape(m_LightShape) || target == null || targets.Length > 1)
return ;
Vector3 lightSize = ((Light)target).transform.localScale;
lightSize = Vector3.Max(Vector3.one * k_MinAreaWidth, lightSize);
if (lightSize == m_OldAreaLightSize)
return ;
switch (m_LightShape)
{
case LightShape.Rectangle:
m_AdditionalLightData.shapeWidth.floatValue = lightSize.x;
m_AdditionalLightData.shapeHeight.floatValue = lightSize.y;
break;
default:
break;
}
UpdateLightIntensity();
m_UpdateAreaLightEmissiveMesh = true;
m_OldAreaLightSize = lightSize;
}
// Caution: this function must match the one in HDAdditionalLightData.ConvertPhysicalLightIntensityToLightIntensity - any change need to be replicated
void UpdateLightIntensity()
{

void DrawLightSettings()
{
EditorGUI.BeginChangeCheck();
if (EditorGUI.EndChangeCheck())
m_UpdateAreaLightEmissiveMesh = true;
EditorGUI.BeginChangeCheck();

if (EditorGUI.EndChangeCheck())
{
UpdateLightIntensity();
m_UpdateAreaLightEmissiveMesh = true;
}
settings.DrawBounceIntensity();

EditorGUI.BeginChangeCheck(); // For GI we need to detect any change on additional data and call SetLightDirty
// No cookie with area light (maybe in future textured area light ?)
if (m_LightShape != LightShape.Rectangle && m_LightShape != LightShape.Line)
if (!IsAreaLightShape(m_LightShape))
{
settings.DrawCookie();

EditorGUILayout.PropertyField(m_AdditionalLightData.volumetricDimmer, s_Styles.volumetricDimmer);
if (m_LightShape != LightShape.Directional)
EditorGUILayout.PropertyField(m_AdditionalLightData.applyRangeAttenuation, s_Styles.applyRangeAttenuation);
// Emissive mesh for area light only
if (IsAreaLightShape(m_LightShape))
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_AdditionalLightData.displayAreaLightEmissiveMesh, s_Styles.displayAreaLightEmissiveMesh);
if (EditorGUI.EndChangeCheck())
m_UpdateAreaLightEmissiveMesh = true;
}
EditorGUI.indentLevel--;
}

24
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs


[CustomEditor(typeof(DensityVolume))]
class DensityVolumeEditor : Editor
{
private static GUIContent albedoLabel = new GUIContent("Scattering Color");
private static GUIContent meanFreePathLabel = new GUIContent("Mean Free Path");
private static GUIContent volumeTextureLabel = new GUIContent("Volume Texture Mask");
private static GUIContent textureScrollLabel = new GUIContent("Texture Scroll Speed");
private static GUIContent textureTileLabel = new GUIContent("Texture Tiling Amount");
private static GUIContent textureSettingsTitle = new GUIContent("Volume Texture Settings");
static GUIContent s_AlbedoLabel = new GUIContent("Single Scattering Albedo", "Hue and saturation control the color of the fog (the wavelength of in-scattered light). Value controls scattering (0 = max absorption & no scattering, 1 = no absorption & max scattering).");
static GUIContent s_MeanFreePathLabel = new GUIContent("Mean Free Path", "Controls the density, which determines how far you can seen through the fog. It's the distance in meters at which 50% of background light is lost in the fog (due to absorption and out-scattering).");
static GUIContent s_VolumeTextureLabel = new GUIContent("Density Mask Texture");
static GUIContent s_TextureScrollLabel = new GUIContent("Texture Scroll Speed");
static GUIContent s_TextureTileLabel = new GUIContent("Texture Tiling Amount");
static GUIContent s_TextureSettingsTitle = new GUIContent("Volume Texture Settings");
private bool showTextureParams = false;

public override void OnInspectorGUI()
{
albedo.colorValue = EditorGUILayout.ColorField(albedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, meanFreePathLabel);
albedo.colorValue = EditorGUILayout.ColorField(s_AlbedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, s_MeanFreePathLabel);
showTextureParams = EditorGUILayout.Foldout(showTextureParams, textureSettingsTitle, true);
showTextureParams = EditorGUILayout.Foldout(showTextureParams, s_TextureSettingsTitle, true);
EditorGUILayout.PropertyField(volumeTexture, volumeTextureLabel);
EditorGUILayout.PropertyField(textureScroll, textureScrollLabel);
EditorGUILayout.PropertyField(textureTile, textureTileLabel);
EditorGUILayout.PropertyField(volumeTexture, s_VolumeTextureLabel);
EditorGUILayout.PropertyField(textureScroll, s_TextureScrollLabel);
EditorGUILayout.PropertyField(textureTile, s_TextureTileLabel);
EditorGUI.indentLevel--;
}

21
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ///
/// MIT License ///
/// ///
/// Copyright (c) 2016 Rapha�l Ernaelsten (@RaphErnaelsten) ///
/// ///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), ///
/// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, ///
/// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: ///
/// ///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ///
/// ///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ///
/// IN THE SOFTWARE. ///
/// ///
/// PLEASE CONSIDER CREDITING AURA IN YOUR PROJECTS. IF RELEVANT, USE THE UNMODIFIED LOGO PROVIDED IN THE "LICENSE" FOLDER. ///
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using UnityEngine;
using System.Collections.Generic;

7
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitShaderPreprocessor.cs


return true;
}
if (!hdrpAsset.renderPipelineSettings.supportOnlyForward)
// TODO: add an option to say we are using only the deferred shader variant (for Lit)
//if (0)
if (isForwardPass && !inputData.shaderKeywordSet.IsEnabled(m_DebugDisplay))
return true;
//if (isForwardPass && !inputData.shaderKeywordSet.IsEnabled(m_DebugDisplay))
// return true;
}
}

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitUI.cs


public static GUIContent baseColorText = new GUIContent("Base Color + Opacity", "Albedo (RGB) and Opacity (A)");
public static GUIContent smoothnessMapChannelText = new GUIContent("Smoothness Source", "Smoothness texture and channel");
public static GUIContent metallicText = new GUIContent("Metallic", "Metallic scale factor");
public static GUIContent smoothnessText = new GUIContent("Smoothness", "Smoothness scale factor");
public static GUIContent smoothnessRemappingText = new GUIContent("Smoothness Remapping", "Smoothness remapping");

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs


m_ChannelProperty = new ComboProperty(parent, propertyName + "Channel", "Channel", Enum.GetNames(typeof(Channel)), false);
m_RemapProperty = new Property(parent, constantPropertyName + "Remap", "Remapping", "Defines the range to remap/scale the values in texture", false);
m_InvertRemapProperty = new Property(parent, constantPropertyName + "RemapInverted", "Invert Remapping", "Whether the mapping values are inverted.", false);
m_RemapProperty = new Property(parent, propertyName + "Remap", "Remapping", "Defines the range to remap/scale the values in texture", false);
m_InvertRemapProperty = new Property(parent, propertyName + "RemapInverted", "Invert Remapping", "Whether the mapping values are inverted.", false);
}
public override void OnFindProperty(MaterialProperty[] props)

127
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs


protected const string k_IridescenceThickness = "_IridescenceThickness";
protected const string k_IridescenceThicknessMap = "_IridescenceThicknessMap";
protected const string k_IridescenceThicknessMapUV = "_IridescenceThicknessMapUV";
protected const string k_IridescenceMask = "_IridescenceMask";
protected const string k_IridescenceMaskMap = "_IridescenceMaskMap";
protected const string k_IridescenceMaskMapUV = "_IridescenceMaskMapUV";
// Details
protected const string k_EnableDetails = "_EnableDetails";
protected const string k_DetailMask = "_DetailMask";
protected const string k_DetailMaskMap = "_DetailMaskMap";
protected const string k_DetailMaskMapUV = "_DetailMaskMapUV";
protected const string k_DetailSmoothness = "_DetailSmoothness";
protected const string k_DetailSmoothnessScale = "_DetailSmoothnessScale";
protected const string k_DetailSmoothnessMap = "_DetailSmoothnessMap";
protected const string k_DetailSmoothnessMapUV = "_DetailSmoothnessMapUV";
protected const string k_DetailNormalMap = "_DetailNormalMap";
protected const string k_DetailNormalMapUV = "_DetailNormalMapUV";
protected const string k_DetailNormalScale = "_DetailNormalScale";
// Stencil is use to control lighting mode (regular, split lighting)
protected const string kStencilRef = "_StencilRef";

private readonly GroupProperty _baseMaterialProperties = null;
private readonly GroupProperty _materialProperties = null;
private Property EnableDetails;
private Property EnableDualSpecularLobe;
private Property EnableDualSpecularLobe;
private Property EnableIridescence;
private Property EnableGeometricNormalFiltering;

});
//
EnableDetails = new Property(this, k_EnableDetails, "Enable Details", "Enable Detail", true);
EnableSSS = new Property(this, k_EnableSubsurfaceScattering, "Enable Subsurface Scattering", "Enable Subsurface Scattering", true);
EnableTransmission = new Property(this, k_EnableTransmission, "Enable Transmission", "Enable Transmission", true);
EnableCoat = new Property(this, k_EnableCoat, "Enable Coat", "Enable coat layer with true vertical physically based BSDF mixing", true);

{
new GroupProperty(this, "_MaterialFeatures", "Material Features", new BaseProperty[]
{
EnableDetails,
EnableDualSpecularLobe,
EnableAnisotropy,
EnableCoat,

new TextureProperty(this, k_AmbientOcclusionMap, k_AmbientOcclusion, "AmbientOcclusion", "AmbientOcclusion Map", false, false),
}),
new GroupProperty(this, "_Details", "Details", new BaseProperty[]
{
new TextureProperty(this, k_DetailMaskMap, "", "Detail Mask Map", "Detail Mask Map", false, false),
new TextureProperty(this, k_DetailNormalMap, k_DetailNormalScale, "Detail Normal Map", "Detail Normal Map Scale", true, false, true),
new TextureProperty(this, k_DetailSmoothnessMap, k_DetailSmoothnessScale, "Detail Smoothness", "Detail Smoothness", true, false),
}, _ => EnableDetails.BoolValue == true),
new GroupProperty(this, "_DualSpecularLobe", "Dual Specular Lobe", new BaseProperty[]
{
new TextureProperty(this, k_SmoothnessBMap, k_SmoothnessB, "Smoothness B", "Smoothness B", false, false),

new GroupProperty(this, "_Iridescence", "Iridescence", new BaseProperty[]
{
new Property(this, "_IridescenceIor", "IOR", "Index of refraction of iridescence layer", false),
new Property(this, "_IridescenceThickness", "Thickness", "Iridescence thickness (Remap to 0..3000nm)", false),
//just to test: to use the same EvalIridescence as lit, find a good mapping for the top IOR (over the iridescence dielectric film)
//when having iridescence:
//new Property(this, "_IridescenceIor", "TopIOR", "Index of refraction on top of iridescence layer", false),
new TextureProperty(this, k_IridescenceMaskMap, k_IridescenceMask, "Iridescence Mask", "Iridescence Mask", false),
new TextureProperty(this, k_IridescenceThicknessMap, k_IridescenceThickness, "Iridescence thickness (Remap to 0..3000nm)", "Iridescence thickness (Remap to 0..3000nm)", false),
}, _ => EnableIridescence.BoolValue == true),
new GroupProperty(this, "_SSS", "Sub-Surface Scattering", new BaseProperty[]

// TODO: Caution this can generate a lot of garbage collection call ?
string useMapPropertyName = basePropertyName + "UseMap";
string mapPropertyName = basePropertyName + "Map";
string remapPropertyName = basePropertyName + "Remap";
string invertPropertyName = basePropertyName + "RemapInverted";
string rangePropertyName = basePropertyName + "Range";
string remapPropertyName = basePropertyName + "MapRemap";
string invertPropertyName = basePropertyName + "MapRemapInverted";
string rangePropertyName = basePropertyName + "MapRange";
Vector4 rangeVector = material.GetVector(remapPropertyName);
if (material.HasProperty(invertPropertyName) && material.GetFloat(invertPropertyName) > 0.0f)
if (material.HasProperty(remapPropertyName) && material.HasProperty(rangePropertyName))
float s = rangeVector.x;
rangeVector.x = rangeVector.y;
rangeVector.y = s;
Vector4 rangeVector = material.GetVector(remapPropertyName);
if (material.HasProperty(invertPropertyName) && material.GetFloat(invertPropertyName) > 0.0f)
{
float s = rangeVector.x;
rangeVector.x = rangeVector.y;
rangeVector.y = s;
}
material.SetVector(rangePropertyName, rangeVector);
material.SetFloat(useMapPropertyName, 1.0f);
material.SetVector(rangePropertyName, rangeVector);
if (material.HasProperty(useMapPropertyName))
{
material.SetFloat(useMapPropertyName, 1.0f);
}
int channel = (int)material.GetFloat(channelPropertyName);
switch (channel)
if (material.HasProperty(channelPropertyName))
case 0:
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
break;
case 1:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
break;
case 2:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));
break;
case 3:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
break;
int channel = (int)material.GetFloat(channelPropertyName);
switch (channel)
{
case 0:
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
break;
case 1:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
break;
case 2:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));
break;
case 3:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
break;
}
material.SetFloat(useMapPropertyName, 0.0f);
material.SetVector(rangePropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
if (material.HasProperty(useMapPropertyName))
{
material.SetFloat(useMapPropertyName, 0.0f);
}
if (material.HasProperty(rangePropertyName))
{
material.SetVector(rangePropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
}
if (material.HasProperty(channelPropertyName))
{
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
}
}
}

//TODO see BaseLitUI.cs:SetupBaseLitKeywords (stencil etc)
SetupBaseUnlitKeywords(material);
SetupBaseUnlitMaterialPass(material);

}
}
//TODO: stencil state, displacement, wind, depthoffset, tessellation
SetupMainTexForAlphaTestGI("_BaseColorMap", "_BaseColor", material);
//TODO: disable DBUFFER

SetupTextureMaterialProperty(material, k_Thickness);
SetupTextureMaterialProperty(material, k_Anisotropy);
SetupTextureMaterialProperty(material, k_IridescenceThickness);
SetupTextureMaterialProperty(material, k_IridescenceMask);
// details
SetupTextureMaterialProperty(material, k_DetailMask);
SetupTextureMaterialProperty(material, k_DetailSmoothness);
// Check if we are using specific UVs.
TextureProperty.UVMapping[] uvIndices = new[]
{

(TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_AnisotropyMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_IridescenceThicknessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_IridescenceMaskMapUV),
// Details
(TextureProperty.UVMapping)material.GetFloat(k_DetailMaskMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_DetailSmoothnessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_DetailNormalMapUV),
};
// Set keyword for mapping

requireTriplanar = requireTriplanar || uvIndices[i] == TextureProperty.UVMapping.Triplanar;
}
CoreUtils.SetKeyword(material, "_USE_TRIPLANAR", requireTriplanar);
bool detailsEnabled = material.HasProperty(k_EnableDetails) && material.GetFloat(k_EnableDetails) > 0.0f;
CoreUtils.SetKeyword(material, "_USE_DETAILMAP", detailsEnabled);
bool dualSpecularLobeEnabled = material.HasProperty(k_EnableDualSpecularLobe) && material.GetFloat(k_EnableDualSpecularLobe) > 0.0f;
CoreUtils.SetKeyword(material, "_MATERIAL_FEATURE_DUAL_SPECULAR_LOBE", dualSpecularLobeEnabled);

5
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDEditorUtils.cs


return "Packages/com.unity.render-pipelines.core/CoreRP/";
}
public static T LoadAsset<T>(string relativePath) where T : UnityEngine.Object
{
return AssetDatabase.LoadAssetAtPath<T>(GetHDRenderPipelinePath() + relativePath);
}
public static bool ResetMaterialKeywords(Material material)
{
MaterialResetter resetter;

10
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/RenderPipelineSettingsUI.cs


EditorGUILayout.PropertyField(d.supportSSR, _.GetContent("Support SSR|Enable memory use by SSR effect."));
EditorGUILayout.PropertyField(d.supportSSAO, _.GetContent("Support SSAO|Enable memory use by SSAO effect."));
EditorGUILayout.PropertyField(d.supportDBuffer, _.GetContent("Support Decal Buffer|Enable memory and variant of decal buffer."));
EditorGUILayout.PropertyField(d.supportMSAA, _.GetContent("Support Multi Sampling Anti-Aliasing|This feature doesn't work currently."));
EditorGUILayout.PropertyField(d.MSAASampleCount, _.GetContent("MSAA Sample Count|Allow to select the level of MSAA."));
// TODO: Implement MSAA - Hide for now as it doesn't work
//EditorGUILayout.PropertyField(d.supportMSAA, _.GetContent("Support Multi Sampling Anti-Aliasing|This feature doesn't work currently."));
//EditorGUILayout.PropertyField(d.MSAASampleCount, _.GetContent("MSAA Sample Count|Allow to select the level of MSAA."));
EditorGUILayout.PropertyField(d.enableUltraQualitySSS, _.GetContent("Increase SSS Sample Count|This allow better SSS quality. Warning: Slow feature, don't use for game."));
EditorGUILayout.PropertyField(d.supportVolumetric, _.GetContent("Support volumetric|Enable memory and shader variant for volumetric."));
EditorGUILayout.PropertyField(d.increaseSssSampleCount, _.GetContent("Increase SSS Sample Count|This allows for better SSS quality. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportVolumetrics, _.GetContent("Support volumetrics|Enable memory and shader variant for volumetric."));
EditorGUILayout.PropertyField(d.increaseResolutionOfVolumetrics, _.GetContent("Increase resolution of volumetrics|Increase the resolution of volumetric lighting buffers. Warning: high performance cost, do not enable on consoles."));
EditorGUILayout.PropertyField(d.supportRuntimeDebugDisplay, _.GetContent("Support runtime debug display|Remove all debug display shader variant only in the player. Allow faster build."));
EditorGUILayout.PropertyField(d.supportDitheringCrossFade, _.GetContent("Support dithering cross fade|Remove all dithering cross fade shader variant only in the player. Allow faster build."));

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedFrameSettings.cs


enableSubsurfaceScattering = root.Find((FrameSettings d) => d.enableSubsurfaceScattering);
enableTransmission = root.Find((FrameSettings d) => d.enableTransmission);
enableAtmosphericScattering = root.Find((FrameSettings d) => d.enableAtmosphericScattering);
enableVolumetric = root.Find((FrameSettings d) => d.enableVolumetric);
enableVolumetric = root.Find((FrameSettings d) => d.enableVolumetrics);
diffuseGlobalDimmer = root.Find((FrameSettings d) => d.diffuseGlobalDimmer);
specularGlobalDimmer = root.Find((FrameSettings d) => d.specularGlobalDimmer);
enableForwardRenderingOnly = root.Find((FrameSettings d) => d.enableForwardRenderingOnly);

40
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedRenderPipelineSettings.cs


public SerializedProperty supportOnlyForward;
public SerializedProperty supportMotionVectors;
public SerializedProperty supportStereo;
public SerializedProperty enableUltraQualitySSS;
public SerializedProperty supportVolumetric;
[UnityEngine.Serialization.FormerlySerializedAs("enableUltraQualitySSS")]
public SerializedProperty increaseSssSampleCount;
[UnityEngine.Serialization.FormerlySerializedAs("supportVolumetric")]
public SerializedProperty supportVolumetrics;
public SerializedProperty increaseResolutionOfVolumetrics;
public SerializedProperty supportRuntimeDebugDisplay;
public SerializedProperty supportDitheringCrossFade;

{
this.root = root;
supportShadowMask = root.Find((RenderPipelineSettings s) => s.supportShadowMask);
supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR);
supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO);
supportDBuffer = root.Find((RenderPipelineSettings s) => s.supportDBuffer);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering);
supportOnlyForward = root.Find((RenderPipelineSettings s) => s.supportOnlyForward);
supportMotionVectors = root.Find((RenderPipelineSettings s) => s.supportMotionVectors);
supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
enableUltraQualitySSS = root.Find((RenderPipelineSettings s) => s.enableUltraQualitySSS);
supportVolumetric = root.Find((RenderPipelineSettings s) => s.supportVolumetric);
supportRuntimeDebugDisplay = root.Find((RenderPipelineSettings s) => s.supportRuntimeDebugDisplay);
supportDitheringCrossFade = root.Find((RenderPipelineSettings s) => s.supportDitheringCrossFade);
supportShadowMask = root.Find((RenderPipelineSettings s) => s.supportShadowMask);
supportSSR = root.Find((RenderPipelineSettings s) => s.supportSSR);
supportSSAO = root.Find((RenderPipelineSettings s) => s.supportSSAO);
supportDBuffer = root.Find((RenderPipelineSettings s) => s.supportDBuffer);
supportMSAA = root.Find((RenderPipelineSettings s) => s.supportMSAA);
MSAASampleCount = root.Find((RenderPipelineSettings s) => s.msaaSampleCount);
supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering);
supportOnlyForward = root.Find((RenderPipelineSettings s) => s.supportOnlyForward);
supportMotionVectors = root.Find((RenderPipelineSettings s) => s.supportMotionVectors);
supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
increaseSssSampleCount = root.Find((RenderPipelineSettings s) => s.increaseSssSampleCount);
supportVolumetrics = root.Find((RenderPipelineSettings s) => s.supportVolumetrics);
increaseResolutionOfVolumetrics = root.Find((RenderPipelineSettings s) => s.increaseResolutionOfVolumetrics);
supportRuntimeDebugDisplay = root.Find((RenderPipelineSettings s) => s.supportRuntimeDebugDisplay);
supportDitheringCrossFade = root.Find((RenderPipelineSettings s) => s.supportDitheringCrossFade);
shadowInitParams = new SerializedShadowInitParameters(root.Find((RenderPipelineSettings s) => s.shadowInitParams));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));
shadowInitParams = new SerializedShadowInitParameters(root.Find((RenderPipelineSettings s) => s.shadowInitParams));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));
}
}
}

7
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/SerializedShadowInitParameters.cs


public SerializedProperty shadowAtlasWidth;
public SerializedProperty shadowAtlasHeight;
public SerializedProperty maxPointLightShadows;
public SerializedProperty maxSpotLightShadows;
public SerializedProperty maxDirectionalLightShadows;
public SerializedShadowInitParameters(SerializedProperty root)
{
this.root = root;

maxPointLightShadows = root.Find((ShadowInitParameters s) => s.maxPointLightShadows);
maxSpotLightShadows = root.Find((ShadowInitParameters s) => s.maxSpotLightShadows);
maxDirectionalLightShadows = root.Find((ShadowInitParameters s) => s.maxDirectionalLightShadows);
}
}
}

24
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/Settings/ShadowInitParametersUI.cs


using UnityEditor.AnimatedValues;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering
{

static void Drawer_FieldShadowSize(ShadowInitParametersUI s, SerializedShadowInitParameters d, Editor o)
{
EditorGUILayout.LabelField(_.GetContent("Shadow Atlas Settings"), EditorStyles.boldLabel);
EditorGUILayout.LabelField(_.GetContent("Shadow"), EditorStyles.boldLabel);
++EditorGUI.indentLevel;
EditorGUILayout.LabelField(_.GetContent("Shadow Atlas"), EditorStyles.boldLabel);
--EditorGUI.indentLevel;
EditorGUILayout.Space();
EditorGUILayout.LabelField(_.GetContent("Shadow Map Budget"), EditorStyles.boldLabel);
++EditorGUI.indentLevel;
EditorGUILayout.PropertyField(d.maxPointLightShadows, _.GetContent("Max Point Light Shadows"));
EditorGUILayout.PropertyField(d.maxSpotLightShadows, _.GetContent("Max Spot Light Shadows"));
EditorGUILayout.PropertyField(d.maxDirectionalLightShadows, _.GetContent("Max Directional Light Shadows"));
--EditorGUI.indentLevel;
// Clamp negative values
d.shadowAtlasHeight.intValue = Mathf.Max(0, d.shadowAtlasHeight.intValue);
d.shadowAtlasWidth.intValue = Mathf.Max(0, d.shadowAtlasWidth.intValue);
d.maxPointLightShadows.intValue = Mathf.Max(0, d.maxPointLightShadows.intValue);
d.maxSpotLightShadows.intValue = Mathf.Max(0, d.maxSpotLightShadows.intValue);
d.maxDirectionalLightShadows.intValue = Mathf.Max(0, d.maxDirectionalLightShadows.intValue);
--EditorGUI.indentLevel;
}
}

38
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRPass.template


$AttributesMesh.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
$AttributesMesh.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
$AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR
$VaryingsMeshToPS.positionWS: #define VARYINGS_NEED_POSITION_WS
$VaryingsMeshToPS.positionRWS: #define VARYINGS_NEED_POSITION_WS
$VaryingsMeshToPS.normalWS: #define VARYINGS_NEED_TANGENT_TO_WORLD
$VaryingsMeshToPS.texCoord0: #define VARYINGS_NEED_TEXCOORD0
$VaryingsMeshToPS.texCoord1: #define VARYINGS_NEED_TEXCOORD1

$VertexDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent);
$VertexDescriptionInputs.TangentSpaceBiTangent: output.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f);
$VertexDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = input.positionOS;
$VertexDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = TransformObjectToWorld(input.positionOS);
$VertexDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = GetAbsolutePositionWS(TransformObjectToWorld(input.positionOS));
$VertexDescriptionInputs.ViewSpacePosition: output.ViewSpacePosition = TransformWorldToView(output.WorldSpacePosition);
$VertexDescriptionInputs.TangentSpacePosition: output.TangentSpacePosition = float3(0.0f, 0.0f, 0.0f);
$VertexDescriptionInputs.WorldSpaceViewDirection: output.WorldSpaceViewDirection = GetWorldSpaceNormalizeViewDir(output.WorldSpacePosition);

output.worldToTangent = k_identity3x3;
output.positionSS = input.positionCS; // input.positionCS is SV_Position
$FragInputs.positionWS: output.positionWS = input.positionWS;
$FragInputs.positionRWS: output.positionRWS = input.positionRWS;
$FragInputs.worldToTangent: output.worldToTangent = BuildWorldToTangent(input.tangentWS, input.normalWS);
$FragInputs.texCoord0: output.texCoord0 = input.texCoord0;
$FragInputs.texCoord1: output.texCoord1 = input.texCoord1;

$SurfaceDescriptionInputs.ViewSpaceNormal: output.ViewSpaceNormal = mul(output.WorldSpaceNormal, (float3x3) UNITY_MATRIX_I_V); // transposed multiplication by inverse matrix to handle normal scale
$SurfaceDescriptionInputs.TangentSpaceNormal: output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescriptionInputs.WorldSpaceTangent: output.WorldSpaceTangent = input.worldToTangent[0].xyz;
$SurfaceDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = mul((float3x3) unity_WorldToObject, output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = mul((float3x3) UNITY_MATRIX_V, output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = TransformWorldToObjectDir(output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = TransformWorldToViewDir(output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = mul((float3x3) unity_WorldToObject, output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = mul((float3x3) UNITY_MATRIX_V, output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = TransformWorldToObjectDir(output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = mul((float3x3) unity_WorldToObject, output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = mul((float3x3) UNITY_MATRIX_V, output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = TransformWorldToObjectDir(output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = TransformWorldToViewDir(output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.WorldSpacePosition: // TODO: FragInputs.positionWS is badly named -- it's camera relative, not in world space
$SurfaceDescriptionInputs.WorldSpacePosition: // we have to fix it up here to match graph input expectations
$SurfaceDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = input.positionWS + _WorldSpaceCameraPos;
$SurfaceDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = mul(unity_WorldToObject, float4(input.positionWS + _WorldSpaceCameraPos, 1.0f)).xyz;
$SurfaceDescriptionInputs.ViewSpacePosition: float4 posViewSpace = mul(UNITY_MATRIX_V, float4(input.positionWS, 1.0f));
$SurfaceDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = GetAbsolutePositionWS(input.positionRWS);
$SurfaceDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = TransformWorldToObject(input.positionRWS);
$SurfaceDescriptionInputs.ViewSpacePosition: float4 posViewSpace = TransformWorldToView(input.positionRWS);
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionWS), _ProjectionParams.x);
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionRWS), _ProjectionParams.x);
$SurfaceDescriptionInputs.VertexColor: output.VertexColor = input.color;
$SurfaceDescriptionInputs.FaceSign: output.FaceSign = input.isFrontFace;

float3 bentNormalWS = surfaceData.normalWS; // TODO : make bent normals work
builtinData.opacity = surfaceDescription.Alpha;
builtinData.bakeDiffuseLighting = SampleBakedGI(fragInputs.positionWS, bentNormalWS, fragInputs.texCoord1, fragInputs.texCoord2); // see GetBuiltinData()
builtinData.bakeDiffuseLighting = SampleBakedGI(fragInputs.positionRWS, bentNormalWS, fragInputs.texCoord1, fragInputs.texCoord2); // see GetBuiltinData()
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
builtinData.bakeDiffuseLighting += SampleBakedGI(fragInputs.positionWS, -fragInputs.worldToTangent[2], fragInputs.texCoord1, fragInputs.texCoord2) * bsdfData.transmittance;
builtinData.bakeDiffuseLighting += SampleBakedGI(fragInputs.positionRWS, -fragInputs.worldToTangent[2], fragInputs.texCoord1, fragInputs.texCoord2) * bsdfData.transmittance;
float4 shadowMask = SampleShadowMask(fragInputs.positionWS, fragInputs.texCoord1);
float4 shadowMask = SampleShadowMask(fragInputs.positionRWS, fragInputs.texCoord1);
builtinData.shadowMask0 = shadowMask.x;
builtinData.shadowMask1 = shadowMask.y;
builtinData.shadowMask2 = shadowMask.z;

29
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDPBRSubShader.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

RequiredFields = new List<string>()
{
"FragInputs.worldToTangent",
"FragInputs.positionWS",
"FragInputs.positionRWS",
"FragInputs.texCoord1",
"FragInputs.texCoord2"
},

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

},
RequiredFields = new List<string>()
{
"FragInputs.positionWS",
"FragInputs.positionRWS",
},
StencilOverride = new List<string>()
{

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

RequiredFields = new List<string>()
{
"FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

RequiredFields = new List<string>()
{
// "FragInputs.worldToTangent",
// "FragInputs.positionWS",
// "FragInputs.positionRWS",
},
PixelShaderSlots = new List<int>()
{

subShader.AddShaderChunk("}", true);
return subShader.GetShaderString(0);
}
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
{
return renderPipelineAsset is HDRenderPipelineAsset;
}
}
}

18
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDSubShaderUtilities.cs


struct VaryingsMeshToPS
{
[Semantic("SV_Position")] Vector4 positionCS;
[Optional] Vector3 positionWS;
[Optional] Vector3 positionRWS;
[Optional] Vector3 normalWS;
[Optional] Vector4 tangentWS; // w contain mirror sign
[Optional] Vector2 texCoord0;

public static Dependency[] tessellationDependencies = new Dependency[]
{
new Dependency("VaryingsMeshToPS.positionWS", "VaryingsMeshToDS.positionWS"),
new Dependency("VaryingsMeshToPS.positionRWS", "VaryingsMeshToDS.positionRWS"),
new Dependency("VaryingsMeshToPS.normalWS", "VaryingsMeshToDS.normalWS"),
new Dependency("VaryingsMeshToPS.tangentWS", "VaryingsMeshToDS.tangentWS"),
new Dependency("VaryingsMeshToPS.texCoord0", "VaryingsMeshToDS.texCoord0"),

public static Dependency[] standardDependencies = new Dependency[]
{
new Dependency("VaryingsMeshToPS.positionWS", "AttributesMesh.positionOS"),
new Dependency("VaryingsMeshToPS.positionRWS", "AttributesMesh.positionOS"),
new Dependency("VaryingsMeshToPS.normalWS", "AttributesMesh.normalOS"),
new Dependency("VaryingsMeshToPS.tangentWS", "AttributesMesh.tangentOS"),
new Dependency("VaryingsMeshToPS.texCoord0", "AttributesMesh.uv0"),

struct VaryingsMeshToDS
{
Vector3 positionWS;
Vector3 positionRWS;
Vector3 normalWS;
[Optional] Vector4 tangentWS;
[Optional] Vector2 texCoord0;

{
public static Dependency[] dependencies = new Dependency[]
{
new Dependency("FragInputs.positionWS", "VaryingsMeshToPS.positionWS"),
new Dependency("FragInputs.positionRWS", "VaryingsMeshToPS.positionRWS"),
new Dependency("FragInputs.worldToTangent", "VaryingsMeshToPS.tangentWS"),
new Dependency("FragInputs.worldToTangent", "VaryingsMeshToPS.normalWS"),
new Dependency("FragInputs.texCoord0", "VaryingsMeshToPS.texCoord0"),

new Dependency("SurfaceDescriptionInputs.ObjectSpaceBiTangent", "SurfaceDescriptionInputs.WorldSpaceBiTangent"),
new Dependency("SurfaceDescriptionInputs.ViewSpaceBiTangent", "SurfaceDescriptionInputs.WorldSpaceBiTangent"),
new Dependency("SurfaceDescriptionInputs.WorldSpacePosition", "FragInputs.positionWS"),
new Dependency("SurfaceDescriptionInputs.ObjectSpacePosition", "FragInputs.positionWS"),
new Dependency("SurfaceDescriptionInputs.ViewSpacePosition", "FragInputs.positionWS"),
new Dependency("SurfaceDescriptionInputs.WorldSpacePosition", "FragInputs.positionRWS"),
new Dependency("SurfaceDescriptionInputs.ObjectSpacePosition", "FragInputs.positionRWS"),
new Dependency("SurfaceDescriptionInputs.ViewSpacePosition", "FragInputs.positionRWS"),
new Dependency("SurfaceDescriptionInputs.WorldSpaceViewDirection", "FragInputs.positionWS"), // we build WorldSpaceViewDirection using FragInputs.positionWS in GetWorldSpaceNormalizeViewDir()
new Dependency("SurfaceDescriptionInputs.WorldSpaceViewDirection", "FragInputs.positionRWS"), // we build WorldSpaceViewDirection using FragInputs.positionRWS in GetWorldSpaceNormalizeViewDir()
new Dependency("SurfaceDescriptionInputs.ObjectSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceViewDirection"),
new Dependency("SurfaceDescriptionInputs.ViewSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceViewDirection"),
new Dependency("SurfaceDescriptionInputs.TangentSpaceViewDirection", "SurfaceDescriptionInputs.WorldSpaceViewDirection"),

32
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitPassForward.template


$AttributesMesh.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
$AttributesMesh.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
$AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR
$VaryingsMeshToPS.positionWS: #define VARYINGS_NEED_POSITION_WS
$VaryingsMeshToPS.positionRWS: #define VARYINGS_NEED_POSITION_WS
$VaryingsMeshToPS.normalWS: #define VARYINGS_NEED_TANGENT_TO_WORLD
$VaryingsMeshToPS.texCoord0: #define VARYINGS_NEED_TEXCOORD0
$VaryingsMeshToPS.texCoord1: #define VARYINGS_NEED_TEXCOORD1

$VertexDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent);
$VertexDescriptionInputs.TangentSpaceBiTangent: output.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f);
$VertexDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = input.positionOS;
$VertexDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = TransformObjectToWorld(input.positionOS);
$VertexDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = GetAbsolutePositionWS(TransformObjectToWorld(input.positionOS));
$VertexDescriptionInputs.ViewSpacePosition: output.ViewSpacePosition = TransformWorldToView(output.WorldSpacePosition);
$VertexDescriptionInputs.TangentSpacePosition: output.TangentSpacePosition = float3(0.0f, 0.0f, 0.0f);
$VertexDescriptionInputs.WorldSpaceViewDirection: output.WorldSpaceViewDirection = GetWorldSpaceNormalizeViewDir(output.WorldSpacePosition);

output.worldToTangent = k_identity3x3;
output.positionSS = input.positionCS; // input.positionCS is SV_Position
$FragInputs.positionWS: output.positionWS = input.positionWS;
$FragInputs.positionRWS: output.positionRWS = input.positionRWS;
$FragInputs.worldToTangent: output.worldToTangent = BuildWorldToTangent(input.tangentWS, input.normalWS);
$FragInputs.texCoord0: output.texCoord0 = input.texCoord0;
$FragInputs.texCoord1: output.texCoord1 = input.texCoord1;

$SurfaceDescriptionInputs.ViewSpaceNormal: output.ViewSpaceNormal = mul(output.WorldSpaceNormal, (float3x3) UNITY_MATRIX_I_V); // transposed multiplication by inverse matrix to handle normal scale
$SurfaceDescriptionInputs.TangentSpaceNormal: output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescriptionInputs.WorldSpaceTangent: output.WorldSpaceTangent = input.worldToTangent[0].xyz;
$SurfaceDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = mul((float3x3) unity_WorldToObject, output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = mul((float3x3) UNITY_MATRIX_V, output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = TransformWorldToObjectDir(output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = TransformWorldToViewDir(output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = mul((float3x3) unity_WorldToObject, output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = mul((float3x3) UNITY_MATRIX_V, output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = TransformWorldToObjectDir(output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = mul((float3x3) unity_WorldToObject, output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = mul((float3x3) UNITY_MATRIX_V, output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = TransformWorldToObjectDir(output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = TransformWorldToViewDir(output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.WorldSpacePosition: // TODO: FragInputs.positionWS is badly named -- it's camera relative, not in world space
$SurfaceDescriptionInputs.WorldSpacePosition: // we have to fix it up here to match graph input expectations
$SurfaceDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = input.positionWS + _WorldSpaceCameraPos;
$SurfaceDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = mul(unity_WorldToObject, float4(input.positionWS + _WorldSpaceCameraPos, 1.0f)).xyz;
$SurfaceDescriptionInputs.ViewSpacePosition: float4 posViewSpace = mul(UNITY_MATRIX_V, float4(input.positionWS, 1.0f));
$SurfaceDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = GetAbsolutePositionWS(input.positionRWS);
$SurfaceDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = TransformWorldToObject(input.positionRWS);
$SurfaceDescriptionInputs.ViewSpacePosition: float4 posViewSpace = TransformWorldToView(input.positionRWS);
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionWS), _ProjectionParams.x);
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionRWS), _ProjectionParams.x);
$SurfaceDescriptionInputs.VertexColor: output.VertexColor = input.color;
$SurfaceDescriptionInputs.FaceSign: output.FaceSign = input.isFrontFace;

9
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/HDUnlitSubShader.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

subShader.AddShaderChunk("}", true);
return subShader.GetShaderString(0);
}
public bool IsPipelineCompatible(RenderPipelineAsset renderPipelineAsset)
{
return renderPipelineAsset is HDRenderPipelineAsset;
}
}
}

20
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/VolumetricFogEditor.cs


private SerializedDataParameter m_Albedo;
private SerializedDataParameter m_MeanFreePath;
private SerializedDataParameter m_Anisotropy;
private SerializedDataParameter m_GlobalLightProbeDimmer;
static GUIContent s_AlbedoLabel = new GUIContent("Single Scattering Albedo", "Hue and saturation control the color of the fog (the wavelength of in-scattered light). Value controls scattering (0 = max absorption & no scattering, 1 = no absorption & max scattering).");
static GUIContent s_MeanFreePathLabel = new GUIContent("Mean Free Path", "Controls the density, which determines how far you can seen through the fog. It's the distance in meters at which 50% of background light is lost in the fog (due to absorption and out-scattering).");
static GUIContent s_AnisotropyLabel = new GUIContent("Anisotropy", "Controls the angular distribution of scattered light. 0 is isotropic, 1 is forward scattering, -1 is backward scattering.");
static GUIContent s_GlobalLightProbeDimmerLabel = new GUIContent("Global Light Probe Dimmer", "Reduces the intensity of the global light probe.");
public override void OnEnable()
{

m_Albedo = Unpack(o.Find(x => x.albedo));
m_MeanFreePath = Unpack(o.Find(x => x.meanFreePath));
m_Anisotropy = Unpack(o.Find(x => x.anisotropy));
m_Albedo = Unpack(o.Find(x => x.albedo));
m_MeanFreePath = Unpack(o.Find(x => x.meanFreePath));
m_Anisotropy = Unpack(o.Find(x => x.anisotropy));
m_GlobalLightProbeDimmer = Unpack(o.Find(x => x.globalLightProbeDimmer));
PropertyField(m_Albedo);
PropertyField(m_MeanFreePath);
PropertyField(m_Anisotropy);
PropertyField(m_Albedo, s_AlbedoLabel);
PropertyField(m_MeanFreePath, s_MeanFreePathLabel);
PropertyField(m_Anisotropy, s_AnisotropyLabel);
PropertyField(m_GlobalLightProbeDimmer, s_GlobalLightProbeDimmerLabel);
}
}
}

17
com.unity.render-pipelines.high-definition/HDRP/HDRenderPipelineAsset.asset


m_Name: HDRenderPipelineAsset
m_EditorClassIdentifier:
version: 1
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7,
type: 2}
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7, type: 2}
m_FrameSettings:
enableShadow: 1
enableContactShadows: 1

enableTransmission: 1
enableAtmosphericScattering: 1
enableVolumetric: 1
enableVolumetrics: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0

supportSSAO: 1
supportSubsurfaceScattering: 1
supportOnlyForward: 0
enableUltraQualitySSS: 0
supportVolumetric: 1
increaseSssSampleCount: 0
supportVolumetrics: 1
increaseResolutionOfVolumetrics: 0
supportDitheringCrossFade: 1
supportDBuffer: 1
supportMSAA: 0
msaaSampleCount: 1

shadowInitParams:
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096
maxPointLightShadows: 6
maxSpotLightShadows: 12
maxDirectionalLightShadows: 1
diffusionProfileSettings: {fileID: 11400000, guid: 404820c4cf36ad944862fa59c56064f0,
type: 2}
diffusionProfileSettings: {fileID: 11400000, guid: 404820c4cf36ad944862fa59c56064f0, type: 2}

3
com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs


public bool featuresFoldout = true;
public bool showAdditionalSettings = false;
// When true, a mesh will be display to represent the area light (Can only be change in editor, component is added in Editor)
public bool displayAreaLightEmissiveMesh = false;
#if UNITY_EDITOR
private void DrawGizmos(bool selected)

69
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs


};
// These structures share between C# and hlsl need to be align on float4, so we pad them.
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public Vector3 positionWS;
public int tileCookie; // TODO: make it a bool
// Packing order depends on chronological access to avoid cache misses
public Vector3 positionRWS;
public int shadowIndex; // -1 if unused
public int contactShadowIndex; // -1 if unused
public Vector3 forward;
public float volumetricDimmer;
public float specularScale;
public Vector3 up; // Rescaled by (2 / shapeHeight)
public Vector3 forward;
public int tileCookie; // TODO: make it a bool
public int shadowIndex; // -1 if unused
public int contactShadowIndex; // -1 if unused
public Vector3 up; // Rescaled by (2 / shapeHeight)
public float diffuseScale;
public Vector4 shadowMaskSelector; // Use with ShadowMask feature
public float volumetricDimmer;
public Vector4 shadowMaskSelector; // Use with ShadowMask feature
public float diffuseScale;
public float specularScale;
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public Vector3 positionWS;
public float invSqrAttenuationRadius;
// Packing order depends on chronological access to avoid cache misses
public Vector3 positionRWS;
public int shadowIndex; // -1 if unused
public float rangeAttenuationScale;
public float rangeAttenuationBias;
public int contactShadowIndex; // -1 if unused
public Vector3 forward;
public float angleScale; // Spot light
public float angleOffset; // Spot light
public GPULightType lightType;
public float specularScale;
public float diffuseScale;
public float angleScale; // Spot light
public float angleOffset; // Spot light
public Vector3 forward;
public int shadowIndex; // -1 if unused
public int contactShadowIndex; // -1 if unused
public int nonLightmappedOnly; // Use with ShadowMask feature // TODO: make it a bool
public Vector2 size; // Used by area (X = length or width, Y = height) and box projector lights (X = range (depth))
public GPULightType lightType;
public int nonLightmappedOnly; // Use with ShadowMask feature // TODO: make it a bool
public float diffuseScale;
public float specularScale;
public float volumetricDimmer; // TODO: improve the cache locality
public Vector2 size; // Used by area (X = length or width, Y = height) and box projector lights (X = range (depth))
public float volumetricDimmer;
};

// 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]
[GenerateHLSL(PackingRules.Exact, false)]
// Caution: The struct need to be align on byte16 (not strictly needed for structured buffer but if we do array later better).
public Vector3 capturePositionWS;
public Vector3 capturePositionRWS;
public EnvShapeType influenceShapeType;
// Box: extents = box extents

public float minProjectionDistance;
public Vector3 proxyPositionWS;
public Vector3 proxyPositionRWS;
public Vector3 influencePositionWS;
public Vector3 influencePositionRWS;
public Vector3 influenceForward;
public Vector3 influenceUp;
public Vector3 influenceRight;

289
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightDefinition.cs.hlsl


// PackingRules = Exact
struct DirectionalLightData
{
float3 positionWS;
int tileCookie;
float3 positionRWS;
int shadowIndex;
int contactShadowIndex;
float3 forward;
float volumetricDimmer;
float specularScale;
float3 forward;
int tileCookie;
int shadowIndex;
int contactShadowIndex;
float4 shadowMaskSelector;
int nonLightmappedOnly;
float volumetricDimmer;
int nonLightmappedOnly;
float4 shadowMaskSelector;
float specularScale;
};
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.LightData

float3 positionWS;
float invSqrAttenuationRadius;
float3 positionRWS;
int shadowIndex;
int contactShadowIndex;
float3 forward;
float rangeAttenuationScale;
float rangeAttenuationBias;
float angleScale;
float angleOffset;
int lightType;
float specularScale;
float diffuseScale;
float angleScale;
float angleOffset;
float3 forward;
int shadowIndex;
int contactShadowIndex;
float4 shadowMaskSelector;
float4 shadowMaskSelector;
float minRoughness;
float diffuseScale;
float specularScale;
int lightType;
float minRoughness;
float volumetricDimmer;
};

{
float3 capturePositionWS;
float3 capturePositionRWS;
float3 proxyPositionWS;
float3 proxyPositionRWS;
float3 influencePositionWS;
float3 influencePositionRWS;
float3 influenceForward;
float3 influenceUp;
float3 influenceRight;

float multiplier;
int envIndex;
};
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DirectionalLightData
//
float3 GetPositionWS(DirectionalLightData value)
{
return value.positionWS;
}
int GetTileCookie(DirectionalLightData value)
{
return value.tileCookie;
}
float3 GetColor(DirectionalLightData value)
{
return value.color;
}
int GetShadowIndex(DirectionalLightData value)
{
return value.shadowIndex;
}
int GetContactShadowIndex(DirectionalLightData value)
{
return value.contactShadowIndex;
}
float3 GetForward(DirectionalLightData value)
{
return value.forward;
}
int GetCookieIndex(DirectionalLightData value)
{
return value.cookieIndex;
}
float3 GetRight(DirectionalLightData value)
{
return value.right;
}
float GetSpecularScale(DirectionalLightData value)
{
return value.specularScale;
}
float3 GetUp(DirectionalLightData value)
{
return value.up;
}
float GetDiffuseScale(DirectionalLightData value)
{
return value.diffuseScale;
}
float GetVolumetricDimmer(DirectionalLightData value)
{
return value.volumetricDimmer;
}
int GetNonLightmappedOnly(DirectionalLightData value)
{
return value.nonLightmappedOnly;
}
float4 GetShadowMaskSelector(DirectionalLightData value)
{
return value.shadowMaskSelector;
}
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.LightData
//
float3 GetPositionWS(LightData value)
{
return value.positionWS;
}
float GetInvSqrAttenuationRadius(LightData value)
{
return value.invSqrAttenuationRadius;
}
float3 GetColor(LightData value)
{
return value.color;
}
int GetShadowIndex(LightData value)
{
return value.shadowIndex;
}
int GetContactShadowIndex(LightData value)
{
return value.contactShadowIndex;
}
float3 GetForward(LightData value)
{
return value.forward;
}
int GetCookieIndex(LightData value)
{
return value.cookieIndex;
}
float3 GetRight(LightData value)
{
return value.right;
}
float GetSpecularScale(LightData value)
{
return value.specularScale;
}
float3 GetUp(LightData value)
{
return value.up;
}
float GetDiffuseScale(LightData value)
{
return value.diffuseScale;
}
float GetAngleScale(LightData value)
{
return value.angleScale;
}
float GetAngleOffset(LightData value)
{
return value.angleOffset;
}
float GetShadowDimmer(LightData value)
{
return value.shadowDimmer;
}
int GetNonLightmappedOnly(LightData value)
{
return value.nonLightmappedOnly;
}
float4 GetShadowMaskSelector(LightData value)
{
return value.shadowMaskSelector;
}
float2 GetSize(LightData value)
{
return value.size;
}
int GetLightType(LightData value)
{
return value.lightType;
}
float GetMinRoughness(LightData value)
{
return value.minRoughness;
}
float GetVolumetricDimmer(LightData value)
{
return value.volumetricDimmer;
}
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
//
float3 GetCapturePositionWS(EnvLightData value)
{
return value.capturePositionWS;
}
int GetInfluenceShapeType(EnvLightData value)
{
return value.influenceShapeType;
}
float3 GetProxyExtents(EnvLightData value)
{
return value.proxyExtents;
}
float GetMinProjectionDistance(EnvLightData value)
{
return value.minProjectionDistance;
}
float3 GetProxyPositionWS(EnvLightData value)
{
return value.proxyPositionWS;
}
float3 GetProxyForward(EnvLightData value)
{
return value.proxyForward;
}
float3 GetProxyUp(EnvLightData value)
{
return value.proxyUp;
}
float3 GetProxyRight(EnvLightData value)
{
return value.proxyRight;
}
float3 GetInfluencePositionWS(EnvLightData value)
{
return value.influencePositionWS;
}
float3 GetInfluenceForward(EnvLightData value)
{
return value.influenceForward;
}
float3 GetInfluenceUp(EnvLightData value)
{
return value.influenceUp;
}
float3 GetInfluenceRight(EnvLightData value)
{
return value.influenceRight;
}
float3 GetInfluenceExtents(EnvLightData value)
{
return value.influenceExtents;
}
float GetUnused00(EnvLightData value)
{
return value.unused00;
}
float3 GetBlendDistancePositive(EnvLightData value)
{
return value.blendDistancePositive;
}
float3 GetBlendDistanceNegative(EnvLightData value)
{
return value.blendDistanceNegative;
}
float3 GetBlendNormalDistancePositive(EnvLightData value)
{
return value.blendNormalDistancePositive;
}
float3 GetBlendNormalDistanceNegative(EnvLightData value)
{
return value.blendNormalDistanceNegative;
}
float3 GetBoxSideFadePositive(EnvLightData value)
{
return value.boxSideFadePositive;
}
float3 GetBoxSideFadeNegative(EnvLightData value)
{
return value.boxSideFadeNegative;
}
float GetWeight(EnvLightData value)
{
return value.weight;
}
float GetMultiplier(EnvLightData value)
{
return value.multiplier;
}
int GetEnvIndex(EnvLightData value)
{
return value.envIndex;
}
#endif

196
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightEvaluation.hlsl


}
// None of the outputs are premultiplied.
// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
void EvaluateLight_Directional(LightLoopContext lightLoopContext, PositionInputs posInput,
DirectionalLightData lightData, BakeLightingData bakeLightingData,
float3 N, float3 L,

float shadow = 1.0;
float shadowMask = 1.0;
float4 shadowData = float4(1, 1, 1, 1);
color = lightData.color;
attenuation = 1.0; // Note: no volumetric attenuation along shadow rays for directional lights

float3 lightToSample = positionWS - lightData.positionWS;
float3 lightToSample = positionWS - lightData.positionRWS;
float3 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSample);
color *= cookie;

shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
#endif
UNITY_BRANCH if (lightData.shadowIndex >= 0)
// We test NdotL >= 0.0 to not sample the shadow map if it is not required.
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (dot(N, L) >= 0.0))
{
#ifdef USE_DEFERRED_DIRECTIONAL_SHADOWS
shadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).x;

float contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
shadow = min(shadow, contactShadow);
#ifdef SHADOWS_SHADOWMASK
// TODO: Optimize this code! Currently it is a bit like brute force to get the last transistion and fade to shadow mask, but there is

// Note: There is no shadowDimmer when there is no shadow mask
#endif
// Transparent have no contact shadow information
#ifndef _SURFACE_TYPE_TRANSPARENT
shadow = min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
#endif
}
attenuation *= shadow;

// Punctual Light evaluation helper
//-----------------------------------------------------------------------------
// Return L vector for punctual light (normalize surface to light), lightToSample (light to surface non normalize) and distances {d, d^2, 1/d, d_proj}
void GetPunctualLightVectors(float3 positionWS, LightData lightData, out float3 L, out float3 lightToSample, out float4 distances)
{
lightToSample = positionWS - lightData.positionRWS;
int lightType = lightData.lightType;
distances.w = dot(lightToSample, lightData.forward);
if (lightType == GPULIGHTTYPE_PROJECTOR_BOX)
{
L = -lightData.forward;
distances.xyz = 1; // No distance or angle attenuation
}
else
{
float3 unL = -lightToSample;
float distSq = dot(unL, unL);
float distRcp = rsqrt(distSq);
float dist = distSq * distRcp;
L = unL * distRcp;
distances.xyz = float3(dist, distSq, distRcp);
}
}
float4 EvaluateCookie_Punctual(LightLoopContext lightLoopContext, LightData lightData,
float3 lightToSample)
{

// None of the outputs are premultiplied.
// distances = {d, d^2, 1/d, d_proj}, where d_proj = dot(lightToSample, lightData.forward).
// Note: When doing transmission we always have only one shadow sample to do: Either front or back. We use NdotL to know on which side we are
void EvaluateLight_Punctual(LightLoopContext lightLoopContext, PositionInputs posInput,
LightData lightData, BakeLightingData bakeLightingData,
float3 N, float3 L, float3 lightToSample, float4 distances,

float shadow = 1.0;
float shadowMask = 1.0;
float contactShadow = 1.0;
attenuation = SmoothPunctualLightAttenuation(distances, lightData.invSqrAttenuationRadius,
attenuation = SmoothPunctualLightAttenuation(distances, lightData.rangeAttenuationScale, lightData.rangeAttenuationBias,
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
#endif
// Projector lights always have cookies, so we can perform clipping inside the if().
UNITY_BRANCH if (lightData.cookieIndex >= 0)

shadow = shadowMask = (lightData.shadowMaskSelector.x >= 0.0) ? dot(bakeLightingData.bakeShadowMask, lightData.shadowMaskSelector) : 1.0;
#endif
UNITY_BRANCH if (lightData.shadowIndex >= 0)
// We test NdotL >= 0.0 to not sample the shadow map if it is not required.
UNITY_BRANCH if (lightData.shadowIndex >= 0 && (dot(N, L) >= 0.0))
// Note:the case of NdotL < 0 can appear with isThinModeTransmission, in this case we need to flip the shadow bias
contactShadow = GetContactShadow(lightLoopContext, lightData.contactShadowIndex);
shadow = min(shadow, contactShadow);
#ifdef SHADOWS_SHADOWMASK
// Note: Legacy Unity have two shadow mask mode. ShadowMask (ShadowMask contain static objects shadow and ShadowMap contain only dynamic objects shadow, final result is the minimun of both value)

#else
shadow = lerp(1.0, shadow, lightData.shadowDimmer);
#endif
// Transparent have no contact shadow information
#ifndef _SURFACE_TYPE_TRANSPARENT
shadow = min(shadow, GetContactShadow(lightLoopContext, lightData.contactShadowIndex));
#endif
}
// Environment map share function

if (influenceShapeType == ENVSHAPETYPE_SPHERE)
{
projectionDistance = IntersectSphereProxy(lightData, dirPS, positionPS);
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionWS
float3 capturePositionWS = lightData.capturePositionWS;
R = (positionWS + projectionDistance * R) - capturePositionWS;
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionRWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionRWS;
weight = InfluenceSphereWeight(lightData, normalWS, positionWS, positionIS, dirIS);
}

// No need to normalize for fetching cubemap
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionWS
float3 capturePositionWS = lightData.capturePositionWS;
R = (positionWS + projectionDistance * R) - capturePositionWS;
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.capturePositionRWS
R = (positionWS + projectionDistance * R) - lightData.capturePositionRWS;
weight = InfluenceBoxWeight(lightData, normalWS, positionWS, positionIS, dirIS);
}

weight *= lightData.weight;
}
// ----------------------------------------------------------------------------
// Helper functions to use Transmission with a material
// ----------------------------------------------------------------------------
// For EvaluateTransmission.hlsl file it is required to define a BRDF for the transmission. Defining USE_DIFFUSE_LAMBERT_BRDF use Lambert, otherwise it use Disneydiffuse
#ifdef MATERIAL_INCLUDE_TRANSMISSION
// This function return transmittance to provide to EvaluateTransmission
float3 PreEvaluatePunctualLightTransmission(LightLoopContext lightLoopContext, PositionInputs posInput, float distFrontFaceToLight,
float NdotL, float3 L, BSDFData bsdfData,
inout float3 normalWS, inout LightData lightData)
{
float3 transmittance = bsdfData.transmittance;
// if NdotL is positive, we do one fetch on front face done by EvaluateLight_XXX. Just regular lighting
// If NdotL is negative, we have two cases:
// - Thin mode: Reuse the front face fetch as shadow for back face - flip the normal for the bias (and the NdotL test) and disable contact shadow
// - Mixed mode: Do a fetch on back face to retrieve the thickness. The thickness will provide a shadow attenuation (with distance travelled there is less transmission).
// (Note: EvaluateLight_Punctual discard the fetch if NdotL < 0)
if (NdotL < 0 && lightData.shadowIndex >= 0)
{
if (HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS))
{
normalWS = -normalWS; // Flip normal for shadow bias
lightData.contactShadowIndex = -1; // Disable shadow contact
}
else // MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS
{
// Recompute transmittance using the thickness value computed from the shadow map.
// Compute the distance from the light to the back face of the object along the light direction.
float distBackFaceToLight = GetPunctualShadowClosestDistance( lightLoopContext.shadowContext, s_linear_clamp_sampler,
posInput.positionWS, lightData.shadowIndex, L, lightData.positionRWS);
// Our subsurface scattering models use the semi-infinite planar slab assumption.
// Therefore, we need to find the thickness along the normal.
float thicknessInUnits = (distFrontFaceToLight - distBackFaceToLight) * -NdotL;
float thicknessInMeters = thicknessInUnits * _WorldScales[bsdfData.diffusionProfile].x;
float thicknessInMillimeters = thicknessInMeters * MILLIMETERS_PER_METER;
#if SHADEROPTIONS_USE_DISNEY_SSS
// We need to make sure it's not less than the baked thickness to minimize light leaking.
float thicknessDelta = max(0, thicknessInMillimeters - bsdfData.thickness);
float3 S = _ShapeParams[bsdfData.diffusionProfile].rgb;
// Approximate the decrease of transmittance by e^(-1/3 * dt * S).
#if 0
float3 expOneThird = exp(((-1.0 / 3.0) * thicknessDelta) * S);
#else
// Help the compiler.
float k = (-1.0 / 3.0) * LOG2_E;
float3 p = (k * thicknessDelta) * S;
float3 expOneThird = exp2(p);
#endif
transmittance *= expOneThird;
#else // SHADEROPTIONS_USE_DISNEY_SSS
// We need to make sure it's not less than the baked thickness to minimize light leaking.
thicknessInMillimeters = max(thicknessInMillimeters, bsdfData.thickness);
transmittance = ComputeTransmittanceJimenez(_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][0].rgb,
_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][0].a,
_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][1].rgb,
_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][1].a,
_TransmissionTintsAndFresnel0[bsdfData.diffusionProfile].rgb,
thicknessInMillimeters);
#endif // SHADEROPTIONS_USE_DISNEY_SSS
// Note: we do not modify the distance to the light, or the light angle for the back face.
// This is a performance-saving optimization which makes sense as long as the thickness is small.
}
}
return transmittance;
}
// This function return transmittance to provide to EvaluateTransmission
float3 PreEvaluateDirectionalLightTransmission(float NdotL, DirectionalLightData lightData, BSDFData bsdfData, inout float3 normalWS, inout int contactShadowIndex)
{
if (NdotL < 0 && lightData.shadowIndex >= 0)
{
if (HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS))
{
normalWS = -normalWS; // Flip normal for shadow bias
contactShadowIndex = -1; // Disable shadow contact
}
}
return bsdfData.transmittance;
}
#define TRANSMISSION_WRAP_ANGLE (PI/12) // 15 degrees
#define TRANSMISSION_WRAP_LIGHT cos(PI/2 - TRANSMISSION_WRAP_ANGLE)
// Currently, we only model diffuse transmission. Specular transmission is not yet supported.
// Transmitted lighting is computed as follows:
// - we assume that the object is a thick plane (slab);
// - we reverse the front-facing normal for the back of the object;
// - we assume that the incoming radiance is constant along the entire back surface;
// - we apply BSDF-specific diffuse transmission to transmit the light subsurface and back;
// - we integrate the diffuse reflectance profile w.r.t. the radius (while also accounting
// for the thickness) to compute the transmittance;
// - we multiply the transmitted radiance by the transmittance.
// transmittance come from the call to PreEvaluateLightTransmission
// attenuation come from the call to EvaluateLight_Punctual
float3 EvaluateTransmission(BSDFData bsdfData, float3 transmittance, float NdotL, float NdotV, float LdotV, float attenuation)
{
// Apply wrapped lighting to better handle thin objects at grazing angles.
float wrappedNdotL = ComputeWrappedDiffuseLighting(-NdotL, TRANSMISSION_WRAP_LIGHT);
// Apply BSDF-specific diffuse transmission to attenuation. See also: [SSS-NOTE-TRSM]
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
#ifdef USE_DIFFUSE_LAMBERT_BRDF
attenuation *= Lambert();
#else
attenuation *= DisneyDiffuse(NdotV, max(0, -NdotL), LdotV, bsdfData.perceptualRoughness);
#endif
float intensity = attenuation * wrappedNdotL;
return intensity * transmittance;
}
#endif // #ifdef MATERIAL_INCLUDE_TRANSMISSION

62
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs


scInit.resourceBinder = binder;
ShadowManager.ShadowBudgets budgets;
budgets.maxPointLights = 6;
budgets.maxSpotLights = 12;
budgets.maxDirectionalLights = 1;
budgets.maxPointLights = shadowInit.maxPointLightShadows;
budgets.maxSpotLights = shadowInit.maxSpotLightShadows;
budgets.maxDirectionalLights = shadowInit.maxDirectionalLightShadows;
m_ShadowMgr = new ShadowManager(shadowSettings, ref scInit, ref budgets, m_Shadowmaps);
// set global overrides - these need to match the override specified in LightLoop/Shadow.hlsl

// Rescale for cookies and windowing.
directionalLightData.right = light.light.transform.right * 2 / Mathf.Max(additionalData.shapeWidth, 0.001f);
directionalLightData.up = light.light.transform.up * 2 / Mathf.Max(additionalData.shapeHeight, 0.001f);
directionalLightData.positionWS = light.light.transform.position;
directionalLightData.positionRWS = light.light.transform.position;
directionalLightData.color = GetLightColor(light);
// Caution: This is bad but if additionalData == HDUtils.s_DefaultHDAdditionalLightData it mean we are trying to promote legacy lights, which is the case for the preview for example, so we need to multiply by PI as legacy Unity do implicit divide by PI for direct intensity.

lightData.lightType = gpuLightType;
lightData.positionWS = light.light.transform.position;
// Setting 0 for invSqrAttenuationRadius mean we have no range attenuation, but still have inverse square attenuation.
lightData.positionRWS = light.light.transform.position;
lightData.invSqrAttenuationRadius = applyRangeAttenuation ? 1.0f / (light.range * light.range) : 0.0f;
// In the shader we do range remapping: (x - start) / (end - start) = (dist^2 * rangeAttenuationScale + rangeAttenuationBias)
if (applyRangeAttenuation)
{
// start = 0.0f, end = range^2
lightData.rangeAttenuationScale = 1.0f / (light.range * light.range);
lightData.rangeAttenuationBias = 0.0f;
}
else // Don't apply any attenuation but do a 'step' at range
{
// start = range^2 - epsilon, end = range^2
lightData.rangeAttenuationScale = 1.0f / 0.01f;
lightData.rangeAttenuationBias = - (light.range * light.range - 0.01f) / 0.01f;
}
lightData.forward = light.light.transform.forward; // Note: Light direction is oriented backward (-Z)
lightData.forward = light.light.transform.forward;
lightData.up = light.light.transform.up;
lightData.right = light.light.transform.right;

lightData.size = new Vector2(additionalLightData.shapeWidth, additionalLightData.shapeHeight);
}
float distanceToCamera = (lightData.positionWS - camera.transform.position).magnitude;
float distanceToCamera = (lightData.positionRWS - camera.transform.position).magnitude;
float distanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalLightData.fadeDistance);
float lightScale = additionalLightData.lightDimmer * distanceFade;

lightData.shadowMaskSelector.x = -1.0f;
lightData.nonLightmappedOnly = 0;
}
// Check if the current light is dominant and store it's index to change it's property later,
// as we can't know which one will be dominant before checking all the lights
GetDominantLightWithShadows(additionalshadowData, light, m_lightList.lights.Count -1);

// Then Culling side
var range = lightDimensions.z;
var lightToWorld = light.localToWorld;
Vector3 positionWS = lightData.positionWS;
Vector3 positionWS = lightData.positionRWS;
Vector3 positionVS = worldToView.MultiplyPoint(positionWS);
Matrix4x4 lightToView = worldToView * lightToWorld;

envLightData.influenceRight = influenceToWorld.GetColumn(0).normalized;
envLightData.influenceUp = influenceToWorld.GetColumn(1).normalized;
envLightData.influenceForward = influenceToWorld.GetColumn(2).normalized;
envLightData.capturePositionWS = capturePosition;
envLightData.influencePositionWS = influenceToWorld.GetColumn(3);
envLightData.capturePositionRWS = capturePosition;
envLightData.influencePositionRWS = influenceToWorld.GetColumn(3);
envLightData.envIndex = envIndex;

envLightData.proxyRight = proxyToWorld.GetColumn(0).normalized;
envLightData.proxyUp = proxyToWorld.GetColumn(1).normalized;
envLightData.proxyForward = proxyToWorld.GetColumn(2).normalized;
envLightData.proxyPositionWS = proxyToWorld.GetColumn(3);
envLightData.proxyPositionRWS = proxyToWorld.GetColumn(3);
m_lightList.envLights.Add(envLightData);
return true;

// Caution: 'DirectionalLightData.positionWS' is camera-relative after this point.
int last = m_lightList.directionalLights.Count - 1;
DirectionalLightData lightData = m_lightList.directionalLights[last];
lightData.positionWS -= camPosWS;
lightData.positionRWS -= camPosWS;
m_lightList.directionalLights[last] = lightData;
}
}

// Caution: 'LightData.positionWS' is camera-relative after this point.
int last = m_lightList.lights.Count - 1;
LightData lightData = m_lightList.lights[last];
lightData.positionWS -= camPosWS;
lightData.positionRWS -= camPosWS;
m_lightList.lights[last] = lightData;
}
}

// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
// Caution: 'EnvLightData.positionRWS' is camera-relative after this point.
envLightData.capturePositionWS -= camPosWS;
envLightData.influencePositionWS -= camPosWS;
envLightData.proxyPositionWS -= camPosWS;
envLightData.capturePositionRWS -= camPosWS;
envLightData.influencePositionRWS -= camPosWS;
envLightData.proxyPositionRWS -= camPosWS;
m_lightList.envLights[last] = envLightData;
}
}

cmd.SetGlobalTexture(HDShaderIDs._DeferredShadowTexture, RuntimeUtilities.whiteTexture);
return;
}
using (new ProfilingSample(cmd, "Deferred Directional Shadow", CustomSamplerId.TPDeferredDirectionalShadow.GetSampler()))
{
Vector4 lightDirection = Vector4.zero;

}
else
kernel = s_deferredDirectionalShadowKernel;
// We use the .w component of the direction/position vectors to choose in the shader the
// light direction of the contact shadows (direction light direction or (pixel position - light position))
if (m_CurrentSunLight != null)

}
if (m_DominantLightIndex != -1)
{
lightPosition = m_DominantLightData.positionWS;
lightPosition = m_DominantLightData.positionRWS;
lightPosition.w = 1;
lightDirection.w = 0;
}

3
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.hlsl


LightLoopContext context;
context.sampleReflection = 0;
context.shadowContext = InitShadowContext();
//We always fetch the screen space shadow texture, it is a 1x1 white texture if deferred directional shadow and/or contact shadow are disabled
context.contactShadow = LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).y; // Contactshadow is store in Green Channel of _DeferredShadowTexture
context.contactShadow = InitContactShadow(posInput);
// This struct is define in the material. the Lightloop must not access it
// PostEvaluateBSDF call at the end will convert Lighting to diffuse and specular lighting

21
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopDef.hlsl


output.influenceForward = float3(0.0, 0.0, 1.0);
output.influenceUp = float3(0.0, 1.0, 0.0);
output.influenceRight = float3(1.0, 0.0, 0.0);
output.influencePositionWS = float3(0.0, 0.0, 0.0);
output.influencePositionRWS = float3(0.0, 0.0, 0.0);
output.weight = 1.0;
output.multiplier = 1.0;

return _EnvLightDatas[j];
}
float GetContactShadow(LightLoopContext lightLoopContact, int contactShadowIndex)
// We always fetch the screen space shadow texture to reduce the number of shader variant, overhead is negligible,
// it is a 1x1 white texture if deferred directional shadow and/or contact shadow are disabled
// We perform a single featch a the beginning of the lightloop
float InitContactShadow(PositionInputs posInput)
{
// For now we only support one contact shadow
// Contactshadow is store in Green Channel of _DeferredShadowTexture
return LOAD_TEXTURE2D(_DeferredShadowTexture, posInput.positionSS).y;
}
float GetContactShadow(LightLoopContext lightLoopContext, int contactShadowIndex)
// Here we take the contact shadow value using the contactShadowIndex of the light
// If the contact shadows are diasbled, it's value is -1 so this function will only
// return 1
// On the other hand, if the feature is active it's value is 0 so we can return
// the value fetched at the begining of LightLoop()
return max(lightLoopContact.contactShadow, abs(contactShadowIndex));
return contactShadowIndex >= 0 ? lightLoopContext.contactShadow : 1.0;
}

8
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/VolumeProjection.hlsl


float3 WorldToProxyPosition(EnvLightData lightData, float3x3 worldToPS, float3 positionWS)
{
float3 positionPS = positionWS - lightData.proxyPositionWS;
float3 positionPS = positionWS - lightData.proxyPositionRWS;
positionPS = mul(positionPS, worldToPS).xyz;
return positionPS;
}

#if defined(ENVMAP_FEATURE_INFLUENCENORMAL)
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.influenceExtents.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionWS));
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionRWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float insideInfluenceNormalVolume = all(belowPositiveInfluenceNormalVolume >= 1.0) && all(aboveNegativeInfluenceNormalVolume >= 1.0) ? 1.0 : 0;
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionWS));
float insideWeight = InfluenceFadeNormalWeight(normalWS, normalize(positionWS - lightData.capturePositionRWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
#endif

float3 WorldToInfluencePosition(EnvLightData lightData, float3x3 worldToIS, float3 positionWS)
{
float3 positionIS = positionWS - lightData.influencePositionWS;
float3 positionIS = positionWS - lightData.influencePositionRWS;
positionIS = mul(positionIS, worldToIS).xyz;
return positionIS;
}

13
com.unity.render-pipelines.high-definition/HDRP/Lighting/SphericalHarmonics.cs


return sh;
}
public static SphericalHarmonicsL2 RescaleCoefficients(SphericalHarmonicsL2 sh, float scalar)
{
for (int c = 0; c < 3; c++)
{
for (int i = 0; i < 9; i++)
{
sh[c, i] *= scalar;
}
}
return sh;
}
// Packs coefficients so that we can use Peter-Pike Sloan's shader code.
// Does not perform premultiplication with coefficients of SH basis functions.
// See SetSHEMapConstants() in "Stupid Spherical Harmonics Tricks".

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/DensityVolume.cs


[AddComponentMenu("Rendering/Density Volume", 1100)]
public class DensityVolume : MonoBehaviour
{
public DensityVolumeParameters parameters = new DensityVolumeParameters(Color.grey, 10.0f, 0.0f);
public DensityVolumeParameters parameters = new DensityVolumeParameters(Color.white, 10.0f, 0.0f);
private Texture3D previousVolumeMask = null;

23
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ///
/// MIT License ///
/// ///
/// Copyright (c) 2016 Rapha�l Ernaelsten (@RaphErnaelsten) ///
/// ///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), ///
/// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, ///
/// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: ///
/// ///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ///
/// ///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ///
/// IN THE SOFTWARE. ///
/// ///
/// PLEASE CONSIDER CREDITING AURA IN YOUR PROJECTS. IF RELEVANT, USE THE UNMODIFIED LOGO PROVIDED IN THE "LICENSE" FOLDER. ///
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;

{
if (textures.Contains(volumeTexture))
{
textures.Add(volumeTexture);
textures.Remove(volumeTexture);
needTextureUpdate = true;
}

133
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute


// Definitions
//--------------------------------------------------------------------------------------------------
#pragma kernel VolumeVoxelizationBruteforce VolumeVoxelization=VolumeVoxelizationBruteforce LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumeVoxelizationClustered VolumeVoxelization=VolumeVoxelizationClustered LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumeVoxelizationBruteforceMQ VolumeVoxelization=VolumeVoxelizationBruteforceMQ VL_PRESET_MQ LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumeVoxelizationClusteredMQ VolumeVoxelization=VolumeVoxelizationClusteredMQ VL_PRESET_MQ LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumeVoxelizationBruteforceHQ VolumeVoxelization=VolumeVoxelizationBruteforceHQ VL_PRESET_HQ LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumeVoxelizationClusteredHQ VolumeVoxelization=VolumeVoxelizationClusteredHQ VL_PRESET_HQ LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUME_VOXELIZATION
#include "../../ShaderConfig.cs.hlsl"
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET == 1)
#ifdef VL_PRESET_MQ
#define VBUFFER_TILE_SIZE 8
#define VBUFFER_SLICE_COUNT 64
#else
#define VBUFFER_TILE_SIZE 8
#endif
#ifdef VL_PRESET_HQ
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 128
#define VBUFFER_TILE_SIZE 4
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUME_VOXELIZATION
//--------------------------------------------------------------------------------------------------
// Included headers

#include "../../ShaderVariables.hlsl"
#include "VolumetricLighting.cs.hlsl"
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#pragma only_renderers d3d11 ps4 xboxone vulkan metal

float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
uint _NumVisibleDensityVolumes;
float3 _VolumeMaskDimensions; //x = 1/totalTextures , y = 1/textureSize, z = textureSize
float4 _VolumeMaskDimensions; //x = 1/numTextures , y = width, z = depth = width * numTextures, w = maxLod
float SampleVolumeMask(DensityVolumeData volumeData, float3 voxelCenterUV, float3 VxUV, float3 VyUV, float3 VzUV)
float SampleVolumeMask(DensityVolumeData volumeData, float3 voxelCenterUVW, float3 duvw_dx, float3 duvw_dy, float3 duvw_dz)
float offset = volumeData.textureIndex * _VolumeMaskDimensions.x;
float clampBorder = 0.5f * _VolumeMaskDimensions.y;
// Scale and bias the UVWs and then take fractional part, will be in [0,1] range.
voxelCenterUVW = frac(voxelCenterUVW * volumeData.textureTiling + volumeData.textureScroll);
float rcpNumTextures = _VolumeMaskDimensions.x;
float textureWidth = _VolumeMaskDimensions.y;
float textureDepth = _VolumeMaskDimensions.z;
float maxLod = _VolumeMaskDimensions.w;
//scale and bias the UVs and then take fractional part, will be in [0,1] range
voxelCenterUV = frac(voxelCenterUV * volumeData.textureTiling + volumeData.textureScroll);
float offset = volumeData.textureIndex * rcpNumTextures;
voxelCenterUVW.z = voxelCenterUVW.z * rcpNumTextures + offset;
voxelCenterUV.z = voxelCenterUV.z * _VolumeMaskDimensions.x;
voxelCenterUV.z += offset;
// TODO: expose the LoD bias parameter.
float lod = ComputeTextureLOD(duvw_dx, duvw_dy, duvw_dz, textureWidth);
lod = clamp(lod, 0, maxLod);
voxelCenterUV.z = clamp(voxelCenterUV.z, offset + clampBorder, offset + _VolumeMaskDimensions.x - clampBorder);
// TODO: bugfix.
// Note that this clamping to edge doesn't quite work.
// First of all, the distance to the edge should depend on the LoD.
// Secondly, for trilinear filtering, which of the two LoDs should you choose to compute the distance to the edge?
// If you use floor(lod), the lower LoD may cause a leak across the edge from the neighbor texture.
// If you use ceil(lod), the upper LoD effectively loses a texel at the border, which may break tileable textures.
// For now, we choose the second option.
// We support texture filtering across the wrap in Z in neither case.
int textureSize = (int)textureDepth;
int mipSize = textureSize >> (int)ceil(lod);
float halfTexelSize = 0.5f * rcp(mipSize);
voxelCenterUVW.z = clamp(voxelCenterUVW.z, offset + halfTexelSize, offset + rcpNumTextures - halfTexelSize);
float lod = ComputeTextureLOD(VxUV * _VolumeMaskDimensions.z, VyUV * _VolumeMaskDimensions.z, VzUV * _VolumeMaskDimensions.z);
float maskValue = SAMPLE_TEXTURE3D_LOD(_VolumeMaskAtlas, s_linear_clamp_sampler, voxelCenterUV, lod).a;
return maskValue;
return SAMPLE_TEXTURE3D_LOD(_VolumeMaskAtlas, s_trilinear_clamp_sampler, voxelCenterUVW, lod).a;
}

float n = _VBufferDepthDecodingParams.x + _VBufferDepthDecodingParams.z;
float z0 = n; // Start the computation from the near plane
float de = rcp(VBUFFER_SLICE_COUNT); // Log-encoded distance between slices
float z0 = n; // Start the computation from the near plane
float de = _VBufferSliceCount.y; // Log-encoded distance between slices
#ifdef USE_CLUSTERED_LIGHTLIST
// The voxel can overlap up to 2 light clusters along Z, so we have to iterate over both.

LIGHTCATEGORY_DENSITY_VOLUME, volumeStarts[0], volumeCounts[0]);
#endif // USE_CLUSTERED_LIGHTLIST
#if defined(SHADER_API_METAL)
[fastopt]
for (uint slice = 0; slice < VBUFFER_SLICE_COUNT; slice++)
#else
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.w); // Prevent unrolling...
// TODO: replace 'sliceCountHack' with VBUFFER_SLICE_COUNT when the shader compiler bug is fixed.
for (uint slice = 0; slice < sliceCountHack; slice++)
#endif
for (uint slice = 0; slice < (uint)_VBufferSliceCount.x; slice++)
{
uint3 voxelCoord = uint3(posInput.positionSS, slice);

float z = z0 + halfDZ;
float3 voxelCenterWS = rayOriginWS + z * rayUnDirWS; // Works due to the length of of the dir
// Dimensions of the voxel as we step along the ray.
float3 voxelRightSize = z * voxelAxisRight;
float3 voxelUpSize = z * voxelAxisUp;
float3 voxelDepthSize = halfDZ * voxelAxisForward;
// TODO: define a function ComputeGlobalFogCoefficients(float3 voxelCenterWS),
// which allows procedural definition of extinction and scattering.
float3 voxelScattering = _GlobalScattering;

{
#endif // USE_CLUSTERED_LIGHTLIST
OrientedBBox obb = _VolumeBounds[volumeIndex];
const OrientedBBox obb = _VolumeBounds[volumeIndex];
float3x3 obbFrame = float3x3(obb.right, obb.up, cross(obb.up, obb.right));
float3 obbExtents = float3(obb.extentX, obb.extentY, obb.extentZ);
const float3x3 obbFrame = float3x3(obb.right, obb.up, cross(obb.up, obb.right));
const float3 obbExtents = float3(obb.extentX, obb.extentY, obb.extentZ);
float3 voxelCenterBS = mul(voxelCenterWS - obb.center, transpose(obbFrame));
float3 voxelCenterUV = (voxelCenterBS / obbExtents) * 0.5 + 0.5;
const float3 voxelCenterBS = mul(voxelCenterWS - obb.center, transpose(obbFrame));
const float3 voxelCenterCS = (voxelCenterBS / obbExtents);
const float3 voxelAxisRightBS = mul(voxelAxisRight, transpose(obbFrame));
const float3 voxelAxisUpBS = mul(voxelAxisUp, transpose(obbFrame));
const float3 voxelAxisForwardBS = mul(voxelAxisForward, transpose(obbFrame));
#if SOFT_VOXELIZATION
// We need to determine which is the face closest to 'voxelCenterBS'.

// We have determined the normal of the closest face.
// We now have to construct the diagonal of the voxel with the longest extent along this normal.
float3 minDiagPointBS, maxDiagPointBS;
float3 voxelAxisRightBS = mul(voxelAxisRight, transpose(obbFrame));
float3 voxelAxisUpBS = mul(voxelAxisUp, transpose(obbFrame));
float3 voxelAxisForwardBS = mul(voxelAxisForward, transpose(obbFrame));
// Start at the center of the voxel.
minDiagPointBS = maxDiagPointBS = voxelCenterBS;

#else // SOFT_VOXELIZATION
bool overlap = abs(voxelCenterUV.x) <= 1 &&
abs(voxelCenterUV.y) <= 1 &&
abs(voxelCenterUV.z) <= 1;
bool overlap = Max3(abs(voxelCenterCS.x), abs(voxelCenterCS.y), abs(voxelCenterCS.z)) <= 1;
float overlapFraction = overlap ? 1 : 0;

{
float scatteringAndExtinctionMask = 1.0f;
float densityMask = 1.0f;
float3 voxelRightSizeBS = mul(voxelRightSize, transpose(obbFrame));
float3 voxelRightSizeUV = (voxelRightSizeBS / obbExtents);
float3 voxelUpSizeBS = mul(voxelUpSize, transpose(obbFrame));
float3 voxelUpSizeUV = (voxelUpSizeBS / obbExtents);
float3 voxelDepthSizeBS = mul(voxelDepthSize, transpose(obbFrame));
float3 voxelDepthSizeUV = (voxelDepthSizeBS / obbExtents);
// We divide extents (half-sizes) by extents here, obtaining full-sized gradients.
float3 voxelGradRightUVW = z * voxelAxisRightBS / obbExtents;
float3 voxelGradUpUVW = z * voxelAxisUpBS / obbExtents;
float3 voxelGradForwardUVW = halfDZ * voxelAxisForwardBS / obbExtents;
float3 voxelCenterUVW = voxelCenterCS * 0.5 + 0.5;
scatteringAndExtinctionMask = SampleVolumeMask(_VolumeData[volumeIndex], voxelCenterUV * 0.5 + 0.5, voxelRightSizeUV, voxelUpSizeUV, voxelDepthSizeUV);
densityMask = SampleVolumeMask(_VolumeData[volumeIndex], voxelCenterUVW, voxelGradRightUVW, voxelGradUpUVW, voxelGradForwardUVW);
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering * scatteringAndExtinctionMask;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction * scatteringAndExtinctionMask;
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering * densityMask;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction * densityMask;
}
#ifndef USE_CLUSTERED_LIGHTLIST

float3 upDirWS = mul(-float3(upCoord, 1), (float3x3)_VBufferCoordToViewDirWS);
// Compute the axes of the voxel. These are not normalized, but rather computed to scale with Z.
// This coordinate system is generally not orthogonal.
float3 voxelAxisForward = centerDirWS;
float3 voxelAxisUp = 0.5 * (upDirWS - centerDirWS);
float3 voxelAxisRight = 0.5 * (centerDirWS - leftDirWS);

97
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.compute


// Definitions
//--------------------------------------------------------------------------------------------------
#pragma kernel VolumetricLightingBruteforce VolumetricLighting=VolumetricLightingBruteforce ENABLE_REPROJECTION=0 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingBruteforceReproj VolumetricLighting=VolumetricLightingBruteforceReproj ENABLE_REPROJECTION=1 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClustered VolumetricLighting=VolumetricLightingClustered ENABLE_REPROJECTION=0 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingClusteredReproj VolumetricLighting=VolumetricLightingClusteredReproj ENABLE_REPROJECTION=1 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingBruteforceMQ VolumetricLighting=VolumetricLightingBruteforceMQ VL_PRESET_MQ ENABLE_REPROJECTION=0 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingBruteforceReprojMQ VolumetricLighting=VolumetricLightingBruteforceReprojMQ VL_PRESET_MQ ENABLE_REPROJECTION=1 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClusteredMQ VolumetricLighting=VolumetricLightingClusteredMQ VL_PRESET_MQ ENABLE_REPROJECTION=0 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingClusteredReprojMQ VolumetricLighting=VolumetricLightingClusteredReprojMQ VL_PRESET_MQ ENABLE_REPROJECTION=1 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingBruteforceHQ VolumetricLighting=VolumetricLightingBruteforceHQ VL_PRESET_HQ ENABLE_REPROJECTION=0 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingBruteforceReprojHQ VolumetricLighting=VolumetricLightingBruteforceReprojHQ VL_PRESET_HQ ENABLE_REPROJECTION=1 LIGHTLOOP_SINGLE_PASS
#pragma kernel VolumetricLightingClusteredHQ VolumetricLighting=VolumetricLightingClusteredHQ VL_PRESET_HQ ENABLE_REPROJECTION=0 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#pragma kernel VolumetricLightingClusteredReprojHQ VolumetricLighting=VolumetricLightingClusteredReprojHQ VL_PRESET_HQ ENABLE_REPROJECTION=1 LIGHTLOOP_TILE_PASS USE_CLUSTERED_LIGHTLIST
#define SHADOW_USE_ONLY_VIEW_BASED_BIASING 1 // We don't use normal biasing as it is not available when doing volumetric
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUMETRIC_LIGHTING
#include "../../ShaderConfig.cs.hlsl"
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET == 1)
#ifdef VL_PRESET_MQ
#define VBUFFER_TILE_SIZE 8
#define VBUFFER_SLICE_COUNT 64
#else
#define VBUFFER_TILE_SIZE 8
#endif
#ifdef VL_PRESET_HQ
#define VBUFFER_TILE_SIZE 4
#define VBUFFER_SLICE_COUNT 128
#define VBUFFER_TILE_SIZE 4
#define SUPPORT_PUNCTUAL_LIGHTS 1 // Punctual lights contribute to fog lighting
#define GROUP_SIZE_1D 8
#define GROUP_SIZE_1D 8
#define SUPPORT_PUNCTUAL_LIGHTS 1 // Punctual lights contribute to fog lighting
#define SHADOW_USE_ONLY_VIEW_BASED_BIASING 1 // We don't use normal biasing as it is not available when doing volumetric
#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0) // Switch between the full and the empty shader
#include "../../ShaderPass/ShaderPass.cs.hlsl"
#define SHADERPASS SHADERPASS_VOLUMETRIC_LIGHTING
//--------------------------------------------------------------------------------------------------
// Included headers

#include "VolumetricLighting.cs.hlsl"
#include "VBuffer.hlsl"
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#define UNITY_MATERIAL_VOLUMETRIC // Define before including Lighting.hlsl and Material.hlsl
#include "../Lighting.hlsl" // Includes Material.hlsl
#include "../LightEvaluation.hlsl"
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch

float3 L = -light.forward; // Lights point backwards in Unity
float3 color; float attenuation;
light.contactShadowIndex = -1; // Disable shadow contact if any
// Note: We provide a normal of 0 here that work with the NdotL >= 0 test inside the EvaluateLight_Punctual call
EvaluateLight_Directional(context, posInput, light, unused, 0, L,
color, attenuation);

float3 coneAxisY = lenMul * light.up;
sampleLight = IntersectRayCone(ray.originWS, ray.jitterDirWS,
light.positionWS, light.forward,
light.positionRWS, light.forward,
coneAxisX, coneAxisY,
t0, t1, tEntr, tExit);
}

float hackMinDistSq = Sq(dt * (0.5 / 7));
float t, distSq, rcpPdf;
ImportanceSamplePunctualLight(rndVal, light.positionWS,
ImportanceSamplePunctualLight(rndVal, light.positionRWS,
ray.originWS, ray.jitterDirWS,
tEntr, tExit, t, distSq, rcpPdf,
hackMinDistSq);

float3 lightToSample = posInput.positionWS - light.positionWS;
float3 lightToSample = posInput.positionWS - light.positionRWS;
float distRcp = rsqrt(distSq);
float dist = distSq * distRcp;
float distProj = dot(lightToSample, light.forward);

float3 color; float attenuation;
light.contactShadowIndex = -1; // Disable shadow contact if any
// Note: We provide a normal of 0 here that work with the NdotL >= 0 test inside the EvaluateLight_Punctual call
0, L, lightToSample, distances, color, attenuation);
0, L, lightToSample, distances,
color, attenuation);
// Important:
// Ideally, all scattering calculations should use the jittered versions

// and any temporal instability of anisotropy causes causes visible jitter.
// In order to stabilize the image, we use the voxel center for all
// anisotropy-related calculations.
float3 centerL = light.positionWS - centerWS;
float3 centerL = light.positionRWS - centerWS;
float cosTheta = dot(centerL, ray.centerDirWS) * rsqrt(dot(centerL, centerL));
float phase = CornetteShanksPhasePartVarying(anisotropy, cosTheta);

// 'light.right' and 'light.up' vectors are pre-scaled on the CPU by (2/w) and (2/h).
float3x3 rotMat = float3x3(light.right, light.up, light.forward);
float3 o = mul(rotMat, ray.originWS - light.positionWS);
float3 o = mul(rotMat, ray.originWS - light.positionRWS);
float3 d = mul(rotMat, ray.jitterDirWS);
float range = light.size.x;

posInput.positionWS = GetPointAtDistance(ray, t);
float3 L = -light.forward;
float3 lightToSample = posInput.positionWS - light.positionWS;
float3 lightToSample = posInput.positionWS - light.positionRWS;
EvaluateLight_Punctual(context, posInput, light, unused,
0, L, lightToSample, distances, color, attenuation);
light.contactShadowIndex = -1; // Disable shadow contact if any
// Note: We provide a normal of 0 here that work with the NdotL >= 0 test inside the EvaluateLight_Punctual call
EvaluateLight_Punctual( context, posInput, light, unused,
0, L, lightToSample, distances,
color, attenuation);
// Important:
// Ideally, all scattering calculations should use the jittered versions

// and any temporal instability of anisotropy causes causes visible jitter.
// In order to stabilize the image, we use the voxel center for all
// anisotropy-related calculations.
float3 centerL = light.positionWS - centerWS;
float3 centerL = light.positionRWS - centerWS;
float cosTheta = dot(centerL, ray.centerDirWS) * rsqrt(dot(centerL, centerL));
float phase = CornetteShanksPhasePartVarying(anisotropy, cosTheta);

PositionInputs posInput, DualRay ray)
{
const float n = _VBufferDepthDecodingParams.x + _VBufferDepthDecodingParams.z;
const float z0 = n; // Start integration from the near plane
const float de = rcp(VBUFFER_SLICE_COUNT); // Log-encoded distance between slices
const float z0 = n; // Start integration from the near plane
const float de = _VBufferSliceCount.y; // Log-encoded distance between slices
float t0 = ConvertLinearDepthToJitterRayDist(ray, z0);

lightClusters[0] = GetLightClusterIndex(posInput.tileCoord, z0);
#endif // USE_CLUSTERED_LIGHTLIST
#if defined(SHADER_API_METAL)
[fastopt]
for (uint slice = 0; slice < VBUFFER_SLICE_COUNT; slice++)
#else
uint sliceCountHack = max(VBUFFER_SLICE_COUNT, (uint)_VBufferDepthEncodingParams.w); // Prevent unrolling...
// TODO: replace 'sliceCountHack' with VBUFFER_SLICE_COUNT when the shader compiler bug is fixed.
for (uint slice = 0; slice < sliceCountHack; slice++)
#endif
for (uint slice = 0; slice < (uint)_VBufferSliceCount.x; slice++)
{
uint3 voxelCoord = uint3(posInput.positionSS, slice);

// TODO
LightLoopContext context;
context.sampleReflection = 0;
context.contactShadow = 1.0;
uint featureFlags = 0xFFFFFFFF;
PositionInputs posInput = GetPositionInput(voxelCoord, _VBufferResolution.zw, tileCoord);

#else
[numthreads(GROUP_SIZE_1D, GROUP_SIZE_1D, 1)]
void VolumetricLighting(uint2 groupId : SV_GroupID,
uint2 groupThreadId : SV_GroupThreadID)
{
// Reduce compile times if the feature is disabled.
}
#endif // SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET

132
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


[GenerateHLSL]
public struct DensityVolumeData
{
public Vector3 scattering; // [0, 1], prefer sRGB
public float extinction;// [0, 1], prefer sRGB
public Vector3 scattering; // [0, 1]
public float extinction; // [0, 1]
public int textureIndex;//
public int textureIndex;
public Vector3 textureScroll;
public static DensityVolumeData GetNeutralValues()

data.scattering = Vector3.zero;
data.extinction = 0;
data.textureIndex = -1;
data.scattering = Vector3.zero;
data.extinction = 0;
data.textureIndex = -1;
data.textureTiling = Vector3.one;
data.textureScroll = Vector3.zero;

public enum VolumetricLightingPreset
{
Off,
Normal,
Ultra,
Medium,
High,
Count
} // enum VolumetricLightingPreset

}
} // struct Parameters
public VolumetricLightingPreset preset { get { return (VolumetricLightingPreset)Math.Min(ShaderConfig.s_VolumetricLightingPreset, (int)VolumetricLightingPreset.Count); } }
public VolumetricLightingPreset preset = VolumetricLightingPreset.Off;
static ComputeShader m_VolumeVoxelizationCS = null;
static ComputeShader m_VolumetricLightingCS = null;

RTHandleSystem.RTHandle m_DensityBufferHandle;
RTHandleSystem.RTHandle m_LightingBufferHandle;
// Do we support volumetric or not?
bool m_supportVolumetric = false;
// Is the feature globally disabled?
bool m_supportVolumetrics = false;
m_supportVolumetric = asset.renderPipelineSettings.supportVolumetric;
m_supportVolumetrics = asset.renderPipelineSettings.supportVolumetrics;
if (!m_supportVolumetric)
if (!m_supportVolumetrics)
preset = asset.renderPipelineSettings.increaseResolutionOfVolumetrics ? VolumetricLightingPreset.High :
VolumetricLightingPreset.Medium;
m_VolumeVoxelizationCS = asset.renderPipelineResources.volumeVoxelizationCS;
m_VolumetricLightingCS = asset.renderPipelineResources.volumetricLightingCS;

{
// Note: Here we can't test framesettings as they are not initialize yet
// TODO: Here we allocate history even for camera that may not use volumetric
if (!m_supportVolumetric)
if (!m_supportVolumetrics)
return;
// Start with the same parameters for both frames. Then update them one by one every frame.

// The results are undefined otherwise.
public void UpdatePerCameraData(HDCamera hdCamera)
{
if (!hdCamera.frameSettings.enableVolumetric)
if (!hdCamera.frameSettings.enableVolumetrics)
return;
var parameters = ComputeVBufferParameters(hdCamera, false);

{
switch (preset)
{
case VolumetricLightingPreset.Normal:
case VolumetricLightingPreset.Medium:
case VolumetricLightingPreset.Ultra:
case VolumetricLightingPreset.High:
return 4;
case VolumetricLightingPreset.Off:
return 0;

{
switch (preset)
{
case VolumetricLightingPreset.Normal:
case VolumetricLightingPreset.Medium:
case VolumetricLightingPreset.Ultra:
case VolumetricLightingPreset.High:
return 128;
case VolumetricLightingPreset.Off:
return 0;

return depthParams;
}
void SetPreconvolvedAmbientLightProbe(CommandBuffer cmd, float anisotropy)
void SetPreconvolvedAmbientLightProbe(CommandBuffer cmd, float dimmer, float anisotropy)
probeSH = SphericalHarmonicMath.RescaleCoefficients(probeSH, dimmer);
ZonalHarmonicsL2 phaseZH = ZonalHarmonicsL2.GetCornetteShanksPhaseFunction(anisotropy);
SphericalHarmonicsL2 finalSH = SphericalHarmonicMath.PremultiplyCoefficients(SphericalHarmonicMath.Convolve(probeSH, phaseZH));

public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex)
{
if (!hdCamera.frameSettings.enableVolumetric)
return;
if (visualEnvironment.fogType != FogType.Volumetric)
if (!hdCamera.frameSettings.enableVolumetrics || visualEnvironment.fogType != FogType.Volumetric)
{
// Set the neutral black texture.
cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, CoreUtils.blackVolumeTexture);

// Get the interpolated anisotropy value.
var fog = VolumeManager.instance.stack.GetComponent<VolumetricFog>();
SetPreconvolvedAmbientLightProbe(cmd, fog.anisotropy);
SetPreconvolvedAmbientLightProbe(cmd, fog.globalLightProbeDimmer, fog.anisotropy);
var currFrameParams = hdCamera.vBufferParams[0];
var prevFrameParams = hdCamera.vBufferParams[1];

{
DensityVolumeList densityVolumes = new DensityVolumeList();
if (!hdCamera.frameSettings.enableVolumetric)
if (!hdCamera.frameSettings.enableVolumetrics)
return densityVolumes;
var visualEnvironment = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();

public void VolumeVoxelizationPass(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex, DensityVolumeList densityVolumes)
{
if (!hdCamera.frameSettings.enableVolumetric)
if (!hdCamera.frameSettings.enableVolumetrics)
return;
var visualEnvironment = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();

{
int numVisibleVolumes = m_VisibleVolumeBounds.Count;
if (numVisibleVolumes == 0)
{
// Clear the render target instead of running the shader.
// Note: the clear must take the global fog into account!
// CoreUtils.SetRenderTarget(cmd, vBuffer.GetDensityBuffer(), ClearFlag.Color, CoreUtils.clearColorAllBlack);
// return;
// Clearing 3D textures does not seem to work!
// Use the workaround by running the full shader with 0 density
}
bool highQuality = preset == VolumetricLightingPreset.High;
int kernel = m_VolumeVoxelizationCS.FindKernel(enableClustered ? "VolumeVoxelizationClustered"
: "VolumeVoxelizationBruteforce");
int kernel;
if (highQuality)
{
kernel = m_VolumeVoxelizationCS.FindKernel(enableClustered ? "VolumeVoxelizationClusteredHQ"
: "VolumeVoxelizationBruteforceHQ");
}
else
{
kernel = m_VolumeVoxelizationCS.FindKernel(enableClustered ? "VolumeVoxelizationClusteredMQ"
: "VolumeVoxelizationBruteforceMQ");
}
var frameParams = hdCamera.vBufferParams[0];
Vector4 resolution = frameParams.resolution;

Matrix4x4 transform = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(vFoV, resolution, hdCamera.viewMatrix, false);
Texture3D volumeAtlas = DensityVolumeManager.manager.volumeAtlas.volumeAtlas;
Vector3 volumeAtlasDimensions = new Vector3(0.0f, 0.0f, 0.0f);
Vector4 volumeAtlasDimensions = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
volumeAtlasDimensions.x = volumeAtlas.width / volumeAtlas.depth; // 1 / number of textures
volumeAtlasDimensions.y = 1.0f / volumeAtlas.width;
volumeAtlasDimensions.z = volumeAtlas.width;
volumeAtlasDimensions.x = (float)volumeAtlas.width / volumeAtlas.depth; // 1 / number of textures
volumeAtlasDimensions.y = volumeAtlas.width;
volumeAtlasDimensions.z = volumeAtlas.depth;
volumeAtlasDimensions.w = Mathf.Log(volumeAtlas.width, 2); // Max LoD
}
else
{
volumeAtlas = CoreUtils.blackVolumeTexture;
}
cmd.SetComputeTextureParam(m_VolumeVoxelizationCS, kernel, HDShaderIDs._VBufferDensity, m_DensityBufferHandle);

public void VolumetricLightingPass(HDCamera hdCamera, CommandBuffer cmd, uint frameIndex)
{
if (!hdCamera.frameSettings.enableVolumetric)
if (!hdCamera.frameSettings.enableVolumetrics)
return;
var visualEnvironment = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();

using (new ProfilingSample(cmd, "Volumetric Lighting"))
{
// Only available in the Play Mode because all the frame counters in the Edit Mode are broken.
bool highQuality = preset == VolumetricLightingPreset.High;
if (enableReprojection)
if (highQuality)
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredReproj"
: "VolumetricLightingBruteforceReproj");
if (enableReprojection)
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredReprojHQ"
: "VolumetricLightingBruteforceReprojHQ");
}
else
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredHQ"
: "VolumetricLightingBruteforceHQ");
}
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClustered"
: "VolumetricLightingBruteforce");
if (enableReprojection)
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredReprojMQ"
: "VolumetricLightingBruteforceReprojMQ");
}
else
{
kernel = m_VolumetricLightingCS.FindKernel(enableClustered ? "VolumetricLightingClusteredMQ"
: "VolumetricLightingBruteforceMQ");
}
}
var frameParams = hdCamera.vBufferParams[0];

// TODO: set 'm_VolumetricLightingPreset'.
// TODO: set the constant buffer data only once.
cmd.SetComputeMatrixParam(m_VolumetricLightingCS, HDShaderIDs._VBufferCoordToViewDirWS, transform);
cmd.SetComputeVectorParam(m_VolumetricLightingCS, HDShaderIDs._VBufferSampleOffset, offset);
cmd.SetComputeFloatParam(m_VolumetricLightingCS, HDShaderIDs._CornetteShanksConstant, CornetteShanksPhasePartConstant(fog.anisotropy));
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferDensity, m_DensityBufferHandle);// Read
cmd.SetComputeMatrixParam( m_VolumetricLightingCS, HDShaderIDs._VBufferCoordToViewDirWS, transform);
cmd.SetComputeVectorParam( m_VolumetricLightingCS, HDShaderIDs._VBufferSampleOffset, offset);
cmd.SetComputeFloatParam( m_VolumetricLightingCS, HDShaderIDs._CornetteShanksConstant, CornetteShanksPhasePartConstant(fog.anisotropy));
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferDensity, m_DensityBufferHandle); // Read
cmd.SetComputeTextureParam(m_VolumetricLightingCS, kernel, HDShaderIDs._VBufferLightingIntegral, m_LightingBufferHandle); // Write
if (enableReprojection)
{

4
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs


sRGBFlags = m_sRGBFlags;
}
}
// normal to world only uses 3x3 for actual matrix so some data is packed in the unused space
// blend:
// float decalBlend = decalData.normalToWorld[0][3];

// float2 uvScale = float2(decalData.normalToWorld[3][0], decalData.normalToWorld[3][1]);
// float2 uvBias = float2(decalData.normalToWorld[3][2], decalData.normalToWorld[3][3]);
[GenerateHLSL]
[GenerateHLSL(PackingRules.Exact, false)]
public struct DecalData
{
public Matrix4x4 worldToDecal;

28
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/Decal.cs.hlsl


};
//
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DecalData
//
float4x4 GetWorldToDecal(DecalData value)
{
return value.worldToDecal;
}
float4x4 GetNormalToWorld(DecalData value)
{
return value.normalToWorld;
}
float4 GetDiffuseScaleBias(DecalData value)
{
return value.diffuseScaleBias;
}
float4 GetNormalScaleBias(DecalData value)
{
return value.normalScaleBias;
}
float4 GetMaskScaleBias(DecalData value)
{
return value.maskScaleBias;
}
float4 GetBaseColor(DecalData value)
{
return value.baseColor;
}
//
// Debug functions
//
void GetGeneratedDecalSurfaceDataDebug(uint paramId, DecalSurfaceData decalsurfacedata, inout float3 result, inout bool needLinearToSRGB)

15
com.unity.render-pipelines.high-definition/HDRP/Material/Decal/DecalUtilities.hlsl


decalStart = 0;
#endif
float3 positionWS = GetAbsolutePositionWS(posInput.positionWS);
float3 positionRWS = posInput.positionWS;
float3 positionWSDdx = ddx(positionWS);
float3 positionWSDdy = ddy(positionWS);
float3 positionRWSDdx = ddx(positionRWS);
float3 positionRWSDdy = ddy(positionRWS);
float3 positionDS = mul(decalData.worldToDecal, float4(positionWS, 1.0)).xyz;
// Get the relative world camera to decal matrix
float4x4 worldToDecal = ApplyCameraTranslationToInverseMatrix(decalData.worldToDecal);
float3 positionDS = mul(worldToDecal, float4(positionRWS, 1.0)).xyz;
positionDS = positionDS * float3(1.0, -1.0, 1.0) + float3(0.5, 0.0f, 0.5); // decal clip space
if ((all(positionDS.xyz > 0.0f) && all(1.0f - positionDS.xyz > 0.0f)))
{

float2 sampleMask = clamp(positionDS.xz * decalData.maskScaleBias.xy + decalData.maskScaleBias.zw, maskMin, maskMax);
// need to compute the mipmap LOD manually because we are sampling inside a loop
float3 positionDSDdx = mul(decalData.worldToDecal, float4(positionWSDdx, 0.0)).xyz; // transform the derivatives to decal space, any translation is irrelevant
float3 positionDSDdy = mul(decalData.worldToDecal, float4(positionWSDdy, 0.0)).xyz;
float3 positionDSDdx = mul(worldToDecal, float4(positionRWSDdx, 0.0)).xyz; // transform the derivatives to decal space, any translation is irrelevant
float3 positionDSDdy = mul(worldToDecal, float4(positionRWSDdy, 0.0)).xyz;
float2 sampleDiffuseDdx = positionDSDdx.xz * decalData.diffuseScaleBias.xy; // factor in the atlas scale
float2 sampleDiffuseDdy = positionDSDdy.xz * decalData.diffuseScaleBias.xy;

2
com.unity.render-pipelines.high-definition/HDRP/Material/GGXConvolution/RuntimeFilterIBL.cs


if (!m_GgxIblSampleData)
{
m_GgxIblSampleData = new RenderTexture(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
m_GgxIblSampleData = new RenderTexture(m_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
m_GgxIblSampleData.useMipMap = false;
m_GgxIblSampleData.autoGenerateMips = false;
m_GgxIblSampleData.enableRandomWrite = true;

22
com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LTCAreaLight.cs


int m_refCounting;
// For area lighting - We pack all texture inside a texture array to reduce the number of resource required
Texture2DArray m_LtcData; // 0: m_LtcGGXMatrix - RGBA, 2: m_LtcDisneyDiffuseMatrix - RGBA, 3: m_LtcMultiGGXFresnelDisneyDiffuse - RGB, A unused
Texture2DArray m_LtcData; // 0: m_LtcGGXMatrix - RGBA, 1: m_LtcDisneyDiffuseMatrix - RGBA
const int k_LtcLUTMatrixDim = 3; // size of the matrix (3x3)
const int k_LtcLUTResolution = 64;

tex.SetPixels(pixels, arrayElement);
}
// Special-case function for 'm_LtcMultiGGXFresnelDisneyDiffuse'.
void LoadLUT(Texture2DArray tex, int arrayElement, TextureFormat format, float[] LtcGGXMagnitudeData, float[] LtcGGXFresnelData, float[] LtcDisneyDiffuseMagnitudeData)
{
const int count = k_LtcLUTResolution * k_LtcLUTResolution;
Color[] pixels = new Color[count];
for (int i = 0; i < count; i++)
{
// We store the result of the subtraction as a run-time optimization.
// See the footnote 2 of "LTC Fresnel Approximation" by Stephen Hill.
pixels[i] = new Color(LtcGGXMagnitudeData[i] - LtcGGXFresnelData[i], LtcGGXFresnelData[i], LtcDisneyDiffuseMagnitudeData[i], 1);
}
tex.SetPixels(pixels, arrayElement);
}
public void Build()
{
Debug.Assert(m_refCounting >= 0);

hideFlags = HideFlags.HideAndDontSave,
wrapMode = TextureWrapMode.Clamp,
filterMode = FilterMode.Bilinear,
name = CoreUtils.GetTextureAutoName(k_LtcLUTResolution, k_LtcLUTResolution, TextureFormat.RGBAHalf, depth: 3, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
name = CoreUtils.GetTextureAutoName(k_LtcLUTResolution, k_LtcLUTResolution, TextureFormat.RGBAHalf, depth: 2, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
// TODO: switch to RGBA64 when it becomes available.
LoadLUT(m_LtcData, 2, TextureFormat.RGBAHalf, s_LtcGGXMagnitudeData, s_LtcGGXFresnelData, s_LtcDisneyDiffuseMagnitudeData);
m_LtcData.Apply();
}

1
com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LTCAreaLight.hlsl


#define LTC_GGX_MATRIX_INDEX 0 // RGBA
#define LTC_DISNEY_DIFFUSE_MATRIX_INDEX 1 // RGBA
#define LTC_MULTI_GGX_FRESNEL_DISNEY_DIFFUSE_INDEX 2 // RGB, A unused
#define LTC_LUT_SIZE 64
#define LTC_LUT_SCALE ((LTC_LUT_SIZE - 1) * rcp(LTC_LUT_SIZE))

998
com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LtcData.DisneyDiffuse.cs
文件差异内容过多而无法显示
查看文件

992
com.unity.render-pipelines.high-definition/HDRP/Material/LTCAreaLight/LtcData.GGX.cs
文件差异内容过多而无法显示
查看文件

2
com.unity.render-pipelines.high-definition/HDRP/Material/LayeredLit/LayeredLitData.hlsl


#endif
GetLayerTexCoord( input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord);
input.positionRWS, input.worldToTangent[2].xyz, layerTexCoord);
}
void ApplyDisplacementTileScale(inout float height0, inout float height1, inout float height2, inout float height3)

521
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl


//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "../SubsurfaceScattering/SubsurfaceScattering.hlsl"
#include "../NormalBuffer.hlsl"
// Those define allow to include desired SSS/Transmission functions
#define MATERIAL_INCLUDE_SUBSURFACESCATTERING
#define MATERIAL_INCLUDE_TRANSMISSION
#include "HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl"
#include "HDRP/Material/NormalBuffer.hlsl"
// Configuration
//-----------------------------------------------------------------------------
// Choose between Lambert diffuse and Disney diffuse (enable only one of them)
// #define USE_DIFFUSE_LAMBERT_BRDF
#define LIT_USE_GGX_ENERGY_COMPENSATION
// Enable reference mode for IBL and area lights
// Both reference define below can be define only if LightLoop is present, else we get a compile error
#ifdef HAS_LIGHTLOOP
// #define LIT_DISPLAY_REFERENCE_AREA
// #define LIT_DISPLAY_REFERENCE_IBL
#endif
// In forward we can chose between reading the normal from the normalBufferTexture or computing it again
// This is tradeoff between performance and quality. As we store the normal conpressed, recomputing again is higher quality.
// Uncomment this to get speed (to measure), let it comment to get quality
// #define FORWARD_MATERIAL_READ_FROM_WRITTEN_NORMAL_BUFFER
//-----------------------------------------------------------------------------
// Texture and constant buffer declaration
//-----------------------------------------------------------------------------

TEXTURE2D(_GBufferTexture2);
TEXTURE2D(_GBufferTexture3);
#include "../LTCAreaLight/LTCAreaLight.hlsl"
#include "../PreIntegratedFGD/PreIntegratedFGD.hlsl"
#include "HDRP/Material/LTCAreaLight/LTCAreaLight.hlsl"
#include "HDRP/Material/PreIntegratedFGD/PreIntegratedFGD.hlsl"
//-----------------------------------------------------------------------------
// Definition

#define CLEAR_COAT_PERCEPTUAL_ROUGHNESS RoughnessToPerceptualRoughness(CLEAR_COAT_ROUGHNESS)
//-----------------------------------------------------------------------------
// Configuration
//-----------------------------------------------------------------------------
// Choose between Lambert diffuse and Disney diffuse (enable only one of them)
// #define LIT_DIFFUSE_LAMBERT_BRDF
#define LIT_USE_GGX_ENERGY_COMPENSATION
// Enable reference mode for IBL and area lights
// Both reference define below can be define only if LightLoop is present, else we get a compile error
#ifdef HAS_LIGHTLOOP
// #define LIT_DISPLAY_REFERENCE_AREA
// #define LIT_DISPLAY_REFERENCE_IBL
#endif
// In forward we can chose between reading the normal from the normalBufferTexture or computing it again
// This is tradeoff between performance and quality. As we store the normal conpressed, recomputing again is higher quality.
// Uncomment this to get speed (to measure), let it comment to get quality
// #define FORWARD_MATERIAL_READ_FROM_WRITTEN_NORMAL_BUFFER
//-----------------------------------------------------------------------------
// Ligth and material classification for the deferred rendering path
// Light and material classification for the deferred rendering path
// Configure what kind of combination is supported
//-----------------------------------------------------------------------------

/* 26 */ LIGHT_FEATURE_MASK_FLAGS_OPAQUE | MATERIAL_FEATURE_MASK_FLAGS, // Catch all case with MATERIAL_FEATURE_MASK_FLAGS is needed in case we disable material classification
};
// Additional bits set in 'bsdfData.materialFeatures' to save registers and simplify feature tracking.
#define MATERIAL_FEATURE_FLAGS_SSS_OUTPUT_SPLIT_LIGHTING ((MATERIAL_FEATURE_MASK_FLAGS + 1) << 0)
#define MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET FastLog2((MATERIAL_FEATURE_MASK_FLAGS + 1) << 1) // 2 bits
#define MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS ((MATERIAL_FEATURE_MASK_FLAGS + 1) << 3)
uint FeatureFlagsToTileVariant(uint featureFlags)
{
for (int i = 0; i < NUM_FEATURE_VARIANTS; i++)

#endif
#endif
// This method allows us to know at compile time what material features should be removed from the code by Tile (Indepenently of the value of material feature flag per pixel).
// This is only useful for classification during lighting, so it's not needed in EncodeIntoGBuffer and ConvertSurfaceDataToBSDFData (where we always know exactly what the material feature is)
bool HasFeatureFlag(uint featureFlags, uint flag)
{
return ((featureFlags & flag) != 0);
}
// Assume that bsdfData.diffusionProfile is init
void FillMaterialSSS(uint diffusionProfile, float subsurfaceMask, inout BSDFData bsdfData)
{
bsdfData.diffusionProfile = diffusionProfile;
bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[diffusionProfile].a;
bsdfData.subsurfaceMask = subsurfaceMask;
bsdfData.materialFeatures |= MATERIAL_FEATURE_FLAGS_SSS_OUTPUT_SPLIT_LIGHTING;
bsdfData.materialFeatures |= GetSubsurfaceScatteringTexturingMode(bsdfData.diffusionProfile) << MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET;
}
// Assume that bsdfData.diffusionProfile is init
void FillMaterialTransmission(uint diffusionProfile, float thickness, inout BSDFData bsdfData)
{
bsdfData.diffusionProfile = diffusionProfile;
bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[diffusionProfile].a;
bsdfData.thickness = _ThicknessRemaps[diffusionProfile].x + _ThicknessRemaps[diffusionProfile].y * thickness;
// The difference between the thin and the regular (a.k.a. auto-thickness) modes is the following:
// * in the thin object mode, we assume that the geometry is thin enough for us to safely share
// the shadowing information between the front and the back faces;
// * the thin mode uses baked (textured) thickness for all transmission calculations;
// * the thin mode uses wrapped diffuse lighting for the NdotL;
// * the auto-thickness mode uses the baked (textured) thickness to compute transmission from
// indirect lighting and non-shadow-casting lights; for shadowed lights, it calculates
// the thickness using the distance to the closest occluder sampled from the shadow map.
// If the distance is large, it may indicate that the closest occluder is not the back face of
// the current object. That's not a problem, since large thickness will result in low intensity.
bool useThinObjectMode = IsBitSet(asuint(_TransmissionFlags), diffusionProfile);
bsdfData.materialFeatures |= useThinObjectMode ? 0 : MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS;
// Compute transmittance using baked thickness here. It may be overridden for direct lighting
// in the auto-thickness mode (but is always be used for indirect lighting).
#if SHADEROPTIONS_USE_DISNEY_SSS
bsdfData.transmittance = ComputeTransmittanceDisney(_ShapeParams[diffusionProfile].rgb,
_TransmissionTintsAndFresnel0[diffusionProfile].rgb,
bsdfData.thickness);
#else
bsdfData.transmittance = ComputeTransmittanceJimenez(_HalfRcpVariancesAndWeights[diffusionProfile][0].rgb,
_HalfRcpVariancesAndWeights[diffusionProfile][0].a,
_HalfRcpVariancesAndWeights[diffusionProfile][1].rgb,
_HalfRcpVariancesAndWeights[diffusionProfile][1].a,
_TransmissionTintsAndFresnel0[diffusionProfile].rgb,
bsdfData.thickness);
#endif
}
// Assume bsdfData.normalWS is init
void FillMaterialAnisotropy(float anisotropy, float3 tangentWS, float3 bitangentWS, inout BSDFData bsdfData)
{

#endif
// There is no metallic with SSS and specular color mode
float metallic = HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR | MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION) ? 0.0 : surfaceData.metallic;
float metallic = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR | MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION) ? 0.0 : surfaceData.metallic;
bsdfData.fresnel0 = HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR) ? surfaceData.specularColor : ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, DEFAULT_SPECULAR_VALUE);
bsdfData.fresnel0 = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR) ? surfaceData.specularColor : ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, DEFAULT_SPECULAR_VALUE);
// Note: we have ZERO_INITIALIZE the struct so bsdfData.anisotropy == 0.0
// Note: DIFFUSION_PROFILE_NEUTRAL_ID is 0

// The UI is in charge of setuping the constrain, not the code. So if users is forward only and want unleash power, it is easy to unleash by some UI change
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
// Modify perceptualRoughness
FillMaterialClearCoatData(surfaceData.coatMask, bsdfData);

// RT2 - 8:8:8:8
uint materialFeatureId;
if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
{
// Reminder that during GBuffer pass we know statically material materialFeatures
if ((surfaceData.materialFeatures & (MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION)) == (MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION))

// It allows us to delay reading the G-Buffer 0 until the end of the deferred lighting shader.
outGBuffer2.rgb = float3(surfaceData.specularOcclusion, surfaceData.thickness, outGBuffer0.a);
}
else if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
else if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
materialFeatureId = GBUFFER_LIT_ANISOTROPIC;

sinOrCos,
PackFloatInt8bit(surfaceData.metallic, storeSin | quadrant, 8));
}
else if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
else if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
{
materialFeatureId = GBUFFER_LIT_IRIDESCENCE;

float3 diffuseColor = surfaceData.baseColor;
float3 fresnel0 = surfaceData.specularColor;
if (!HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR))
if (!HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR))
{
// Convert from the metallic parametrization.
diffuseColor = ComputeDiffuseColor(surfaceData.baseColor, surfaceData.metallic);

}
// Ensure that surfaceData.coatMask is 0 if the feature is not enabled
float coatMask = HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT) ? surfaceData.coatMask : 0.0;
float coatMask = HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT) ? surfaceData.coatMask : 0.0;
// Note: no need to store MATERIALFEATUREFLAGS_LIT_STANDARD, always present
outGBuffer2.a = PackFloatInt8bit(coatMask, materialFeatureId, 8);

bakeDiffuseLighting = inGBuffer3.rgb;
// Decompress feature-specific data from the G-Buffer.
bool pixelHasMetallic = HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE);
bool pixelHasMetallic = HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY | MATERIALFEATUREFLAGS_LIT_IRIDESCENCE);
if (pixelHasMetallic)
{

bsdfData.fresnel0 = FastSRGBToLinear(inGBuffer2.rgb); // Later possibly overwritten by SSS
}
if (HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
{
SSSData sssData;

// in case one feature is enabled and not the other.
// The neutral value of subsurfaceMask is 0 (handled by ZERO_INITIALIZE).
if (HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
if (HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
if (HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
{
FillMaterialTransmission(sssData.diffusionProfile, inGBuffer2.g, bsdfData);
}

// Special handling for anisotropy: When anisotropy is present in a tile, the whole tile will use anisotropy to avoid divergent evaluation of GGX that increase the cost
// Note that it mean that when we have the worse case, we always use Anisotropy and shader like deferred.shader are always the worst case (but only used for debugging)
if (HasFeatureFlag(tileFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFlag(tileFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
anisotropy = inGBuffer2.r * 2.0 - 1.0;

}
// The neutral value of iridescenceMask is 0 (handled by ZERO_INITIALIZE).
if (HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFeatureFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(pixelFeatureFlags, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
// Modify perceptualRoughness
FillMaterialClearCoatData(coatMask, bsdfData);

float energyCompensation;
// IBL
float3 iblR; // Dominant specular direction, used for IBL in EvaluateBSDF_Env()
float3 iblR; // Reflected specular direction, used for IBL in EvaluateBSDF_Env()
float3 specularFGD; // Store preconvoled BRDF for both specular and diffuse
float3 specularFGD; // Store preintegrated BSDF for both specular and diffuse
float diffuseFGD;
// Area lights (17 VGPRs)

float3x3 ltcTransformSpecular; // Inverse transformation for GGX (4x VGPRs)
float ltcMagnitudeDiffuse;
float3 ltcMagnitudeFresnel;
// Clear coat
float coatPartLambdaV;

float ltcMagnitudeCoatFresnel;
#if HAS_REFRACTION
// Refraction

float NdotV = ClampNdotV(preLightData.NdotV);
// We modify the bsdfData.fresnel0 here for iridescence
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
topIor = lerp(1.0, CLEAR_COAT_IOR, bsdfData.coatMask);
// HACK: Use the reflected direction to specify the Fresnel coefficient for pre-convolved envmaps

}
// We modify the bsdfData.fresnel0 here for clearCoat
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
// Fresnel0 is deduced from interface between air and material (Assume to be 1.5 in Unity, or a metal).
// but here we go from clear coat (1.5) to material, we need to update fresnel0

preLightData.coatIblF = F_Schlick(CLEAR_COAT_F0, NdotV) * bsdfData.coatMask;
}
float3 iblN, iblR;
// We avoid divergent evaluation of the GGX, as that nearly doubles the cost.
// If the tile has anisotropy, all the pixels within the tile are evaluated as anisotropic.
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
float TdotV = dot(bsdfData.tangentWS, V);
float BdotV = dot(bsdfData.bitangentWS, V);
preLightData.partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, NdotV, bsdfData.roughnessT, bsdfData.roughnessB);
// For GGX aniso and IBL we have done an empirical (eye balled) approximation compare to the reference.
// We use a single fetch, and we stretch the normal to use based on various criteria.
// result are far away from the reference but better than nothing
// For positive anisotropy values: tangent = highlight stretch (anisotropy) direction, bitangent = grain (brush) direction.
float3 grainDirWS = (bsdfData.anisotropy >= 0.0) ? bsdfData.bitangentWS : bsdfData.tangentWS;
// Reduce stretching for (perceptualRoughness < 0.2).
float stretch = abs(bsdfData.anisotropy) * saturate(5 * preLightData.iblPerceptualRoughness);
// NOTE: If we follow the theory we should use the modified normal for the different calculation implying a normal (like NdotV) and use 'anisoIblNormalWS'
// into function like GetSpecularDominantDir(). However modified normal is just a hack. The goal is just to stretch a cubemap, no accuracy here.
// With this in mind and for performance reasons we chose to only use modified normal to calculate R.
iblN = GetAnisotropicModifiedNormal(grainDirWS, N, V, stretch);
}
else
{
preLightData.partLambdaV = GetSmithJointGGXPartLambdaV(NdotV, bsdfData.roughnessT);
iblN = N;
}
// IBL
// Handle IBL + multiscattering
// Handle IBL + area light + multiscattering.
// Note: use the not modified by anisotropy iblPerceptualRoughness here.
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
#ifdef USE_DIFFUSE_LAMBERT_BRDF
iblR = reflect(-V, iblN);
// This is a ad-hoc tweak to better match reference of anisotropic GGX.
// TODO: We need a better hack.
preLightData.iblPerceptualRoughness *= saturate(1.2 - abs(bsdfData.anisotropy));
// Corretion of reflected direction for better handling of rough material
preLightData.iblR = iblR;
#ifdef LIT_USE_GGX_ENERGY_COMPENSATION
// Ref: Practical multiple scattering compensation for microfacet models.
// We only apply the formulation for metals.

preLightData.energyCompensation = 0.0;
#endif // LIT_USE_GGX_ENERGY_COMPENSATION
float3 iblN;
// We avoid divergent evaluation of the GGX, as that nearly doubles the cost.
// If the tile has anisotropy, all the pixels within the tile are evaluated as anisotropic.
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
float TdotV = dot(bsdfData.tangentWS, V);
float BdotV = dot(bsdfData.bitangentWS, V);
preLightData.partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, NdotV, bsdfData.roughnessT, bsdfData.roughnessB);
// perceptualRoughness is use as input and output here
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS, N, V, bsdfData.anisotropy, preLightData.iblPerceptualRoughness, iblN, preLightData.iblPerceptualRoughness);
}
else
{
preLightData.partLambdaV = GetSmithJointGGXPartLambdaV(NdotV, bsdfData.roughnessT);
iblN = N;
}
preLightData.iblR = reflect(-V, iblN);
// Area light
// UVs for sampling the LUTs
float theta = FastACosPos(NdotV); // For Area light - UVs for sampling the LUTs

#ifdef LIT_DIFFUSE_LAMBERT_BRDF
#ifdef USE_DIFFUSE_LAMBERT_BRDF
preLightData.ltcTransformDiffuse = k_identity3x3;
#else
// Get the inverse LTC matrix for Disney Diffuse

preLightData.orthoBasisViewNormal[2] = N;
preLightData.orthoBasisViewNormal[1] = cross(preLightData.orthoBasisViewNormal[2], preLightData.orthoBasisViewNormal[0]);
float3 ltcMagnitude = SAMPLE_TEXTURE2D_ARRAY_LOD(_LtcData, s_linear_clamp_sampler, uv, LTC_MULTI_GGX_FRESNEL_DISNEY_DIFFUSE_INDEX, 0).rgb;
float ltcGGXFresnelMagnitudeDiff = ltcMagnitude.r; // The difference of magnitudes of GGX and Fresnel
float ltcGGXFresnelMagnitude = ltcMagnitude.g;
float ltcDisneyDiffuseMagnitude = ltcMagnitude.b;
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
preLightData.ltcMagnitudeDiffuse = 1;
#else
preLightData.ltcMagnitudeDiffuse = ltcDisneyDiffuseMagnitude;
#endif
// TODO: the fit seems rather poor. The scaling factor of 0.5 allows us
// to match the reference for rough metals, but further darkens dielectrics.
preLightData.ltcMagnitudeFresnel = bsdfData.fresnel0 * ltcGGXFresnelMagnitudeDiff + (float3)ltcGGXFresnelMagnitude;
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
preLightData.ltcTransformCoat = 0.0;
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
preLightData.ltcTransformCoat = 0.0;
ltcMagnitude = SAMPLE_TEXTURE2D_ARRAY_LOD(_LtcData, s_linear_clamp_sampler, uv, LTC_MULTI_GGX_FRESNEL_DISNEY_DIFFUSE_INDEX, 0).rgb;
ltcGGXFresnelMagnitudeDiff = ltcMagnitude.r; // The difference of magnitudes of GGX and Fresnel
ltcGGXFresnelMagnitude = ltcMagnitude.g;
preLightData.ltcMagnitudeCoatFresnel = (CLEAR_COAT_F0 * ltcGGXFresnelMagnitudeDiff + ltcGGXFresnelMagnitude) * bsdfData.coatMask;
}
else
{
preLightData.ltcTransformCoat = 0.0;
preLightData.ltcMagnitudeCoatFresnel = 0.0;
}
// refraction (forward only)

// This function require the 3 structure surfaceData, builtinData, bsdfData because it may require both the engine side data, and data that will not be store inside the gbuffer.
float3 GetBakedDiffuseLighting(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData, PreLightData preLightData)
{
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
{
uint texturingMode = (bsdfData.materialFeatures >> MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET) & 3;
bsdfData.diffuseColor = ApplySubsurfaceScatteringTexturingMode(texturingMode, bsdfData.diffuseColor);
}
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
{

#endif
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING)) // This test is static as it is done in GBuffer or forward pass, will be remove by compiler
{
bsdfData.diffuseColor = GetModifiedDiffuseColorForSSS(bsdfData); // local modification of bsdfData
}
// Premultiply bake diffuse lighting information with DisneyDiffuse pre-integration
return builtinData.bakeDiffuseLighting * preLightData.diffuseFGD * surfaceData.ambientOcclusion * bsdfData.diffuseColor + builtinData.emissiveColor;

}
//-----------------------------------------------------------------------------
// Subsurface Scattering functions
//-----------------------------------------------------------------------------
bool ShouldOutputSplitLighting(BSDFData bsdfData)
{
return HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_SSS_OUTPUT_SPLIT_LIGHTING);
}
//-----------------------------------------------------------------------------
// LightLoop related function (Only include if required)
// HAS_LIGHTLOOP is define in Lighting.hlsl
//-----------------------------------------------------------------------------

#ifndef _SURFACE_TYPE_TRANSPARENT
// For /Lighting/LightEvaluation.hlsl:
#define USE_DEFERRED_DIRECTIONAL_SHADOWS // Deferred shadows are always enabled for opaque objects
#endif

// Instead we use the incorrect angle NdotV as an approximation for LdotH for Fresnel evaluation.
// The Fresnel with iridescence and NDotV angle is precomputed ahead and here we jsut reuse the result.
// Thus why we shouldn't apply a second time Fresnel on the value if iridescence is enabled.
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_IRIDESCENCE))
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
float3 H = (L + V) * invLenLV;

}
specularLighting = F * DV;
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
#ifdef USE_DIFFUSE_LAMBERT_BRDF
float diffuseTerm = Lambert();
#else
// A note on subsurface scattering: [SSS-NOTE-TRSM]

// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
diffuseLighting = diffuseTerm;
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
// Apply isotropic GGX for clear coat
// Note: coat F is scalar as it is a dieletric

}
}
// Currently, we only model diffuse transmission. Specular transmission is not yet supported.
// Transmitted lighting is computed as follows:
// - we assume that the object is a thick plane (slab);
// - we reverse the front-facing normal for the back of the object;
// - we assume that the incoming radiance is constant along the entire back surface;
// - we apply BSDF-specific diffuse transmission to transmit the light subsurface and back;
// - we integrate the diffuse reflectance profile w.r.t. the radius (while also accounting
// for the thickness) to compute the transmittance;
// - we multiply the transmitted radiance by the transmittance.
float3 EvaluateTransmission(BSDFData bsdfData, float3 transmittance, float NdotL, float NdotV, float LdotV, float attenuation)
{
// Apply wrapped lighting to better handle thin objects at grazing angles.
float wrappedNdotL = ComputeWrappedDiffuseLighting(-NdotL, SSS_WRAP_LIGHT);
// Apply BSDF-specific diffuse transmission to attenuation. See also: [SSS-NOTE-TRSM]
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
attenuation *= Lambert();
#else
attenuation *= DisneyDiffuse(NdotV, max(0, -NdotL), LdotV, bsdfData.perceptualRoughness);
#endif
float intensity = attenuation * wrappedNdotL;
return intensity * transmittance;
}
//-----------------------------------------------------------------------------
// EvaluateBSDF_Directional
//-----------------------------------------------------------------------------

DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 N = bsdfData.normalWS;
float3 L = -lightData.forward; // Lights point backward in Unity
float NdotV = ClampNdotV(preLightData.NdotV);
float NdotL = dot(N, L);
float LdotV = dot(L, V);
float3 L = -lightData.forward;
float3 N = bsdfData.normalWS;
float NdotL = dot(N, L);
float3 transmittance = float3(0.0, 0.0, 0.0);
if (HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS))
{
// Caution: This function modify N and contactShadowIndex
transmittance = PreEvaluateDirectionalLightTransmission(NdotL, lightData, bsdfData, N, lightData.contactShadowIndex); // contactShadowIndex is only modify for the code of this function
}
float3 color;
float attenuation;

}
// The mixed thickness mode is not supported by directional lights due to poor quality and high performance impact.
bool mixedThicknessMode = HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS);
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION) && !mixedThicknessMode)
if (HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS))
float NdotV = ClampNdotV(preLightData.NdotV);
float LdotV = dot(L, V);
lighting.diffuse += EvaluateTransmission(bsdfData, bsdfData.transmittance, NdotL, NdotV, LdotV, attenuation * lightData.diffuseScale);
lighting.diffuse += EvaluateTransmission(bsdfData, transmittance, NdotL, NdotV, LdotV, attenuation * lightData.diffuseScale);
}
// Save ALU by applying light and cookie colors only once.

DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 lightToSample = posInput.positionWS - lightData.positionWS;
int lightType = lightData.lightType;
float3 lightToSample;
distances.w = dot(lightToSample, lightData.forward);
if (lightType == GPULIGHTTYPE_PROJECTOR_BOX)
{
L = -lightData.forward;
distances.xyz = 1; // No distance or angle attenuation
}
else
{
float3 unL = -lightToSample;
float distSq = dot(unL, unL);
float distRcp = rsqrt(distSq);
float dist = distSq * distRcp;
L = unL * distRcp;
distances.xyz = float3(dist, distSq, distRcp);
}
GetPunctualLightVectors(posInput.positionWS, lightData, L, lightToSample, distances);
float NdotV = ClampNdotV(preLightData.NdotV);
float LdotV = dot(L, V);
bool mixedThicknessMode = HasFeatureFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS)
&& NdotL < 0 && lightData.shadowIndex >= 0;
// Save the original version for the transmission code below.
int originalShadowIndex = lightData.shadowIndex;
if (mixedThicknessMode)
float3 transmittance = float3(0.0, 0.0, 0.0);
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
// Make sure we do not sample the shadow map twice.
lightData.shadowIndex = -1;
// Caution: This function modify N and lightData.contactShadowIndex
transmittance = PreEvaluatePunctualLightTransmission(lightLoopContext, posInput, distances.x, NdotL, L, bsdfData, N, lightData);
}
float3 color;

// Restore the original shadow index.
lightData.shadowIndex = originalShadowIndex;
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light)

lighting.specular *= intensity * lightData.specularScale;
}
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
float3 transmittance = bsdfData.transmittance;
if (mixedThicknessMode)
{
// Recompute transmittance using the thickness value computed from the shadow map.
// Compute the distance from the light to the back face of the object along the light direction.
float distBackFaceToLight = GetPunctualShadowClosestDistance(lightLoopContext.shadowContext, s_linear_clamp_sampler,
posInput.positionWS, lightData.shadowIndex, L, lightData.positionWS);
// Our subsurface scattering models use the semi-infinite planar slab assumption.
// Therefore, we need to find the thickness along the normal.
float distFrontFaceToLight = distances.x;
float thicknessInUnits = (distFrontFaceToLight - distBackFaceToLight) * -NdotL;
float thicknessInMeters = thicknessInUnits * _WorldScales[bsdfData.diffusionProfile].x;
float thicknessInMillimeters = thicknessInMeters * MILLIMETERS_PER_METER;
#if SHADEROPTIONS_USE_DISNEY_SSS
// We need to make sure it's not less than the baked thickness to minimize light leaking.
float thicknessDelta = max(0, thicknessInMillimeters - bsdfData.thickness);
float3 S = _ShapeParams[bsdfData.diffusionProfile].rgb;
// Approximate the decrease of transmittance by e^(-1/3 * dt * S).
#if 0
float3 expOneThird = exp(((-1.0 / 3.0) * thicknessDelta) * S);
#else
// Help the compiler.
float k = (-1.0 / 3.0) * LOG2_E;
float3 p = (k * thicknessDelta) * S;
float3 expOneThird = exp2(p);
#endif
transmittance *= expOneThird;
#else // SHADEROPTIONS_USE_DISNEY_SSS
// We need to make sure it's not less than the baked thickness to minimize light leaking.
thicknessInMillimeters = max(thicknessInMillimeters, bsdfData.thickness);
transmittance = ComputeTransmittanceJimenez(_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][0].rgb,
_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][0].a,
_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][1].rgb,
_HalfRcpVariancesAndWeights[bsdfData.diffusionProfile][1].a,
_TransmissionTintsAndFresnel0[bsdfData.diffusionProfile].rgb,
thicknessInMillimeters);
#endif // SHADEROPTIONS_USE_DISNEY_SSS
}
// Note: we do not modify the distance to the light, or the light angle for the back face.
// This is a performance-saving optimization which makes sense as long as the thickness is small.
float NdotV = ClampNdotV(preLightData.NdotV);
float LdotV = dot(L, V);
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass.
lighting.diffuse += EvaluateTransmission(bsdfData, transmittance, NdotL, NdotV, LdotV, attenuation * lightData.diffuseScale);
}

float len = lightData.size.x;
float3 T = lightData.right;
float3 unL = lightData.positionWS - positionWS;
float3 unL = lightData.positionRWS - positionWS;
// Pick the major axis of the ellipsoid.
float3 axis = lightData.right;

float radius = rsqrt(lightData.invSqrAttenuationRadius);
float radius = rsqrt(lightData.rangeAttenuationScale); // // rangeAttenuationScale is inverse Square Radius
float intensity = EllipsoidalDistanceAttenuation(unL, lightData.invSqrAttenuationRadius,
float intensity = EllipsoidalDistanceAttenuation(unL, lightData.rangeAttenuationScale, lightData.rangeAttenuationBias,
axis, invAspectRatio);
// Terminate if the shaded point is too far away.

lightData.specularScale *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
lightData.positionRWS -= positionWS;
float3 P1 = lightData.positionWS - T * (0.5 * len);
float3 P2 = lightData.positionWS + T * (0.5 * len);
float3 P1 = lightData.positionRWS - T * (0.5 * len);
float3 P2 = lightData.positionRWS + T * (0.5 * len);
// Rotate the endpoints into the local coordinate system.
P1 = mul(P1, transpose(preLightData.orthoBasisViewNormal));

ltcValue = LTCEvaluate(P1, P2, B, preLightData.ltcTransformDiffuse);
ltcValue *= lightData.diffuseScale;
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
lighting.diffuse = preLightData.ltcMagnitudeDiffuse * ltcValue;
UNITY_BRANCH if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
// See comment for specular magnitude, it apply to diffuse as well
lighting.diffuse = preLightData.diffuseFGD * ltcValue;
UNITY_BRANCH if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
{
// Flip the view vector and the normal. The bitangent stays the same.
float3x3 flipMatrix = float3x3(-1, 0, 0,

// Evaluate the specular part
ltcValue = LTCEvaluate(P1, P2, B, preLightData.ltcTransformSpecular);
ltcValue *= lightData.specularScale;
lighting.specular = preLightData.ltcMagnitudeFresnel * ltcValue;
// We need to multiply by the magnitude of the integral of the BRDF
// ref: http://advances.realtimerendering.com/s2016/s2016_ltc_fresnel.pdf
// This value is what we store in specularFGD, so reuse it
lighting.specular = preLightData.specularFGD * ltcValue;
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
lighting.diffuse *= (1.0 - preLightData.ltcMagnitudeCoatFresnel);
lighting.specular *= (1.0 - preLightData.ltcMagnitudeCoatFresnel);
lighting.specular += preLightData.ltcMagnitudeCoatFresnel * ltcValue;
// For clear coat we don't fetch specularFGD we can use directly the perfect fresnel coatIblF
lighting.diffuse *= (1.0 - preLightData.coatIblF);
lighting.specular *= (1.0 - preLightData.coatIblF);
lighting.specular += preLightData.coatIblF * ltcValue;
}
// Save ALU by applying 'lightData.color' only once.

}
//-----------------------------------------------------------------------------
// EvaluateBSDF_Area - Approximation with Linearly Transformed Cosines
// EvaluateBSDF_Rect - Approximation with Linearly Transformed Cosines
//-----------------------------------------------------------------------------
// #define ELLIPSOIDAL_ATTENUATION

IntegrateBSDF_AreaRef(V, positionWS, preLightData, lightData, bsdfData,
lighting.diffuse, lighting.specular);
#else
float3 unL = lightData.positionWS - positionWS;
float3 unL = lightData.positionRWS - positionWS;
if (dot(lightData.forward, unL) >= 0.0001)
{

// Define the dimensions of the attenuation volume.
// TODO: This could be precomputed.
float radius = rsqrt(lightData.invSqrAttenuationRadius);
float radius = rsqrt(lightData.rangeAttenuationScale); // rangeAttenuationScale is inverse Square Radius
float3 invHalfDim = rcp(float3(radius + halfWidth,
radius + halfHeight,
radius));

lightData.specularScale *= intensity;
// Translate the light s.t. the shaded point is at the origin of the coordinate system.
lightData.positionWS -= positionWS;
lightData.positionRWS -= positionWS;
lightVerts[0] = lightData.positionWS + lightData.right * halfWidth + lightData.up * halfHeight;
lightVerts[1] = lightData.positionWS + lightData.right * halfWidth + lightData.up * -halfHeight;
lightVerts[2] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * -halfHeight;
lightVerts[3] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * halfHeight;
lightVerts[0] = lightData.positionRWS + lightData.right * halfWidth + lightData.up * halfHeight;
lightVerts[1] = lightData.positionRWS + lightData.right * halfWidth + lightData.up * -halfHeight;
lightVerts[2] = lightData.positionRWS + lightData.right * -halfWidth + lightData.up * -halfHeight;
lightVerts[3] = lightData.positionRWS + lightData.right * -halfWidth + lightData.up * halfHeight;
// Rotate the endpoints into the local coordinate system.
lightVerts = mul(lightVerts, transpose(preLightData.orthoBasisViewNormal));

ltcValue = PolygonIrradiance(mul(lightVerts, preLightData.ltcTransformDiffuse));
ltcValue *= lightData.diffuseScale;
// We don't multiply by 'bsdfData.diffuseColor' here. It's done only once in PostEvaluateBSDF().
lighting.diffuse = preLightData.ltcMagnitudeDiffuse * ltcValue;
// See comment for specular magnitude, it apply to diffuse as well
lighting.diffuse = preLightData.diffuseFGD * ltcValue;
UNITY_BRANCH if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
UNITY_BRANCH if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
{
// Flip the view vector and the normal. The bitangent stays the same.
float3x3 flipMatrix = float3x3(-1, 0, 0,

// Polygon irradiance in the transformed configuration.
ltcValue = PolygonIrradiance(mul(lightVerts, preLightData.ltcTransformSpecular));
ltcValue *= lightData.specularScale;
lighting.specular += preLightData.ltcMagnitudeFresnel * ltcValue;
// We need to multiply by the magnitude of the integral of the BRDF
// ref: http://advances.realtimerendering.com/s2016/s2016_ltc_fresnel.pdf
// This value is what we store in specularFGD, so reuse it
lighting.specular += preLightData.specularFGD * ltcValue;
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
lighting.diffuse *= (1.0 - preLightData.ltcMagnitudeCoatFresnel);
lighting.specular *= (1.0 - preLightData.ltcMagnitudeCoatFresnel);
lighting.specular += preLightData.ltcMagnitudeCoatFresnel * ltcValue;
// For clear coat we don't fetch specularFGD we can use directly the perfect fresnel coatIblF
lighting.diffuse *= (1.0 - preLightData.coatIblF);
lighting.specular *= (1.0 - preLightData.coatIblF);
lighting.specular += preLightData.coatIblF * ltcValue;
}
// Save ALU by applying 'lightData.color' only once.

// TODO: handle clear coat
// #ifdef LIT_DIFFUSE_LAMBERT_BRDF
// #ifdef USE_DIFFUSE_LAMBERT_BRDF
// envLighting += IntegrateLambertIBLRef(lightData, V, bsdfData);
// #else
// envLighting += IntegrateDisneyDiffuseIBLRef(lightLoopContext, V, preLightData, lightData, bsdfData);

else
#endif
{
if ((lightData.envIndex & 1) == ENVCACHETYPE_CUBEMAP)
if (!IsEnvIndexTexture2D(lightData.envIndex)) // ENVCACHETYPE_CUBEMAP
{
R = GetSpecularDominantDir(bsdfData.normalWS, R, preLightData.iblPerceptualRoughness, ClampNdotV(preLightData.NdotV));
// When we are rough, we tend to see outward shifting of the reflection when at the boundary of the projection volume

// Don't do clear coating for refraction
float3 coatR = preLightData.coatIblR;
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION && HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION && HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
float unusedWeight = 0.0;
EvaluateLight_EnvIntersection(positionWS, bsdfData.normalWS, lightData, influenceShapeType, coatR, unusedWeight);

envLighting = F * preLD.rgb;
// Evaluate the Clear Coat component if needed
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
// No correction needed for coatR as it is smooth
// Note: coat F is scalar as it is a dieletric

#else
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, 1.0, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
#endif
// Subsurface scattering mdoe
uint texturingMode = (bsdfData.materialFeatures >> MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET) & 3;
float3 modifiedDiffuseColor = ApplySubsurfaceScatteringTexturingMode(texturingMode, bsdfData.diffuseColor);
// Subsurface scattering mode
float3 modifiedDiffuseColor = GetModifiedDiffuseColorForSSS(bsdfData);
// Apply the albedo to the direct diffuse lighting (only once). The indirect (baked)
// diffuse lighting has already had the albedo applied in GetBakedDiffuseLighting().

10
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitBuiltinData.hlsl


// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, bentNormalWS, input.texCoord1, input.texCoord2);
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionRWS, bentNormalWS, input.texCoord1, input.texCoord2);
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
builtinData.bakeDiffuseLighting += SampleBakedGI(input.positionWS, -input.worldToTangent[2], input.texCoord1, input.texCoord2) * bsdfData.transmittance;
builtinData.bakeDiffuseLighting += SampleBakedGI(input.positionRWS, -input.worldToTangent[2], input.texCoord1, input.texCoord2) * bsdfData.transmittance;
float4 shadowMask = SampleShadowMask(input.positionWS, input.texCoord1);
float4 shadowMask = SampleShadowMask(input.positionRWS, input.texCoord1);
builtinData.shadowMask0 = shadowMask.x;
builtinData.shadowMask1 = shadowMask.y;
builtinData.shadowMask2 = shadowMask.z;

#endif
input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, _UVMappingMaskEmissive, _UVMappingMaskEmissive,
_EmissiveColorMap_ST.xy, _EmissiveColorMap_ST.zw, float2(0.0, 0.0), float2(0.0, 0.0), 1.0, false,
input.positionWS, _TexWorldScaleEmissive,
input.positionRWS, _TexWorldScaleEmissive,
mappingType, layerTexCoord);
#ifndef LAYERED_LIT_SHADER

11
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitData.hlsl


layerTexCoord.vertexTangentWS0 = input.worldToTangent[0];
layerTexCoord.vertexBitangentWS0 = input.worldToTangent[1];
// TODO: We should use relative camera position here - This will be automatic when we will move to camera relative space.
float3 dPdx = ddx_fine(input.positionWS);
float3 dPdy = ddy_fine(input.positionWS);
float3 dPdx = ddx_fine(input.positionRWS);
float3 dPdy = ddy_fine(input.positionRWS);
float3 sigmaX = dPdx - dot(dPdx, vertexNormalWS) * vertexNormalWS;
float3 sigmaY = dPdy - dot(dPdy, vertexNormalWS) * vertexNormalWS;

// in function with FragInputs input as parameters
// layerTexCoord must have been initialize to 0 outside of this function
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,
float3 positionWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord)
float3 positionRWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord)
{
layerTexCoord.vertexNormalWS = vertexNormalWS;
layerTexCoord.triplanarWeights = ComputeTriplanarWeights(vertexNormalWS);

// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code
ComputeLayerTexCoord( texCoord0, texCoord1, texCoord2, texCoord3, _UVMappingMask, _UVDetailsMappingMask,
_BaseColorMap_ST.xy, _BaseColorMap_ST.zw, _DetailMap_ST.xy, _DetailMap_ST.zw, 1.0, _LinkDetailsWithBase,
positionWS, _TexWorldScale,
positionRWS, _TexWorldScale,
mappingType, layerTexCoord);
}

#endif
GetLayerTexCoord( input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord);
input.positionRWS, input.worldToTangent[2].xyz, layerTexCoord);
}
#include "LitDataDisplacement.hlsl"

10
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitDataDisplacement.hlsl


{
float3 objectScale = float3(1.0, 1.0, 1.0);
// TODO: This should be an uniform for the object, this code should be remove once we have it. - Workaround for now
// To handle object scaling with pixel displacement we need to multiply the view vector by the inverse scale.
// To Handle object scaling with vertex/tessellation displacement we must multiply displacement by object scale
// Currently we extract either the scale (ObjectToWorld) or the inverse scale (worldToObject) directly by taking the transform matrix
float4x4 worldTransform;
// TODO: This should be an uniform for the object, this code should be remove once we have it. - Workaround for now
// To handle object scaling with pixel displacement we need to multiply the view vector by the inverse scale.
// To Handle object scaling with vertex/tessellation displacement we must multiply displacement by object scale
// Currently we extract either the scale (ObjectToWorld) or the inverse scale (worldToObject) directly by taking the transform matrix
float4x4 worldTransform;
if (vertexDisplacement)
{
worldTransform = GetObjectToWorldMatrix();

4
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitDataIndividualLayer.hlsl


// scale and bias for base and detail + global tiling factor (for layered lit only)
float2 texScale, float2 texBias, float2 texScaleDetails, float2 texBiasDetails, float additionalTiling, float linkDetailsWithBase,
// parameter for planar/triplanar
float3 positionWS, float worldScale,
float3 positionRWS, float worldScale,
// mapping type and output
int mappingType, inout LayerTexCoord layerTexCoord)
{

float2 uvXY;
float2 uvZY;
GetTriplanarCoordinate(GetAbsolutePositionWS(positionWS) * worldScale, uvXZ, uvXY, uvZY);
GetTriplanarCoordinate(GetAbsolutePositionWS(positionRWS) * worldScale, uvXZ, uvXY, uvZY);
// Planar is just XZ of triplanar
if (mappingType == UV_MAPPING_PLANAR)

21
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitDataMeshModification.hlsl


float3 GetVertexDisplacement(float3 positionWS, float3 normalWS, float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, float4 vertexColor)
// Note: positionWS can be either in camera relative space or not
float3 GetVertexDisplacement(float3 positionRWS, float3 normalWS, float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, float4 vertexColor)
GetLayerTexCoord(texCoord0, texCoord1, texCoord2, texCoord3, positionWS, normalWS, layerTexCoord);
GetLayerTexCoord(texCoord0, texCoord1, texCoord2, texCoord3, positionRWS, normalWS, layerTexCoord);
// TODO: do this algorithm for lod fetching as lod not available in vertex/domain shader
// http://www.sebastiansylvan.com/post/the-problem-with-tessellation-in-directx-11/

void ApplyVertexModification(AttributesMesh input, float3 normalWS, inout float3 positionWS, float4 time)
// Note: positionWS can be either in camera relative space or not
void ApplyVertexModification(AttributesMesh input, float3 normalWS, inout float3 positionRWS, float4 time)
positionWS += GetVertexDisplacement(positionWS, normalWS,
positionRWS += GetVertexDisplacement(positionRWS, normalWS,
#ifdef ATTRIBUTES_NEED_TEXCOORD0
input.uv0,
#else

#endif
#ifdef _VERTEX_WIND
float3 rootWP = mul(GetObjectToWorldMatrix(), float4(0, 0, 0, 1)).xyz;
ApplyWindDisplacement(positionWS, normalWS, rootWP, _Stiffness, _Drag, _ShiverDrag, _ShiverDirectionality, _InitialBend, input.color.a, time);
// current wind implementation is in absolute world space
float3 rootWP = GetObjectAbsolutePositionWS();
float3 absolutePositionWS = GetAbsolutePositionWS(positionRWS);
ApplyWindDisplacement(absolutePositionWS, normalWS, rootWP, _Stiffness, _Drag, _ShiverDrag, _ShiverDirectionality, _InitialBend, input.color.a, time);
positionRWS = GetCameraRelativePositionWS(absolutePositionWS);
#endif
}

// y - 2->0 edge
// z - 0->1 edge
// w - inside tessellation factor
void ApplyTessellationModification(VaryingsMeshToDS input, float3 normalWS, inout float3 positionWS)
void ApplyTessellationModification(VaryingsMeshToDS input, float3 normalWS, inout float3 positionRWS)
positionWS += GetVertexDisplacement(positionWS, normalWS,
positionRWS += GetVertexDisplacement(positionRWS, normalWS,
#ifdef VARYINGS_DS_NEED_TEXCOORD0
input.texCoord0,
#else

8
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/LitReference.hlsl


const float len = lightData.size.x;
const float3 T = lightData.right;
const float3 P1 = lightData.positionWS - T * (0.5 * len);
const float3 P1 = lightData.positionRWS - T * (0.5 * len);
const float dt = len * rcp(sampleCount);
const float off = 0.5 * dt;

u = frac(u + randNum);
// Lights in Unity point backward.
float4x4 localToWorld = float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(-lightData.forward, 0.0), float4(lightData.positionWS, 1.0));
float4x4 localToWorld = float4x4(float4(lightData.right, 0.0), float4(lightData.up, 0.0), float4(-lightData.forward, 0.0), float4(lightData.positionRWS, 1.0));
switch (lightData.lightType)
{

{
float3x3 localToWorld;
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
localToWorld = float3x3(bsdfData.tangentWS, bsdfData.bitangentWS, bsdfData.normalWS);
}

float weightOverPdf;
// GGX BRDF
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_ANISOTROPY))
{
ImportanceSampleAnisoGGX(u, V, localToWorld, bsdfData.roughnessT, bsdfData.roughnessB, NdotV, L, VdotH, NdotL, weightOverPdf);
}

16
com.unity.render-pipelines.high-definition/HDRP/Material/MaterialUtilities.hlsl


// Return camera relative probe volume world to object transformation
float4x4 GetProbeVolumeWorldToObject()
{
return ApplyCameraTranslationToInverseMatrix(unity_ProbeVolumeWorldToObject);
}
float3 SampleBakedGI(float3 positionWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap)
float3 SampleBakedGI(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap)
{
// If there is no lightmap, it assume lightprobe
#if !defined(LIGHTMAP_ON) && !defined(DYNAMICLIGHTMAP_ON)

}
else
{
// TODO: We use GetAbsolutePositionWS(positionWS) to handle the camera relative case here but this should be part of the unity_ProbeVolumeWorldToObject matrix on C++ side (sadly we can't modify it for HDRenderPipeline...)
return SampleProbeVolumeSH4(TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), GetAbsolutePositionWS(positionWS), normalWS, unity_ProbeVolumeWorldToObject,
return SampleProbeVolumeSH4(TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionRWS, normalWS, GetProbeVolumeWorldToObject(),
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z, unity_ProbeVolumeMin, unity_ProbeVolumeSizeInv);
}

#endif
}
float4 SampleShadowMask(float3 positionWS, float2 uvStaticLightmap) // normalWS not use for now
float4 SampleShadowMask(float3 positionRWS, float2 uvStaticLightmap) // normalWS not use for now
{
#if defined(LIGHTMAP_ON)
float2 uv = uvStaticLightmap * unity_LightmapST.xy + unity_LightmapST.zw;

if (unity_ProbeVolumeParams.x == 1.0)
{
// TODO: We use GetAbsolutePositionWS(positionWS) to handle the camera relative case here but this should be part of the unity_ProbeVolumeWorldToObject matrix on C++ side (sadly we can't modify it for HDRenderPipeline...)
rawOcclusionMask = SampleProbeOcclusion(TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), GetAbsolutePositionWS(positionWS), unity_ProbeVolumeWorldToObject,
rawOcclusionMask = SampleProbeOcclusion(TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionRWS, GetProbeVolumeWorldToObject(),
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z, unity_ProbeVolumeMin, unity_ProbeVolumeSizeInv);
}
else

3
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs


public float iridescenceIor;
[SurfaceDataAttributes("IridescenceThickness")]
public float iridescenceThickness;
[SurfaceDataAttributes("Iridescence Mask")]
public float iridescenceMask;
// Top interface and media (clearcoat)
[SurfaceDataAttributes("Coat Smoothness")]

// iridescence
public float iridescenceIor;
public float iridescenceThickness;
public float iridescenceMask;
// SSS
public uint diffusionProfile;

34
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.cs.hlsl


#define DEBUGVIEW_STACKLIT_SURFACEDATA_ANISOTROPY (1115)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_IOR (1116)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_THICKNESS (1117)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS (1118)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_IOR (1119)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_THICKNESS (1120)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_EXTINCTION_COEFFICIENT (1121)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_DIFFUSION_PROFILE (1122)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SUBSURFACE_MASK (1123)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_THICKNESS (1124)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_MASK (1118)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS (1119)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_IOR (1120)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_THICKNESS (1121)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_EXTINCTION_COEFFICIENT (1122)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_DIFFUSION_PROFILE (1123)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_SUBSURFACE_MASK (1124)
#define DEBUGVIEW_STACKLIT_SURFACEDATA_THICKNESS (1125)
//
// UnityEngine.Experimental.Rendering.HDPipeline.StackLit+BSDFData: static fields

#define DEBUGVIEW_STACKLIT_BSDFDATA_COAT_EXTINCTION (1174)
#define DEBUGVIEW_STACKLIT_BSDFDATA_IRIDESCENCE_IOR (1175)
#define DEBUGVIEW_STACKLIT_BSDFDATA_IRIDESCENCE_THICKNESS (1176)
#define DEBUGVIEW_STACKLIT_BSDFDATA_DIFFUSION_PROFILE (1177)
#define DEBUGVIEW_STACKLIT_BSDFDATA_SUBSURFACE_MASK (1178)
#define DEBUGVIEW_STACKLIT_BSDFDATA_THICKNESS (1179)
#define DEBUGVIEW_STACKLIT_BSDFDATA_USE_THICK_OBJECT_MODE (1180)
#define DEBUGVIEW_STACKLIT_BSDFDATA_TRANSMITTANCE (1181)
#define DEBUGVIEW_STACKLIT_BSDFDATA_IRIDESCENCE_MASK (1177)
#define DEBUGVIEW_STACKLIT_BSDFDATA_DIFFUSION_PROFILE (1178)
#define DEBUGVIEW_STACKLIT_BSDFDATA_SUBSURFACE_MASK (1179)
#define DEBUGVIEW_STACKLIT_BSDFDATA_THICKNESS (1180)
#define DEBUGVIEW_STACKLIT_BSDFDATA_USE_THICK_OBJECT_MODE (1181)
#define DEBUGVIEW_STACKLIT_BSDFDATA_TRANSMITTANCE (1182)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.StackLit+SurfaceData
// PackingRules = Exact

float anisotropy;
float iridescenceIor;
float iridescenceThickness;
float iridescenceMask;
float coatPerceptualSmoothness;
float coatIor;
float coatThickness;

float3 coatExtinction;
float iridescenceIor;
float iridescenceThickness;
float iridescenceMask;
uint diffusionProfile;
float subsurfaceMask;
float thickness;

break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_THICKNESS:
result = surfacedata.iridescenceThickness.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_IRIDESCENCE_MASK:
result = surfacedata.iridescenceMask.xxx;
break;
case DEBUGVIEW_STACKLIT_SURFACEDATA_COAT_SMOOTHNESS:
result = surfacedata.coatPerceptualSmoothness.xxx;

break;
case DEBUGVIEW_STACKLIT_BSDFDATA_IRIDESCENCE_THICKNESS:
result = bsdfdata.iridescenceThickness.xxx;
break;
case DEBUGVIEW_STACKLIT_BSDFDATA_IRIDESCENCE_MASK:
result = bsdfdata.iridescenceMask.xxx;
break;
case DEBUGVIEW_STACKLIT_BSDFDATA_DIFFUSION_PROFILE:
result = GetIndexColor(bsdfdata.diffusionProfile);

741
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl
文件差异内容过多而无法显示
查看文件

125
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.shader


_MetallicMapUV("Metallic Map UV", Float) = 0.0
_MetallicMapUVLocal("Metallic Map UV Local", Float) = 0.0
_MetallicMapChannel("Metallic Map Channel", Float) = 0.0
_MetallicMapChannelMask("Metallic Map Channel Mask", Vector) = (1, 0, 0, 0)
_MetallicRemap("Metallic Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _MetallicRange("Metallic Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _MetallicMapChannelMask("Metallic Map Channel Mask", Vector) = (1, 0, 0, 0)
_MetallicMapRemap("Metallic Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _MetallicMapRange("Metallic Range", Vector) = (0, 1, 0, 0)
_DielectricIor("DielectricIor IOR", Range(1.0, 2.5)) = 1.5

_SmoothnessAUseMap("SmoothnessA Use Map", Float) = 0
_SmoothnessAMapUV("SmoothnessA Map UV", Float) = 0.0
_SmoothnessAMapUVLocal("_SmoothnessA Map UV Local", Float) = 0.0
_SmoothnessAMapUVLocal("SmoothnessA Map UV Local", Float) = 0.0
_SmoothnessAMapChannelMask("SmoothnessA Map Channel Mask", Vector) = (1, 0, 0, 0)
_SmoothnessARemap("SmoothnessA Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessARemapInverted("Invert SmoothnessA Remap", Float) = 0.0
[HideInInspector] _SmoothnessARange("SmoothnessA Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _SmoothnessAMapChannelMask("SmoothnessA Map Channel Mask", Vector) = (1, 0, 0, 0)
_SmoothnessAMapRemap("SmoothnessA Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessAMapRemapInverted("Invert SmoothnessA Remap", Float) = 0.0
[HideInInspector] _SmoothnessAMapRange("SmoothnessA Range", Vector) = (0, 1, 0, 0)
[ToggleUI] _EnableDualSpecularLobe("Enable Dual Specular Lobe", Float) = 0.0 // UI only
[HideInInspector] _SmoothnessBMapShow("SmoothnessB Map Show", Float) = 0

_SmoothnessBMapUV("SmoothnessB Map UV", Float) = 0.0
_SmoothnessAMapUVLocal("_SmoothnessB Map UV Local", Float) = 0.0
_SmoothnessBMapChannel("SmoothnessB Map Channel", Float) = 0.0
_SmoothnessBMapChannelMask("SmoothnessB Map Channel Mask", Vector) = (1, 0, 0, 0)
_SmoothnessBRemap("SmoothnessB Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessBRemapInverted("Invert SmoothnessB Remap", Float) = 0.0
[HideInInspector] _SmoothnessBRange("SmoothnessB Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _SmoothnessBMapChannelMask("SmoothnessB Map Channel Mask", Vector) = (1, 0, 0, 0)
_SmoothnessBMapRemap("SmoothnessB Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _SmoothnessBMapRemapInverted("Invert SmoothnessB Remap", Float) = 0.0
[HideInInspector] _SmoothnessBMapRange("SmoothnessB Range", Vector) = (0, 1, 0, 0)
_LobeMix("Lobe Mix", Range(0.0, 1.0)) = 0
[ToggleUI] _VlayerRecomputePerLight("Vlayer Recompute Per Light", Float) = 0.0 // UI only

_AnisotropyMapUV("Anisotropy Map UV", Float) = 0.0
_AnisotropyMapUVLocal("Anisotropy Map UV Local", Float) = 0.0
_AnisotropyMapChannel("Anisotropy Map Channel", Float) = 0.0
_AnisotropyMapChannelMask("Anisotropy Map Channel Mask", Vector) = (1, 0, 0, 0)
_AnisotropyRemap("Anisotropy Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _AnisotropyRange("Anisotropy Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _AnisotropyMapChannelMask("Anisotropy Map Channel Mask", Vector) = (1, 0, 0, 0)
_AnisotropyMapRemap("Anisotropy Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _AnisotropyMapRange("Anisotropy Range", Vector) = (0, 1, 0, 0)
[ToggleUI] _EnableCoat("Enable Coat", Float) = 0.0 // UI only
[HideInInspector] _CoatSmoothnessMapShow("CoatSmoothness Show", Float) = 0

_CoatSmoothnessMapUV("CoatSmoothness Map UV", Float) = 0.0
_CoatSmoothnessMapUVLocal("CoatSmoothness Map UV Local", Float) = 0.0
_CoatSmoothnessMapChannel("CoatSmoothness Map Channel", Float) = 0.0
_CoatSmoothnessMapChannelMask("CoatSmoothness Map Channel Mask", Vector) = (1, 0, 0, 0)
_CoatSmoothnessRemap("CoatSmoothness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _CoatSmoothnessRemapInverted("Invert CoatSmoothness Remap", Float) = 0.0
[HideInInspector] _CoatSmoothnessRange("CoatSmoothness Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _CoatSmoothnessMapChannelMask("CoatSmoothness Map Channel Mask", Vector) = (1, 0, 0, 0)
_CoatSmoothnessMapRemap("CoatSmoothness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _CoatSmoothnessMapRemapInverted("Invert CoatSmoothness Remap", Float) = 0.0
[HideInInspector] _CoatSmoothnessMapRange("CoatSmoothness Range", Vector) = (0, 1, 0, 0)
_CoatIor("Coat IOR", Range(1.0001, 2.0)) = 1.5
_CoatThickness("Coat Thickness", Range(0.0, 0.99)) = 0.0

_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_NormalMapUV("NormalMapUV", Float) = 0.0
_NormalMapUVLocal("NormalMapUV Local", Float) = 0.0
_NormalMapObjSpace("NormalMapUV Local", Float) = 0.0
_NormalMapObjSpace("NormalMapObjSpace", Float) = 0.0
_NormalScale("Normal Scale", Range(0.0, 2.0)) = 1
[HideInInspector] _AmbientOcclusionMapShow("AmbientOcclusion Map Show", Float) = 0

_AmbientOcclusionMapUV("AmbientOcclusion Map UV", Float) = 0.0
_AmbientOcclusionMapUVLocal("AmbientOcclusion Map UV Local", Float) = 0.0
_AmbientOcclusionMapChannel("AmbientOcclusion Map Channel", Float) = 0.0
_AmbientOcclusionMapChannelMask("AmbientOcclusion Map Channel Mask", Vector) = (1, 0, 0, 0)
_AmbientOcclusionRemap("AmbientOcclusion Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _AmbientOcclusionRange("AmbientOcclusion Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _AmbientOcclusionMapChannelMask("AmbientOcclusion Map Channel Mask", Vector) = (1, 0, 0, 0)
_AmbientOcclusionMapRemap("AmbientOcclusion Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _AmbientOcclusionMapRange("AmbientOcclusion Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _EmissiveColorMapShow("Emissive Color Map Show", Float) = 0.0
[HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)

_SubsurfaceMaskMapUV("Subsurface Mask Map UV", Float) = 0.0
_SubsurfaceMaskMapUVLocal("Subsurface Mask UV Local", Float) = 0.0
_SubsurfaceMaskMapChannel("Subsurface Mask Map Channel", Float) = 0.0
_SubsurfaceMaskMapChannelMask("Subsurface Mask Map Channel Mask", Vector) = (1, 0, 0, 0)
_SubsurfaceMaskRemap("Subsurface Mask Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _SubsurfaceMaskRange("Subsurface Mask Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _SubsurfaceMaskMapChannelMask("Subsurface Mask Map Channel Mask", Vector) = (1, 0, 0, 0)
_SubsurfaceMaskMapRemap("Subsurface Mask Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _SubsurfaceMaskMapRange("Subsurface Mask Range", Vector) = (0, 1, 0, 0)
[ToggleUI] _EnableTransmission("Enable Transmission", Float) = 0.0
[HideInInspector] _ThicknessMapShow("Thickness Show", Float) = 0

_ThicknessMapUV("Thickness Map UV", Float) = 0.0
_ThicknessMapUVLocal("Thickness Map UV Local", Float) = 0.0
_ThicknessMapChannel("Thickness Map Channel", Float) = 0.0
_ThicknessMapChannelMask("Thickness Map Channel Mask", Vector) = (1, 0, 0, 0)
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _ThicknessRemapInverted("Invert Thickness Remap", Float) = 0.0
[HideInInspector] _ThicknessRange("Thickness Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _ThicknessMapChannelMask("Thickness Map Channel Mask", Vector) = (1, 0, 0, 0)
_ThicknessMapRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _ThicknessMapRemapInverted("Invert Thickness Remap", Float) = 0.0
[HideInInspector] _ThicknessMapRange("Thickness Range", Vector) = (0, 1, 0, 0)
_IridescenceIor("Coat IOR", Range(1.0, 2.0)) = 1.5
_IridescenceThickness("_IridescenceThickness", Range(0.0, 1.0)) = 0.0
_IridescenceThicknessMap("IridescenceThickness Color Map", 2D) = "black" {}
_IridescenceIor("TopIOR over iridescent layer", Range(1.0, 2.0)) = 1.5
[HideInInspector] _IridescenceThicknessMapShow("IridescenceThickness Map Show", Float) = 0
_IridescenceThickness("IridescenceThickness", Range(0.0, 1.0)) = 0.0
_IridescenceThicknessMap("IridescenceThickness Map", 2D) = "black" {}
_IridescenceThicknessMapChannel("IridescenceThickness Mask Map Channel", Float) = 0.0
_IridescenceThicknessMapChannelMask("IridescenceThickness Mask Map Channel Mask", Vector) = (1, 0, 0, 0)
[HideInInspector] _IridescenceThicknessRange("IridescenceThickness Range", Vector) = (0, 1, 0, 0)
_IridescenceThicknessMapChannel("IridescenceThickness Map Channel", Float) = 0.0
[HideInInspector] _IridescenceThicknessMapChannelMask("IridescenceThickness Map Channel Mask", Vector) = (1, 0, 0, 0)
_IridescenceThicknessMapRemap("IridescenceThickness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _IridescenceThicknessMapRemapInverted("Invert IridescenceThickness Remap", Float) = 0.0
[HideInInspector] _IridescenceThicknessMapRange("IridescenceThickness Range", Vector) = (0, 1, 0, 0)
[HideInInspector] _IridescenceMaskMapShow("Iridescence Mask Map Show", Float) = 0
_IridescenceMask("Iridescence Mask", Range(0.0, 1.0)) = 1.0
_IridescenceMaskMap("Iridescence Mask Map", 2D) = "black" {}
_IridescenceMaskUseMap("Iridescence Mask Use Map", Float) = 0
_IridescenceMaskMapUV("Iridescence Mask Map UV", Float) = 0.0
_IridescenceMaskMapUVLocal("Iridescence Mask UV Local", Float) = 0.0
_IridescenceMaskMapChannel("Iridescence Mask Map Channel", Float) = 0.0
[HideInInspector] _IridescenceMaskMapChannelMask("Iridescence Mask Map Channel Mask", Vector) = (1, 0, 0, 0)
_IridescenceMaskMapRemap("Iridescence Mask Remap", Vector) = (0, 1, 0, 0)
[HideInInspector] _IridescenceMaskMapRange("Iridescence Mask Range", Vector) = (0, 1, 0, 0)
// Detail map (mask, normal, smoothness)
[ToggleUI] _EnableDetails("Enable Details", Float) = 0.0
[HideInInspector] _DetailMaskMapShow("DetailMask Map Show", Float) = 0
_DetailMaskMap("DetailMask Map", 2D) = "white" {}
_DetailMaskMapUV("DetailMask Map UV", Float) = 0.0
_DetailMaskMapUVLocal("DetailMask Map UV Local", Float) = 0.0
_DetailMaskMapChannel("DetailMask Map Channel", Float) = 0.0
[HideInInspector] _DetailMaskMapChannelMask("DetailSmoothness Map Channel Mask", Vector) = (1, 0, 0, 0)
[HideInInspector] _DetailNormalMapShow("DetailNormalMap Show", Float) = 0.0
_DetailNormalMap("DetailNormalMap", 2D) = "bump" {} // Tangent space normal map
_DetailNormalMapUV("DetailNormalMapUV", Float) = 0.0
_DetailNormalMapUVLocal("DetailNormalMapUV Local", Float) = 0.0
_DetailNormalScale("DetailNormal Scale", Range(0.0, 2.0)) = 1
[HideInInspector] _DetailSmoothnessMapShow("DetailSmoothness Map Show", Float) = 0
_DetailSmoothnessMap("DetailSmoothness Map", 2D) = "grey" {} // Neutral is 0.5 for detail map
_DetailSmoothnessMapUV("DetailSmoothness Map UV", Float) = 0.0
_DetailSmoothnessMapUVLocal("DetailSmoothness Map UV Local", Float) = 0.0
_DetailSmoothnessMapChannel("DetailSmoothness Map Channel", Float) = 0.0
[HideInInspector] _DetailSmoothnessMapChannelMask("DetailSmoothness Map Channel Mask", Vector) = (1, 0, 0, 0)
_DetailSmoothnessMapRemap("DetailSmoothness Remap", Vector) = (0, 1, 0, 0)
[ToggleUI] _DetailSmoothnessMapRemapInverted("Invert SmoothnessA Remap", Float) = 0.0
[HideInInspector] _DetailSmoothnessMapRange("DetailSmoothness Range", Vector) = (0, 1, 0, 0)
_DetailSmoothnessScale("DetailSmoothness Scale", Range(0.0, 2.0)) = 1
// Distortion
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
[ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0
[ToggleUI] _DistortionOnly("Distortion Only", Float) = 0.0

// Sections show values.
[HideInInspector] _MaterialFeaturesShow("_MaterialFeaturesShow", Float) = 1.0
[HideInInspector] _StandardShow("_StandardShow", Float) = 0.0
[HideInInspector] _DetailsShow("_DetailsShow", Float) = 0.0
[HideInInspector] _EmissiveShow("_EmissiveShow", Float) = 0.0
[HideInInspector] _CoatShow("_CoatShow", Float) = 0.0
[HideInInspector] _DebugShow("_DebugShow", Float) = 0.0

#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DOUBLESIDED_ON
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _USE_DETAILMAP
#pragma shader_feature _USE_UV2
#pragma shader_feature _USE_UV3
#pragma shader_feature _USE_TRIPLANAR

#pragma multi_compile _ DEBUG_DISPLAY
//NEWLITTODO
//#pragma multi_compile _ LIGHTMAP_ON
//#pragma multi_compile _ DIRLIGHTMAP_COMBINED
//#pragma multi_compile _ DYNAMICLIGHTMAP_ON
//#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile _ SHADOWS_SHADOWMASK
// #include "../../Lighting/Forward.hlsl" : nothing left in there.
//#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS

75
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitData.hlsl


void InitializeMappingData(FragInputs input, out TextureUVMapping uvMapping)
{
float3 position = GetAbsolutePositionWS(input.positionWS);
float2 uvXZ;
float2 uvXY;
float2 uvZY;

uvMapping.texcoords[TEXCOORD_INDEX_UV3][0] = uvMapping.texcoords[TEXCOORD_INDEX_UV3][1] = input.texCoord3.xy;
// planar/triplanar
GetTriplanarCoordinate(position, uvXZ, uvXY, uvZY);
GetTriplanarCoordinate(GetAbsolutePositionWS(input.positionRWS), uvXZ, uvXY, uvZY);
position = TransformWorldToObject(position);
GetTriplanarCoordinate(position, uvXZ, uvXY, uvZY);
GetTriplanarCoordinate(TransformWorldToObject(input.positionRWS), uvXZ, uvXY, uvZY);
uvMapping.texcoords[TEXCOORD_INDEX_PLANAR_XY][1] = uvXY;
uvMapping.texcoords[TEXCOORD_INDEX_PLANAR_YZ][1] = uvZY;
uvMapping.texcoords[TEXCOORD_INDEX_PLANAR_ZX][1] = uvXZ;

uvMapping.vertexTangentWS[0] = input.worldToTangent[0];
uvMapping.vertexBitangentWS[0] = input.worldToTangent[1];
float3 dPdx = ddx_fine(input.positionWS);
float3 dPdy = ddy_fine(input.positionWS);
float3 dPdx = ddx_fine(input.positionRWS);
float3 dPdy = ddy_fine(input.positionRWS);
float3 sigmaX = dPdx - dot(dPdx, vertexNormalWS) * vertexNormalWS;
float3 sigmaY = dPdy - dot(dPdy, vertexNormalWS) * vertexNormalWS;

}
#define SAMPLE_TEXTURE2D_SCALE_BIAS(name) SampleTexture2DTriplanarScaleBias(name, sampler##name, name##UV, name##UVLocal, name##_ST, uvMapping)
#define SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(name, scale) SampleTexture2DTriplanarNormalScaleBias(name, sampler##name, name##UV, name##UVLocal, name##_ST, name##ObjSpace, uvMapping, scale)
#define SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(name, scale, objSpace) SampleTexture2DTriplanarNormalScaleBias(name, sampler##name, name##UV, name##UVLocal, name##_ST, objSpace, uvMapping, scale)
//-----------------------------------------------------------------------------
// GetSurfaceAndBuiltinData

// Standard
surfaceData.baseColor = SAMPLE_TEXTURE2D_SCALE_BIAS(_BaseColorMap).rgb * _BaseColor.rgb;
float4 gradient = SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(_NormalMap, _NormalScale);
float4 gradient = SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(_NormalMap, _NormalScale, _NormalMapObjSpace);
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessARange.x, _SmoothnessARange.y, surfaceData.perceptualSmoothnessA);
surfaceData.perceptualSmoothnessA = lerp(_SmoothnessAMapRange.x, _SmoothnessAMapRange.y, surfaceData.perceptualSmoothnessA);
surfaceData.metallic = lerp(_MetallicRange.x, _MetallicRange.y, surfaceData.metallic);
surfaceData.metallic = lerp(_MetallicMapRange.x, _MetallicMapRange.y, surfaceData.metallic);
surfaceData.ambientOcclusion = lerp(_AmbientOcclusionRange.x, _AmbientOcclusionRange.y, surfaceData.ambientOcclusion);
surfaceData.ambientOcclusion = lerp(_AmbientOcclusionMapRange.x, _AmbientOcclusionMapRange.y, surfaceData.ambientOcclusion);
surfaceData.ambientOcclusion = lerp(_AmbientOcclusion, surfaceData.ambientOcclusion, _AmbientOcclusionUseMap);
// These static material feature allow compile time optimization

surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_DUAL_SPECULAR_LOBE;
surfaceData.lobeMix = _LobeMix;
surfaceData.perceptualSmoothnessB = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_SmoothnessBMap), _SmoothnessBMapChannelMask);
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessBRange.x, _SmoothnessBRange.y, surfaceData.perceptualSmoothnessB);
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessBMapRange.x, _SmoothnessBMapRange.y, surfaceData.perceptualSmoothnessB);
surfaceData.perceptualSmoothnessB = lerp(_SmoothnessB, surfaceData.perceptualSmoothnessB, _SmoothnessBUseMap);
#else
surfaceData.lobeMix = 0.0;

surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_ANISOTROPY;
// TODO: manage anistropy map
//surfaceData.anisotropy = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_AnistropyMap), _AnistropyMapChannelMask);
//surfaceData.anisotropy = lerp(_AnistropyRange.x, _AnistropyRange.y, surfaceData.anisotropy);
//surfaceData.anisotropy = lerp(_AnistropyMapRange.x, _AnistropyMapRange.y, surfaceData.anisotropy);
surfaceData.anisotropy = _Anisotropy; // In all cases we must multiply anisotropy with the map
#else
surfaceData.anisotropy = 0.0;

#ifdef _MATERIAL_FEATURE_COAT
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_COAT;
surfaceData.coatPerceptualSmoothness = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_CoatSmoothnessMap), _CoatSmoothnessMapChannelMask);
surfaceData.coatPerceptualSmoothness = lerp(_CoatSmoothnessRange.x, _CoatSmoothnessRange.y, surfaceData.coatPerceptualSmoothness);
surfaceData.coatPerceptualSmoothness = lerp(_CoatSmoothnessMapRange.x, _CoatSmoothnessMapRange.y, surfaceData.coatPerceptualSmoothness);
surfaceData.coatPerceptualSmoothness = lerp(_CoatSmoothness, surfaceData.coatPerceptualSmoothness, _CoatSmoothnessUseMap);
surfaceData.coatIor = _CoatIor;
surfaceData.coatThickness = _CoatThickness;

surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_COAT_NORMAL_MAP;
coatGradient = SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(_CoatNormalMap, _CoatNormalScale);
coatGradient = SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(_CoatNormalMap, _CoatNormalScale, _CoatNormalMapObjSpace);
#endif
#else

surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_IRIDESCENCE;
surfaceData.iridescenceIor = _IridescenceIor;
surfaceData.iridescenceThickness = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_IridescenceThicknessMap), _IridescenceThicknessMapChannelMask);
surfaceData.iridescenceThickness = lerp(_IridescenceThicknessRange.x, _IridescenceThicknessRange.y, surfaceData.iridescenceThickness);
surfaceData.iridescenceThickness = lerp(_IridescenceThicknessMapRange.x, _IridescenceThicknessMapRange.y, surfaceData.iridescenceThickness);
surfaceData.iridescenceMask = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_IridescenceMaskMap), _IridescenceMaskMapChannelMask);
surfaceData.iridescenceMask = lerp(_IridescenceMaskMapRange.x, _IridescenceMaskMapRange.y, surfaceData.iridescenceMask);
surfaceData.iridescenceMask = lerp(_IridescenceMask, surfaceData.iridescenceMask, _IridescenceMaskUseMap);
surfaceData.iridescenceMask = 0.0;
#endif
#if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) || defined(_MATERIAL_FEATURE_TRANSMISSION)

#ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_SUBSURFACE_SCATTERING;
surfaceData.subsurfaceMask = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_SubsurfaceMaskMap), _SubsurfaceMaskMapChannelMask);
surfaceData.subsurfaceMask = lerp(_SubsurfaceMaskRange.x, _SubsurfaceMaskRange.y, surfaceData.subsurfaceMask);
surfaceData.subsurfaceMask = lerp(_SubsurfaceMaskMapRange.x, _SubsurfaceMaskMapRange.y, surfaceData.subsurfaceMask);
surfaceData.subsurfaceMask = lerp(_SubsurfaceMask, surfaceData.subsurfaceMask, _SubsurfaceMaskUseMap);
#else
surfaceData.subsurfaceMask = 0.0;

surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_STACK_LIT_TRANSMISSION;
surfaceData.thickness = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_ThicknessMap), _ThicknessMapChannelMask);
surfaceData.thickness = lerp(_ThicknessRange.x, _ThicknessRange.y, surfaceData.thickness);
surfaceData.thickness = lerp(_ThicknessMapRange.x, _ThicknessMapRange.y, surfaceData.thickness);
#ifdef _USE_DETAILMAP
float detailMask = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_DetailMaskMap), _DetailMaskMapChannelMask);
float4 detailGradient = SAMPLE_TEXTURE2D_NORMAL_SCALE_BIAS(_DetailNormalMap, _DetailNormalScale, 0.0);
gradient += detailGradient * detailMask;
gradient.w *= 0.5; // Take mean of average normal length
float detailPerceptualSmoothness = dot(SAMPLE_TEXTURE2D_SCALE_BIAS(_DetailSmoothnessMap), _DetailSmoothnessMapChannelMask);
detailPerceptualSmoothness = lerp(_DetailSmoothnessMapRange.x, _DetailSmoothnessMapRange.y, detailPerceptualSmoothness);
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
float smoothnessOverlay = (detailPerceptualSmoothness < 0.5) ?
surfaceData.perceptualSmoothnessA * PositivePow(2.0 * detailPerceptualSmoothness, _DetailSmoothnessScale) :
1.0 - (1.0 - surfaceData.perceptualSmoothnessA) * PositivePow(2.0 * (1.0 - detailPerceptualSmoothness), _DetailSmoothnessScale);
// Lerp with details mask
surfaceData.perceptualSmoothnessA = lerp(surfaceData.perceptualSmoothnessA, saturate(smoothnessOverlay), detailMask);
#ifdef _MATERIAL_FEATURE_DUAL_SPECULAR_LOBE
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
smoothnessOverlay = (detailPerceptualSmoothness < 0.5) ?
surfaceData.perceptualSmoothnessB * PositivePow(2.0 * detailPerceptualSmoothness, _DetailSmoothnessScale) :
1.0 - (1.0 - surfaceData.perceptualSmoothnessB) * PositivePow(2.0 * (1.0 - detailPerceptualSmoothness), _DetailSmoothnessScale);
// Lerp with details mask
surfaceData.perceptualSmoothnessB = lerp(surfaceData.perceptualSmoothnessB, saturate(smoothnessOverlay), detailMask);
#endif
#endif
// -------------------------------------------------------------
// Surface Data Part 2 (outsite GetSurfaceData( ) in Lit shader):
// -------------------------------------------------------------

surfaceData.normalWS = SurfaceGradientResolveNormal(input.worldToTangent[2], gradient.xyz);
surfaceData.coatNormalWS = SurfaceGradientResolveNormal(input.worldToTangent[2], coatGradient.xyz);
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
if ((_GeometricNormalFilteringEnabled + _TextureNormalFilteringEnabled) > 0.0)
{
float geometricVariance = _GeometricNormalFilteringEnabled ? GeometricNormalVariance(input.worldToTangent[2], _SpecularAntiAliasingScreenSpaceVariance) : 0.0;

builtinData.opacity = alpha;
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionWS, surfaceData.normalWS, input.texCoord1, input.texCoord2);
builtinData.bakeDiffuseLighting = SampleBakedGI(input.positionRWS, surfaceData.normalWS, input.texCoord1, input.texCoord2);
if (HasFeatureFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_TRANSMISSION))
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_TRANSMISSION))
builtinData.bakeDiffuseLighting += SampleBakedGI(input.positionWS, -input.worldToTangent[2], input.texCoord1, input.texCoord2) * bsdfData.transmittance;
builtinData.bakeDiffuseLighting += SampleBakedGI(input.positionRWS, -input.worldToTangent[2], input.texCoord1, input.texCoord2) * bsdfData.transmittance;
}
builtinData.emissiveColor = _EmissiveColor * lerp(float3(1.0, 1.0, 1.0), surfaceData.baseColor.rgb, _AlbedoAffectEmissive);

builtinData.velocity = float2(0.0, 0.0);
#ifdef SHADOWS_SHADOWMASK
float4 shadowMask = SampleShadowMask(input.positionWS, input.texCoord1);
float4 shadowMask = SampleShadowMask(input.positionRWS, input.texCoord1);
builtinData.shadowMask0 = shadowMask.x;
builtinData.shadowMask1 = shadowMask.y;
builtinData.shadowMask2 = shadowMask.z;

67
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLitProperties.hlsl


TEXTURE2D(_IridescenceThicknessMap);
SAMPLER(sampler_IridescenceThicknessMap);
TEXTURE2D(_IridescenceMaskMap);
SAMPLER(sampler_IridescenceMaskMap);
TEXTURE2D(_SubsurfaceMaskMap);
SAMPLER(sampler_SubsurfaceMaskMap);

// Details
TEXTURE2D(_DetailMaskMap);
SAMPLER(sampler_DetailMaskMap);
TEXTURE2D(_DetailSmoothnessMap);
SAMPLER(sampler_DetailSmoothnessMap);
TEXTURE2D(_DetailNormalMap);
SAMPLER(sampler_DetailNormalMap);
TEXTURE2D(_EmissiveColorMap);
SAMPLER(sampler_EmissiveColorMap);

float4 _MetallicMap_TexelSize;
float4 _MetallicMap_MipInfo;
float4 _MetallicMapChannelMask;
float4 _MetallicRange;
float4 _MetallicMapRange;
float _DielectricIor;

float4 _SmoothnessAMap_TexelSize;
float4 _SmoothnessAMap_MipInfo;
float4 _SmoothnessAMapChannelMask;
float4 _SmoothnessARange;
float4 _SmoothnessAMapRange;
float4 _DebugEnvLobeMask;
float4 _DebugLobeMask;

float4 _AmbientOcclusionMap_TexelSize;
float4 _AmbientOcclusionMap_MipInfo;
float4 _AmbientOcclusionMapChannelMask;
float4 _AmbientOcclusionRange;
float4 _AmbientOcclusionMapRange;
float _SmoothnessB;
float _SmoothnessBUseMap;

float4 _SmoothnessBMap_TexelSize;
float4 _SmoothnessBMap_MipInfo;
float4 _SmoothnessBMapChannelMask;
float4 _SmoothnessBRange;
float4 _SmoothnessBMapRange;
float _LobeMix;
float _Anisotropy;

float4 _AnisotropyMap_TexelSize;
float4 _AnisotropyMap_MipInfo;
float4 _AnisotropyMapChannelMask;
float4 _AnisotropyRange;
float4 _AnisotropyMapRange;
float _CoatSmoothness;
float _CoatSmoothnessUseMap;

float4 _CoatSmoothnessMap_TexelSize;
float4 _CoatSmoothnessMap_MipInfo;
float4 _CoatSmoothnessMapChannelMask;
float4 _CoatSmoothnessRange;
float4 _CoatSmoothnessMapRange;
float _CoatIor;
float _CoatThickness;
float3 _CoatExtinction;

float4 _CoatNormalMap_ST;
float4 _CoatNormalMap_TexelSize;
float4 _CoatNormalMap_MipInfo;
float _IridescenceThickness;
float _IridescenceThicknessUseMap;

float4 _IridescenceThicknessMap_TexelSize;
float4 _IridescenceThicknessMap_MipInfo;
float4 _IridescenceThicknessMapChannelMask;
float4 _IridescenceThicknessRange;
float4 _IridescenceThicknessMapRange;
float _IridescenceMask;
float _IridescenceMaskUseMap;
float _IridescenceMaskMapUV;
float _IridescenceMaskMapUVLocal;
float4 _IridescenceMaskMap_ST;
float4 _IridescenceMaskMap_TexelSize;
float4 _IridescenceMaskMap_MipInfo;
float4 _IridescenceMaskMapChannelMask;
float4 _IridescenceMaskMapRange;
int _DiffusionProfile;
float _SubsurfaceMask;
float _SubsurfaceMaskUseMap;

float4 _SubsurfaceMaskMap_TexelSize;
float4 _SubsurfaceMaskMap_MipInfo;
float4 _SubsurfaceMaskMapChannelMask;
float4 _SubsurfaceMaskRange;
float4 _SubsurfaceMaskMapRange;
float _Thickness;
float _ThicknessUseMap;

float4 _ThicknessMap_TexelSize;
float4 _ThicknessMap_MipInfo;
float4 _ThicknessMapChannelMask;
float4 _ThicknessRange;
float4 _ThicknessMapRange;
// Details
float _DetailMaskMapUV;
float _DetailMaskMapUVLocal;
float4 _DetailMaskMap_ST;
float4 _DetailMaskMap_TexelSize;
float4 _DetailMaskMap_MipInfo;
float4 _DetailMaskMapChannelMask;
float _DetailSmoothnessMapUV;
float _DetailSmoothnessMapUVLocal;
float4 _DetailSmoothnessMap_ST;
float4 _DetailSmoothnessMap_TexelSize;
float4 _DetailSmoothnessMap_MipInfo;
float4 _DetailSmoothnessMapChannelMask;
float4 _DetailSmoothnessMapRange;
float _DetailSmoothnessScale;
float _DetailNormalScale;
float _DetailNormalMapUV;
float _DetailNormalMapUVLocal;
float4 _DetailNormalMap_ST;
float4 _DetailNormalMap_TexelSize;
float4 _DetailNormalMap_MipInfo;
float3 _EmissiveColor;
float4 _EmissiveColorMap_ST;

4
com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.compute


// Definitions
//--------------------------------------------------------------------------------------------------
#pragma kernel SubsurfaceScatteringQualityNormal SubsurfaceScattering=SubsurfaceScatteringQualityNormal SSS_ENABLE_NEAR_FIELD=0
#pragma kernel SubsurfaceScatteringQualityUltra SubsurfaceScattering=SubsurfaceScatteringQualityUltra SSS_ENABLE_NEAR_FIELD=1
#pragma kernel SubsurfaceScatteringMQ SubsurfaceScattering=SubsurfaceScatteringMQ SSS_ENABLE_NEAR_FIELD=0
#pragma kernel SubsurfaceScatteringHQ SubsurfaceScattering=SubsurfaceScatteringHQ SSS_ENABLE_NEAR_FIELD=1
// #pragma enable_d3d11_debug_symbols
// TODO: use sharp load hoisting on PS4.

109
com.unity.render-pipelines.high-definition/HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl


#include "../DiffusionProfile/DiffusionProfileSettings.cs.hlsl"
#include "../DiffusionProfile/DiffusionProfile.hlsl"
// Subsurface scattering constant
#define SSS_WRAP_ANGLE (PI/12) // 15 degrees
#define SSS_WRAP_LIGHT cos(PI/2 - SSS_WRAP_ANGLE)
// constant buffer declaration
CBUFFER_START(UnitySSSAndTransmissionParameters)
// Warning: Unity is not able to losslessly transfer integers larger than 2^24 to the shader system.

{
return subsurfaceLighting.b > 0;
}
// ----------------------------------------------------------------------------
// Helper functions to use SSS/Transmission with a material
// ----------------------------------------------------------------------------
// Following function allow to easily setup SSS and transmission inside a material.
// User can request either SSS functions, or Transmission functions, or both, by defining MATERIAL_INCLUDE_SUBSURFACESCATTERING and/or MATERIAL_INCLUDE_TRANSMISSION
// before including this file.
// + It require that the material follow naming convention for properties inside BSDFData
// struct BSDFData
// {
// (...)
// // Share for SSS and Transmission
// uint materialFeatures;
// uint diffusionProfile;
// // For SSS
// float3 diffuseColor;
// float3 fresnel0;
// float subsurfaceMask;
// // For transmission
// float thickness;
// bool useThickObjectMode;
// float3 transmittance;
// perceptualRoughness; // Only if user chose to support DisneyDiffuse
// (...)
// }
// Note: Transmission functions for light evaluation are included in LightEvaluation.hlsl file also based on the MATERIAL_INCLUDE_TRANSMISSION
// For LightEvaluation.hlsl file it is required to define a BRDF for the transmission. Defining USE_DIFFUSE_LAMBERT_BRDF use Lambert, otherwise it use Disneydiffuse
#define MATERIAL_FEATURE_SSS_TRANSMISSION_START (1 << 16) // It should be safe to start these flags
#define MATERIAL_FEATURE_FLAGS_SSS_OUTPUT_SPLIT_LIGHTING ((MATERIAL_FEATURE_SSS_TRANSMISSION_START) << 0)
#define MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET FastLog2((MATERIAL_FEATURE_SSS_TRANSMISSION_START) << 1) // Note: The texture mode is 2bit, thus go from '<< 1' to '<< 3'
#define MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS ((MATERIAL_FEATURE_SSS_TRANSMISSION_START) << 3)
// Flags used as a shortcut to know if we have thin mode transmission
#define MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS ((MATERIAL_FEATURE_SSS_TRANSMISSION_START) << 4)
#ifdef MATERIAL_INCLUDE_SUBSURFACESCATTERING
void FillMaterialSSS(uint diffusionProfile, float subsurfaceMask, inout BSDFData bsdfData)
{
bsdfData.diffusionProfile = diffusionProfile;
bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[diffusionProfile].a;
bsdfData.subsurfaceMask = subsurfaceMask;
bsdfData.materialFeatures |= MATERIAL_FEATURE_FLAGS_SSS_OUTPUT_SPLIT_LIGHTING;
bsdfData.materialFeatures |= GetSubsurfaceScatteringTexturingMode(diffusionProfile) << MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET;
}
bool ShouldOutputSplitLighting(BSDFData bsdfData)
{
return HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_SSS_OUTPUT_SPLIT_LIGHTING);
}
float3 GetModifiedDiffuseColorForSSS(BSDFData bsdfData)
{
// Subsurface scattering mode
uint texturingMode = (bsdfData.materialFeatures >> MATERIAL_FEATURE_FLAGS_SSS_TEXTURING_MODE_OFFSET) & 3;
return ApplySubsurfaceScatteringTexturingMode(texturingMode, bsdfData.diffuseColor);
}
#endif
#ifdef MATERIAL_INCLUDE_TRANSMISSION
// Assume that bsdfData.diffusionProfile is init
void FillMaterialTransmission(uint diffusionProfile, float thickness, inout BSDFData bsdfData)
{
bsdfData.diffusionProfile = diffusionProfile;
bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[diffusionProfile].a;
bsdfData.thickness = _ThicknessRemaps[diffusionProfile].x + _ThicknessRemaps[diffusionProfile].y * thickness;
// The difference between the thin and the regular (a.k.a. auto-thickness) modes is the following:
// * in the thin object mode, we assume that the geometry is thin enough for us to safely share
// the shadowing information between the front and the back faces;
// * the thin mode uses baked (textured) thickness for all transmission calculations;
// * the thin mode uses wrapped diffuse lighting for the NdotL;
// * the auto-thickness mode uses the baked (textured) thickness to compute transmission from
// indirect lighting and non-shadow-casting lights; for shadowed lights, it calculates
// the thickness using the distance to the closest occluder sampled from the shadow map.
// If the distance is large, it may indicate that the closest occluder is not the back face of
// the current object. That's not a problem, since large thickness will result in low intensity.
bool useThinObjectMode = IsBitSet(asuint(_TransmissionFlags), diffusionProfile);
bsdfData.materialFeatures |= useThinObjectMode ? MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS : MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_MIXED_THICKNESS;
// Compute transmittance using baked thickness here. It may be overridden for direct lighting
// in the auto-thickness mode (but is always used for indirect lighting).
#if SHADEROPTIONS_USE_DISNEY_SSS
bsdfData.transmittance = ComputeTransmittanceDisney(_ShapeParams[diffusionProfile].rgb,
_TransmissionTintsAndFresnel0[diffusionProfile].rgb,
bsdfData.thickness);
#else
bsdfData.transmittance = ComputeTransmittanceJimenez( _HalfRcpVariancesAndWeights[diffusionProfile][0].rgb,
_HalfRcpVariancesAndWeights[diffusionProfile][0].a,
_HalfRcpVariancesAndWeights[diffusionProfile][1].rgb,
_HalfRcpVariancesAndWeights[diffusionProfile][1].a,
_TransmissionTintsAndFresnel0[diffusionProfile].rgb,
bsdfData.thickness);
#endif
}
#endif

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存